/** @packageDocumentation * @module iModelHubClient */ import { GuidString, Id64String } from "@bentley/bentleyjs-core"; import { AuthorizedClientRequestContext, WsgInstance, WsgQuery } from "@bentley/itwin-client"; import { IModelBaseHandler } from "./BaseHandler"; import { IModelHubError } from "./Errors"; /** * [[Lock]] type describes the kind of object that is locked. * @internal */ export declare enum LockType { /** Lock for the entire file. This is a global Lock that can only be taken with objectId 1. */ Db = 0, /** Lock for a model. It should be acquired together with a [[LockLevel.Shared]] Db Lock. */ Model = 1, /** Lock for a single element. It should be acquired together with a [[LockLevel.Shared]] Model Lock. */ Element = 2, /** Lock used to change schemas. This is a global Lock that can only be taken with objectId 1. This lock cannot have [[LockLevel.Shared]]. */ Schemas = 3, /** Lock used to change CodeSpecs. This is a global Lock that can only be taken with objectId 1. This lock cannot have [[LockLevel.Shared]]. */ CodeSpecs = 4 } /** * [[Lock]] level describes how restrictive the Lock is. * @internal */ export declare enum LockLevel { /** Lock is not owned. */ None = 0, /** Lock can be owned by multiple [[Briefcase]]s. Shared Lock is usually acquired together with Locks for lower level objects that depend on this object. */ Shared = 1, /** Lock can only be owned by a single briefcase. Exclusive Lock is required to modify model or element when using pessimistic concurrency. */ Exclusive = 2 } /** * Object for specifying options when sending [[Lock]]s update requests. See [[LockHandler.update]]. * @internal */ export interface LockUpdateOptions { /** Return [[Lock]]s that could not be acquired. Conflicting Locks will be set to [[ConflictingLocksError.conflictingLocks]]. If unlimitedReporting is enabled and locksPerRequest value is high, some conflicting Locks could be missed. */ deniedLocks?: boolean; /** Attempt to get all failed [[Lock]]s, ignoring iModelHub limits. Server responses might fail when trying to return large number of conflicting Locks. */ unlimitedReporting?: boolean; /** Number of [[Lock]]s per single request. Multiple requests will be sent if there are more Locks. If an error happens on a subsequent request, previous successful updates will not be reverted. */ locksPerRequest?: number; /** Don't fail request on a conflict. If conflict occurs, [[Lock]]s that didn't have conflicts will be updated and any remaining subsequent requests will still be sent. */ continueOnConflict?: boolean; } /** Provider for default LockUpdateOptions, used by LockHandler to set defaults. * @internal */ export declare class DefaultLockUpdateOptionsProvider { protected _defaultOptions: LockUpdateOptions; /** Creates an instance of DefaultRequestOptionsProvider and sets up the default options. */ constructor(); /** Augments options with the provider's default values. * @note The options passed in override any defaults where necessary. * @param options Options that should be augmented. */ assignOptions(options: LockUpdateOptions): Promise; } /** * Error for conflicting [[Lock]]s. It contains an array of Locks that failed to acquire. This is returned when calling [[LockHandler.update]] with [[LockUpdateOptions.deniedLocks]] set to true. * @internal */ export declare class ConflictingLocksError extends IModelHubError { /** Locks that couldn't be updated due to other users owning them. */ conflictingLocks?: Lock[]; /** Create ConflictingLocksError from IModelHubError instance. * @param error IModelHubError to get error data from. * @returns Undefined if the error is not for a lock conflict, otherwise newly created error instance. * @internal */ static fromError(error: IModelHubError): ConflictingLocksError | undefined; /** * Amends this error instance with conflicting locks from another IModelHubError. * @param error Error to get additional conflicting locks from. * @internal */ addLocks(error: IModelHubError): void; } /** * Base class for [[Lock]]s. * @internal */ export declare class LockBase extends WsgInstance { /** Type of the Lock. It describes what kind of object is locked. */ lockType?: LockType; /** Level of the Lock. It describes how restrictive the Lock is. */ lockLevel?: LockLevel; /** Id of the [[Briefcase]] that owns the Lock. */ briefcaseId?: number; /** Id of the file, that the Lock belongs to. See [[Briefcase.fileId]]. */ seedFileId?: GuidString; /** Id of the [[ChangeSet]] that the Lock was last used with. */ releasedWithChangeSet?: string; /** Index of the [[ChangeSet]] that the Lock was last used with. */ releasedWithChangeSetIndex?: string; } /** * Lock instance. When using pessimistic concurrency, locks ensure that only a single user can modify an object at a time. * @internal */ export declare class Lock extends LockBase { /** Id of the locked object. */ objectId?: Id64String; } /** * MultiLock: data about locks grouped by BriefcaseId, LockLevel and LockType. * @internal */ export declare class MultiLock extends LockBase { objectIds?: Id64String[]; } /** * Query object for getting [[Lock]]s. You can use this to modify the [[LockHandler.get]] results. * @internal */ export declare class LockQuery extends WsgQuery { private _isMultiLockQuery; /** * Default page size which is used when querying Locks * @internal */ static defaultPageSize: number; /** Constructor that sets default page size. */ constructor(); /** * Used by the handler to check whether locks in query can be grouped. * @internal */ get isMultiLockQuery(): boolean; /** * Query [[Lock]]s by [[Briefcase]] id. * @param briefcaseId Id of the Briefcase. * @returns This query. * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) or [IModelHubStatus.InvalidArgumentError]($bentley) if briefcaseId is undefined or it contains an invalid [[Briefcase]] id value. */ byBriefcaseId(briefcaseId: number): this; /** * Query [[Lock]]s by [[LockType]]. * @param lockType Lock type to query. * @returns This query. */ byLockType(lockType: LockType): this; /** * Query [[Lock]]s by [[LockLevel]]. * @param lockLevel Lock level to query. * @returns This query. */ byLockLevel(lockLevel: LockLevel): this; /** * Query [[Lock]]s by ObjectId. * @param objectId Id of the object. * @returns This query. * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) if objectId is undefined. */ byObjectId(objectId: Id64String): this; /** * Query [[Lock]]s by [[ChangeSet]] id that it was released with. * @param changesetId Id of the ChangeSet. * @returns This query. * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) or [IModelHubStatus.InvalidArgumentError]($bentley) if changeSetId is undefined or empty, or it contains an invalid [[ChangeSet]] id value. */ byReleasedWithChangeSet(changeSetId: string): this; /** * Query [[Lock]]s by [[ChangeSet]] index that it was released with. * @param changeSetIndex Index of the changeSet. * @returns This query. * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) * if changeSetIndex is undefined. */ byReleasedWithChangeSetIndex(changeSetIndex: number): this; /** * Query [[Lock]]s by their instance ids. * @param locks Locks to query. They must have their BriefcaseId, LockType and ObjectId set. * @returns This query. * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) or [IModelHubStatus.InvalidArgumentError]($bentley) if locks array is undefined or empty, or it contains invalid [[Lock]] values. */ byLocks(locks: Lock[]): this; /** * Query unavailable [[Lock]]s. It will include all Locks owned by other [[Briefcase]]s and locks that were released with a newer [[ChangeSet]]. * @param briefcaseId Id of the Briefcase. * @param lastChangeSetIndex Index of the last ChangeSet that user has pulled. * @returns This query. * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) or [IModelHubStatus.InvalidArgumentError]($bentley) if one of the values is undefined or briefcaseId is not in a valid [[Briefcase]] id value. */ unavailableLocks(briefcaseId: number, lastChangeSetIndex: string): this; } /** * Handler for managing [[Lock]]s. Use [[IModelClient.Locks]] to get an instance of this class. * In most cases, you should use [ConcurrencyControl]($backend) methods instead. You can read more about concurrency control [here]($docs/learning/backend/concurrencycontrol). * @internal */ export declare class LockHandler { private _handler; private static _defaultUpdateOptionsProvider; /** * Constructor for LockHandler. * @param handler Handler for WSG requests. * @internal */ constructor(handler: IModelBaseHandler); private getRelativeUrl; private static convertLocksToMultiLocks; private static convertMultiLocksToLocks; /** Augment update options with defaults returned by the DefaultLockUpdateOptionsProvider. * The options passed in by clients override any defaults where necessary. * @param options Options the caller wants to augment with the defaults. */ private setupOptionDefaults; /** Send partial request for lock updates */ private updateInternal; /** Update multiple [[Lock]]s. This call can simultaneously acquire new Locks and update states of already owned Locks. If large amount of Locks are updated, they are split across multiple requests. See [[LockUpdateOptions.locksPerRequest]]. Default is 2000 Locks per request. * @param requestContext The client request context. * @param iModelId Id of the iModel. See [[HubIModel]]. * @param locks Locks to acquire. Requires briefcaseId, seedFileId to be set for every * Lock instance. They must be consistent throughout all of the Locks. * @param updateOptions Options for the update request. You can set this to change * how conflicts are handled or to handle different amount of Locks per request. * @returns Updated Lock values. * @throws [[ConflictingLocksError]] when [[LockUpdateOptions.deniedLocks]] is set and conflicts occurred. See [Handling Conflicts]($docs/learning/iModelHub/CodesAndLocksConflicts.md) for more information. * @throws [[AggregateResponseError]] when multiple requests where sent and more than 1 of the following errors occurred. * @throws [[IModelHubError]] with status indicating a conflict. See [Handling Conflicts]($docs/learning/iModelHub/CodesAndLocksConflicts.md) section for more information. * @throws [[IModelHubError]] with [IModelHubStatus.InvalidBriefcase]($bentley) when including locks with different briefcaseId values in the request. * @throws [[IModelHubError]] with [IModelHubStatus.OperationFailed]($bentley) when including multiple identical locks in the request. * @throws [Common iModelHub errors]($docs/learning/iModelHub/CommonErrors) */ update(requestContext: AuthorizedClientRequestContext, iModelId: GuidString, locks: Lock[], updateOptions?: LockUpdateOptions): Promise; /** Get the [[Lock]]s that have been issued for the iModel. * @param requestContext The client request context. * @param iModelId Id of the iModel. See [[HubIModel]]. * @param query Optional query object to filter the queried Locks or select different data from them. * @returns Resolves to an array of Locks matching the query. * @throws [Common iModelHub errors]($docs/learning/iModelHub/CommonErrors) */ get(requestContext: AuthorizedClientRequestContext, iModelId: GuidString, query?: LockQuery): Promise; /** Delete all [[Lock]]s owned by the specified [[Briefcase]]. * @param requestContext The client request context. * @param iModelId Id of the iModel. See [[HubIModel]]. * @param briefcaseId Id of the Briefcase. * @throws [[IModelHubError]] with [IModelHubStatus.BriefcaseDoesNotExist]($bentley) if [[Briefcase]] with specified briefcaseId does not exist. This can happen if number was not given as a Briefcase id yet, or Briefcase with that id was already deleted. * @throws [[IModelHubError]] with [IModelHubStatus.UserDoesNotHavePermission]($bentley) if [[Briefcase]] belongs to another user and user sending the request does not have ManageResources permission. * @throws [Common iModelHub errors]($docs/learning/iModelHub/CommonErrors) */ deleteAll(requestContext: AuthorizedClientRequestContext, iModelId: GuidString, briefcaseId: number): Promise; /** Helper method to iteratively delete chunks of [[Lock]]s for the specified [[Briefcase]] until there are no more left. * @param requestContext The client request context. * @param iModelId Id of the iModel. See [[HubIModel]]. * @param briefcaseId Id of the Briefcase. */ private deleteAllLocksInChunks; } //# sourceMappingURL=Locks.d.ts.map