/** @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"; /** * [Code]($common) state describes whether the code is currently in use or owned by a [[Briefcase]]. * @internal */ export declare enum CodeState { /** Code with this state is not persisted in iModelHub. Code that is updated to 'Available' state is deleted from iModelHub. */ Available = 0, /** Code is reserved by the [[Briefcase]], no one else is allowed to change its state. */ Reserved = 1, /** Code is used in a [[ChangeSet]] committed to iModelHub. */ Used = 2, /** Retired Code can not be reserved or used. It can only be deleted and then reserved again */ Retired = 3 } /** Base class for [Code]($common)s. * @internal */ export declare class CodeBase extends WsgInstance { /** Code specification Id. */ codeSpecId?: Id64String; /** Code scope. */ codeScope?: string; /** Code state. */ state?: CodeState; /** Date the Code was created. */ createdDate?: string; /** Id of the Briefcase that owns the Code. */ briefcaseId?: number; /** If set to true in a request, it will only check whether code state can be modified, but will not actually change it. */ queryOnly?: boolean; } /** * Code instance. Codes ensure uniqueness of names in the file. * @internal */ export declare class HubCode extends CodeBase { /** The unique string that can be used as a name value in iModel. */ value?: string; } /** * MultiCode: Data about codes grouped by CodeSpecId, State and Briefcase * @internal */ export declare class MultiCode extends CodeBase { values?: string[]; } /** * Object for specifying options when sending [Code]($common) update requests. See [[CodeHandler.update]]. * @internal */ export interface CodeUpdateOptions { /** Return [Code]($common)s that could not be acquired. Conflicting Codes will be set to [[ConflictingCodesError.conflictingCodes]]. If unlimitedReporting is enabled and CodesPerRequest value is high, some conflicting Codes could be missed. */ deniedCodes?: boolean; /** Attempt to get all failed [Code]($common)s, ignoring iModelHub limits. Server responses might fail when trying to return large number of conflicting Codes. */ unlimitedReporting?: boolean; /** Number of [Code]($common)s per single request. Multiple requests will be sent if there are more Codes. If an error happens on a subsequent request, previous successful updates will not be reverted. */ codesPerRequest?: number; /** Don't fail request on a conflict. If conflict occurs, [Code]($common)s that didn't have conflicts will be updated and any remaining subsequent requests will still be sent. */ continueOnConflict?: boolean; } /** * Provider for default CodeUpdateOptions, used by CodeHandler to set defaults. * @internal */ export declare class DefaultCodeUpdateOptionsProvider { protected _defaultOptions: CodeUpdateOptions; /** Creates an instance of DefaultRequestOptionsProvider and sets up the default options. */ constructor(); /** * Augments options with the provider's default values. The options passed in override any defaults where necessary. * @param options Options that should be augmented. */ assignOptions(options: CodeUpdateOptions): Promise; } /** * Error for conflicting [Code]($common)s. It contains an array of Codes that failed to acquire. This is returned when calling [[CodeHandler.update]] with [[CodeUpdateOptions.deniedCodes]] set to true. * @internal */ export declare class ConflictingCodesError extends IModelHubError { /** Codes that couldn't be updated due to other users owning them or setting them to [[CodeState.Retired]]. */ conflictingCodes?: HubCode[]; /** * Create ConflictingCodesError from IModelHubError instance. * @param error IModelHubError to get error data from. * @returns Undefined if the error is not for a code conflict, otherwise newly created error instance. * @internal */ static fromError(error: IModelHubError): ConflictingCodesError | undefined; /** * Amend this error instance with conflicting codes from another IModelHubError. * @param error Error to get additional conflicting codes from. * @internal */ addCodes(error: IModelHubError): void; } /** * Query object for getting [Code]($common)s. You can use this to modify the query. See [[CodeHandler.get]]. * @internal */ export declare class CodeQuery extends WsgQuery { private _isMultiCodeQuery; /** * Default page size which is used when querying Codes * @internal */ static defaultPageSize: number; /** Constructor that sets default page size. */ constructor(); /** * Used by the handler to check whether codes in query can be grouped. * @internal */ get isMultiCodeQuery(): boolean; /** * Query Codes by [[Briefcase]] id. * @param briefcaseId Id of the Briefcase. * @returns This query. * @throws [[IModelHubError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) or [IModelHubStatus.InvalidArgumentError]($bentley) if briefcaseId is undefined or has an invalid [[Briefcase]] id value. */ byBriefcaseId(briefcaseId: number): this; /** * Query Codes by CodeSpec id. * @param codeSpecId Id of the CodeSpec. * @returns This query. * @throws [[IModelHubError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) if codeSpecId is undefined or empty. */ byCodeSpecId(codeSpecId: Id64String): this; /** * Query Codes by Code scope. * @param codeScope Scope of the Code. * @returns This query. * @throws [[IModelHubError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) if codeScope is undefined or empty. */ byCodeScope(codeScope: string): this; /** * Query [Code]($common)s by their instance ids. * @param codes Codes to query. They must have their codeSpec, scope and value set. * @returns This query. * @throws [[IModelHubError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) or [IModelHubStatus.InvalidArgumentError]($bentley) if codes array is undefined, empty or it contains invalid [Code]($common) values. */ byCodes(codes: HubCode[]): this; /** * Query unavailable [Code]($common)s. It will include all Codes owned by other [[Briefcase]]s. * @param briefcaseId Id of the Briefcase. * @returns This query. * @throws [[IModelHubError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) or [IModelHubStatus.InvalidArgumentError]($bentley) if briefcaseId is undefined or has an invalid [[Briefcase]] id value. */ unavailableCodes(briefcaseId: number): this; } /** Type of [[CodeSequence]] results. * @internal */ export declare enum CodeSequenceType { /** Return largest already used value. */ LargestUsed = 0, /** Return next available value in the sequence. */ NextAvailable = 1 } /** Sequence of [Code]($common)s matching a pattern. This class allows getting next available index based [Code]($common) * @internal */ export declare class CodeSequence extends WsgInstance { /** Code specification Id (hexadecimal ("0XA") or decimal ("10") string)). */ codeSpecId?: Id64String; /** Code scope. */ codeScope?: string; /** Pattern describing the sequence. # characters will be replaced with the index. Only a single group of # characters is allowed in the pattern. */ valuePattern?: string; /** Suggested index value returned from the query. */ value?: string; /** Starting index of the sequence. */ startIndex?: number; /** Index difference between two consecutive members in this sequence. */ incrementBy?: number; /** Type of the sequence results. */ type?: CodeSequenceType; } /** * Handler for querying [[CodeSequence]]s. Use [[CodeHandler.Sequences]] to get an instance of this class. * @internal */ export declare class CodeSequenceHandler { private _handler; /** * Constructor for CodeHandler. * @param handler Handler for WSG requests. * @internal */ constructor(handler: IModelBaseHandler); /** Get relative url for Code sequence requests. * @param iModelId Id of the iModel. See [[HubIModel]]. */ private getRelativeUrl; /** Get an index value based on the [[CodeSequence]]. This only suggests the last used or next available index value in the sequence and does not reserve the Code. * @param requestContext The client request context * @param iModelId Id of the iModel. See [[HubIModel]]. * @param sequence Code sequence describing the format of the Code value. * @returns Resolves to the suggested index value. * @throws [Common iModelHub errors]($docs/learning/iModelHub/CommonErrors) */ get(requestContext: AuthorizedClientRequestContext, iModelId: GuidString, sequence: CodeSequence): Promise; } /** * Handler for managing [Code]($common)s. Use [[IModelClient.Codes]] 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 CodeHandler { private _handler; private static _defaultUpdateOptionsProvider; /** * Constructor for CodeHandler. * @param handler Handler for WSG requests. * @internal */ constructor(handler: IModelBaseHandler); /** Get handler for querying [[CodeSequence]]s. */ get sequences(): CodeSequenceHandler; /** Get relative url for Code requests. * @param iModelId Id of the iModel. See [[HubIModel]]. * @param codeId Id of the code. */ private getRelativeUrl; /** Convert Codes to MultiCodes. */ private static convertCodesToMultiCodes; /** Convert MultiCodes to Codes. */ private static convertMultiCodesToCodes; /** * Augment update options with defaults returned by the DefaultCodeUpdateOptionsProvider. The options passed in by clients override any defaults where necessary. * @param options Options the caller wants to augment with the defaults. * @returns Promise resolves after the defaults are setup. */ private setupOptionDefaults; /** Send partial request for code updates */ private updateInternal; /** * Update multiple [Code]($common)s. This call can simultaneously reserve new Codes and update states of already owned Codes. If large amount of Codes are updated, they are split across multiple requests. See [[CodeUpdateOptions.codesPerRequest]]. Default is 2000 Codes per request. * @param requestContext The client request context * @param iModelId Id of the iModel. See [[HubIModel]]. * @param codes Codes to update. Requires briefcaseId, state, codeSpecId, codeScope and value to be set on every instance. briefcaseId must be the same for every Code. Set queryOnly to true to just check if a Code can be reserved. * @param updateOptions Options for the update request. You can set this to change how conflicts are handled or to handle different amount of Codes per request. * @returns The code that was just obtained from the server. * @throws [[ConflictingCodesError]] when [[CodeUpdateOptions.deniedCodes]] 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 Codes with different briefcaseId values in the request. * @throws [[IModelHubError]] with [IModelHubStatus.OperationFailed]($bentley) when including multiple identical Codes in the request. * @throws [Common iModelHub errors]($docs/learning/iModelHub/CommonErrors) */ update(requestContext: AuthorizedClientRequestContext, iModelId: GuidString, codes: HubCode[], updateOptions?: CodeUpdateOptions): Promise; /** * Get the [Code]($common)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 Codes or select different data from them. * @returns Resolves to an array of Codes matching the query. * @throws [Common iModelHub errors]($docs/learning/iModelHub/CommonErrors) */ get(requestContext: AuthorizedClientRequestContext, iModelId: GuidString, query?: CodeQuery): Promise; /** Delete all [Code]($common)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; } //# sourceMappingURL=Codes.d.ts.map