@itwin/core-backend 4.2.0-dev.13 → 4.2.0-dev.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/BlobContainerService.d.ts +6 -2
- package/lib/cjs/BlobContainerService.d.ts.map +1 -1
- package/lib/cjs/BlobContainerService.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +5 -1
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +3 -0
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/CloudSqlite.js +1 -1
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/package.json +11 -11
|
@@ -77,6 +77,11 @@ export declare namespace BlobContainer {
|
|
|
77
77
|
interface AccessContainerProps extends UriAndId {
|
|
78
78
|
userToken: UserToken;
|
|
79
79
|
}
|
|
80
|
+
/** Information about a newly created container. */
|
|
81
|
+
interface CreatedContainerProps extends UriAndId {
|
|
82
|
+
/** name of the blob storage provider. */
|
|
83
|
+
provider: Provider;
|
|
84
|
+
}
|
|
80
85
|
/**
|
|
81
86
|
* Access level to request for token.
|
|
82
87
|
* - `"write"`: request a writeable AccessToken.
|
|
@@ -88,7 +93,6 @@ export declare namespace BlobContainer {
|
|
|
88
93
|
type RequestAccessLevel = "write" | "read" | "admin" | "writeIfPossible";
|
|
89
94
|
/** Information required to request an access token for a container. */
|
|
90
95
|
interface RequestTokenProps extends AccessContainerProps {
|
|
91
|
-
storageType: Provider;
|
|
92
96
|
/** the level of access requested. If not specified, defaults to `"writeIfPossible"`. */
|
|
93
97
|
accessLevel?: RequestAccessLevel;
|
|
94
98
|
/** the number of seconds before the token should expire.
|
|
@@ -113,7 +117,7 @@ export declare namespace BlobContainer {
|
|
|
113
117
|
/** Methods to create, delete, and access blob containers. */
|
|
114
118
|
interface ContainerService {
|
|
115
119
|
/** Create a new blob container. Throws on failure (e.g. access denied or container already exists.) */
|
|
116
|
-
create(props: CreateNewContainerProps): Promise<
|
|
120
|
+
create(props: CreateNewContainerProps): Promise<CreatedContainerProps>;
|
|
117
121
|
/**
|
|
118
122
|
* Delete an existing blob container.
|
|
119
123
|
* @note This method requires that the user be authorized with "delete container" RBAC role for the iTwin.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlobContainerService.d.ts","sourceRoot":"","sources":["../../src/BlobContainerService.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,yBAAiB,aAAa,CAAC;IAE7B,+FAA+F;IACxF,IAAI,OAAO,EAAE,aAAa,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAE/D,8CAA8C;IAC9C,KAAY,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IAE1C,mDAAmD;IACnD,KAAY,WAAW,GAAG,MAAM,CAAC;IAEjC,4FAA4F;IAC5F,KAAY,SAAS,GAAG,WAAW,CAAC;IAEpC,+EAA+E;IAC/E,KAAY,cAAc,GAAG,WAAW,CAAC;IAEzC;;;;;;;;OAQG;IACH,UAAiB,KAAK;QACpB,8CAA8C;QAC9C,OAAO,EAAE,UAAU,CAAC;QACpB,6GAA6G;QAC7G,QAAQ,CAAC,EAAE,UAAU,CAAC;QACtB,iEAAiE;QACjE,SAAS,CAAC,EAAE,UAAU,CAAC;KACxB;IAED;;;;;;OAMG;IACH,UAAiB,QAAQ;QACvB,yIAAyI;QACzI,aAAa,EAAE,MAAM,CAAC;QACtB,qJAAqJ;QACrJ,KAAK,EAAE,MAAM,CAAC;QACd,kKAAkK;QAClK,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,4CAA4C;QAC5C,IAAI,CAAC,EAAE,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BAAuB;QACtC,qCAAqC;QACrC,KAAK,EAAE,KAAK,CAAC;QACb,iDAAiD;QACjD,QAAQ,EAAE,QAAQ,CAAC;QACnB,4GAA4G;QAC5G,SAAS,EAAE,SAAS,CAAC;QACrB;;;WAGG;QACH,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B;IAED,6DAA6D;IAC7D,UAAiB,gBAAgB;QAC/B,wGAAwG;QACxG,MAAM,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAEvE;;;WAGG;QACH,MAAM,CAAC,SAAS,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAEvD,sCAAsC;QACtC,UAAU,CAAC,SAAS,EAAE,oBAAoB,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAE5D,yCAAyC;QACzC,aAAa,CAAC,SAAS,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAElE,mDAAmD;QACnD,UAAU,CAAC,SAAS,EAAE,oBAAoB,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAEhF,qEAAqE;QACrE,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;KAC7D;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlobContainerService.js","sourceRoot":"","sources":["../../src/BlobContainerService.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAOH;;;GAGG;AACH,IAAiB,aAAa,
|
|
1
|
+
{"version":3,"file":"BlobContainerService.js","sourceRoot":"","sources":["../../src/BlobContainerService.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAOH;;;GAGG;AACH,IAAiB,aAAa,CAiJ7B;AAjJD,WAAiB,aAAa;AAiJ9B,CAAC,EAjJgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAiJ7B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module BlobContainers\r\n */\r\n\r\n// spell:ignore datacenter\r\n\r\nimport { AccessToken, GuidString, Id64String } from \"@itwin/core-bentley\";\r\nimport { SettingObject } from \"./workspace/Settings\";\r\n\r\n/**\r\n * Types and functions for creating, deleting and authorizing access to cloud-based blob containers for an iTwin.\r\n * @beta\r\n */\r\nexport namespace BlobContainer {\r\n\r\n /** Object that implements the methods to create, delete, and request access to a container. */\r\n export let service: BlobContainer.ContainerService | undefined;\r\n\r\n /** name of cloud provider for a container. */\r\n export type Provider = \"azure\" | \"google\";\r\n\r\n /** the name of the container within its `Scope` */\r\n export type ContainerId = string;\r\n\r\n /** token that authenticates a user. This token is required to obtain a `ContainerToken`. */\r\n export type UserToken = AccessToken;\r\n\r\n /** token that authenticates access to a container for either read or write. */\r\n export type ContainerToken = AccessToken;\r\n\r\n /**\r\n * The scope for a container. This determines:\r\n * - the \"owner\" organization, including the contract that governs its legal and commercial terms and obligations\r\n * - the administrators who may configure RBAC permissions\r\n * - the datacenter for the container. Every container resides in a datacenter as determined by the iTwinId. This\r\n * determines the region for data residency requirements.\r\n * - the lifecycle constraints for the container. No container can outlive its iTwin or its iModel (if defined). That is,\r\n * when the iTwin/iModel is deleted (either explicitly or due to contract expiration), the container is also deleted.\r\n */\r\n export interface Scope {\r\n /** iTwinId of the owner of this container. */\r\n iTwinId: Id64String;\r\n /** optionally, an iModelId within the iTwin. If present, container is deleted when the iModel is deleted. */\r\n iModelId?: Id64String;\r\n /** the user GUID an individual, if this container is private. */\r\n ownerGuid?: GuidString;\r\n }\r\n\r\n /**\r\n * Metadata about the use of a container so that:\r\n * - administrators can understand why a container exists for assigning RBAC permissions appropriately\r\n * - usage reports can aggregate types of containers\r\n * - applications can identify their containers\r\n * - applications can store properties about their containers\r\n */\r\n export interface Metadata {\r\n /** The machine-readable string that describes what the container is being used for (e.g. \"workspace\"). Always lowercase and singular. */\r\n containerType: string;\r\n /** Human-readable name for the container. This will be displayed in the administrator RBAC panel, and on usage reports. Not required to be unique.*/\r\n label: string;\r\n /** Optional human-readable explanation of the information held in the container. This will be displayed in the administrator RBAC panel, and on usage reports. */\r\n description?: string;\r\n /** optional properties for the container */\r\n json?: SettingObject;\r\n }\r\n\r\n /** Properties returned by `Service.requestToken` */\r\n export interface TokenProps {\r\n /**\r\n * expiring token that provides the requested access to the container. Should be used in all subsequent requests for blobs within the container,\r\n * and must be refreshed before it expires\r\n */\r\n token: ContainerToken;\r\n /** scope of the container. */\r\n scope: Scope;\r\n /** name of the blob storage provider. */\r\n provider: Provider;\r\n /** Time at which the token will expire. The token should be refreshed (that is, a new token should be requested) before this time. */\r\n expiration: Date;\r\n /** Metadata of the container. */\r\n metadata: Metadata;\r\n }\r\n\r\n /** The URI and Id of the container. */\r\n export interface UriAndId {\r\n baseUri: string;\r\n containerId: ContainerId;\r\n }\r\n\r\n /** Information required to access an existing container. */\r\n export interface AccessContainerProps extends UriAndId {\r\n userToken: UserToken;\r\n }\r\n\r\n /** Information about a newly created container. */\r\n export interface CreatedContainerProps extends UriAndId {\r\n /** name of the blob storage provider. */\r\n provider: Provider;\r\n }\r\n\r\n /**\r\n * Access level to request for token.\r\n * - `\"write\"`: request a writeable AccessToken.\r\n * - `\"read\"`: request a read-only AccessToken.\r\n * - `\"admin\"`: request a admin AccessToken.\r\n * - `\"writeIfPossible\"`: first request a writeable AccessToken. If the user is not authorized for write, request a read-only AccessToken.\r\n * If the user is not authorized for the level requested, an exception is thrown.\r\n */\r\n export type RequestAccessLevel = \"write\" | \"read\" | \"admin\" | \"writeIfPossible\";\r\n\r\n /** Information required to request an access token for a container. */\r\n export interface RequestTokenProps extends AccessContainerProps {\r\n /** the level of access requested. If not specified, defaults to `\"writeIfPossible\"`. */\r\n accessLevel?: RequestAccessLevel;\r\n /** the number of seconds before the token should expire.\r\n * @note A maximum duration is determined by the service. If no value is supplied, or the value is larger than the maximum, the maximum duration is used.\r\n */\r\n durationSeconds?: number;\r\n }\r\n\r\n /** Information required to create a new container. */\r\n export interface CreateNewContainerProps {\r\n /** the scope of the new container */\r\n scope: Scope;\r\n /** metadata to be stored on the new container */\r\n metadata: Metadata;\r\n /** The user's access token. The user must be authorized with \"create container\" RBAC role for the iTwin. */\r\n userToken: UserToken;\r\n /**\r\n * the id for the container. Useful for tests.\r\n * @internal\r\n */\r\n containerId?: ContainerId;\r\n }\r\n\r\n /** Methods to create, delete, and access blob containers. */\r\n export interface ContainerService {\r\n /** Create a new blob container. Throws on failure (e.g. access denied or container already exists.) */\r\n create(props: CreateNewContainerProps): Promise<CreatedContainerProps>;\r\n\r\n /**\r\n * Delete an existing blob container.\r\n * @note This method requires that the user be authorized with \"delete container\" RBAC role for the iTwin.\r\n */\r\n delete(container: AccessContainerProps): Promise<void>;\r\n\r\n /** query the Scope for a container */\r\n queryScope(container: AccessContainerProps): Promise<Scope>;\r\n\r\n /** query the Metadata for a container */\r\n queryMetadata(container: AccessContainerProps): Promise<Metadata>;\r\n\r\n /** update the json properties of this container */\r\n updateJson(container: AccessContainerProps, json: SettingObject): Promise<void>;\r\n\r\n /** Request a `ContainerToken` for a container. Throws on failure. */\r\n requestToken(props: RequestTokenProps): Promise<TokenProps>;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BriefcaseManager.d.ts","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EACL,WAAW,EAAE,UAAU,EAAmB,UAAU,EACrD,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EAAoB,cAAc,EAAsB,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAA6C,mBAAmB,EACrM,YAAY,EAAE,aAAa,EAAE,wBAAw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E,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAIpH,wEAAwE;WACpD,kBAAkB,CAAC,GAAG,EAAE;QAAE,QAAQ,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAI9F;;;OAGG;WACiB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAI1F;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;mBAajB,oBAAoB;IAWzC,gBAAgB;WACI,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC7F,4EAA4E;mBACvD,WAAW;IA4ChC;;OAEG;WACiB,aAAa,CAAC,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAcxF"}
|
|
@@ -345,8 +345,12 @@ class BriefcaseManager {
|
|
|
345
345
|
return; // nothing to apply
|
|
346
346
|
if (reverse)
|
|
347
347
|
changesets.reverse();
|
|
348
|
-
for (const changeset of changesets)
|
|
348
|
+
for (const changeset of changesets) {
|
|
349
|
+
const stopwatch = new core_bentley_1.StopWatch(`[${changeset.id}]`, true);
|
|
350
|
+
core_bentley_1.Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description}`);
|
|
349
351
|
await this.applySingleChangeset(db, changeset);
|
|
352
|
+
core_bentley_1.Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);
|
|
353
|
+
}
|
|
350
354
|
// notify listeners
|
|
351
355
|
db.notifyChangesetApplied();
|
|
352
356
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BriefcaseManager.js","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,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,CAAC;gBAEF,IAAI,CAAC,WAAW,EAAE,EAAE;oBAClB,EAAE,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC;oBACrC,MAAM,GAAG,CAAC;iBACX;aACF;oBAAS;gBACR,uBAAU,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;aAChD;SACF;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAe,EAAE,GAAoB;QACrE,IAAI,UAAU,GAAG,GAAG,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,EAAE;YACX,IAAI;gBACF,MAAM,gBAAgB,CAAC,sBAAsB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACvD,OAAO,MAAM,gBAAgB,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;aACpD;YAAC,OAAO,GAAQ,EAAE;gBACjB,IAAI,UAAU,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,WAAW,KAAK,8BAAe,CAAC,cAAc;oBACzE,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACjE;SACF;IACH,CAAC;;AAnac,iCAAgB,GAAG,YAAY,CAAC;AAbpC,4CAAgB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore cset csets ecchanges\r\n\r\nimport * as path from \"path\";\r\nimport {\r\n AccessToken, BeDuration, ChangeSetStatus, GuidString, IModelHubStatus, IModelStatus, Logger, OpenMode,\r\n} from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseId, BriefcaseIdValue, BriefcaseProps, ChangesetFileProps, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange, ChangesetType, IModelError, IModelVersion, LocalBriefcaseProps,\r\n LocalDirName, LocalFileName, RequestNewBriefcaseProps,\r\n} from \"@itwin/core-common\";\r\nimport { AcquireNewBriefcaseIdArg, IModelNameArg } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { CheckpointManager, CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, TokenArg } from \"./IModelDb\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/** The argument for [[BriefcaseManager.downloadBriefcase]]\r\n * @public\r\n*/\r\nexport interface RequestNewBriefcaseArg extends TokenArg, RequestNewBriefcaseProps {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n}\r\n\r\n/**\r\n * Parameters for pushing changesets to iModelHub\r\n * @public\r\n */\r\nexport interface PushChangesArgs extends TokenArg {\r\n /** A description of the changes. This is visible on the iModel's timeline. */\r\n description: string;\r\n /** if present, the locks are retained after the operation. Otherwise, *all* locks are released after the changeset is successfully pushed. */\r\n retainLocks?: true;\r\n /** number of times to retry pull/merge if other users are pushing at the same time. Default is 5 */\r\n mergeRetryCount?: number;\r\n /** delay to wait between pull/merge retry attempts. Default is 3 seconds */\r\n mergeRetryDelay?: BeDuration;\r\n /** the number of time to attempt to retry to push the changeset upon failure. Default is 3 */\r\n pushRetryCount?: number;\r\n /** The delay to wait between retry attempts on failed pushes. Default is 3 seconds. */\r\n pushRetryDelay?: BeDuration;\r\n}\r\n\r\n/**\r\n * Specifies a specific index for pulling changes.\r\n * @public\r\n */\r\nexport interface ToChangesetArgs extends TokenArg {\r\n /** The last ChangesetIndex to pull. If not present, pull *all* newer changesets. */\r\n toIndex?: ChangesetIndex;\r\n}\r\n\r\n/** Arguments for [[BriefcaseManager.pullAndApplyChangesets]]\r\n * @public\r\n */\r\nexport type PullChangesArgs = ToChangesetArgs & {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n};\r\n\r\n/** Manages downloading Briefcases and downloading and uploading changesets.\r\n * @public\r\n */\r\nexport class BriefcaseManager {\r\n /** Get the local path of the folder storing files that are associated with an imodel */\r\n public static getIModelPath(iModelId: GuidString): LocalDirName { return path.join(this._cacheDir, iModelId); }\r\n\r\n /** @internal */\r\n public static getChangeSetsPath(iModelId: GuidString): LocalDirName { return path.join(this.getIModelPath(iModelId), \"changesets\"); }\r\n\r\n /** @internal */\r\n public static getChangeCachePathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.ecchanges\")); }\r\n\r\n /** @internal */\r\n public static getChangedElementsPathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.elems\")); }\r\n\r\n private static _briefcaseSubDir = \"briefcases\";\r\n /** Get the local path of the folder storing briefcases associated with the specified iModel. */\r\n public static getBriefcaseBasePath(iModelId: GuidString): LocalDirName {\r\n return path.join(this.getIModelPath(iModelId), this._briefcaseSubDir);\r\n }\r\n\r\n /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.\r\n * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].\r\n * @param briefcase the iModelId and BriefcaseId for the filename\r\n * @see getIModelPath\r\n */\r\n public static getFileName(briefcase: BriefcaseProps): LocalFileName {\r\n return path.join(this.getBriefcaseBasePath(briefcase.iModelId), `${briefcase.briefcaseId}.bim`);\r\n }\r\n\r\n private static setupCacheDir(cacheRootDir: LocalDirName) {\r\n this._cacheDir = cacheRootDir;\r\n IModelJsFs.recursiveMkDirSync(this._cacheDir);\r\n }\r\n\r\n private static _initialized?: boolean;\r\n /** Initialize BriefcaseManager\r\n * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.\r\n * Briefcases are stored relative to this path in sub-folders organized by IModelId.\r\n * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.\r\n */\r\n public static initialize(cacheRootDir: LocalDirName) {\r\n if (this._initialized)\r\n return;\r\n this.setupCacheDir(cacheRootDir);\r\n IModelHost.onBeforeShutdown.addOnce(() => this.finalize());\r\n this._initialized = true;\r\n }\r\n\r\n private static finalize() {\r\n this._initialized = false;\r\n }\r\n\r\n /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId\r\n * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all\r\n * iModels in the briefcase cache are returned.\r\n * @note usually there should only be one briefcase per iModel.\r\n */\r\n public static getCachedBriefcases(iModelId?: GuidString): LocalBriefcaseProps[] {\r\n const briefcaseList: LocalBriefcaseProps[] = [];\r\n const iModelDirs = IModelJsFs.readdirSync(this._cacheDir);\r\n for (const iModelDir of iModelDirs) {\r\n if (iModelId && iModelId !== iModelDir)\r\n continue;\r\n const bcPath = path.join(this._cacheDir, iModelDir, this._briefcaseSubDir);\r\n try {\r\n if (!IModelJsFs.lstatSync(bcPath)?.isDirectory)\r\n continue;\r\n } catch (err) {\r\n continue;\r\n }\r\n\r\n const briefcases = IModelJsFs.readdirSync(bcPath);\r\n for (const briefcaseName of briefcases) {\r\n if (briefcaseName.endsWith(\".bim\")) {\r\n try {\r\n const fileName = path.join(bcPath, briefcaseName);\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const db = IModelDb.openDgnDb({ path: fileName }, OpenMode.Readonly);\r\n briefcaseList.push({ fileName, iTwinId: db.getITwinId(), iModelId: db.getIModelId(), briefcaseId: db.getBriefcaseId(), changeset: db.getCurrentChangeset(), fileSize });\r\n db.closeIModel();\r\n } catch (_err) {\r\n }\r\n }\r\n }\r\n }\r\n return briefcaseList;\r\n }\r\n\r\n private static _cacheDir: LocalDirName;\r\n /** Get the root directory for the briefcase cache */\r\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\r\n\r\n /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub\r\n * @note this does check whether the id was actually acquired by the caller.\r\n */\r\n public static isValidBriefcaseId(id: BriefcaseId) {\r\n return id >= BriefcaseIdValue.FirstValid && id <= BriefcaseIdValue.LastValid;\r\n }\r\n\r\n /** Acquire a new briefcaseId from iModelHub for the supplied iModelId\r\n * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,\r\n * it's a good idea to supply different aliases for each of them.\r\n */\r\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<BriefcaseId> {\r\n return IModelHost.hubAccess.acquireNewBriefcaseId(arg);\r\n }\r\n\r\n /**\r\n * Download a new briefcase from iModelHub for the supplied iModelId.\r\n *\r\n * Briefcases are local files holding a copy of an iModel.\r\n * Briefcases may either be specific to an individual user (so that it can be modified to create changesets), or it can be readonly so it can accept but not create changesets.\r\n * Every briefcase internally holds its [[BriefcaseId]]. Writeable briefcases have a `BriefcaseId` \"assigned\" to them by iModelHub. No two users will ever have the same BriefcaseId.\r\n * Readonly briefcases are \"unassigned\" with the special value [[BriefcaseId.Unassigned]].\r\n *\r\n * Typically a given user will have only one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one\r\n * briefcase to make isolated independent sets of changes, but that is exceedingly complicated and rare.\r\n *\r\n * Callers of this method may supply a BriefcaseId, or if none is supplied, a new one is acquired from iModelHub.\r\n *\r\n * @param arg The arguments that specify the briefcase file to be downloaded.\r\n * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).\r\n * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply\r\n * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named\r\n * for the IModelId.\r\n * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)\r\n */\r\n public static async downloadBriefcase(arg: RequestNewBriefcaseArg): Promise<LocalBriefcaseProps> {\r\n const briefcaseId = arg.briefcaseId ?? await this.acquireNewBriefcaseId(arg);\r\n const fileName = arg.fileName ?? this.getFileName({ ...arg, briefcaseId });\r\n\r\n if (IModelJsFs.existsSync(fileName))\r\n throw new IModelError(IModelStatus.FileAlreadyExists, `Briefcase \"${fileName}\" already exists`);\r\n\r\n const asOf = arg.asOf ?? IModelVersion.latest().toJSON();\r\n const changeset = await IModelHost.hubAccess.getChangesetFromVersion({ ...arg, version: IModelVersion.fromJSON(asOf) });\r\n const checkpoint: CheckpointProps = { ...arg, changeset };\r\n\r\n try {\r\n await CheckpointManager.downloadCheckpoint({ localFile: fileName, checkpoint, onProgress: arg.onProgress });\r\n } catch (error: unknown) {\r\n if (arg.accessToken && arg.briefcaseId === undefined)\r\n await this.releaseBriefcase(arg.accessToken, { briefcaseId, iModelId: arg.iModelId });\r\n\r\n throw error;\r\n }\r\n\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const response: LocalBriefcaseProps = {\r\n fileName,\r\n briefcaseId,\r\n iModelId: arg.iModelId,\r\n iTwinId: arg.iTwinId,\r\n changeset: checkpoint.changeset,\r\n fileSize,\r\n };\r\n\r\n // now open the downloaded checkpoint and reset its BriefcaseId\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.ReadWrite);\r\n } catch (err: any) {\r\n throw new IModelError(err.errorNumber, `Could not open downloaded briefcase for write access: ${fileName}, err=${err.message}`);\r\n }\r\n try {\r\n nativeDb.enableWalMode(); // local briefcases should use WAL journal mode\r\n nativeDb.resetBriefcaseId(briefcaseId);\r\n if (nativeDb.getCurrentChangeset().id !== checkpoint.changeset.id)\r\n throw new IModelError(IModelStatus.InvalidId, `Downloaded briefcase has wrong changesetId: ${fileName}`);\r\n } finally {\r\n nativeDb.saveChanges();\r\n nativeDb.closeIModel();\r\n }\r\n return response;\r\n }\r\n\r\n /** Deletes change sets of an iModel from local disk\r\n * @internal\r\n */\r\n public static deleteChangeSetsFromLocalDisk(iModelId: string) {\r\n const changesetsPath = BriefcaseManager.getChangeSetsPath(iModelId);\r\n BriefcaseManager.deleteFolderAndContents(changesetsPath);\r\n }\r\n\r\n /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.\r\n * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].\r\n * @see deleteBriefcaseFiles\r\n */\r\n public static async releaseBriefcase(accessToken: AccessToken, briefcase: BriefcaseProps): Promise<void> {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId))\r\n return IModelHost.hubAccess.releaseBriefcase({ accessToken, iModelId: briefcase.iModelId, briefcaseId: briefcase.briefcaseId });\r\n }\r\n\r\n /**\r\n * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.\r\n * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and\r\n * associated files (that is, all files in the same directory that start with the briefcase name).\r\n * @param filePath the full file name of the Briefcase to delete\r\n * @param accessToken for releasing the briefcaseId\r\n */\r\n public static async deleteBriefcaseFiles(filePath: LocalFileName, accessToken?: AccessToken): Promise<void> {\r\n try {\r\n const db = IModelDb.openDgnDb({ path: filePath }, OpenMode.Readonly);\r\n const briefcase: BriefcaseProps = {\r\n iModelId: db.getIModelId(),\r\n briefcaseId: db.getBriefcaseId(),\r\n };\r\n db.closeIModel();\r\n\r\n if (accessToken) {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId)) {\r\n await BriefcaseManager.releaseBriefcase(accessToken, briefcase);\r\n }\r\n }\r\n } catch (error) {\r\n }\r\n\r\n // first try to delete the briefcase file\r\n try {\r\n if (IModelJsFs.existsSync(filePath))\r\n IModelJsFs.unlinkSync(filePath);\r\n } catch (err) {\r\n throw new IModelError(IModelStatus.BadRequest, `cannot delete briefcase file ${err}`);\r\n }\r\n\r\n // next, delete all files that start with the briefcase's filePath (e.g. \"a.bim-locks\", \"a.bim-journal\", etc.)\r\n try {\r\n const dirName = path.dirname(filePath);\r\n const fileName = path.basename(filePath);\r\n const files = IModelJsFs.readdirSync(dirName);\r\n for (const file of files) {\r\n if (file.startsWith(fileName))\r\n this.deleteFile(path.join(dirName, file)); // don't throw on error\r\n }\r\n } catch (err) {\r\n }\r\n }\r\n\r\n /** Deletes a file\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFile(pathname: LocalFileName): boolean {\r\n try {\r\n IModelJsFs.unlinkSync(pathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${error}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes a folder, checking if it's empty\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFolderIfEmpty(folderPathname: LocalDirName): boolean {\r\n try {\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n if (files.length > 0)\r\n return false;\r\n\r\n IModelJsFs.rmdirSync(folderPathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete folder: ${folderPathname}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes the contents of a folder, but not the folder itself\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return false;\r\n\r\n let status = true;\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n for (const file of files) {\r\n const curPath = path.join(folderPathname, file);\r\n const locStatus = (IModelJsFs.lstatSync(curPath)?.isDirectory) ? BriefcaseManager.deleteFolderAndContents(curPath) : BriefcaseManager.deleteFile(curPath);\r\n if (!locStatus)\r\n status = false;\r\n }\r\n return status;\r\n }\r\n\r\n /** Query the hub for the properties for a ChangesetIndex or ChangesetId */\r\n public static async queryChangeset(arg: { iModelId: GuidString, changeset: ChangesetIndexOrId }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.queryChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for an array of changeset properties given a ChangesetRange */\r\n public static async queryChangesets(arg: { iModelId: GuidString, range: ChangesetRange }): Promise<ChangesetProps[]> {\r\n return IModelHost.hubAccess.queryChangesets({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for the ChangesetProps of the most recent changeset */\r\n public static async getLatestChangeset(arg: { iModelId: GuidString }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.getLatestChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the Id of an iModel by name.\r\n * @param arg Identifies the iModel of interest\r\n * @returns the Id of the corresponding iModel, or `undefined` if no such iModel exists.\r\n */\r\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\r\n return IModelHost.hubAccess.queryIModelByName(arg);\r\n }\r\n\r\n /** Deletes a folder and all it's contents.\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderAndContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return true;\r\n\r\n let status = false;\r\n status = BriefcaseManager.deleteFolderContents(folderPathname);\r\n if (!status)\r\n return false;\r\n\r\n status = BriefcaseManager.deleteFolderIfEmpty(folderPathname);\r\n return status;\r\n }\r\n\r\n private static async applySingleChangeset(db: IModelDb, changesetFile: ChangesetFileProps) {\r\n if (changesetFile.changesType === ChangesetType.Schema)\r\n db.clearCaches(); // for schema changesets, statement caches may become invalid. Do this *before* applying, in case db needs to be closed (open statements hold db open.)\r\n\r\n db.nativeDb.applyChangeset(changesetFile);\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n\r\n // we're done with this changeset, delete it\r\n IModelJsFs.removeSync(changesetFile.pathname);\r\n }\r\n\r\n /** @internal */\r\n public static async pullAndApplyChangesets(db: IModelDb, arg: PullChangesArgs): Promise<void> {\r\n if (!db.isOpen || db.nativeDb.isReadonly()) // don't use db.isReadonly - we reopen the file writable just for this operation but db.isReadonly is still true\r\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to process change sets\");\r\n\r\n let currentIndex = db.changeset.index;\r\n if (currentIndex === undefined)\r\n currentIndex = (await IModelHost.hubAccess.queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\r\n\r\n const reverse = (arg.toIndex && arg.toIndex < currentIndex) ? true : false;\r\n\r\n // Download change sets\r\n const changesets = await IModelHost.hubAccess.downloadChangesets({\r\n accessToken: arg.accessToken,\r\n iModelId: db.iModelId,\r\n range: { first: reverse ? arg.toIndex! + 1 : currentIndex + 1, end: reverse ? currentIndex : arg.toIndex }, // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\r\n progressCallback: arg.onProgress,\r\n });\r\n\r\n if (changesets.length === 0)\r\n return; // nothing to apply\r\n\r\n if (reverse)\r\n changesets.reverse();\r\n\r\n for (const changeset of changesets)\r\n await this.applySingleChangeset(db, changeset);\r\n\r\n // notify listeners\r\n db.notifyChangesetApplied();\r\n }\r\n\r\n /** create a changeset from the current changes, and push it to iModelHub */\r\n private static async pushChanges(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n const changesetProps = db.nativeDb.startCreateChangeset() as ChangesetFileProps;\r\n changesetProps.briefcaseId = db.briefcaseId;\r\n changesetProps.description = arg.description;\r\n const fileSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\r\n if (!fileSize) // either undefined or 0 means error\r\n throw new IModelError(IModelStatus.NoContent, \"error creating changeset\");\r\n\r\n changesetProps.size = fileSize;\r\n\r\n let retryCount = arg.pushRetryCount ?? 3;\r\n while (true) {\r\n try {\r\n const accessToken = await IModelHost.getAccessToken();\r\n const index = await IModelHost.hubAccess.pushChangeset({ accessToken, iModelId: db.iModelId, changesetProps });\r\n db.nativeDb.completeCreateChangeset({ index });\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n if (!arg.retainLocks)\r\n await db.locks.releaseAllLocks();\r\n\r\n return;\r\n } catch (err: any) {\r\n const shouldRetry = () => {\r\n if (retryCount-- <= 0)\r\n return false;\r\n switch (err.errorNumber) {\r\n case IModelHubStatus.AnotherUserPushing:\r\n case IModelHubStatus.DatabaseTemporarilyLocked:\r\n case IModelHubStatus.OperationFailed:\r\n return true;\r\n }\r\n return false;\r\n };\r\n\r\n if (!shouldRetry()) {\r\n db.nativeDb.abandonCreateChangeset();\r\n throw err;\r\n }\r\n } finally {\r\n IModelJsFs.removeSync(changesetProps.pathname);\r\n }\r\n }\r\n }\r\n\r\n /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]\r\n * @internal\r\n */\r\n public static async pullMergePush(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n let retryCount = arg.mergeRetryCount ?? 5;\r\n while (true) {\r\n try {\r\n await BriefcaseManager.pullAndApplyChangesets(db, arg);\r\n return await BriefcaseManager.pushChanges(db, arg);\r\n } catch (err: any) {\r\n if (retryCount-- <= 0 || err.errorNumber !== IModelHubStatus.PullIsRequired)\r\n throw (err);\r\n await (arg.mergeRetryDelay ?? BeDuration.fromSeconds(3)).wait();\r\n }\r\n }\r\n }\r\n\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"BriefcaseManager.js","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qCAAqC;AAErC,6BAA6B;AAC7B,sDAE6B;AAC7B,oDAG4B;AAE5B,mEAAgE;AAChE,2DAA2F;A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CAAC;oBACf,QAAQ,GAAG,CAAC,WAAW,EAAE;wBACvB,KAAK,8BAAe,CAAC,kBAAkB,CAAC;wBACxC,KAAK,8BAAe,CAAC,yBAAyB,CAAC;wBAC/C,KAAK,8BAAe,CAAC,eAAe;4BAClC,OAAO,IAAI,CAAC;qBACf;oBACD,OAAO,KAAK,CAAC;gBACf,CAAC,CAAC;gBAEF,IAAI,CAAC,WAAW,EAAE,EAAE;oBAClB,EAAE,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC;oBACrC,MAAM,GAAG,CAAC;iBACX;aACF;oBAAS;gBACR,uBAAU,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;aAChD;SACF;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAe,EAAE,GAAoB;QACrE,IAAI,UAAU,GAAG,GAAG,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,EAAE;YACX,IAAI;gBACF,MAAM,gBAAgB,CAAC,sBAAsB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACvD,OAAO,MAAM,gBAAgB,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;aACpD;YAAC,OAAO,GAAQ,EAAE;gBACjB,IAAI,UAAU,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,WAAW,KAAK,8BAAe,CAAC,cAAc;oBACzE,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACjE;SACF;IACH,CAAC;;AAtac,iCAAgB,GAAG,YAAY,CAAC;AAbpC,4CAAgB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore cset csets ecchanges\r\n\r\nimport * as path from \"path\";\r\nimport {\r\n AccessToken, BeDuration, ChangeSetStatus, GuidString, IModelHubStatus, IModelStatus, Logger, OpenMode, StopWatch,\r\n} from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseId, BriefcaseIdValue, BriefcaseProps, ChangesetFileProps, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange, ChangesetType, IModelError, IModelVersion, LocalBriefcaseProps,\r\n LocalDirName, LocalFileName, RequestNewBriefcaseProps,\r\n} from \"@itwin/core-common\";\r\nimport { AcquireNewBriefcaseIdArg, IModelNameArg } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { CheckpointManager, CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, TokenArg } from \"./IModelDb\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/** The argument for [[BriefcaseManager.downloadBriefcase]]\r\n * @public\r\n*/\r\nexport interface RequestNewBriefcaseArg extends TokenArg, RequestNewBriefcaseProps {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n}\r\n\r\n/**\r\n * Parameters for pushing changesets to iModelHub\r\n * @public\r\n */\r\nexport interface PushChangesArgs extends TokenArg {\r\n /** A description of the changes. This is visible on the iModel's timeline. */\r\n description: string;\r\n /** if present, the locks are retained after the operation. Otherwise, *all* locks are released after the changeset is successfully pushed. */\r\n retainLocks?: true;\r\n /** number of times to retry pull/merge if other users are pushing at the same time. Default is 5 */\r\n mergeRetryCount?: number;\r\n /** delay to wait between pull/merge retry attempts. Default is 3 seconds */\r\n mergeRetryDelay?: BeDuration;\r\n /** the number of time to attempt to retry to push the changeset upon failure. Default is 3 */\r\n pushRetryCount?: number;\r\n /** The delay to wait between retry attempts on failed pushes. Default is 3 seconds. */\r\n pushRetryDelay?: BeDuration;\r\n}\r\n\r\n/**\r\n * Specifies a specific index for pulling changes.\r\n * @public\r\n */\r\nexport interface ToChangesetArgs extends TokenArg {\r\n /** The last ChangesetIndex to pull. If not present, pull *all* newer changesets. */\r\n toIndex?: ChangesetIndex;\r\n}\r\n\r\n/** Arguments for [[BriefcaseManager.pullAndApplyChangesets]]\r\n * @public\r\n */\r\nexport type PullChangesArgs = ToChangesetArgs & {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n};\r\n\r\n/** Manages downloading Briefcases and downloading and uploading changesets.\r\n * @public\r\n */\r\nexport class BriefcaseManager {\r\n /** Get the local path of the folder storing files that are associated with an imodel */\r\n public static getIModelPath(iModelId: GuidString): LocalDirName { return path.join(this._cacheDir, iModelId); }\r\n\r\n /** @internal */\r\n public static getChangeSetsPath(iModelId: GuidString): LocalDirName { return path.join(this.getIModelPath(iModelId), \"changesets\"); }\r\n\r\n /** @internal */\r\n public static getChangeCachePathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.ecchanges\")); }\r\n\r\n /** @internal */\r\n public static getChangedElementsPathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.elems\")); }\r\n\r\n private static _briefcaseSubDir = \"briefcases\";\r\n /** Get the local path of the folder storing briefcases associated with the specified iModel. */\r\n public static getBriefcaseBasePath(iModelId: GuidString): LocalDirName {\r\n return path.join(this.getIModelPath(iModelId), this._briefcaseSubDir);\r\n }\r\n\r\n /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.\r\n * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].\r\n * @param briefcase the iModelId and BriefcaseId for the filename\r\n * @see getIModelPath\r\n */\r\n public static getFileName(briefcase: BriefcaseProps): LocalFileName {\r\n return path.join(this.getBriefcaseBasePath(briefcase.iModelId), `${briefcase.briefcaseId}.bim`);\r\n }\r\n\r\n private static setupCacheDir(cacheRootDir: LocalDirName) {\r\n this._cacheDir = cacheRootDir;\r\n IModelJsFs.recursiveMkDirSync(this._cacheDir);\r\n }\r\n\r\n private static _initialized?: boolean;\r\n /** Initialize BriefcaseManager\r\n * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.\r\n * Briefcases are stored relative to this path in sub-folders organized by IModelId.\r\n * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.\r\n */\r\n public static initialize(cacheRootDir: LocalDirName) {\r\n if (this._initialized)\r\n return;\r\n this.setupCacheDir(cacheRootDir);\r\n IModelHost.onBeforeShutdown.addOnce(() => this.finalize());\r\n this._initialized = true;\r\n }\r\n\r\n private static finalize() {\r\n this._initialized = false;\r\n }\r\n\r\n /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId\r\n * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all\r\n * iModels in the briefcase cache are returned.\r\n * @note usually there should only be one briefcase per iModel.\r\n */\r\n public static getCachedBriefcases(iModelId?: GuidString): LocalBriefcaseProps[] {\r\n const briefcaseList: LocalBriefcaseProps[] = [];\r\n const iModelDirs = IModelJsFs.readdirSync(this._cacheDir);\r\n for (const iModelDir of iModelDirs) {\r\n if (iModelId && iModelId !== iModelDir)\r\n continue;\r\n const bcPath = path.join(this._cacheDir, iModelDir, this._briefcaseSubDir);\r\n try {\r\n if (!IModelJsFs.lstatSync(bcPath)?.isDirectory)\r\n continue;\r\n } catch (err) {\r\n continue;\r\n }\r\n\r\n const briefcases = IModelJsFs.readdirSync(bcPath);\r\n for (const briefcaseName of briefcases) {\r\n if (briefcaseName.endsWith(\".bim\")) {\r\n try {\r\n const fileName = path.join(bcPath, briefcaseName);\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const db = IModelDb.openDgnDb({ path: fileName }, OpenMode.Readonly);\r\n briefcaseList.push({ fileName, iTwinId: db.getITwinId(), iModelId: db.getIModelId(), briefcaseId: db.getBriefcaseId(), changeset: db.getCurrentChangeset(), fileSize });\r\n db.closeIModel();\r\n } catch (_err) {\r\n }\r\n }\r\n }\r\n }\r\n return briefcaseList;\r\n }\r\n\r\n private static _cacheDir: LocalDirName;\r\n /** Get the root directory for the briefcase cache */\r\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\r\n\r\n /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub\r\n * @note this does check whether the id was actually acquired by the caller.\r\n */\r\n public static isValidBriefcaseId(id: BriefcaseId) {\r\n return id >= BriefcaseIdValue.FirstValid && id <= BriefcaseIdValue.LastValid;\r\n }\r\n\r\n /** Acquire a new briefcaseId from iModelHub for the supplied iModelId\r\n * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,\r\n * it's a good idea to supply different aliases for each of them.\r\n */\r\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<BriefcaseId> {\r\n return IModelHost.hubAccess.acquireNewBriefcaseId(arg);\r\n }\r\n\r\n /**\r\n * Download a new briefcase from iModelHub for the supplied iModelId.\r\n *\r\n * Briefcases are local files holding a copy of an iModel.\r\n * Briefcases may either be specific to an individual user (so that it can be modified to create changesets), or it can be readonly so it can accept but not create changesets.\r\n * Every briefcase internally holds its [[BriefcaseId]]. Writeable briefcases have a `BriefcaseId` \"assigned\" to them by iModelHub. No two users will ever have the same BriefcaseId.\r\n * Readonly briefcases are \"unassigned\" with the special value [[BriefcaseId.Unassigned]].\r\n *\r\n * Typically a given user will have only one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one\r\n * briefcase to make isolated independent sets of changes, but that is exceedingly complicated and rare.\r\n *\r\n * Callers of this method may supply a BriefcaseId, or if none is supplied, a new one is acquired from iModelHub.\r\n *\r\n * @param arg The arguments that specify the briefcase file to be downloaded.\r\n * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).\r\n * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply\r\n * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named\r\n * for the IModelId.\r\n * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)\r\n */\r\n public static async downloadBriefcase(arg: RequestNewBriefcaseArg): Promise<LocalBriefcaseProps> {\r\n const briefcaseId = arg.briefcaseId ?? await this.acquireNewBriefcaseId(arg);\r\n const fileName = arg.fileName ?? this.getFileName({ ...arg, briefcaseId });\r\n\r\n if (IModelJsFs.existsSync(fileName))\r\n throw new IModelError(IModelStatus.FileAlreadyExists, `Briefcase \"${fileName}\" already exists`);\r\n\r\n const asOf = arg.asOf ?? IModelVersion.latest().toJSON();\r\n const changeset = await IModelHost.hubAccess.getChangesetFromVersion({ ...arg, version: IModelVersion.fromJSON(asOf) });\r\n const checkpoint: CheckpointProps = { ...arg, changeset };\r\n\r\n try {\r\n await CheckpointManager.downloadCheckpoint({ localFile: fileName, checkpoint, onProgress: arg.onProgress });\r\n } catch (error: unknown) {\r\n if (arg.accessToken && arg.briefcaseId === undefined)\r\n await this.releaseBriefcase(arg.accessToken, { briefcaseId, iModelId: arg.iModelId });\r\n\r\n throw error;\r\n }\r\n\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const response: LocalBriefcaseProps = {\r\n fileName,\r\n briefcaseId,\r\n iModelId: arg.iModelId,\r\n iTwinId: arg.iTwinId,\r\n changeset: checkpoint.changeset,\r\n fileSize,\r\n };\r\n\r\n // now open the downloaded checkpoint and reset its BriefcaseId\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.ReadWrite);\r\n } catch (err: any) {\r\n throw new IModelError(err.errorNumber, `Could not open downloaded briefcase for write access: ${fileName}, err=${err.message}`);\r\n }\r\n try {\r\n nativeDb.enableWalMode(); // local briefcases should use WAL journal mode\r\n nativeDb.resetBriefcaseId(briefcaseId);\r\n if (nativeDb.getCurrentChangeset().id !== checkpoint.changeset.id)\r\n throw new IModelError(IModelStatus.InvalidId, `Downloaded briefcase has wrong changesetId: ${fileName}`);\r\n } finally {\r\n nativeDb.saveChanges();\r\n nativeDb.closeIModel();\r\n }\r\n return response;\r\n }\r\n\r\n /** Deletes change sets of an iModel from local disk\r\n * @internal\r\n */\r\n public static deleteChangeSetsFromLocalDisk(iModelId: string) {\r\n const changesetsPath = BriefcaseManager.getChangeSetsPath(iModelId);\r\n BriefcaseManager.deleteFolderAndContents(changesetsPath);\r\n }\r\n\r\n /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.\r\n * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].\r\n * @see deleteBriefcaseFiles\r\n */\r\n public static async releaseBriefcase(accessToken: AccessToken, briefcase: BriefcaseProps): Promise<void> {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId))\r\n return IModelHost.hubAccess.releaseBriefcase({ accessToken, iModelId: briefcase.iModelId, briefcaseId: briefcase.briefcaseId });\r\n }\r\n\r\n /**\r\n * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.\r\n * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and\r\n * associated files (that is, all files in the same directory that start with the briefcase name).\r\n * @param filePath the full file name of the Briefcase to delete\r\n * @param accessToken for releasing the briefcaseId\r\n */\r\n public static async deleteBriefcaseFiles(filePath: LocalFileName, accessToken?: AccessToken): Promise<void> {\r\n try {\r\n const db = IModelDb.openDgnDb({ path: filePath }, OpenMode.Readonly);\r\n const briefcase: BriefcaseProps = {\r\n iModelId: db.getIModelId(),\r\n briefcaseId: db.getBriefcaseId(),\r\n };\r\n db.closeIModel();\r\n\r\n if (accessToken) {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId)) {\r\n await BriefcaseManager.releaseBriefcase(accessToken, briefcase);\r\n }\r\n }\r\n } catch (error) {\r\n }\r\n\r\n // first try to delete the briefcase file\r\n try {\r\n if (IModelJsFs.existsSync(filePath))\r\n IModelJsFs.unlinkSync(filePath);\r\n } catch (err) {\r\n throw new IModelError(IModelStatus.BadRequest, `cannot delete briefcase file ${err}`);\r\n }\r\n\r\n // next, delete all files that start with the briefcase's filePath (e.g. \"a.bim-locks\", \"a.bim-journal\", etc.)\r\n try {\r\n const dirName = path.dirname(filePath);\r\n const fileName = path.basename(filePath);\r\n const files = IModelJsFs.readdirSync(dirName);\r\n for (const file of files) {\r\n if (file.startsWith(fileName))\r\n this.deleteFile(path.join(dirName, file)); // don't throw on error\r\n }\r\n } catch (err) {\r\n }\r\n }\r\n\r\n /** Deletes a file\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFile(pathname: LocalFileName): boolean {\r\n try {\r\n IModelJsFs.unlinkSync(pathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${error}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes a folder, checking if it's empty\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFolderIfEmpty(folderPathname: LocalDirName): boolean {\r\n try {\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n if (files.length > 0)\r\n return false;\r\n\r\n IModelJsFs.rmdirSync(folderPathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete folder: ${folderPathname}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes the contents of a folder, but not the folder itself\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return false;\r\n\r\n let status = true;\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n for (const file of files) {\r\n const curPath = path.join(folderPathname, file);\r\n const locStatus = (IModelJsFs.lstatSync(curPath)?.isDirectory) ? BriefcaseManager.deleteFolderAndContents(curPath) : BriefcaseManager.deleteFile(curPath);\r\n if (!locStatus)\r\n status = false;\r\n }\r\n return status;\r\n }\r\n\r\n /** Query the hub for the properties for a ChangesetIndex or ChangesetId */\r\n public static async queryChangeset(arg: { iModelId: GuidString, changeset: ChangesetIndexOrId }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.queryChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for an array of changeset properties given a ChangesetRange */\r\n public static async queryChangesets(arg: { iModelId: GuidString, range: ChangesetRange }): Promise<ChangesetProps[]> {\r\n return IModelHost.hubAccess.queryChangesets({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for the ChangesetProps of the most recent changeset */\r\n public static async getLatestChangeset(arg: { iModelId: GuidString }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.getLatestChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the Id of an iModel by name.\r\n * @param arg Identifies the iModel of interest\r\n * @returns the Id of the corresponding iModel, or `undefined` if no such iModel exists.\r\n */\r\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\r\n return IModelHost.hubAccess.queryIModelByName(arg);\r\n }\r\n\r\n /** Deletes a folder and all it's contents.\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderAndContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return true;\r\n\r\n let status = false;\r\n status = BriefcaseManager.deleteFolderContents(folderPathname);\r\n if (!status)\r\n return false;\r\n\r\n status = BriefcaseManager.deleteFolderIfEmpty(folderPathname);\r\n return status;\r\n }\r\n\r\n private static async applySingleChangeset(db: IModelDb, changesetFile: ChangesetFileProps) {\r\n if (changesetFile.changesType === ChangesetType.Schema)\r\n db.clearCaches(); // for schema changesets, statement caches may become invalid. Do this *before* applying, in case db needs to be closed (open statements hold db open.)\r\n\r\n db.nativeDb.applyChangeset(changesetFile);\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n\r\n // we're done with this changeset, delete it\r\n IModelJsFs.removeSync(changesetFile.pathname);\r\n }\r\n\r\n /** @internal */\r\n public static async pullAndApplyChangesets(db: IModelDb, arg: PullChangesArgs): Promise<void> {\r\n if (!db.isOpen || db.nativeDb.isReadonly()) // don't use db.isReadonly - we reopen the file writable just for this operation but db.isReadonly is still true\r\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to process change sets\");\r\n\r\n let currentIndex = db.changeset.index;\r\n if (currentIndex === undefined)\r\n currentIndex = (await IModelHost.hubAccess.queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\r\n\r\n const reverse = (arg.toIndex && arg.toIndex < currentIndex) ? true : false;\r\n\r\n // Download change sets\r\n const changesets = await IModelHost.hubAccess.downloadChangesets({\r\n accessToken: arg.accessToken,\r\n iModelId: db.iModelId,\r\n range: { first: reverse ? arg.toIndex! + 1 : currentIndex + 1, end: reverse ? currentIndex : arg.toIndex }, // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\r\n progressCallback: arg.onProgress,\r\n });\r\n\r\n if (changesets.length === 0)\r\n return; // nothing to apply\r\n\r\n if (reverse)\r\n changesets.reverse();\r\n\r\n for (const changeset of changesets) {\r\n const stopwatch = new StopWatch(`[${changeset.id}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description}`);\r\n await this.applySingleChangeset(db, changeset);\r\n Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\r\n }\r\n // notify listeners\r\n db.notifyChangesetApplied();\r\n }\r\n\r\n /** create a changeset from the current changes, and push it to iModelHub */\r\n private static async pushChanges(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n const changesetProps = db.nativeDb.startCreateChangeset() as ChangesetFileProps;\r\n changesetProps.briefcaseId = db.briefcaseId;\r\n changesetProps.description = arg.description;\r\n const fileSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\r\n if (!fileSize) // either undefined or 0 means error\r\n throw new IModelError(IModelStatus.NoContent, \"error creating changeset\");\r\n\r\n changesetProps.size = fileSize;\r\n\r\n let retryCount = arg.pushRetryCount ?? 3;\r\n while (true) {\r\n try {\r\n const accessToken = await IModelHost.getAccessToken();\r\n const index = await IModelHost.hubAccess.pushChangeset({ accessToken, iModelId: db.iModelId, changesetProps });\r\n db.nativeDb.completeCreateChangeset({ index });\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n if (!arg.retainLocks)\r\n await db.locks.releaseAllLocks();\r\n\r\n return;\r\n } catch (err: any) {\r\n const shouldRetry = () => {\r\n if (retryCount-- <= 0)\r\n return false;\r\n switch (err.errorNumber) {\r\n case IModelHubStatus.AnotherUserPushing:\r\n case IModelHubStatus.DatabaseTemporarilyLocked:\r\n case IModelHubStatus.OperationFailed:\r\n return true;\r\n }\r\n return false;\r\n };\r\n\r\n if (!shouldRetry()) {\r\n db.nativeDb.abandonCreateChangeset();\r\n throw err;\r\n }\r\n } finally {\r\n IModelJsFs.removeSync(changesetProps.pathname);\r\n }\r\n }\r\n }\r\n\r\n /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]\r\n * @internal\r\n */\r\n public static async pullMergePush(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n let retryCount = arg.mergeRetryCount ?? 5;\r\n while (true) {\r\n try {\r\n await BriefcaseManager.pullAndApplyChangesets(db, arg);\r\n return await BriefcaseManager.pushChanges(db, arg);\r\n } catch (err: any) {\r\n if (retryCount-- <= 0 || err.errorNumber !== IModelHubStatus.PullIsRequired)\r\n throw (err);\r\n await (arg.mergeRetryDelay ?? BeDuration.fromSeconds(3)).wait();\r\n }\r\n }\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckpointManager.d.ts","sourceRoot":"","sources":["../../src/CheckpointManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAMH,OAAO,EAAE,OAAO,EAAyB,UAAU,EAAgE,MAAM,qBAAqB,CAAC;AAC/I,OAAO,EACa,WAAW,EAAE,oBAAoB,EAAmD,YAAY,EAAE,aAAa,EAClI,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAIlD;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAE5B,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAE7B,uBAAuB;IACvB,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAE9B,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IAEzC,8IAA8I;IAC9I,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAElC,qHAAqH;IACrH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CACzC;AAED;;GAEG;AACH,oBAAY,cAAc;IACxB,yBAAyB;IACzB,QAAQ,IAAI;IACZ,sBAAsB;IACtB,KAAK,IAAI;CACV;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,cAAc,CAAC;AAEjF;;GAEG;AACH,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AAE,eAAe,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO;IAmB7F,uEAAuE;WACzD,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,UAAU,GAAG,SAAS;CAgBjF"}
|
|
@@ -224,7 +224,10 @@ class CheckpointManager {
|
|
|
224
224
|
static async doDownload(request) {
|
|
225
225
|
try {
|
|
226
226
|
// first see if there's a V2 checkpoint available.
|
|
227
|
+
const stopwatch = new core_bentley_1.StopWatch(`[${request.checkpoint.changeset.id}]`, true);
|
|
228
|
+
core_bentley_1.Logger.logInfo(loggerCategory, `Starting download of V2 checkpoint with id ${stopwatch.description}`);
|
|
227
229
|
const changesetId = await V2CheckpointManager.downloadCheckpoint(request);
|
|
230
|
+
core_bentley_1.Logger.logInfo(loggerCategory, `Downloaded V2 checkpoint with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);
|
|
228
231
|
if (changesetId !== request.checkpoint.changeset.id)
|
|
229
232
|
core_bentley_1.Logger.logInfo(loggerCategory, `Downloaded previous v2 checkpoint because requested checkpoint not found.`, { requestedChangesetId: request.checkpoint.changeset.id, iModelId: request.checkpoint.iModelId, changesetId, iTwinId: request.checkpoint.iTwinId });
|
|
230
233
|
else
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckpointManager.js","sourceRoot":"","sources":["../../src/CheckpointManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2BAA2B;AAE3B,6BAA6B;AAC7B,8DAAgE;AAChE,sDAA+I;AAC/I,oDAE4B;AAE5B,mEAAgE;AAChE,yDAAsD;AACtD,+CAA4C;AAC5C,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAkD;AAElD,MAAM,cAAc,GAAG,6CAAqB,CAAC,QAAQ,CAAC;AAyBtD;;GAEG;AACH,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yBAAyB;IACzB,2DAAY,CAAA;IACZ,sBAAsB;IACtB,qDAAS,CAAA;AAC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jH,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,UAAU,EAAE;gBACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE;oBAC5C,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;oBAC1B,OAAO,qBAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;iBACvD;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;;AAzJsB,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AACzD,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AAFrE,8CAAiB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore BLOCKCACHE\r\n\r\nimport * as path from \"path\";\r\nimport { NativeLoggerCategory } from \"@bentley/imodeljs-native\";\r\nimport { BeEvent, ChangeSetStatus, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, OpenMode, StopWatch } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseIdValue, ChangesetId, ChangesetIdWithIndex, ChangesetIndexAndId, IModelError, IModelVersion, LocalDirName, LocalFileName,\r\n} from \"@itwin/core-common\";\r\nimport { V2CheckpointAccessProps } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SnapshotDb, TokenArg } from \"./IModelDb\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/**\r\n * Properties of a checkpoint\r\n * @public\r\n */\r\nexport interface CheckpointProps extends TokenArg {\r\n readonly expectV2?: boolean;\r\n\r\n /** iTwin that the iModel belongs to */\r\n readonly iTwinId: GuidString;\r\n\r\n /** Id of the iModel */\r\n readonly iModelId: GuidString;\r\n\r\n /** changeset for the checkpoint */\r\n readonly changeset: ChangesetIdWithIndex;\r\n\r\n /** If true, then the latest successful v2 checkpoint at or before the provided changeset will be returned when calling queryV2Checkpoint. */\r\n readonly allowPreceding?: boolean;\r\n\r\n /** The number of seconds before the current token expires to attempt to reacquire a new token. Default is 1 hour. */\r\n readonly reattachSafetySeconds?: number;\r\n}\r\n\r\n/** Return value from [[ProgressFunction]].\r\n * @public\r\n */\r\nexport enum ProgressStatus {\r\n /** Continue download. */\r\n Continue = 0,\r\n /** Abort download. */\r\n Abort = 1,\r\n}\r\n\r\n/** Called to show progress during a download. If this function returns non-zero, the download is aborted.\r\n * @public\r\n */\r\nexport type ProgressFunction = (loaded: number, total: number) => ProgressStatus;\r\n\r\n/** The parameters that specify a request to download a checkpoint file from iModelHub.\r\n * @internal\r\n */\r\nexport interface DownloadRequest {\r\n /** name of local file to hold the downloaded data. */\r\n localFile: LocalFileName;\r\n\r\n /** A list of full fileName paths to test before downloading. If a valid file exists by one of these names,\r\n * no download is performed and `localFile` is updated to reflect the fact that the file exists with that name.\r\n * This can be used, for example, to look for checkpoints from previous versions if the naming strategy changes.\r\n */\r\n readonly aliasFiles?: ReadonlyArray<string>;\r\n\r\n /** Properties of the checkpoint to be downloaded */\r\n readonly checkpoint: CheckpointProps;\r\n\r\n /** If present, this function will be called to indicate progress as the briefcase is downloaded. If this\r\n * function returns a non-zero value, the download is aborted.\r\n */\r\n readonly onProgress?: ProgressFunction;\r\n}\r\n\r\n/** @internal */\r\nexport interface DownloadJob {\r\n request: DownloadRequest;\r\n promise?: Promise<any>;\r\n}\r\n\r\n/** @internal */\r\nexport class Downloads {\r\n private static _active = new Map<string, DownloadJob>();\r\n\r\n private static async process<T>(job: DownloadJob, fn: (job: DownloadJob) => Promise<T>) {\r\n const jobName = job.request.localFile; // save this, it can change inside call to `fn`!\r\n this._active.set(jobName, job);\r\n try {\r\n return await fn(job);\r\n } finally {\r\n this._active.delete(jobName);\r\n }\r\n }\r\n\r\n public static isInProgress(pathName: LocalFileName): DownloadJob | undefined {\r\n return this._active.get(pathName);\r\n }\r\n\r\n public static async download<T>(request: DownloadRequest, downloadFn: (job: DownloadJob) => Promise<T>) {\r\n const pathName = request.localFile;\r\n let job = this.isInProgress(pathName);\r\n if (undefined !== job)\r\n return job.promise;\r\n\r\n IModelJsFs.recursiveMkDirSync(path.dirname(pathName));\r\n job = { request };\r\n return job.promise = this.process(job, downloadFn);\r\n }\r\n}\r\n\r\n/**\r\n * Utility class for opening V2 checkpoints from cloud containers, and also for downloading them.\r\n * @internal\r\n*/\r\nexport class V2CheckpointManager {\r\n public static readonly cloudCacheName = \"v2Checkpoints\";\r\n private static _cloudCache?: CloudSqlite.CloudCache;\r\n private static containers = new Map<string, CloudSqlite.CloudContainer>();\r\n\r\n public static getFolder(): LocalDirName {\r\n const cloudCachePath = path.join(BriefcaseManager.cacheDir, V2CheckpointManager.cloudCacheName);\r\n if (!(IModelJsFs.existsSync(cloudCachePath))) {\r\n IModelJsFs.recursiveMkDirSync(cloudCachePath);\r\n }\r\n return cloudCachePath;\r\n }\r\n\r\n /* only used by tests that reset the state of the v2CheckpointManager. all dbs should be closed before calling this function. */\r\n public static cleanup(): void {\r\n for (const [_, value] of this.containers.entries()) {\r\n if (value.isConnected)\r\n value.disconnect({ detach: true });\r\n }\r\n\r\n CloudSqlite.CloudCaches.dropCache(this.cloudCacheName)?.destroy();\r\n this._cloudCache = undefined;\r\n this.containers.clear();\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(), `${changesetId}.bim`);\r\n }\r\n\r\n private static get cloudCache(): CloudSqlite.CloudCache {\r\n if (!this._cloudCache) {\r\n let cacheDir = process.env.CHECKPOINT_CACHE_DIR;\r\n if (!cacheDir) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No CHECKPOINT_CACHE_DIR found in process.env, using ${cacheDir} instead.`);\r\n } else {\r\n // Make sure the checkpoint_cache_dir has an iTwinDaemon specific file in it, otherwise fall back to other directory.\r\n if (!(IModelJsFs.existsSync(path.join(cacheDir, \"portnumber.bcv\")))) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No evidence of the iTwinDaemon in provided CHECKPOINT_CACHE_DIR: ${process.env.CHECKPOINT_CACHE_DIR}, using ${cacheDir} instead.`);\r\n }\r\n }\r\n\r\n this._cloudCache = CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir });\r\n\r\n // Its fine if its not a daemon, but lets log an info message\r\n if (!this._cloudCache.isDaemon)\r\n Logger.logInfo(loggerCategory, \"V2Checkpoint manager running with no iTwinDaemon.\");\r\n }\r\n return this._cloudCache;\r\n }\r\n\r\n /** Member names differ slightly between the V2Checkpoint api and the CloudSqlite api. Add aliases `accessName` for `accountName` and `accessToken` for `sasToken` */\r\n private static toCloudContainerProps(from: V2CheckpointAccessProps): CloudSqlite.ContainerAccessProps {\r\n return { ...from, baseUri: `https://${from.accountName}.blob.core.windows.net`, accessToken: from.sasToken, storageType: \"azure\" };\r\n }\r\n\r\n private static getContainer(v2Props: V2CheckpointAccessProps) {\r\n let container = this.containers.get(v2Props.containerId);\r\n if (!container) {\r\n // note checkpoint tokens can't be auto-refreshed because they rely on user credentials supplied through RPC. They're refreshed in SnapshotDb._refreshSas.\r\n container = CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1, logId: process.env.POD_NAME });\r\n this.containers.set(v2Props.containerId, container);\r\n }\r\n return container;\r\n }\r\n\r\n public static async attach(checkpoint: CheckpointProps): Promise<{ dbName: string, container: CloudSqlite.CloudContainer }> {\r\n let v2props: V2CheckpointAccessProps | undefined;\r\n try {\r\n v2props = await IModelHost.hubAccess.queryV2Checkpoint(checkpoint);\r\n if (!v2props)\r\n throw new Error(\"no checkpoint\");\r\n } catch (err: any) {\r\n throw new IModelError(IModelStatus.NotFound, `V2 checkpoint not found: err: ${err.message}`);\r\n }\r\n\r\n try {\r\n const container = this.getContainer(v2props);\r\n const dbName = v2props.dbName;\r\n if (!container.isConnected)\r\n container.connect(this.cloudCache);\r\n container.checkForChanges();\r\n const dbStats = container.queryDatabase(dbName);\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"Checkpoints/prefetch\", false)) {\r\n const getPrefetchConfig = (name: string, defaultVal: number) => IModelHost.appWorkspace.settings.getNumber(`Checkpoints/prefetch/${name}`, defaultVal);\r\n const minRequests = getPrefetchConfig(\"minRequests\", 3);\r\n const maxRequests = getPrefetchConfig(\"maxRequests\", 6);\r\n const timeout = getPrefetchConfig(\"timeout\", 100);\r\n const maxBlocks = getPrefetchConfig(\"maxBlocks\", 500); // default size of 2GB. Assumes a checkpoint block size of 4MB.\r\n if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks && dbStats.nPrefetch === 0) {\r\n const logPrefetch = async (prefetch: CloudSqlite.CloudPrefetch) => {\r\n const stopwatch = new StopWatch(`[${container.containerId}/${dbName}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`, { minRequests, maxRequests, timeout });\r\n const done = await prefetch.promise;\r\n Logger.logInfo(loggerCategory, `Prefetch of ${stopwatch.description} complete=${done} (${stopwatch.elapsedSeconds} seconds)`, { minRequests, maxRequests, timeout });\r\n };\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n logPrefetch(CloudSqlite.startCloudPrefetch(container, dbName, { minRequests, nRequests: maxRequests, timeout }));\r\n } else {\r\n Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits or ongoing prefetch.`, { maxBlocks, numPrefetches: dbStats?.nPrefetch, totalBlocksInDb: dbStats?.totalBlocks, v2props });\r\n }\r\n }\r\n return { dbName, container };\r\n } catch (e: any) {\r\n const error = `Cloud cache connect failed: ${e.message}`;\r\n if (checkpoint.expectV2)\r\n Logger.logError(loggerCategory, error);\r\n\r\n throw new IModelError(e.errorNumber, error);\r\n }\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n const request = job.request;\r\n const v2props: V2CheckpointAccessProps | undefined = await IModelHost.hubAccess.queryV2Checkpoint({ ...request.checkpoint, allowPreceding: true });\r\n if (!v2props)\r\n throw new IModelError(IModelStatus.NotFound, \"V2 checkpoint not found\");\r\n\r\n CheckpointManager.onDownloadV2.raiseEvent(job);\r\n const container = CloudSqlite.createCloudContainer(this.toCloudContainerProps(v2props));\r\n await CloudSqlite.transferDb(\"download\", container, { dbName: v2props.dbName, localFileName: request.localFile, onProgress: request.onProgress });\r\n return request.checkpoint.changeset.id;\r\n }\r\n\r\n /** Fully download a V2 checkpoint to a local file that can be used to create a briefcase or to work offline.\r\n * @returns a Promise that is resolved when the download completes with the changesetId of the downloaded checkpoint (which will\r\n * be the same as the requested changesetId or the most recent checkpoint before it.)\r\n */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n}\r\n\r\n/** Utility class to deal with downloading V1 checkpoints from iModelHub.\r\n * @internal\r\n */\r\nexport class V1CheckpointManager {\r\n public static getFolder(iModelId: GuidString): LocalDirName {\r\n return path.join(BriefcaseManager.getIModelPath(iModelId), \"checkpoints\");\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(checkpoint.iModelId), `${changesetId}.bim`);\r\n }\r\n\r\n public static async getCheckpointDb(request: DownloadRequest): Promise<SnapshotDb> {\r\n const db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(request.checkpoint));\r\n return (undefined !== db) ? db : Downloads.download(request, async (job: DownloadJob) => this.downloadAndOpen(job));\r\n }\r\n\r\n /** Download a V1 checkpoint */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n\r\n private static async downloadAndOpen(job: DownloadJob) {\r\n const db = CheckpointManager.tryOpenLocalFile(job.request);\r\n if (db)\r\n return db;\r\n await this.performDownload(job);\r\n await CheckpointManager.updateToRequestedVersion(job.request);\r\n return SnapshotDb.openCheckpointV1(job.request.localFile, job.request.checkpoint);\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n CheckpointManager.onDownloadV1.raiseEvent(job);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await IModelHost.hubAccess.downloadV1Checkpoint(job.request)).id;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class CheckpointManager {\r\n public static readonly onDownloadV1 = new BeEvent<(job: DownloadJob) => void>();\r\n public static readonly onDownloadV2 = new BeEvent<(job: DownloadJob) => void>();\r\n public static getKey(checkpoint: CheckpointProps) { return `${checkpoint.iModelId}:${checkpoint.changeset.id}`; }\r\n\r\n private static async doDownload(request: DownloadRequest): Promise<ChangesetId> {\r\n try {\r\n // first see if there's a V2 checkpoint available.\r\n const changesetId = await V2CheckpointManager.downloadCheckpoint(request);\r\n if (changesetId !== request.checkpoint.changeset.id)\r\n Logger.logInfo(loggerCategory, `Downloaded previous v2 checkpoint because requested checkpoint not found.`, { requestedChangesetId: request.checkpoint.changeset.id, iModelId: request.checkpoint.iModelId, changesetId, iTwinId: request.checkpoint.iTwinId });\r\n else\r\n Logger.logInfo(loggerCategory, `Downloaded v2 checkpoint.`, { iModelId: request.checkpoint.iModelId, changesetId: request.checkpoint.changeset.id, iTwinId: request.checkpoint.iTwinId });\r\n return changesetId;\r\n } catch (error: any) {\r\n if (error.errorNumber === IModelStatus.NotFound) { // No V2 checkpoint available, try a v1 checkpoint\r\n const changeset = await V1CheckpointManager.downloadCheckpoint(request);\r\n Logger.logWarning(loggerCategory, `Got an error downloading v2 checkpoint, but downloaded v1 checkpoint successfully!`, { error, iModelId: request.checkpoint.iModelId, iTwinId: request.checkpoint.iTwinId, requestedChangesetId: request.checkpoint.changeset.id, changesetId: changeset });\r\n return changeset;\r\n }\r\n throw error; // most likely, was aborted\r\n }\r\n }\r\n\r\n public static async updateToRequestedVersion(request: DownloadRequest) {\r\n const checkpoint = request.checkpoint;\r\n const targetFile = request.localFile;\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId, changeset: checkpoint.changeset };\r\n try {\r\n // Open checkpoint for write\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.None); // Ignores noisy error messages when applying changesets.\r\n const db = SnapshotDb.openForApplyChangesets(targetFile);\r\n const nativeDb = db.nativeDb;\r\n try {\r\n\r\n if (nativeDb.hasPendingTxns()) {\r\n Logger.logWarning(loggerCategory, \"Checkpoint with Txns found - deleting them\", () => traceInfo);\r\n nativeDb.deleteAllTxns();\r\n }\r\n\r\n if (nativeDb.getBriefcaseId() !== BriefcaseIdValue.Unassigned)\r\n nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);\r\n\r\n CheckpointManager.validateCheckpointGuids(checkpoint, db);\r\n // Apply change sets if necessary\r\n const currentChangeset: Mutable<ChangesetIndexAndId> = nativeDb.getCurrentChangeset();\r\n if (currentChangeset.id !== checkpoint.changeset.id) {\r\n const accessToken = checkpoint.accessToken;\r\n const toIndex = checkpoint.changeset.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId: checkpoint.iModelId, version: IModelVersion.asOfChangeSet(checkpoint.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n } else {\r\n // make sure the parent changeset index is saved in the file - old versions didn't have it.\r\n currentChangeset.index = checkpoint.changeset.index!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(currentChangeset));\r\n }\r\n } finally {\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.Error); // Turn logging back on after applying changesets.\r\n db.saveChanges();\r\n db.close();\r\n }\r\n } catch (error: any) {\r\n\r\n Logger.logError(loggerCategory, \"Error downloading checkpoint - deleting it\", () => traceInfo);\r\n IModelJsFs.removeSync(targetFile);\r\n\r\n if (error.errorNumber === ChangeSetStatus.CorruptedChangeStream || error.errorNumber === ChangeSetStatus.InvalidId || error.errorNumber === ChangeSetStatus.InvalidVersion) {\r\n Logger.logError(loggerCategory, \"Detected potential corruption of change sets. Deleting them to enable retries\", () => traceInfo);\r\n BriefcaseManager.deleteChangeSetsFromLocalDisk(checkpoint.iModelId);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** Download a checkpoint file from iModelHub into a local file specified in the request parameters. */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<void> {\r\n if (this.verifyCheckpoint(request.checkpoint, request.localFile))\r\n return;\r\n\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(request.checkpoint, alias)) {\r\n request.localFile = alias;\r\n return;\r\n }\r\n }\r\n }\r\n\r\n await this.doDownload(request);\r\n return this.updateToRequestedVersion(request);\r\n }\r\n\r\n /** checks a file's dbGuid & iTwinId for consistency, and updates the dbGuid when possible */\r\n public static validateCheckpointGuids(checkpoint: CheckpointProps, snapshotDb: SnapshotDb) {\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId };\r\n\r\n const nativeDb = snapshotDb.nativeDb;\r\n const dbChangeset = nativeDb.getCurrentChangeset();\r\n const iModelId = Guid.normalize(nativeDb.getIModelId());\r\n if (iModelId !== Guid.normalize(checkpoint.iModelId)) {\r\n if (nativeDb.isReadonly())\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iModelId is not properly set up in the checkpoint\");\r\n\r\n Logger.logWarning(loggerCategory, \"iModelId is not properly set up in the checkpoint. Updated checkpoint to the correct iModelId.\", () => ({ ...traceInfo, dbGuid: iModelId }));\r\n const iModelIdNormalized = Guid.normalize(checkpoint.iModelId);\r\n nativeDb.setIModelId(iModelIdNormalized);\r\n (snapshotDb as any)._iModelId = iModelIdNormalized;\r\n // Required to reset the ChangeSetId because setDbGuid clears the value.\r\n nativeDb.saveLocalValue(\"ParentChangeSetId\", dbChangeset.id);\r\n if (undefined !== dbChangeset.index)\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(dbChangeset));\r\n }\r\n\r\n const iTwinId = Guid.normalize(nativeDb.getITwinId());\r\n if (iTwinId !== Guid.normalize(checkpoint.iTwinId))\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iTwinId was not properly set up in the checkpoint\");\r\n }\r\n\r\n /** @returns true if the file is the checkpoint requested */\r\n public static verifyCheckpoint(checkpoint: CheckpointProps, fileName: LocalFileName): boolean {\r\n if (!IModelJsFs.existsSync(fileName))\r\n return false;\r\n\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.Readonly);\r\n } catch (error) {\r\n return false;\r\n }\r\n\r\n const isValid = checkpoint.iModelId === nativeDb.getIModelId() && checkpoint.changeset.id === nativeDb.getCurrentChangeset().id;\r\n nativeDb.closeIModel();\r\n if (!isValid)\r\n IModelJsFs.removeSync(fileName);\r\n\r\n return isValid;\r\n }\r\n\r\n /** try to open an existing local file to satisfy a download request */\r\n public static tryOpenLocalFile(request: DownloadRequest): SnapshotDb | undefined {\r\n const checkpoint = request.checkpoint;\r\n if (this.verifyCheckpoint(checkpoint, request.localFile))\r\n return SnapshotDb.openCheckpointV1(request.localFile, checkpoint);\r\n\r\n // check a list of aliases for finding checkpoints downloaded to non-default locations (e.g. from older versions)\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(checkpoint, alias)) {\r\n request.localFile = alias;\r\n return SnapshotDb.openCheckpointV1(alias, checkpoint);\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"CheckpointManager.js","sourceRoot":"","sources":["../../src/CheckpointManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2BAA2B;AAE3B,6BAA6B;AAC7B,8DAAgE;AAChE,sDAA+I;AAC/I,oDAE4B;AAE5B,mEAAgE;AAChE,yDAAsD;AACtD,+CAA4C;AAC5C,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAkD;AAElD,MAAM,cAAc,GAAG,6CAAqB,CAAC,QAAQ,CAAC;AAyBtD;;GAEG;AACH,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yBAAyB;IACzB,2DAAY,CAAA;IACZ,sBAAsB;IACtB,qDAAS,CAAA;AACX,CAAC,EALW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAKzB;AAmCD,gBAAgB;AAChB,MAAa,SAAS;IAGZ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,GAAgB,EAAE,EAAoC;QACpF,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,gDAAgD;QACvF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC/B,IAAI;YACF,OAAO,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;SACtB;gBAAS;YACR,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC9B;IACH,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,QAAuB;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAI,OAAwB,EAAE,UAA4C;QACpG,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,GAAG,GAAG,I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,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AAFrE,8CAAiB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore BLOCKCACHE\r\n\r\nimport * as path from \"path\";\r\nimport { NativeLoggerCategory } from \"@bentley/imodeljs-native\";\r\nimport { BeEvent, ChangeSetStatus, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, OpenMode, StopWatch } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseIdValue, ChangesetId, ChangesetIdWithIndex, ChangesetIndexAndId, IModelError, IModelVersion, LocalDirName, LocalFileName,\r\n} from \"@itwin/core-common\";\r\nimport { V2CheckpointAccessProps } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SnapshotDb, TokenArg } from \"./IModelDb\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/**\r\n * Properties of a checkpoint\r\n * @public\r\n */\r\nexport interface CheckpointProps extends TokenArg {\r\n readonly expectV2?: boolean;\r\n\r\n /** iTwin that the iModel belongs to */\r\n readonly iTwinId: GuidString;\r\n\r\n /** Id of the iModel */\r\n readonly iModelId: GuidString;\r\n\r\n /** changeset for the checkpoint */\r\n readonly changeset: ChangesetIdWithIndex;\r\n\r\n /** If true, then the latest successful v2 checkpoint at or before the provided changeset will be returned when calling queryV2Checkpoint. */\r\n readonly allowPreceding?: boolean;\r\n\r\n /** The number of seconds before the current token expires to attempt to reacquire a new token. Default is 1 hour. */\r\n readonly reattachSafetySeconds?: number;\r\n}\r\n\r\n/** Return value from [[ProgressFunction]].\r\n * @public\r\n */\r\nexport enum ProgressStatus {\r\n /** Continue download. */\r\n Continue = 0,\r\n /** Abort download. */\r\n Abort = 1,\r\n}\r\n\r\n/** Called to show progress during a download. If this function returns non-zero, the download is aborted.\r\n * @public\r\n */\r\nexport type ProgressFunction = (loaded: number, total: number) => ProgressStatus;\r\n\r\n/** The parameters that specify a request to download a checkpoint file from iModelHub.\r\n * @internal\r\n */\r\nexport interface DownloadRequest {\r\n /** name of local file to hold the downloaded data. */\r\n localFile: LocalFileName;\r\n\r\n /** A list of full fileName paths to test before downloading. If a valid file exists by one of these names,\r\n * no download is performed and `localFile` is updated to reflect the fact that the file exists with that name.\r\n * This can be used, for example, to look for checkpoints from previous versions if the naming strategy changes.\r\n */\r\n readonly aliasFiles?: ReadonlyArray<string>;\r\n\r\n /** Properties of the checkpoint to be downloaded */\r\n readonly checkpoint: CheckpointProps;\r\n\r\n /** If present, this function will be called to indicate progress as the briefcase is downloaded. If this\r\n * function returns a non-zero value, the download is aborted.\r\n */\r\n readonly onProgress?: ProgressFunction;\r\n}\r\n\r\n/** @internal */\r\nexport interface DownloadJob {\r\n request: DownloadRequest;\r\n promise?: Promise<any>;\r\n}\r\n\r\n/** @internal */\r\nexport class Downloads {\r\n private static _active = new Map<string, DownloadJob>();\r\n\r\n private static async process<T>(job: DownloadJob, fn: (job: DownloadJob) => Promise<T>) {\r\n const jobName = job.request.localFile; // save this, it can change inside call to `fn`!\r\n this._active.set(jobName, job);\r\n try {\r\n return await fn(job);\r\n } finally {\r\n this._active.delete(jobName);\r\n }\r\n }\r\n\r\n public static isInProgress(pathName: LocalFileName): DownloadJob | undefined {\r\n return this._active.get(pathName);\r\n }\r\n\r\n public static async download<T>(request: DownloadRequest, downloadFn: (job: DownloadJob) => Promise<T>) {\r\n const pathName = request.localFile;\r\n let job = this.isInProgress(pathName);\r\n if (undefined !== job)\r\n return job.promise;\r\n\r\n IModelJsFs.recursiveMkDirSync(path.dirname(pathName));\r\n job = { request };\r\n return job.promise = this.process(job, downloadFn);\r\n }\r\n}\r\n\r\n/**\r\n * Utility class for opening V2 checkpoints from cloud containers, and also for downloading them.\r\n * @internal\r\n*/\r\nexport class V2CheckpointManager {\r\n public static readonly cloudCacheName = \"v2Checkpoints\";\r\n private static _cloudCache?: CloudSqlite.CloudCache;\r\n private static containers = new Map<string, CloudSqlite.CloudContainer>();\r\n\r\n public static getFolder(): LocalDirName {\r\n const cloudCachePath = path.join(BriefcaseManager.cacheDir, V2CheckpointManager.cloudCacheName);\r\n if (!(IModelJsFs.existsSync(cloudCachePath))) {\r\n IModelJsFs.recursiveMkDirSync(cloudCachePath);\r\n }\r\n return cloudCachePath;\r\n }\r\n\r\n /* only used by tests that reset the state of the v2CheckpointManager. all dbs should be closed before calling this function. */\r\n public static cleanup(): void {\r\n for (const [_, value] of this.containers.entries()) {\r\n if (value.isConnected)\r\n value.disconnect({ detach: true });\r\n }\r\n\r\n CloudSqlite.CloudCaches.dropCache(this.cloudCacheName)?.destroy();\r\n this._cloudCache = undefined;\r\n this.containers.clear();\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(), `${changesetId}.bim`);\r\n }\r\n\r\n private static get cloudCache(): CloudSqlite.CloudCache {\r\n if (!this._cloudCache) {\r\n let cacheDir = process.env.CHECKPOINT_CACHE_DIR;\r\n if (!cacheDir) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No CHECKPOINT_CACHE_DIR found in process.env, using ${cacheDir} instead.`);\r\n } else {\r\n // Make sure the checkpoint_cache_dir has an iTwinDaemon specific file in it, otherwise fall back to other directory.\r\n if (!(IModelJsFs.existsSync(path.join(cacheDir, \"portnumber.bcv\")))) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No evidence of the iTwinDaemon in provided CHECKPOINT_CACHE_DIR: ${process.env.CHECKPOINT_CACHE_DIR}, using ${cacheDir} instead.`);\r\n }\r\n }\r\n\r\n this._cloudCache = CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir });\r\n\r\n // Its fine if its not a daemon, but lets log an info message\r\n if (!this._cloudCache.isDaemon)\r\n Logger.logInfo(loggerCategory, \"V2Checkpoint manager running with no iTwinDaemon.\");\r\n }\r\n return this._cloudCache;\r\n }\r\n\r\n /** Member names differ slightly between the V2Checkpoint api and the CloudSqlite api. Add aliases `accessName` for `accountName` and `accessToken` for `sasToken` */\r\n private static toCloudContainerProps(from: V2CheckpointAccessProps): CloudSqlite.ContainerAccessProps {\r\n return { ...from, baseUri: `https://${from.accountName}.blob.core.windows.net`, accessToken: from.sasToken, storageType: \"azure\" };\r\n }\r\n\r\n private static getContainer(v2Props: V2CheckpointAccessProps) {\r\n let container = this.containers.get(v2Props.containerId);\r\n if (!container) {\r\n // note checkpoint tokens can't be auto-refreshed because they rely on user credentials supplied through RPC. They're refreshed in SnapshotDb._refreshSas.\r\n container = CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1, logId: process.env.POD_NAME });\r\n this.containers.set(v2Props.containerId, container);\r\n }\r\n return container;\r\n }\r\n\r\n public static async attach(checkpoint: CheckpointProps): Promise<{ dbName: string, container: CloudSqlite.CloudContainer }> {\r\n let v2props: V2CheckpointAccessProps | undefined;\r\n try {\r\n v2props = await IModelHost.hubAccess.queryV2Checkpoint(checkpoint);\r\n if (!v2props)\r\n throw new Error(\"no checkpoint\");\r\n } catch (err: any) {\r\n throw new IModelError(IModelStatus.NotFound, `V2 checkpoint not found: err: ${err.message}`);\r\n }\r\n\r\n try {\r\n const container = this.getContainer(v2props);\r\n const dbName = v2props.dbName;\r\n if (!container.isConnected)\r\n container.connect(this.cloudCache);\r\n container.checkForChanges();\r\n const dbStats = container.queryDatabase(dbName);\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"Checkpoints/prefetch\", false)) {\r\n const getPrefetchConfig = (name: string, defaultVal: number) => IModelHost.appWorkspace.settings.getNumber(`Checkpoints/prefetch/${name}`, defaultVal);\r\n const minRequests = getPrefetchConfig(\"minRequests\", 3);\r\n const maxRequests = getPrefetchConfig(\"maxRequests\", 6);\r\n const timeout = getPrefetchConfig(\"timeout\", 100);\r\n const maxBlocks = getPrefetchConfig(\"maxBlocks\", 500); // default size of 2GB. Assumes a checkpoint block size of 4MB.\r\n if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks && dbStats.nPrefetch === 0) {\r\n const logPrefetch = async (prefetch: CloudSqlite.CloudPrefetch) => {\r\n const stopwatch = new StopWatch(`[${container.containerId}/${dbName}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`, { minRequests, maxRequests, timeout });\r\n const done = await prefetch.promise;\r\n Logger.logInfo(loggerCategory, `Prefetch of ${stopwatch.description} complete=${done} (${stopwatch.elapsedSeconds} seconds)`, { minRequests, maxRequests, timeout });\r\n };\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n logPrefetch(CloudSqlite.startCloudPrefetch(container, dbName, { minRequests, nRequests: maxRequests, timeout }));\r\n } else {\r\n Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits or ongoing prefetch.`, { maxBlocks, numPrefetches: dbStats?.nPrefetch, totalBlocksInDb: dbStats?.totalBlocks, v2props });\r\n }\r\n }\r\n return { dbName, container };\r\n } catch (e: any) {\r\n const error = `Cloud cache connect failed: ${e.message}`;\r\n if (checkpoint.expectV2)\r\n Logger.logError(loggerCategory, error);\r\n\r\n throw new IModelError(e.errorNumber, error);\r\n }\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n const request = job.request;\r\n const v2props: V2CheckpointAccessProps | undefined = await IModelHost.hubAccess.queryV2Checkpoint({ ...request.checkpoint, allowPreceding: true });\r\n if (!v2props)\r\n throw new IModelError(IModelStatus.NotFound, \"V2 checkpoint not found\");\r\n\r\n CheckpointManager.onDownloadV2.raiseEvent(job);\r\n const container = CloudSqlite.createCloudContainer(this.toCloudContainerProps(v2props));\r\n await CloudSqlite.transferDb(\"download\", container, { dbName: v2props.dbName, localFileName: request.localFile, onProgress: request.onProgress });\r\n return request.checkpoint.changeset.id;\r\n }\r\n\r\n /** Fully download a V2 checkpoint to a local file that can be used to create a briefcase or to work offline.\r\n * @returns a Promise that is resolved when the download completes with the changesetId of the downloaded checkpoint (which will\r\n * be the same as the requested changesetId or the most recent checkpoint before it.)\r\n */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n}\r\n\r\n/** Utility class to deal with downloading V1 checkpoints from iModelHub.\r\n * @internal\r\n */\r\nexport class V1CheckpointManager {\r\n public static getFolder(iModelId: GuidString): LocalDirName {\r\n return path.join(BriefcaseManager.getIModelPath(iModelId), \"checkpoints\");\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(checkpoint.iModelId), `${changesetId}.bim`);\r\n }\r\n\r\n public static async getCheckpointDb(request: DownloadRequest): Promise<SnapshotDb> {\r\n const db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(request.checkpoint));\r\n return (undefined !== db) ? db : Downloads.download(request, async (job: DownloadJob) => this.downloadAndOpen(job));\r\n }\r\n\r\n /** Download a V1 checkpoint */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n\r\n private static async downloadAndOpen(job: DownloadJob) {\r\n const db = CheckpointManager.tryOpenLocalFile(job.request);\r\n if (db)\r\n return db;\r\n await this.performDownload(job);\r\n await CheckpointManager.updateToRequestedVersion(job.request);\r\n return SnapshotDb.openCheckpointV1(job.request.localFile, job.request.checkpoint);\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n CheckpointManager.onDownloadV1.raiseEvent(job);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await IModelHost.hubAccess.downloadV1Checkpoint(job.request)).id;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class CheckpointManager {\r\n public static readonly onDownloadV1 = new BeEvent<(job: DownloadJob) => void>();\r\n public static readonly onDownloadV2 = new BeEvent<(job: DownloadJob) => void>();\r\n public static getKey(checkpoint: CheckpointProps) { return `${checkpoint.iModelId}:${checkpoint.changeset.id}`; }\r\n\r\n private static async doDownload(request: DownloadRequest): Promise<ChangesetId> {\r\n try {\r\n // first see if there's a V2 checkpoint available.\r\n const stopwatch = new StopWatch(`[${request.checkpoint.changeset.id}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting download of V2 checkpoint with id ${stopwatch.description}`);\r\n const changesetId = await V2CheckpointManager.downloadCheckpoint(request);\r\n Logger.logInfo(loggerCategory, `Downloaded V2 checkpoint with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\r\n if (changesetId !== request.checkpoint.changeset.id)\r\n Logger.logInfo(loggerCategory, `Downloaded previous v2 checkpoint because requested checkpoint not found.`, { requestedChangesetId: request.checkpoint.changeset.id, iModelId: request.checkpoint.iModelId, changesetId, iTwinId: request.checkpoint.iTwinId });\r\n else\r\n Logger.logInfo(loggerCategory, `Downloaded v2 checkpoint.`, { iModelId: request.checkpoint.iModelId, changesetId: request.checkpoint.changeset.id, iTwinId: request.checkpoint.iTwinId });\r\n return changesetId;\r\n } catch (error: any) {\r\n if (error.errorNumber === IModelStatus.NotFound) { // No V2 checkpoint available, try a v1 checkpoint\r\n const changeset = await V1CheckpointManager.downloadCheckpoint(request);\r\n Logger.logWarning(loggerCategory, `Got an error downloading v2 checkpoint, but downloaded v1 checkpoint successfully!`, { error, iModelId: request.checkpoint.iModelId, iTwinId: request.checkpoint.iTwinId, requestedChangesetId: request.checkpoint.changeset.id, changesetId: changeset });\r\n return changeset;\r\n }\r\n throw error; // most likely, was aborted\r\n }\r\n }\r\n\r\n public static async updateToRequestedVersion(request: DownloadRequest) {\r\n const checkpoint = request.checkpoint;\r\n const targetFile = request.localFile;\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId, changeset: checkpoint.changeset };\r\n try {\r\n // Open checkpoint for write\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.None); // Ignores noisy error messages when applying changesets.\r\n const db = SnapshotDb.openForApplyChangesets(targetFile);\r\n const nativeDb = db.nativeDb;\r\n try {\r\n\r\n if (nativeDb.hasPendingTxns()) {\r\n Logger.logWarning(loggerCategory, \"Checkpoint with Txns found - deleting them\", () => traceInfo);\r\n nativeDb.deleteAllTxns();\r\n }\r\n\r\n if (nativeDb.getBriefcaseId() !== BriefcaseIdValue.Unassigned)\r\n nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);\r\n\r\n CheckpointManager.validateCheckpointGuids(checkpoint, db);\r\n // Apply change sets if necessary\r\n const currentChangeset: Mutable<ChangesetIndexAndId> = nativeDb.getCurrentChangeset();\r\n if (currentChangeset.id !== checkpoint.changeset.id) {\r\n const accessToken = checkpoint.accessToken;\r\n const toIndex = checkpoint.changeset.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId: checkpoint.iModelId, version: IModelVersion.asOfChangeSet(checkpoint.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n } else {\r\n // make sure the parent changeset index is saved in the file - old versions didn't have it.\r\n currentChangeset.index = checkpoint.changeset.index!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(currentChangeset));\r\n }\r\n } finally {\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.Error); // Turn logging back on after applying changesets.\r\n db.saveChanges();\r\n db.close();\r\n }\r\n } catch (error: any) {\r\n\r\n Logger.logError(loggerCategory, \"Error downloading checkpoint - deleting it\", () => traceInfo);\r\n IModelJsFs.removeSync(targetFile);\r\n\r\n if (error.errorNumber === ChangeSetStatus.CorruptedChangeStream || error.errorNumber === ChangeSetStatus.InvalidId || error.errorNumber === ChangeSetStatus.InvalidVersion) {\r\n Logger.logError(loggerCategory, \"Detected potential corruption of change sets. Deleting them to enable retries\", () => traceInfo);\r\n BriefcaseManager.deleteChangeSetsFromLocalDisk(checkpoint.iModelId);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** Download a checkpoint file from iModelHub into a local file specified in the request parameters. */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<void> {\r\n if (this.verifyCheckpoint(request.checkpoint, request.localFile))\r\n return;\r\n\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(request.checkpoint, alias)) {\r\n request.localFile = alias;\r\n return;\r\n }\r\n }\r\n }\r\n\r\n await this.doDownload(request);\r\n return this.updateToRequestedVersion(request);\r\n }\r\n\r\n /** checks a file's dbGuid & iTwinId for consistency, and updates the dbGuid when possible */\r\n public static validateCheckpointGuids(checkpoint: CheckpointProps, snapshotDb: SnapshotDb) {\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId };\r\n\r\n const nativeDb = snapshotDb.nativeDb;\r\n const dbChangeset = nativeDb.getCurrentChangeset();\r\n const iModelId = Guid.normalize(nativeDb.getIModelId());\r\n if (iModelId !== Guid.normalize(checkpoint.iModelId)) {\r\n if (nativeDb.isReadonly())\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iModelId is not properly set up in the checkpoint\");\r\n\r\n Logger.logWarning(loggerCategory, \"iModelId is not properly set up in the checkpoint. Updated checkpoint to the correct iModelId.\", () => ({ ...traceInfo, dbGuid: iModelId }));\r\n const iModelIdNormalized = Guid.normalize(checkpoint.iModelId);\r\n nativeDb.setIModelId(iModelIdNormalized);\r\n (snapshotDb as any)._iModelId = iModelIdNormalized;\r\n // Required to reset the ChangeSetId because setDbGuid clears the value.\r\n nativeDb.saveLocalValue(\"ParentChangeSetId\", dbChangeset.id);\r\n if (undefined !== dbChangeset.index)\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(dbChangeset));\r\n }\r\n\r\n const iTwinId = Guid.normalize(nativeDb.getITwinId());\r\n if (iTwinId !== Guid.normalize(checkpoint.iTwinId))\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iTwinId was not properly set up in the checkpoint\");\r\n }\r\n\r\n /** @returns true if the file is the checkpoint requested */\r\n public static verifyCheckpoint(checkpoint: CheckpointProps, fileName: LocalFileName): boolean {\r\n if (!IModelJsFs.existsSync(fileName))\r\n return false;\r\n\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.Readonly);\r\n } catch (error) {\r\n return false;\r\n }\r\n\r\n const isValid = checkpoint.iModelId === nativeDb.getIModelId() && checkpoint.changeset.id === nativeDb.getCurrentChangeset().id;\r\n nativeDb.closeIModel();\r\n if (!isValid)\r\n IModelJsFs.removeSync(fileName);\r\n\r\n return isValid;\r\n }\r\n\r\n /** try to open an existing local file to satisfy a download request */\r\n public static tryOpenLocalFile(request: DownloadRequest): SnapshotDb | undefined {\r\n const checkpoint = request.checkpoint;\r\n if (this.verifyCheckpoint(checkpoint, request.localFile))\r\n return SnapshotDb.openCheckpointV1(request.localFile, checkpoint);\r\n\r\n // check a list of aliases for finding checkpoints downloaded to non-default locations (e.g. from older versions)\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(checkpoint, alias)) {\r\n request.localFile = alias;\r\n return SnapshotDb.openCheckpointV1(alias, checkpoint);\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
|
package/lib/cjs/CloudSqlite.js
CHANGED
|
@@ -48,7 +48,7 @@ var CloudSqlite;
|
|
|
48
48
|
container.lockExpireSeconds = args.lockExpireSeconds ?? 60 * 60; // default is 1 hour
|
|
49
49
|
// don't refresh tokens for public containers or if refreshSeconds<=0
|
|
50
50
|
if (!args.isPublic && refreshSeconds > 0) {
|
|
51
|
-
const tokenProps = { baseUri: args.baseUri, containerId: args.containerId,
|
|
51
|
+
const tokenProps = { baseUri: args.baseUri, containerId: args.containerId, accessLevel: args.accessLevel };
|
|
52
52
|
const doRefresh = async () => {
|
|
53
53
|
let newToken;
|
|
54
54
|
const url = `[${tokenProps.baseUri}/${tokenProps.containerId}]`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../src/CloudSqlite.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2BAA2C;AAC3C,+BAAqC;AACrC,8DAAyD;AACzD,sDAE6B;AAE7B,iEAAuD;AACvD,6CAA0D;AAC1D,6CAA0C;AAC1C,2CAAyC;AAIzC,+BAA+B;AAE/B;;;GAGG;AACH,IAAiB,WAAW,CAo3B3B;AAp3BD,WAAiB,WAAW;IAE1B,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,qBAAM,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IACpE,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,qBAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IAEtE;;;OAGG;IACI,KAAK,UAAU,YAAY,CAAC,IAA4D;QAC7F,wGAAwG;QACxG,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,uBAAU,CAAC,cAAc,EAAE,CAAC,CAAC;QACxF,MAAM,QAAQ,GAAG,MAAM,oCAAa,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACnF,OAAO,QAAQ,EAAE,KAAK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right (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport { mkdirSync, unlinkSync } from \"fs\";\r\nimport { dirname, join } from \"path\";\r\nimport { NativeLibrary } from \"@bentley/imodeljs-native\";\r\nimport {\r\n AccessToken, BeDuration, BriefcaseStatus, Constructor, GuidString, Logger, OpenMode, Optional, PickAsyncMethods, PickMethods, StopWatch,\r\n} from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { BlobContainer } from \"./BlobContainerService\";\r\nimport { IModelHost, KnownLocations } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { RpcTrace } from \"./rpc/tracing\";\r\n\r\nimport type { SQLiteDb, VersionedSqliteDb } from \"./SQLiteDb\";\r\n\r\n// spell:ignore logmsg httpcode\r\n\r\n/**\r\n * Types for accessing SQLite databases stored in cloud containers.\r\n * @beta\r\n */\r\nexport namespace CloudSqlite {\r\n\r\n const logInfo = (msg: string) => Logger.logInfo(\"CloudSqlite\", msg);\r\n const logError = (msg: string) => Logger.logError(\"CloudSqlite\", msg);\r\n\r\n /**\r\n * Request a new AccessToken for a cloud container using the [[BlobContainer]] service.\r\n * If the service is unavailable or returns an error, an empty token is returned.\r\n */\r\n export async function requestToken(args: Optional<BlobContainer.RequestTokenProps, \"userToken\">): Promise<AccessToken> {\r\n // allow the userToken to be supplied via Rpc. If not supplied, or blank, use the backend's accessToken.\r\n const userToken = args.userToken ? args.userToken : (await IModelHost.getAccessToken());\r\n const response = await BlobContainer.service?.requestToken({ ...args, userToken });\r\n return response?.token ?? \"\";\r\n }\r\n\r\n interface CloudContainerInternal extends CloudContainer {\r\n timer?: NodeJS.Timeout;\r\n refreshPromise?: Promise<void>;\r\n lockExpireSeconds: number;\r\n writeLockHeldBy?: string;\r\n writeLockExpires?: string;\r\n }\r\n\r\n /**\r\n * Create a new CloudContainer from a ContainerAccessProps. For non-public containers, a valid accessToken must be provided before the container\r\n * can be used (e.g. via [[CloudSqlite.requestToken]]).\r\n * @note After the container is successfully connected to a CloudCache, it will begin auto-refreshing its accessToken every `tokenRefreshSeconds` seconds (default is 1 hour)\r\n * until it is disconnected. However, if the container is public, or if `tokenRefreshSeconds` is <=0, auto-refresh is not enabled.\r\n */\r\n export function createCloudContainer(args: ContainerAccessProps & { accessLevel?: BlobContainer.RequestAccessLevel }): CloudContainer {\r\n const container = new NativeLibrary.nativeLib.CloudContainer(args) as CloudContainerInternal;\r\n const refreshSeconds = (undefined !== args.tokenRefreshSeconds) ? args.tokenRefreshSeconds : 60 * 60; // default is 1 hour\r\n container.lockExpireSeconds = args.lockExpireSeconds ?? 60 * 60; // default is 1 hour\r\n\r\n // don't refresh tokens for public containers or if refreshSeconds<=0\r\n if (!args.isPublic && refreshSeconds > 0) {\r\n const tokenProps = { baseUri: args.baseUri, containerId: args.containerId, storageType: args.storageType, accessLevel: args.accessLevel };\r\n const doRefresh = async () => {\r\n let newToken: AccessToken | undefined;\r\n const url = `[${tokenProps.baseUri}/${tokenProps.containerId}]`;\r\n try {\r\n newToken = await CloudSqlite.requestToken(tokenProps);\r\n logInfo(`Refreshed token for container ${url}`);\r\n } catch (err: any) {\r\n logError(`Error refreshing token for container ${url}: ${err.message}`);\r\n }\r\n container.accessToken = newToken ?? \"\";\r\n };\r\n const tokenRefreshFn = () => {\r\n container.timer = setTimeout(async () => {\r\n container.refreshPromise = doRefresh(); // this promise is stored on the container so it can be awaited in tests\r\n await container.refreshPromise;\r\n container.refreshPromise = undefined;\r\n tokenRefreshFn(); // schedule next refresh\r\n }, refreshSeconds * 1000);\r\n };\r\n container.onConnected = tokenRefreshFn; // schedule the first refresh when the container is connected\r\n container.onDisconnect = () => { // clear the refresh timer when the container is disconnected\r\n if (container.timer !== undefined) {\r\n clearTimeout(container.timer);\r\n container.timer = undefined;\r\n }\r\n };\r\n }\r\n return container;\r\n }\r\n\r\n /** Begin prefetching all blocks for a database in a CloudContainer in the background. */\r\n export function startCloudPrefetch(container: CloudContainer, dbName: string, args?: PrefetchProps): CloudPrefetch {\r\n return new NativeLibrary.nativeLib.CloudPrefetch(container, dbName, args);\r\n }\r\n export interface ContainerProps {\r\n /** The type of storage provider. */\r\n storageType: \"azure\" | \"google\";\r\n /** The base URI for the container. */\r\n baseUri: string;\r\n /** The name of the container. */\r\n containerId: string;\r\n /** true if the container is public (doesn't require authorization) */\r\n isPublic?: boolean;\r\n }\r\n\r\n /** Properties to access a CloudContainer. */\r\n export interface ContainerAccessProps extends ContainerProps {\r\n /** an alias for the container. Defaults to `containerId` */\r\n alias?: string;\r\n /** SAS token that grants access to the container. */\r\n accessToken: string;\r\n /** if true, container is allowed to request the write lock. */\r\n writeable?: boolean;\r\n /** if true, container is attached in \"secure\" mode (blocks are encrypted). Only supported in daemon mode. */\r\n secure?: boolean;\r\n /** string attached to log messages from CloudSQLite. This is most useful for identifying usage from daemon mode. */\r\n logId?: string;\r\n /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */\r\n lockExpireSeconds?: number;\r\n /** number of seconds between auto-refresh of access token. If <=0 no auto-refresh. Default is 1 hour (60*60) */\r\n tokenRefreshSeconds?: number;\r\n }\r\n\r\n /** Returned from `CloudContainer.queryDatabase` describing one database in the container */\r\n export interface CachedDbProps {\r\n /** The total number of blocks in the database. */\r\n readonly totalBlocks: number;\r\n /** the number of blocks of the database that have been downloaded into the CloudCache */\r\n readonly localBlocks: number;\r\n /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */\r\n readonly dirtyBlocks: number;\r\n /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */\r\n readonly transactions: boolean;\r\n /** the state of this database. Indicates whether the database is new or deleted since last upload */\r\n readonly state: \"\" | \"copied\" | \"deleted\";\r\n /** current number of clients that have this database open. */\r\n readonly nClient: number;\r\n /** current number of ongoing prefetches on this database. */\r\n readonly nPrefetch: number;\r\n }\r\n\r\n /** Filter options passed to CloudContainer.queryHttpLog\r\n * @internal\r\n */\r\n export interface BcvHttpLogFilterOptions {\r\n /** only return rows whose ID is >= the provided id */\r\n startFromId?: number;\r\n /** only return rows whose endTime is null OR >= the provided endTime. */\r\n finishedAtOrAfterTime?: string;\r\n /** only return rows with a non-null end_time. */\r\n showOnlyFinished?: boolean;\r\n }\r\n\r\n /** Returned from 'CloudContainer.queryHttpLog' describing a row in the bcv_http_log table.\r\n * @internal\r\n */\r\n export interface BcvHttpLog {\r\n /** Unique, monotonically increasing id value */\r\n readonly id: number;\r\n /** Time request was made, as iso-8601 */\r\n readonly startTime: string;\r\n /** Time reply received, as iso-8601 (may be undefined) */\r\n readonly endTime: string | undefined;\r\n /** \"PUT\", \"GET\", etc. */\r\n readonly method: string;\r\n /** LogId of client that caused this request. Will be \"prefetch\" for prefetch requests. */\r\n readonly logId: string;\r\n /** Log message associated with request */\r\n readonly logmsg: string;\r\n /** URI of request */\r\n readonly uri: string;\r\n /** HTTP response code (e.g. 200) */\r\n readonly httpcode: number;\r\n }\r\n\r\n /** The name of a CloudSqlite database within a CloudContainer. */\r\n export interface DbNameProp {\r\n /** the name of the database within the CloudContainer.\r\n * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/\r\n dbName: string;\r\n }\r\n\r\n /** Properties for accessing a database within a CloudContainer */\r\n export interface DbProps extends DbNameProp {\r\n /** the name of the local file to access the database. */\r\n localFileName: LocalFileName;\r\n }\r\n\r\n export type TransferDirection = \"upload\" | \"download\";\r\n export interface TransferProgress {\r\n /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */\r\n onProgress?: (loaded: number, total: number) => number;\r\n }\r\n\r\n export interface CloudHttpProps {\r\n /** The number of simultaneous HTTP requests. Default is 6. */\r\n nRequests?: number;\r\n }\r\n\r\n export interface PrefetchProps extends CloudHttpProps {\r\n /** timeout between requests, in milliseconds. Default is 100. */\r\n timeout?: number;\r\n /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */\r\n minRequests?: number;\r\n }\r\n\r\n export type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;\r\n\r\n /** Properties for creating a CloudCache. */\r\n export interface CacheProps extends CloudHttpProps {\r\n /** full path of directory for cache to store its files. Must be on a (preferably fast) local drive, and must be empty when the cache is first created. */\r\n rootDir: string;\r\n /** name of this cache. It is possible to have more than one CloudCache in the same session, but each must have a unique name. */\r\n name: string;\r\n /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */\r\n cacheSize?: string;\r\n /** turn on diagnostics for `curl` (outputs to stderr) */\r\n curlDiagnostics?: boolean;\r\n }\r\n\r\n /** Parameters used to obtain the write lock on a cloud container */\r\n export interface ObtainLockParams {\r\n /** a string that identifies me to others if I hold the lock while they attempt to acquire it. */\r\n user?: string;\r\n /** number of times to retry in the event the lock currently held by someone else.\r\n * After this number of attempts, `onFailure` is called. Default is 20.\r\n */\r\n nRetries: number;\r\n /** Delay between retries, in milliseconds. Default is 100. */\r\n retryDelayMs: number;\r\n /** function called if lock cannot be obtained after all retries. It is called with the name of the user currently holding the lock and\r\n * generally is expected that the user will be consulted whether to wait further.\r\n * If this function returns \"stop\", an exception will be thrown. Otherwise the retry cycle is restarted.\r\n */\r\n onFailure?: WriteLockBusyHandler;\r\n }\r\n\r\n /** @internal */\r\n export interface LockAndOpenArgs extends SQLiteDb.WithOpenDbArgs {\r\n /** a string that identifies me to others if I hold the lock while they attempt to acquire it. */\r\n user: string;\r\n /** the name of the database within the container */\r\n dbName: string;\r\n /** the CloudContainer on which the operation will be performed */\r\n container: CloudContainer;\r\n /** if present, function called when the write lock is currently held by another user. */\r\n busyHandler?: WriteLockBusyHandler;\r\n /** if present, open mode for Db. Default is ReadWrite */\r\n openMode?: OpenMode;\r\n }\r\n\r\n /** Logging categories for `CloudCache.setLogMask` */\r\n export enum LoggingMask {\r\n /** log all HTTP requests and responses */\r\n HTTP = 0x01,\r\n /** log as blocks become dirty and must be uploaded */\r\n DirtyBlocks = 0x02,\r\n /** log as blocks are added to the delete list */\r\n AddToDelete = 0x04,\r\n /** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */\r\n LifecycleEvents = 0x08,\r\n /** Turn on all logging categories */\r\n All = 0xff,\r\n /** Disable logging */\r\n None = 0,\r\n }\r\n\r\n /**\r\n * A local cache for storing data downloaded from many CloudSqlite databases. This object refers to a directory on the local filesystem\r\n * and is used to **connect** CloudContainers so they may be accessed. It maintains the state of the local copy of\r\n * the downloaded data from SQLiteDbs in CloudContainers across sessions.\r\n *\r\n * Notes:\r\n * - CloudCaches have a name, used internally by CloudSqlite, that must be unique. CloudCaches are created and maintained via [[CloudCaches.getCache]].\r\n * - All CloudContainers connected to a given CloudCache must have the same block size, as determined by the first CloudContainer connected.\r\n * - they have a maximum size that limits the amount of disk space they can consume. When the maximum size of a CloudCache is reached,\r\n * the least recently used blocks are removed to make room for new blocks.\r\n * - CloudCaches may only be used by a single process at a time. An exception is thrown if you attempt to access a CloudCache from a\r\n * second process if it is already in use by another process. Note: for a readonly CloudCache, a \"daemon\" process can be used to\r\n * share a CloudCache across processes. See its documentation for details.\r\n * - Generally, it is expected that there only be a few CloudCaches and they be shared by all applications. Each CloudCache can consume\r\n * its maximum disk space, so controlling system-wide disk usage is complicated. The only reason to make a new CloudCache is either\r\n * for containers with a different block size, or to purposely control local disk space usage for a specific set of containers.\r\n * - The contents of the cache directory are entirely controlled by CloudSqlite and should be empty when the cache is\r\n * first created and never modified directly thereafter.\r\n */\r\n export interface CloudCache {\r\n /** `true` if this CloudCache is connected to a daemon process */\r\n get isDaemon(): boolean;\r\n /** The name for this CloudCache. */\r\n get name(): string;\r\n /** The root directory of this CloudCache on a local drive. */\r\n get rootDir(): LocalDirName;\r\n /** A guid for this CloudCache. It is assigned when the CloudCache is first created and used for acquiring write locks. */\r\n get guid(): GuidString;\r\n /** Configure logging for this CloudCache.\r\n * @param mask A bitmask of `LoggingMask` values\r\n * @note this method does nothing if [[isDaemon]] is true. Daemon logging is configured when the daemon is started.\r\n * @note HTTP logging can be happen on multiple threads and may be buffered. To see buffered log messages, periodically call\r\n * `[[IModelHost.flushLog]]\r\n */\r\n setLogMask(mask: number): void;\r\n /**\r\n * destroy this CloudCache to end this session. All currently connected CloudContainers are disconnected first.\r\n * @note this does *not* delete the local directory. Its contents are maintained so it can be used in future sessions.\r\n * @note this function is automatically called on [[IModelHost.shutdown]], so it is only called directly for tests.\r\n * @internal\r\n */\r\n destroy(): void;\r\n }\r\n\r\n /**\r\n * A CloudSqlite container that may be connected to a CloudCache. A CloudContainer maps a container in a cloud blob-storage\r\n * account to a local cache, so that the contents of a database in the container may be accessed as if it were a local file.\r\n *\r\n * Notes:\r\n * - all methods and accessors of this interface (other than `initializeContainer`) require that the `connect` method be successfully called first.\r\n * Otherwise they will throw an exception or return meaningless values.\r\n * - before a SQLiteDb in a container may be opened for write access, the container's write lock must be held (see [[acquireWriteLock]].)\r\n * - a single CloudContainer may hold more than one SQLiteDb, but often they are 1:1.\r\n * - the write lock is per-Container, not per-SQLiteDb (which is the reason they are often 1:1)\r\n * - the accessToken (a SAS key) member provides time limited, restricted, access to the container. It must be refreshed before it expires.\r\n * - when a CloudContainer is created, it may either be readonly or writeable. If a container is never meant to be used for writes,\r\n * it is slightly more efficient to indicate that by passing `writeable: false`\r\n */\r\n export interface CloudContainer {\r\n onConnect?: (container: CloudContainer, cache: CloudCache) => void;\r\n onConnected?: (container: CloudContainer) => void;\r\n onDisconnect?: (container: CloudContainer, detach: boolean) => void;\r\n onDisconnected?: (container: CloudContainer, detach: boolean) => void;\r\n\r\n readonly cache?: CloudCache;\r\n /** the baseUri of this container */\r\n get baseUri(): string;\r\n /** the storageType of this container */\r\n get storageType(): string;\r\n /** The ContainerId within a storage account. */\r\n get containerId(): string;\r\n /** The *alias* to identify this CloudContainer in a CloudCache. Usually just the ContainerId. */\r\n get alias(): string;\r\n /** The logId. */\r\n get logId(): string;\r\n /** true if this CloudContainer is currently connected to a CloudCache via the `connect` method. */\r\n get isConnected(): boolean;\r\n /** true if this CloudContainer was created with the `writeable` flag (and its `accessToken` supplies write access). */\r\n get isWriteable(): boolean;\r\n /** true if this container is public (doesn't require authorization ). */\r\n get isPublic(): boolean;\r\n /** true if this CloudContainer currently holds the write lock for its container in the cloud. */\r\n get hasWriteLock(): boolean;\r\n /** true if this CloudContainer has local changes that have not be uploaded to its container in the cloud. */\r\n get hasLocalChanges(): boolean;\r\n /** The current accessToken providing access to the cloud container */\r\n get accessToken(): string;\r\n set accessToken(val: string);\r\n /** Get the number of garbage blocks in this container that can be purged. */\r\n get garbageBlocks(): number;\r\n /** The block size for this CloudContainer. */\r\n get blockSize(): number;\r\n\r\n /**\r\n * initialize a cloud blob-store container to be used as a new CloudContainer. This creates the container's manifest of its contents, and should be\r\n * performed on an empty container. If an existing manifest is present, it is destroyed and a new one is created (essentially emptying the container.)\r\n */\r\n initializeContainer(args: { checksumBlockNames?: boolean, blockSize: number }): void;\r\n\r\n /**\r\n * Connect this CloudContainer to a CloudCache for accessing and/or modifying its contents.\r\n * @note A CloudCache is a local directory holding copies of information from the cloud. It is persistent across sessions,\r\n * but this method must be called each session to (re)establish the connection to the CloudCache. If the CloudCache was previously populated,\r\n * this method may be called and will succeed *even when offline* or without a valid `accessToken`.\r\n */\r\n connect(cache: CloudCache): void;\r\n\r\n /**\r\n * Attempt to acquire the write lock for this CloudContainer. For this to succeed:\r\n * 1. it must be connected to a `CloudCache`\r\n * 2. this CloudContainer must have been constructed with `writeable: true`\r\n * 3. the `accessToken` must authorize write access\r\n * 4. no other process may be holding an unexpired write lock\r\n * @throws if any of the above conditions fail\r\n * @note Write locks *expire* after the duration specified in the `durationSeconds` property of the constructor argument, in case a process\r\n * crashes or otherwise fails to release the lock. Calling `acquireWriteLock` with the lock already held resets the lock duration from the current time,\r\n * so long running processes should call this method periodically to ensure their lock doesn't expire (they should also make sure their accessToken is refreshed\r\n * before it expires.)\r\n * @note on success, the container is synchronized with its contents in the cloud before the promise resolves.\r\n * @param user An identifier of the process/user locking the CloudContainer. In the event of a write lock\r\n * collision, this string will be included in the exception string of the *other* process attempting to obtain a write lock so that users may identify who currently holds\r\n * the lock.\r\n */\r\n acquireWriteLock(user: string): void;\r\n\r\n /**\r\n * Release the write lock if it is currently held.\r\n *\r\n * Notes:\r\n * - if there are local changes that have not been uploaded, they are automatically uploaded before the write lock is released.\r\n * - if the write lock is not held, this method does nothing.\r\n */\r\n releaseWriteLock(): void;\r\n\r\n /**\r\n * Destroy any currently valid write lock from this or any other process. This is obviously very dangerous and defeats the purpose of write locking.\r\n * This method exists only for administrator tools to clear a failed process without waiting for the expiration period. It can also be useful for tests.\r\n * For this to succeed, all of the conditions of `acquireWriteLock` must be true other than #4.\r\n */\r\n clearWriteLock(): void;\r\n\r\n /**\r\n * Abandon any local changes in this container. If the write lock is currently held, it is released.\r\n * This function fails with BE_SQLITE_BUSY if there are any open read or write transactions on *any* database in the container.\r\n */\r\n abandonChanges(): void;\r\n\r\n /**\r\n * Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container. Leaves the container's contents in the\r\n * CloudCache so it is available for future sessions.\r\n * @note This function does nothing (and does not throw) if the CloudContainer is not connected to a CloudCache.\r\n */\r\n disconnect(args?: {\r\n /** if true removes the container from the CloudCache, otherwise Leaves the container in the CloudCache so it is available for future sessions. */\r\n detach?: boolean;\r\n }): void;\r\n\r\n /**\r\n * Poll cloud storage for changes from other processes.\r\n *\r\n * Notes:\r\n * - no changes made by other processes are visible to this CloudContainer unless/until this method is called.\r\n * - note this is automatically called whenever the write lock is obtained to ensure all changes are against the latest version.\r\n */\r\n checkForChanges(): void;\r\n\r\n /**\r\n * Upload any changed blocks from the databases in this CloudContainer.\r\n * @note this is called automatically from `releaseWriteLock` before the write lock is released. It is only necessary to call this directly if you\r\n * wish to upload changes while the write lock is still held.\r\n * @see hasLocalChanges\r\n */\r\n uploadChanges(): Promise<void>;\r\n\r\n /**\r\n * Clean any unused deleted blocks from cloud storage. When a database is written, a subset of its blocks are replaced\r\n * by new versions, sometimes leaving the originals unused. In this case, they are not deleted immediately.\r\n * Instead, they are scheduled for deletion at some later time. Calling this method deletes all blocks in the cloud container\r\n * for which the scheduled deletion time has passed.\r\n * @param nSeconds Any block that was marked as unused before this number of seconds ago will be deleted. Specifying a non-zero\r\n * value gives a period of time for other clients to refresh their manifests and stop using the now-garbage blocks. Otherwise they may get\r\n * a 404 error. Default is 1 hour.\r\n */\r\n cleanDeletedBlocks(nSeconds?: number): Promise<void>;\r\n\r\n /**\r\n * Create a copy of an existing database within this CloudContainer with a new name.\r\n * @note CloudSqlite uses copy-on-write semantics for this operation. That is, this method merely makes a\r\n * new entry in the manifest with the new name that *shares* all of its blocks with the original database.\r\n * If either database subsequently changes, the only modified blocks are not shared.\r\n */\r\n copyDatabase(dbName: string, toAlias: string): Promise<void>;\r\n\r\n /** Remove a database from this CloudContainer.\r\n * @see cleanDeletedBlocks\r\n */\r\n deleteDatabase(dbName: string): Promise<void>;\r\n\r\n /** Get the list of database names in this CloudContainer.\r\n * @param globArg if present, filter the results with SQLite [GLOB](https://www.sqlite.org/lang_expr.html#glob) operator.\r\n */\r\n queryDatabases(globArg?: string): string[];\r\n\r\n /**\r\n * Get the status of a specific database in this CloudContainer.\r\n * @param dbName the name of the database of interest\r\n */\r\n queryDatabase(dbName: string): CachedDbProps | undefined;\r\n\r\n /**\r\n * query the bcv_http_log table\r\n * @note the bcv_http_log table contains one row for each HTTP request made by the VFS or connected daemon.\r\n * @note Entries are automatically removed from the table on a FIFO basis. By default entries which are 1 hr old will be removed.\r\n * @internal\r\n */\r\n queryHttpLog(filterOptions?: BcvHttpLogFilterOptions): CloudSqlite.BcvHttpLog[];\r\n\r\n /**\r\n * Get the SHA1 hash of the content of a database.\r\n * @param dbName the name of the database of interest\r\n * @note the hash will be empty if the database does not exist\r\n */\r\n queryDatabaseHash(dbName: string): string;\r\n }\r\n\r\n /**\r\n * Object returned by [[CloudSqlite.startCloudPrefetch]].\r\n * It holds a promise that is fulfilled when a Prefetch is completed. May also be used to cancel an in-progress prefetch.\r\n */\r\n export interface CloudPrefetch {\r\n readonly cloudContainer: CloudContainer;\r\n readonly dbName: string;\r\n\r\n /** Cancel a currently pending prefetch. The promise will be resolved immediately after this call. */\r\n cancel(): void;\r\n\r\n /**\r\n * Promise that is resolved when the prefetch completes or is cancelled. Await this promise to ensure that the\r\n * database has been fully downloaded before going offline, for example.\r\n *\r\n * Notes:\r\n * - resolves to `true` if the prefetch completed and the entire database is local, or `false` if it was aborted or failed.\r\n * - it is *not* rejected on `cancel`. Some progress may (or may not) have been made by the request.\r\n * - To monitor the progress being made during prefetch, call `CloudContainer.queryDatabase` periodically.\r\n */\r\n promise: Promise<boolean>;\r\n }\r\n\r\n /** @internal */\r\n export async function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps) {\r\n if (direction === \"download\")\r\n mkdirSync(dirname(props.localFileName), { recursive: true }); // make sure the directory exists before starting download\r\n\r\n let timer: NodeJS.Timeout | undefined;\r\n try {\r\n const transfer = new NativeLibrary.nativeLib.CloudDbTransfer(direction, container, props);\r\n let total = 0;\r\n const onProgress = props.onProgress;\r\n if (onProgress) {\r\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\r\n const progress = transfer.getProgress();\r\n total = progress.total;\r\n if (onProgress(progress.loaded, progress.total))\r\n transfer.cancelTransfer();\r\n }, 250);\r\n }\r\n await transfer.promise;\r\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\r\n } catch (err: any) {\r\n if (err.message === \"cancelled\")\r\n err.errorNumber = BriefcaseStatus.DownloadCancelled;\r\n\r\n throw err;\r\n } finally {\r\n if (timer)\r\n clearInterval(timer);\r\n }\r\n }\r\n\r\n /** Upload a local SQLite database file into a CloudContainer.\r\n * @param container the CloudContainer holding the database. Must be connected.\r\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\r\n * @note this function requires that the write lock be held on the container\r\n */\r\n export async function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\r\n await transferDb(\"upload\", container, props);\r\n container.checkForChanges(); // re-read the manifest so the database is available locally.\r\n }\r\n\r\n /** Download a database from a CloudContainer.\r\n * @param container the CloudContainer holding the database. Must be connected.\r\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\r\n * @returns a Promise that is resolved when the download completes.\r\n * @note the download is \"restartable.\" If the transfer is aborted and then re-requested, it will continue from where\r\n * it left off rather than re-downloading the entire file.\r\n */\r\n export async function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\r\n await transferDb(\"download\", container, props);\r\n }\r\n\r\n /** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.\r\n * @param lockedBy The identifier supplied by the application/user that currently holds the lock.\r\n * @param expires a stringified Date (in local time) indicating when the lock will expire.\r\n * @return \"stop\" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.\r\n */\r\n export type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | \"stop\">;\r\n\r\n /**\r\n * Attempt to acquire the write lock for a container, with retries.\r\n * If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns \"stop\", throw. Otherwise try again.\r\n * @note if write lock is already held, this function does nothing.\r\n * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us\r\n * @param container the CloudContainer for which the lock is to be acquired\r\n * @param busyHandler if present, function called when the write lock is currently held by another user.\r\n * @throws if [[container]] is not connected to a CloudCache.\r\n */\r\n export async function acquireWriteLock(args: { user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler }) {\r\n const container = args.container as CloudContainerInternal;\r\n while (true) {\r\n try {\r\n if (container.hasWriteLock) {\r\n if (container.writeLockHeldBy === args.user)\r\n return; // current user already has the lock\r\n\r\n const err = new Error() as any; // lock held by another user within this process\r\n err.errorNumber = 5;\r\n err.lockedBy = container.writeLockHeldBy;\r\n err.expires = container.writeLockExpires;\r\n throw err;\r\n }\r\n return container.acquireWriteLock(args.user);\r\n\r\n } catch (e: any) {\r\n if (e.errorNumber === 5 && args.busyHandler && \"stop\" !== await args.busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY\r\n continue; // busy handler wants to try again\r\n throw e;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Perform an asynchronous write operation on a CloudContainer with the write lock held.\r\n * 1. if write lock is already held by the current user, call operation and return.\r\n * 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.\r\n * 3. perform the operation\r\n * 3.a if the operation throws, abandon all changes and re-throw\r\n * 4. release the write lock.\r\n * 5. return value from operation\r\n * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us\r\n * @param container the CloudContainer for which the lock is to be acquired\r\n * @param operation an asynchronous operation performed with the write lock held.\r\n * @param busyHandler if present, function called when the write lock is currently held by another user.\r\n * @returns a Promise with the result of `operation`\r\n */\r\n export async function withWriteLock<T>(args: { user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler }, operation: () => Promise<T>): Promise<T> {\r\n await acquireWriteLock(args);\r\n const containerInternal = args.container as CloudContainerInternal;\r\n try {\r\n if (containerInternal.writeLockHeldBy === args.user) // If the user already had the write lock, then don't release it.\r\n return await operation();\r\n containerInternal.writeLockHeldBy = args.user;\r\n containerInternal.writeLockExpires = new Date(Date.now() + 1000 * containerInternal.lockExpireSeconds).toLocaleString();\r\n // eslint-disable-next-line @typescript-eslint/await-thenable\r\n const val = await operation(); // wait for work to finish or fail\r\n containerInternal.releaseWriteLock();\r\n containerInternal.writeLockHeldBy = undefined;\r\n containerInternal.writeLockExpires = undefined;\r\n return val;\r\n } catch (e) {\r\n args.container.abandonChanges(); // if operation threw, abandon all changes\r\n containerInternal.writeLockHeldBy = undefined;\r\n containerInternal.writeLockExpires = undefined;\r\n throw e;\r\n }\r\n }\r\n\r\n /** Arguments to create or find a CloudCache */\r\n export interface CreateCloudCacheArg {\r\n /** The name of the CloudCache. CloudCache names must be unique. */\r\n cacheName: string;\r\n /** A string that specifies the maximum size of the CloudCache. It should be a number followed by \"K\",\r\n * \"M\" \"G\", or \"T\". Default is \"10G\". */\r\n cacheSize?: string;\r\n /** A local directory in temporary storage for the CloudCache. If not supplied, it is a subdirectory called `cacheName`\r\n * in the `CloudCaches` temporary directory.\r\n * If the directory does not exist, it is created. */\r\n cacheDir?: string;\r\n }\r\n\r\n /** The collection of currently extant `CloudCache`s, by name. */\r\n export class CloudCaches {\r\n private static readonly cloudCaches = new Map<string, CloudCache>();\r\n\r\n /** create a new CloudCache */\r\n private static makeCache(args: CreateCloudCacheArg): CloudCache {\r\n const cacheName = args.cacheName;\r\n const rootDir = args.cacheDir ?? join(IModelHost.profileDir, \"CloudCaches\", cacheName);\r\n IModelJsFs.recursiveMkDirSync(rootDir);\r\n const cache = new NativeLibrary.nativeLib.CloudCache({ rootDir, name: cacheName, cacheSize: args.cacheSize ?? \"10G\" });\r\n this.cloudCaches.set(cacheName, cache);\r\n return cache;\r\n }\r\n\r\n /** find a CloudCache by name, if it exists */\r\n public static findCache(cacheName: string): CloudCache | undefined {\r\n return this.cloudCaches.get(cacheName);\r\n }\r\n /** @internal */\r\n public static dropCache(cacheName: string): CloudCache | undefined {\r\n const cache = this.cloudCaches.get(cacheName);\r\n this.cloudCaches.delete(cacheName);\r\n return cache;\r\n }\r\n /** called by IModelHost after shutdown.\r\n * @internal\r\n */\r\n public static destroy() {\r\n this.cloudCaches.forEach((cache) => cache.destroy());\r\n this.cloudCaches.clear();\r\n }\r\n\r\n /** Get a CloudCache by name. If the CloudCache doesn't yet exist, it is created. */\r\n public static getCache(args: CreateCloudCacheArg): CloudCache {\r\n return this.cloudCaches.get(args.cacheName) ?? this.makeCache(args);\r\n }\r\n }\r\n\r\n /** Class that provides convenient local access to a SQLite database in a CloudContainer. */\r\n export class DbAccess<DbType extends VersionedSqliteDb, ReadMethods = DbType, WriteMethods = DbType> {\r\n /** The name of the database within the cloud container. */\r\n public readonly dbName: string;\r\n /** Parameters for obtaining the write lock for this container. */\r\n public readonly lockParams: ObtainLockParams = {\r\n user: \"\",\r\n nRetries: 20,\r\n retryDelayMs: 100,\r\n };\r\n protected static _cacheName = \"default-64k\";\r\n protected _container: CloudContainer;\r\n protected _cloudDb: DbType;\r\n private _writeLockProxy?: PickAsyncMethods<WriteMethods>;\r\n private _readerProxy?: PickMethods<ReadMethods>;\r\n private get _ctor() { return this.constructor as typeof DbAccess; }\r\n\r\n /** @internal */\r\n public static getCacheForClass() {\r\n return CloudCaches.getCache({ cacheName: this._cacheName });\r\n }\r\n private _cache?: CloudCache;\r\n /** only for tests\r\n * @internal\r\n */\r\n public setCache(cache: CloudCache) {\r\n this._cache = cache;\r\n }\r\n /** @internal */\r\n public getCache(): CloudCache {\r\n return this._cache ??= this._ctor.getCacheForClass();\r\n }\r\n /** @internal */\r\n public getCloudDb(): DbType {\r\n return this._cloudDb;\r\n }\r\n\r\n /**\r\n * The token that grants access to the cloud container for this DbAccess. If it does not grant write permissions, all\r\n * write operations will fail. It should be refreshed (via a timer) before it expires.\r\n */\r\n public get sasToken() { return this._container.accessToken; }\r\n public set sasToken(token: AccessToken) { this._container.accessToken = token; }\r\n\r\n /** the container for this DbAccess. It is automatically connected to the CloudCache whenever it is accessed. */\r\n public get container(): CloudContainer {\r\n const container = this._container;\r\n if (!container.isConnected)\r\n container.connect(this.getCache());\r\n return container;\r\n }\r\n\r\n /** Start a prefetch operation to download all the blocks for the VersionedSqliteDb */\r\n public startPrefetch(): CloudPrefetch {\r\n return startCloudPrefetch(this.container, this.dbName);\r\n }\r\n\r\n /** Create a new DbAccess for a database stored in a cloud container. */\r\n public constructor(args: {\r\n /** The Constructor for DbType. */\r\n dbType: Constructor<DbType>;\r\n /** The properties of the cloud container holding the database. */\r\n props: ContainerAccessProps;\r\n /** The name of the database within the container. */\r\n dbName: string;\r\n }) {\r\n this._container = createCloudContainer({ writeable: true, ...args.props });\r\n this._cloudDb = new args.dbType(args.props);\r\n this.dbName = args.dbName;\r\n this.lockParams.user = IModelHost.userMoniker;\r\n }\r\n\r\n /** Close the database for this DbAccess, if it is open */\r\n public closeDb() {\r\n if (this._cloudDb.isOpen)\r\n this._cloudDb.closeDb();\r\n }\r\n\r\n /** Close the database for this DbAccess if it is opened, and disconnect this `DbAccess from its CloudContainer. */\r\n public close() {\r\n this.closeDb();\r\n this._container.disconnect();\r\n }\r\n\r\n /**\r\n * Initialize a cloud container to hold a Cloud SQliteDb. The container must first be created via its storage supplier api (e.g. Azure, or Google).\r\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty database into the container.\r\n * @note this deletes any existing content in the container.\r\n */\r\n protected static async _initializeDb(args: { dbType: typeof VersionedSqliteDb, props: ContainerAccessProps, dbName: string, blockSize?: \"64K\" | \"4M\" }) {\r\n const container = createCloudContainer({ ...args.props, writeable: true });\r\n container.initializeContainer({ blockSize: args.blockSize === \"4M\" ? 4 * 1024 * 1024 : 64 * 1024 });\r\n container.connect(CloudCaches.getCache({ cacheName: this._cacheName }));\r\n await withWriteLock({ user: \"initialize\", container }, async () => {\r\n const localFileName = join(KnownLocations.tmpdir, \"blank.db\");\r\n args.dbType.createNewDb(localFileName);\r\n await transferDb(\"upload\", container, { dbName: args.dbName, localFileName });\r\n unlinkSync(localFileName);\r\n });\r\n container.disconnect({ detach: true });\r\n }\r\n\r\n /**\r\n * Synchronize the local cache of this database with any changes by made by others.\r\n * @note This is called automatically whenever any write operation is performed on this DbAccess. It is only necessary to\r\n * call this directly if you have not changed the database recently, but wish to perform a readonly operation and want to\r\n * ensure it is up-to-date as of now.\r\n * @note There is no guarantee that the database is up-to-date even immediately after calling this method, since others\r\n * may be modifying it at any time.\r\n */\r\n public synchronizeWithCloud() {\r\n this.closeDb();\r\n this.container.checkForChanges();\r\n }\r\n\r\n /**\r\n * Ensure that the database controlled by this `DbAccess` is open for read access and return the database object.\r\n * @note if the database is already open (either for read or write), this method merely returns the database object.\r\n */\r\n public openForRead(): DbType {\r\n if (!this._cloudDb.isOpen)\r\n this._cloudDb.openDb(this.dbName, OpenMode.Readonly, this.container);\r\n return this._cloudDb;\r\n }\r\n\r\n /**\r\n * Perform an operation on this database with the lock held and the database opened for write\r\n * @param operationName the name of the operation. Only used for logging.\r\n * @param operation a function called with the lock held and the database open for write.\r\n * @returns A promise that resolves to the the return value of `operation`.\r\n * @see `SQLiteDb.withLockedContainer`\r\n * @note Most uses of `CloudSqliteDbAccess` require that the lock not be held by any operation for long. Make sure you don't\r\n * do any avoidable or time consuming work in your operation function.\r\n */\r\n public async withLockedDb<T>(args: { operationName: string, openMode?: OpenMode, user?: string }, operation: () => Promise<T>): Promise<T> {\r\n let nRetries = this.lockParams.nRetries;\r\n const cacheGuid = this.container.cache!.guid; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n const user = args.user ?? this.lockParams.user ?? cacheGuid;\r\n const timer = new StopWatch(undefined, true);\r\n const showMs = () => `(${timer.elapsed.milliseconds}ms)`;\r\n\r\n const busyHandler = async (lockedBy: string, expires: string): Promise<void | \"stop\"> => {\r\n if (--nRetries <= 0) {\r\n if (\"stop\" === await this.lockParams.onFailure?.(lockedBy, expires))\r\n return \"stop\";\r\n nRetries = this.lockParams.nRetries;\r\n }\r\n const delay = this.lockParams.retryDelayMs;\r\n logInfo(`lock retry for ${cacheGuid} after ${showMs()}, waiting ${delay}`);\r\n await BeDuration.fromMilliseconds(delay).wait();\r\n };\r\n\r\n this.closeDb(); // in case it is currently open for read.\r\n let lockObtained = false;\r\n const operationName = args.operationName;\r\n try {\r\n return await this._cloudDb.withLockedContainer({ user, dbName: this.dbName, container: this.container, busyHandler, openMode: args.openMode }, async () => {\r\n lockObtained = true;\r\n logInfo(`lock acquired by ${cacheGuid} for ${operationName} ${showMs()}`);\r\n return operation();\r\n });\r\n } finally {\r\n if (lockObtained)\r\n logInfo(`lock released by ${cacheGuid} after ${operationName} ${showMs()} `);\r\n else\r\n logError(`could not obtain lock for ${cacheGuid} to perform ${operationName} ${showMs()} `);\r\n }\r\n }\r\n\r\n /** get a method member, by name, from the database object. Throws if not a Function. */\r\n private getDbMethod(methodName: string): Function {\r\n const fn = (this._cloudDb as any)[methodName] as Function;\r\n if (typeof fn !== \"function\")\r\n throw new Error(`illegal method name ${methodName}`);\r\n return fn;\r\n }\r\n\r\n /**\r\n * A Proxy Object to call a writeable async method on the cloud database controlled by this `DbAccess`.\r\n *\r\n * Whenever a method is called through this Proxy, it will:\r\n * - attempt to acquire the write lock on the container\r\n * - open the database for write\r\n * - call the method\r\n * - close the database\r\n * - upload changes\r\n * - release the write lock.\r\n *\r\n * @see [[withLockedDb]]\r\n */\r\n public get writeLocker() {\r\n return this._writeLockProxy ??= new Proxy(this, {\r\n get(access, operationName: string) {\r\n const fn = access.getDbMethod(operationName);\r\n return async (...args: any[]) => access.withLockedDb({ operationName, user: RpcTrace.currentActivity?.user }, fn.bind(access._cloudDb, ...args));\r\n },\r\n }) as PickAsyncMethods<WriteMethods>;\r\n }\r\n\r\n /**\r\n * A Proxy Object to call a synchronous readonly method on the database controlled by this `DbAccess`.\r\n * Whenever a method is called through this Proxy, it will first ensure that the database is opened for at least read access.\r\n */\r\n public get reader() {\r\n return this._readerProxy ??= new Proxy(this, {\r\n get(access, methodName: string) {\r\n const fn = access.getDbMethod(methodName);\r\n return (...args: any[]) => fn.call(access.openForRead(), ...args);\r\n },\r\n }) as PickMethods<ReadMethods>;\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../src/CloudSqlite.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2BAA2C;AAC3C,+BAAqC;AACrC,8DAAyD;AACzD,sDAE6B;AAE7B,iEAAuD;AACvD,6CAA0D;AAC1D,6CAA0C;AAC1C,2CAAyC;AAIzC,+BAA+B;AAE/B;;;GAGG;AACH,IAAiB,WAAW,CAo3B3B;AAp3BD,WAAiB,WAAW;IAE1B,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,qBAAM,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AI,KAAK,CAAC,IAAI,EAAE;gBAC3C,GAAG,CAAC,MAAM,EAAE,UAAkB;oBAC5B,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;oBAC1C,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;gBACpE,CAAC;aACF,CAA6B,CAAC;QACjC,CAAC;;IAxMgB,mBAAU,GAAG,aAAa,AAAhB,CAAiB;IATjC,oBAAQ,WAkNpB,CAAA;AACH,CAAC,EAp3BgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAo3B3B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport { mkdirSync, unlinkSync } from \"fs\";\r\nimport { dirname, join } from \"path\";\r\nimport { NativeLibrary } from \"@bentley/imodeljs-native\";\r\nimport {\r\n AccessToken, BeDuration, BriefcaseStatus, Constructor, GuidString, Logger, OpenMode, Optional, PickAsyncMethods, PickMethods, StopWatch,\r\n} from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { BlobContainer } from \"./BlobContainerService\";\r\nimport { IModelHost, KnownLocations } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { RpcTrace } from \"./rpc/tracing\";\r\n\r\nimport type { SQLiteDb, VersionedSqliteDb } from \"./SQLiteDb\";\r\n\r\n// spell:ignore logmsg httpcode\r\n\r\n/**\r\n * Types for accessing SQLite databases stored in cloud containers.\r\n * @beta\r\n */\r\nexport namespace CloudSqlite {\r\n\r\n const logInfo = (msg: string) => Logger.logInfo(\"CloudSqlite\", msg);\r\n const logError = (msg: string) => Logger.logError(\"CloudSqlite\", msg);\r\n\r\n /**\r\n * Request a new AccessToken for a cloud container using the [[BlobContainer]] service.\r\n * If the service is unavailable or returns an error, an empty token is returned.\r\n */\r\n export async function requestToken(args: Optional<BlobContainer.RequestTokenProps, \"userToken\">): Promise<AccessToken> {\r\n // allow the userToken to be supplied via Rpc. If not supplied, or blank, use the backend's accessToken.\r\n const userToken = args.userToken ? args.userToken : (await IModelHost.getAccessToken());\r\n const response = await BlobContainer.service?.requestToken({ ...args, userToken });\r\n return response?.token ?? \"\";\r\n }\r\n\r\n interface CloudContainerInternal extends CloudContainer {\r\n timer?: NodeJS.Timeout;\r\n refreshPromise?: Promise<void>;\r\n lockExpireSeconds: number;\r\n writeLockHeldBy?: string;\r\n writeLockExpires?: string;\r\n }\r\n\r\n /**\r\n * Create a new CloudContainer from a ContainerAccessProps. For non-public containers, a valid accessToken must be provided before the container\r\n * can be used (e.g. via [[CloudSqlite.requestToken]]).\r\n * @note After the container is successfully connected to a CloudCache, it will begin auto-refreshing its accessToken every `tokenRefreshSeconds` seconds (default is 1 hour)\r\n * until it is disconnected. However, if the container is public, or if `tokenRefreshSeconds` is <=0, auto-refresh is not enabled.\r\n */\r\n export function createCloudContainer(args: ContainerAccessProps & { accessLevel?: BlobContainer.RequestAccessLevel }): CloudContainer {\r\n const container = new NativeLibrary.nativeLib.CloudContainer(args) as CloudContainerInternal;\r\n const refreshSeconds = (undefined !== args.tokenRefreshSeconds) ? args.tokenRefreshSeconds : 60 * 60; // default is 1 hour\r\n container.lockExpireSeconds = args.lockExpireSeconds ?? 60 * 60; // default is 1 hour\r\n\r\n // don't refresh tokens for public containers or if refreshSeconds<=0\r\n if (!args.isPublic && refreshSeconds > 0) {\r\n const tokenProps = { baseUri: args.baseUri, containerId: args.containerId, accessLevel: args.accessLevel };\r\n const doRefresh = async () => {\r\n let newToken: AccessToken | undefined;\r\n const url = `[${tokenProps.baseUri}/${tokenProps.containerId}]`;\r\n try {\r\n newToken = await CloudSqlite.requestToken(tokenProps);\r\n logInfo(`Refreshed token for container ${url}`);\r\n } catch (err: any) {\r\n logError(`Error refreshing token for container ${url}: ${err.message}`);\r\n }\r\n container.accessToken = newToken ?? \"\";\r\n };\r\n const tokenRefreshFn = () => {\r\n container.timer = setTimeout(async () => {\r\n container.refreshPromise = doRefresh(); // this promise is stored on the container so it can be awaited in tests\r\n await container.refreshPromise;\r\n container.refreshPromise = undefined;\r\n tokenRefreshFn(); // schedule next refresh\r\n }, refreshSeconds * 1000);\r\n };\r\n container.onConnected = tokenRefreshFn; // schedule the first refresh when the container is connected\r\n container.onDisconnect = () => { // clear the refresh timer when the container is disconnected\r\n if (container.timer !== undefined) {\r\n clearTimeout(container.timer);\r\n container.timer = undefined;\r\n }\r\n };\r\n }\r\n return container;\r\n }\r\n\r\n /** Begin prefetching all blocks for a database in a CloudContainer in the background. */\r\n export function startCloudPrefetch(container: CloudContainer, dbName: string, args?: PrefetchProps): CloudPrefetch {\r\n return new NativeLibrary.nativeLib.CloudPrefetch(container, dbName, args);\r\n }\r\n export interface ContainerProps {\r\n /** The type of storage provider. */\r\n storageType: \"azure\" | \"google\";\r\n /** The base URI for the container. */\r\n baseUri: string;\r\n /** The name of the container. */\r\n containerId: string;\r\n /** true if the container is public (doesn't require authorization) */\r\n isPublic?: boolean;\r\n }\r\n\r\n /** Properties to access a CloudContainer. */\r\n export interface ContainerAccessProps extends ContainerProps {\r\n /** an alias for the container. Defaults to `containerId` */\r\n alias?: string;\r\n /** SAS token that grants access to the container. */\r\n accessToken: string;\r\n /** if true, container is allowed to request the write lock. */\r\n writeable?: boolean;\r\n /** if true, container is attached in \"secure\" mode (blocks are encrypted). Only supported in daemon mode. */\r\n secure?: boolean;\r\n /** string attached to log messages from CloudSQLite. This is most useful for identifying usage from daemon mode. */\r\n logId?: string;\r\n /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */\r\n lockExpireSeconds?: number;\r\n /** number of seconds between auto-refresh of access token. If <=0 no auto-refresh. Default is 1 hour (60*60) */\r\n tokenRefreshSeconds?: number;\r\n }\r\n\r\n /** Returned from `CloudContainer.queryDatabase` describing one database in the container */\r\n export interface CachedDbProps {\r\n /** The total number of blocks in the database. */\r\n readonly totalBlocks: number;\r\n /** the number of blocks of the database that have been downloaded into the CloudCache */\r\n readonly localBlocks: number;\r\n /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */\r\n readonly dirtyBlocks: number;\r\n /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */\r\n readonly transactions: boolean;\r\n /** the state of this database. Indicates whether the database is new or deleted since last upload */\r\n readonly state: \"\" | \"copied\" | \"deleted\";\r\n /** current number of clients that have this database open. */\r\n readonly nClient: number;\r\n /** current number of ongoing prefetches on this database. */\r\n readonly nPrefetch: number;\r\n }\r\n\r\n /** Filter options passed to CloudContainer.queryHttpLog\r\n * @internal\r\n */\r\n export interface BcvHttpLogFilterOptions {\r\n /** only return rows whose ID is >= the provided id */\r\n startFromId?: number;\r\n /** only return rows whose endTime is null OR >= the provided endTime. */\r\n finishedAtOrAfterTime?: string;\r\n /** only return rows with a non-null end_time. */\r\n showOnlyFinished?: boolean;\r\n }\r\n\r\n /** Returned from 'CloudContainer.queryHttpLog' describing a row in the bcv_http_log table.\r\n * @internal\r\n */\r\n export interface BcvHttpLog {\r\n /** Unique, monotonically increasing id value */\r\n readonly id: number;\r\n /** Time request was made, as iso-8601 */\r\n readonly startTime: string;\r\n /** Time reply received, as iso-8601 (may be undefined) */\r\n readonly endTime: string | undefined;\r\n /** \"PUT\", \"GET\", etc. */\r\n readonly method: string;\r\n /** LogId of client that caused this request. Will be \"prefetch\" for prefetch requests. */\r\n readonly logId: string;\r\n /** Log message associated with request */\r\n readonly logmsg: string;\r\n /** URI of request */\r\n readonly uri: string;\r\n /** HTTP response code (e.g. 200) */\r\n readonly httpcode: number;\r\n }\r\n\r\n /** The name of a CloudSqlite database within a CloudContainer. */\r\n export interface DbNameProp {\r\n /** the name of the database within the CloudContainer.\r\n * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/\r\n dbName: string;\r\n }\r\n\r\n /** Properties for accessing a database within a CloudContainer */\r\n export interface DbProps extends DbNameProp {\r\n /** the name of the local file to access the database. */\r\n localFileName: LocalFileName;\r\n }\r\n\r\n export type TransferDirection = \"upload\" | \"download\";\r\n export interface TransferProgress {\r\n /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */\r\n onProgress?: (loaded: number, total: number) => number;\r\n }\r\n\r\n export interface CloudHttpProps {\r\n /** The number of simultaneous HTTP requests. Default is 6. */\r\n nRequests?: number;\r\n }\r\n\r\n export interface PrefetchProps extends CloudHttpProps {\r\n /** timeout between requests, in milliseconds. Default is 100. */\r\n timeout?: number;\r\n /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */\r\n minRequests?: number;\r\n }\r\n\r\n export type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;\r\n\r\n /** Properties for creating a CloudCache. */\r\n export interface CacheProps extends CloudHttpProps {\r\n /** full path of directory for cache to store its files. Must be on a (preferably fast) local drive, and must be empty when the cache is first created. */\r\n rootDir: string;\r\n /** name of this cache. It is possible to have more than one CloudCache in the same session, but each must have a unique name. */\r\n name: string;\r\n /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */\r\n cacheSize?: string;\r\n /** turn on diagnostics for `curl` (outputs to stderr) */\r\n curlDiagnostics?: boolean;\r\n }\r\n\r\n /** Parameters used to obtain the write lock on a cloud container */\r\n export interface ObtainLockParams {\r\n /** a string that identifies me to others if I hold the lock while they attempt to acquire it. */\r\n user?: string;\r\n /** number of times to retry in the event the lock currently held by someone else.\r\n * After this number of attempts, `onFailure` is called. Default is 20.\r\n */\r\n nRetries: number;\r\n /** Delay between retries, in milliseconds. Default is 100. */\r\n retryDelayMs: number;\r\n /** function called if lock cannot be obtained after all retries. It is called with the name of the user currently holding the lock and\r\n * generally is expected that the user will be consulted whether to wait further.\r\n * If this function returns \"stop\", an exception will be thrown. Otherwise the retry cycle is restarted.\r\n */\r\n onFailure?: WriteLockBusyHandler;\r\n }\r\n\r\n /** @internal */\r\n export interface LockAndOpenArgs extends SQLiteDb.WithOpenDbArgs {\r\n /** a string that identifies me to others if I hold the lock while they attempt to acquire it. */\r\n user: string;\r\n /** the name of the database within the container */\r\n dbName: string;\r\n /** the CloudContainer on which the operation will be performed */\r\n container: CloudContainer;\r\n /** if present, function called when the write lock is currently held by another user. */\r\n busyHandler?: WriteLockBusyHandler;\r\n /** if present, open mode for Db. Default is ReadWrite */\r\n openMode?: OpenMode;\r\n }\r\n\r\n /** Logging categories for `CloudCache.setLogMask` */\r\n export enum LoggingMask {\r\n /** log all HTTP requests and responses */\r\n HTTP = 0x01,\r\n /** log as blocks become dirty and must be uploaded */\r\n DirtyBlocks = 0x02,\r\n /** log as blocks are added to the delete list */\r\n AddToDelete = 0x04,\r\n /** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */\r\n LifecycleEvents = 0x08,\r\n /** Turn on all logging categories */\r\n All = 0xff,\r\n /** Disable logging */\r\n None = 0,\r\n }\r\n\r\n /**\r\n * A local cache for storing data downloaded from many CloudSqlite databases. This object refers to a directory on the local filesystem\r\n * and is used to **connect** CloudContainers so they may be accessed. It maintains the state of the local copy of\r\n * the downloaded data from SQLiteDbs in CloudContainers across sessions.\r\n *\r\n * Notes:\r\n * - CloudCaches have a name, used internally by CloudSqlite, that must be unique. CloudCaches are created and maintained via [[CloudCaches.getCache]].\r\n * - All CloudContainers connected to a given CloudCache must have the same block size, as determined by the first CloudContainer connected.\r\n * - they have a maximum size that limits the amount of disk space they can consume. When the maximum size of a CloudCache is reached,\r\n * the least recently used blocks are removed to make room for new blocks.\r\n * - CloudCaches may only be used by a single process at a time. An exception is thrown if you attempt to access a CloudCache from a\r\n * second process if it is already in use by another process. Note: for a readonly CloudCache, a \"daemon\" process can be used to\r\n * share a CloudCache across processes. See its documentation for details.\r\n * - Generally, it is expected that there only be a few CloudCaches and they be shared by all applications. Each CloudCache can consume\r\n * its maximum disk space, so controlling system-wide disk usage is complicated. The only reason to make a new CloudCache is either\r\n * for containers with a different block size, or to purposely control local disk space usage for a specific set of containers.\r\n * - The contents of the cache directory are entirely controlled by CloudSqlite and should be empty when the cache is\r\n * first created and never modified directly thereafter.\r\n */\r\n export interface CloudCache {\r\n /** `true` if this CloudCache is connected to a daemon process */\r\n get isDaemon(): boolean;\r\n /** The name for this CloudCache. */\r\n get name(): string;\r\n /** The root directory of this CloudCache on a local drive. */\r\n get rootDir(): LocalDirName;\r\n /** A guid for this CloudCache. It is assigned when the CloudCache is first created and used for acquiring write locks. */\r\n get guid(): GuidString;\r\n /** Configure logging for this CloudCache.\r\n * @param mask A bitmask of `LoggingMask` values\r\n * @note this method does nothing if [[isDaemon]] is true. Daemon logging is configured when the daemon is started.\r\n * @note HTTP logging can be happen on multiple threads and may be buffered. To see buffered log messages, periodically call\r\n * `[[IModelHost.flushLog]]\r\n */\r\n setLogMask(mask: number): void;\r\n /**\r\n * destroy this CloudCache to end this session. All currently connected CloudContainers are disconnected first.\r\n * @note this does *not* delete the local directory. Its contents are maintained so it can be used in future sessions.\r\n * @note this function is automatically called on [[IModelHost.shutdown]], so it is only called directly for tests.\r\n * @internal\r\n */\r\n destroy(): void;\r\n }\r\n\r\n /**\r\n * A CloudSqlite container that may be connected to a CloudCache. A CloudContainer maps a container in a cloud blob-storage\r\n * account to a local cache, so that the contents of a database in the container may be accessed as if it were a local file.\r\n *\r\n * Notes:\r\n * - all methods and accessors of this interface (other than `initializeContainer`) require that the `connect` method be successfully called first.\r\n * Otherwise they will throw an exception or return meaningless values.\r\n * - before a SQLiteDb in a container may be opened for write access, the container's write lock must be held (see [[acquireWriteLock]].)\r\n * - a single CloudContainer may hold more than one SQLiteDb, but often they are 1:1.\r\n * - the write lock is per-Container, not per-SQLiteDb (which is the reason they are often 1:1)\r\n * - the accessToken (a SAS key) member provides time limited, restricted, access to the container. It must be refreshed before it expires.\r\n * - when a CloudContainer is created, it may either be readonly or writeable. If a container is never meant to be used for writes,\r\n * it is slightly more efficient to indicate that by passing `writeable: false`\r\n */\r\n export interface CloudContainer {\r\n onConnect?: (container: CloudContainer, cache: CloudCache) => void;\r\n onConnected?: (container: CloudContainer) => void;\r\n onDisconnect?: (container: CloudContainer, detach: boolean) => void;\r\n onDisconnected?: (container: CloudContainer, detach: boolean) => void;\r\n\r\n readonly cache?: CloudCache;\r\n /** the baseUri of this container */\r\n get baseUri(): string;\r\n /** the storageType of this container */\r\n get storageType(): string;\r\n /** The ContainerId within a storage account. */\r\n get containerId(): string;\r\n /** The *alias* to identify this CloudContainer in a CloudCache. Usually just the ContainerId. */\r\n get alias(): string;\r\n /** The logId. */\r\n get logId(): string;\r\n /** true if this CloudContainer is currently connected to a CloudCache via the `connect` method. */\r\n get isConnected(): boolean;\r\n /** true if this CloudContainer was created with the `writeable` flag (and its `accessToken` supplies write access). */\r\n get isWriteable(): boolean;\r\n /** true if this container is public (doesn't require authorization ). */\r\n get isPublic(): boolean;\r\n /** true if this CloudContainer currently holds the write lock for its container in the cloud. */\r\n get hasWriteLock(): boolean;\r\n /** true if this CloudContainer has local changes that have not be uploaded to its container in the cloud. */\r\n get hasLocalChanges(): boolean;\r\n /** The current accessToken providing access to the cloud container */\r\n get accessToken(): string;\r\n set accessToken(val: string);\r\n /** Get the number of garbage blocks in this container that can be purged. */\r\n get garbageBlocks(): number;\r\n /** The block size for this CloudContainer. */\r\n get blockSize(): number;\r\n\r\n /**\r\n * initialize a cloud blob-store container to be used as a new CloudContainer. This creates the container's manifest of its contents, and should be\r\n * performed on an empty container. If an existing manifest is present, it is destroyed and a new one is created (essentially emptying the container.)\r\n */\r\n initializeContainer(args: { checksumBlockNames?: boolean, blockSize: number }): void;\r\n\r\n /**\r\n * Connect this CloudContainer to a CloudCache for accessing and/or modifying its contents.\r\n * @note A CloudCache is a local directory holding copies of information from the cloud. It is persistent across sessions,\r\n * but this method must be called each session to (re)establish the connection to the CloudCache. If the CloudCache was previously populated,\r\n * this method may be called and will succeed *even when offline* or without a valid `accessToken`.\r\n */\r\n connect(cache: CloudCache): void;\r\n\r\n /**\r\n * Attempt to acquire the write lock for this CloudContainer. For this to succeed:\r\n * 1. it must be connected to a `CloudCache`\r\n * 2. this CloudContainer must have been constructed with `writeable: true`\r\n * 3. the `accessToken` must authorize write access\r\n * 4. no other process may be holding an unexpired write lock\r\n * @throws if any of the above conditions fail\r\n * @note Write locks *expire* after the duration specified in the `durationSeconds` property of the constructor argument, in case a process\r\n * crashes or otherwise fails to release the lock. Calling `acquireWriteLock` with the lock already held resets the lock duration from the current time,\r\n * so long running processes should call this method periodically to ensure their lock doesn't expire (they should also make sure their accessToken is refreshed\r\n * before it expires.)\r\n * @note on success, the container is synchronized with its contents in the cloud before the promise resolves.\r\n * @param user An identifier of the process/user locking the CloudContainer. In the event of a write lock\r\n * collision, this string will be included in the exception string of the *other* process attempting to obtain a write lock so that users may identify who currently holds\r\n * the lock.\r\n */\r\n acquireWriteLock(user: string): void;\r\n\r\n /**\r\n * Release the write lock if it is currently held.\r\n *\r\n * Notes:\r\n * - if there are local changes that have not been uploaded, they are automatically uploaded before the write lock is released.\r\n * - if the write lock is not held, this method does nothing.\r\n */\r\n releaseWriteLock(): void;\r\n\r\n /**\r\n * Destroy any currently valid write lock from this or any other process. This is obviously very dangerous and defeats the purpose of write locking.\r\n * This method exists only for administrator tools to clear a failed process without waiting for the expiration period. It can also be useful for tests.\r\n * For this to succeed, all of the conditions of `acquireWriteLock` must be true other than #4.\r\n */\r\n clearWriteLock(): void;\r\n\r\n /**\r\n * Abandon any local changes in this container. If the write lock is currently held, it is released.\r\n * This function fails with BE_SQLITE_BUSY if there are any open read or write transactions on *any* database in the container.\r\n */\r\n abandonChanges(): void;\r\n\r\n /**\r\n * Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container. Leaves the container's contents in the\r\n * CloudCache so it is available for future sessions.\r\n * @note This function does nothing (and does not throw) if the CloudContainer is not connected to a CloudCache.\r\n */\r\n disconnect(args?: {\r\n /** if true removes the container from the CloudCache, otherwise Leaves the container in the CloudCache so it is available for future sessions. */\r\n detach?: boolean;\r\n }): void;\r\n\r\n /**\r\n * Poll cloud storage for changes from other processes.\r\n *\r\n * Notes:\r\n * - no changes made by other processes are visible to this CloudContainer unless/until this method is called.\r\n * - note this is automatically called whenever the write lock is obtained to ensure all changes are against the latest version.\r\n */\r\n checkForChanges(): void;\r\n\r\n /**\r\n * Upload any changed blocks from the databases in this CloudContainer.\r\n * @note this is called automatically from `releaseWriteLock` before the write lock is released. It is only necessary to call this directly if you\r\n * wish to upload changes while the write lock is still held.\r\n * @see hasLocalChanges\r\n */\r\n uploadChanges(): Promise<void>;\r\n\r\n /**\r\n * Clean any unused deleted blocks from cloud storage. When a database is written, a subset of its blocks are replaced\r\n * by new versions, sometimes leaving the originals unused. In this case, they are not deleted immediately.\r\n * Instead, they are scheduled for deletion at some later time. Calling this method deletes all blocks in the cloud container\r\n * for which the scheduled deletion time has passed.\r\n * @param nSeconds Any block that was marked as unused before this number of seconds ago will be deleted. Specifying a non-zero\r\n * value gives a period of time for other clients to refresh their manifests and stop using the now-garbage blocks. Otherwise they may get\r\n * a 404 error. Default is 1 hour.\r\n */\r\n cleanDeletedBlocks(nSeconds?: number): Promise<void>;\r\n\r\n /**\r\n * Create a copy of an existing database within this CloudContainer with a new name.\r\n * @note CloudSqlite uses copy-on-write semantics for this operation. That is, this method merely makes a\r\n * new entry in the manifest with the new name that *shares* all of its blocks with the original database.\r\n * If either database subsequently changes, the only modified blocks are not shared.\r\n */\r\n copyDatabase(dbName: string, toAlias: string): Promise<void>;\r\n\r\n /** Remove a database from this CloudContainer.\r\n * @see cleanDeletedBlocks\r\n */\r\n deleteDatabase(dbName: string): Promise<void>;\r\n\r\n /** Get the list of database names in this CloudContainer.\r\n * @param globArg if present, filter the results with SQLite [GLOB](https://www.sqlite.org/lang_expr.html#glob) operator.\r\n */\r\n queryDatabases(globArg?: string): string[];\r\n\r\n /**\r\n * Get the status of a specific database in this CloudContainer.\r\n * @param dbName the name of the database of interest\r\n */\r\n queryDatabase(dbName: string): CachedDbProps | undefined;\r\n\r\n /**\r\n * query the bcv_http_log table\r\n * @note the bcv_http_log table contains one row for each HTTP request made by the VFS or connected daemon.\r\n * @note Entries are automatically removed from the table on a FIFO basis. By default entries which are 1 hr old will be removed.\r\n * @internal\r\n */\r\n queryHttpLog(filterOptions?: BcvHttpLogFilterOptions): CloudSqlite.BcvHttpLog[];\r\n\r\n /**\r\n * Get the SHA1 hash of the content of a database.\r\n * @param dbName the name of the database of interest\r\n * @note the hash will be empty if the database does not exist\r\n */\r\n queryDatabaseHash(dbName: string): string;\r\n }\r\n\r\n /**\r\n * Object returned by [[CloudSqlite.startCloudPrefetch]].\r\n * It holds a promise that is fulfilled when a Prefetch is completed. May also be used to cancel an in-progress prefetch.\r\n */\r\n export interface CloudPrefetch {\r\n readonly cloudContainer: CloudContainer;\r\n readonly dbName: string;\r\n\r\n /** Cancel a currently pending prefetch. The promise will be resolved immediately after this call. */\r\n cancel(): void;\r\n\r\n /**\r\n * Promise that is resolved when the prefetch completes or is cancelled. Await this promise to ensure that the\r\n * database has been fully downloaded before going offline, for example.\r\n *\r\n * Notes:\r\n * - resolves to `true` if the prefetch completed and the entire database is local, or `false` if it was aborted or failed.\r\n * - it is *not* rejected on `cancel`. Some progress may (or may not) have been made by the request.\r\n * - To monitor the progress being made during prefetch, call `CloudContainer.queryDatabase` periodically.\r\n */\r\n promise: Promise<boolean>;\r\n }\r\n\r\n /** @internal */\r\n export async function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps) {\r\n if (direction === \"download\")\r\n mkdirSync(dirname(props.localFileName), { recursive: true }); // make sure the directory exists before starting download\r\n\r\n let timer: NodeJS.Timeout | undefined;\r\n try {\r\n const transfer = new NativeLibrary.nativeLib.CloudDbTransfer(direction, container, props);\r\n let total = 0;\r\n const onProgress = props.onProgress;\r\n if (onProgress) {\r\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\r\n const progress = transfer.getProgress();\r\n total = progress.total;\r\n if (onProgress(progress.loaded, progress.total))\r\n transfer.cancelTransfer();\r\n }, 250);\r\n }\r\n await transfer.promise;\r\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\r\n } catch (err: any) {\r\n if (err.message === \"cancelled\")\r\n err.errorNumber = BriefcaseStatus.DownloadCancelled;\r\n\r\n throw err;\r\n } finally {\r\n if (timer)\r\n clearInterval(timer);\r\n }\r\n }\r\n\r\n /** Upload a local SQLite database file into a CloudContainer.\r\n * @param container the CloudContainer holding the database. Must be connected.\r\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\r\n * @note this function requires that the write lock be held on the container\r\n */\r\n export async function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\r\n await transferDb(\"upload\", container, props);\r\n container.checkForChanges(); // re-read the manifest so the database is available locally.\r\n }\r\n\r\n /** Download a database from a CloudContainer.\r\n * @param container the CloudContainer holding the database. Must be connected.\r\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\r\n * @returns a Promise that is resolved when the download completes.\r\n * @note the download is \"restartable.\" If the transfer is aborted and then re-requested, it will continue from where\r\n * it left off rather than re-downloading the entire file.\r\n */\r\n export async function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\r\n await transferDb(\"download\", container, props);\r\n }\r\n\r\n /** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.\r\n * @param lockedBy The identifier supplied by the application/user that currently holds the lock.\r\n * @param expires a stringified Date (in local time) indicating when the lock will expire.\r\n * @return \"stop\" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.\r\n */\r\n export type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | \"stop\">;\r\n\r\n /**\r\n * Attempt to acquire the write lock for a container, with retries.\r\n * If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns \"stop\", throw. Otherwise try again.\r\n * @note if write lock is already held, this function does nothing.\r\n * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us\r\n * @param container the CloudContainer for which the lock is to be acquired\r\n * @param busyHandler if present, function called when the write lock is currently held by another user.\r\n * @throws if [[container]] is not connected to a CloudCache.\r\n */\r\n export async function acquireWriteLock(args: { user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler }) {\r\n const container = args.container as CloudContainerInternal;\r\n while (true) {\r\n try {\r\n if (container.hasWriteLock) {\r\n if (container.writeLockHeldBy === args.user)\r\n return; // current user already has the lock\r\n\r\n const err = new Error() as any; // lock held by another user within this process\r\n err.errorNumber = 5;\r\n err.lockedBy = container.writeLockHeldBy;\r\n err.expires = container.writeLockExpires;\r\n throw err;\r\n }\r\n return container.acquireWriteLock(args.user);\r\n\r\n } catch (e: any) {\r\n if (e.errorNumber === 5 && args.busyHandler && \"stop\" !== await args.busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY\r\n continue; // busy handler wants to try again\r\n throw e;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Perform an asynchronous write operation on a CloudContainer with the write lock held.\r\n * 1. if write lock is already held by the current user, call operation and return.\r\n * 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.\r\n * 3. perform the operation\r\n * 3.a if the operation throws, abandon all changes and re-throw\r\n * 4. release the write lock.\r\n * 5. return value from operation\r\n * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us\r\n * @param container the CloudContainer for which the lock is to be acquired\r\n * @param operation an asynchronous operation performed with the write lock held.\r\n * @param busyHandler if present, function called when the write lock is currently held by another user.\r\n * @returns a Promise with the result of `operation`\r\n */\r\n export async function withWriteLock<T>(args: { user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler }, operation: () => Promise<T>): Promise<T> {\r\n await acquireWriteLock(args);\r\n const containerInternal = args.container as CloudContainerInternal;\r\n try {\r\n if (containerInternal.writeLockHeldBy === args.user) // If the user already had the write lock, then don't release it.\r\n return await operation();\r\n containerInternal.writeLockHeldBy = args.user;\r\n containerInternal.writeLockExpires = new Date(Date.now() + 1000 * containerInternal.lockExpireSeconds).toLocaleString();\r\n // eslint-disable-next-line @typescript-eslint/await-thenable\r\n const val = await operation(); // wait for work to finish or fail\r\n containerInternal.releaseWriteLock();\r\n containerInternal.writeLockHeldBy = undefined;\r\n containerInternal.writeLockExpires = undefined;\r\n return val;\r\n } catch (e) {\r\n args.container.abandonChanges(); // if operation threw, abandon all changes\r\n containerInternal.writeLockHeldBy = undefined;\r\n containerInternal.writeLockExpires = undefined;\r\n throw e;\r\n }\r\n }\r\n\r\n /** Arguments to create or find a CloudCache */\r\n export interface CreateCloudCacheArg {\r\n /** The name of the CloudCache. CloudCache names must be unique. */\r\n cacheName: string;\r\n /** A string that specifies the maximum size of the CloudCache. It should be a number followed by \"K\",\r\n * \"M\" \"G\", or \"T\". Default is \"10G\". */\r\n cacheSize?: string;\r\n /** A local directory in temporary storage for the CloudCache. If not supplied, it is a subdirectory called `cacheName`\r\n * in the `CloudCaches` temporary directory.\r\n * If the directory does not exist, it is created. */\r\n cacheDir?: string;\r\n }\r\n\r\n /** The collection of currently extant `CloudCache`s, by name. */\r\n export class CloudCaches {\r\n private static readonly cloudCaches = new Map<string, CloudCache>();\r\n\r\n /** create a new CloudCache */\r\n private static makeCache(args: CreateCloudCacheArg): CloudCache {\r\n const cacheName = args.cacheName;\r\n const rootDir = args.cacheDir ?? join(IModelHost.profileDir, \"CloudCaches\", cacheName);\r\n IModelJsFs.recursiveMkDirSync(rootDir);\r\n const cache = new NativeLibrary.nativeLib.CloudCache({ rootDir, name: cacheName, cacheSize: args.cacheSize ?? \"10G\" });\r\n this.cloudCaches.set(cacheName, cache);\r\n return cache;\r\n }\r\n\r\n /** find a CloudCache by name, if it exists */\r\n public static findCache(cacheName: string): CloudCache | undefined {\r\n return this.cloudCaches.get(cacheName);\r\n }\r\n /** @internal */\r\n public static dropCache(cacheName: string): CloudCache | undefined {\r\n const cache = this.cloudCaches.get(cacheName);\r\n this.cloudCaches.delete(cacheName);\r\n return cache;\r\n }\r\n /** called by IModelHost after shutdown.\r\n * @internal\r\n */\r\n public static destroy() {\r\n this.cloudCaches.forEach((cache) => cache.destroy());\r\n this.cloudCaches.clear();\r\n }\r\n\r\n /** Get a CloudCache by name. If the CloudCache doesn't yet exist, it is created. */\r\n public static getCache(args: CreateCloudCacheArg): CloudCache {\r\n return this.cloudCaches.get(args.cacheName) ?? this.makeCache(args);\r\n }\r\n }\r\n\r\n /** Class that provides convenient local access to a SQLite database in a CloudContainer. */\r\n export class DbAccess<DbType extends VersionedSqliteDb, ReadMethods = DbType, WriteMethods = DbType> {\r\n /** The name of the database within the cloud container. */\r\n public readonly dbName: string;\r\n /** Parameters for obtaining the write lock for this container. */\r\n public readonly lockParams: ObtainLockParams = {\r\n user: \"\",\r\n nRetries: 20,\r\n retryDelayMs: 100,\r\n };\r\n protected static _cacheName = \"default-64k\";\r\n protected _container: CloudContainer;\r\n protected _cloudDb: DbType;\r\n private _writeLockProxy?: PickAsyncMethods<WriteMethods>;\r\n private _readerProxy?: PickMethods<ReadMethods>;\r\n private get _ctor() { return this.constructor as typeof DbAccess; }\r\n\r\n /** @internal */\r\n public static getCacheForClass() {\r\n return CloudCaches.getCache({ cacheName: this._cacheName });\r\n }\r\n private _cache?: CloudCache;\r\n /** only for tests\r\n * @internal\r\n */\r\n public setCache(cache: CloudCache) {\r\n this._cache = cache;\r\n }\r\n /** @internal */\r\n public getCache(): CloudCache {\r\n return this._cache ??= this._ctor.getCacheForClass();\r\n }\r\n /** @internal */\r\n public getCloudDb(): DbType {\r\n return this._cloudDb;\r\n }\r\n\r\n /**\r\n * The token that grants access to the cloud container for this DbAccess. If it does not grant write permissions, all\r\n * write operations will fail. It should be refreshed (via a timer) before it expires.\r\n */\r\n public get sasToken() { return this._container.accessToken; }\r\n public set sasToken(token: AccessToken) { this._container.accessToken = token; }\r\n\r\n /** the container for this DbAccess. It is automatically connected to the CloudCache whenever it is accessed. */\r\n public get container(): CloudContainer {\r\n const container = this._container;\r\n if (!container.isConnected)\r\n container.connect(this.getCache());\r\n return container;\r\n }\r\n\r\n /** Start a prefetch operation to download all the blocks for the VersionedSqliteDb */\r\n public startPrefetch(): CloudPrefetch {\r\n return startCloudPrefetch(this.container, this.dbName);\r\n }\r\n\r\n /** Create a new DbAccess for a database stored in a cloud container. */\r\n public constructor(args: {\r\n /** The Constructor for DbType. */\r\n dbType: Constructor<DbType>;\r\n /** The properties of the cloud container holding the database. */\r\n props: ContainerAccessProps;\r\n /** The name of the database within the container. */\r\n dbName: string;\r\n }) {\r\n this._container = createCloudContainer({ writeable: true, ...args.props });\r\n this._cloudDb = new args.dbType(args.props);\r\n this.dbName = args.dbName;\r\n this.lockParams.user = IModelHost.userMoniker;\r\n }\r\n\r\n /** Close the database for this DbAccess, if it is open */\r\n public closeDb() {\r\n if (this._cloudDb.isOpen)\r\n this._cloudDb.closeDb();\r\n }\r\n\r\n /** Close the database for this DbAccess if it is opened, and disconnect this `DbAccess from its CloudContainer. */\r\n public close() {\r\n this.closeDb();\r\n this._container.disconnect();\r\n }\r\n\r\n /**\r\n * Initialize a cloud container to hold a Cloud SQliteDb. The container must first be created via its storage supplier api (e.g. Azure, or Google).\r\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty database into the container.\r\n * @note this deletes any existing content in the container.\r\n */\r\n protected static async _initializeDb(args: { dbType: typeof VersionedSqliteDb, props: ContainerAccessProps, dbName: string, blockSize?: \"64K\" | \"4M\" }) {\r\n const container = createCloudContainer({ ...args.props, writeable: true });\r\n container.initializeContainer({ blockSize: args.blockSize === \"4M\" ? 4 * 1024 * 1024 : 64 * 1024 });\r\n container.connect(CloudCaches.getCache({ cacheName: this._cacheName }));\r\n await withWriteLock({ user: \"initialize\", container }, async () => {\r\n const localFileName = join(KnownLocations.tmpdir, \"blank.db\");\r\n args.dbType.createNewDb(localFileName);\r\n await transferDb(\"upload\", container, { dbName: args.dbName, localFileName });\r\n unlinkSync(localFileName);\r\n });\r\n container.disconnect({ detach: true });\r\n }\r\n\r\n /**\r\n * Synchronize the local cache of this database with any changes by made by others.\r\n * @note This is called automatically whenever any write operation is performed on this DbAccess. It is only necessary to\r\n * call this directly if you have not changed the database recently, but wish to perform a readonly operation and want to\r\n * ensure it is up-to-date as of now.\r\n * @note There is no guarantee that the database is up-to-date even immediately after calling this method, since others\r\n * may be modifying it at any time.\r\n */\r\n public synchronizeWithCloud() {\r\n this.closeDb();\r\n this.container.checkForChanges();\r\n }\r\n\r\n /**\r\n * Ensure that the database controlled by this `DbAccess` is open for read access and return the database object.\r\n * @note if the database is already open (either for read or write), this method merely returns the database object.\r\n */\r\n public openForRead(): DbType {\r\n if (!this._cloudDb.isOpen)\r\n this._cloudDb.openDb(this.dbName, OpenMode.Readonly, this.container);\r\n return this._cloudDb;\r\n }\r\n\r\n /**\r\n * Perform an operation on this database with the lock held and the database opened for write\r\n * @param operationName the name of the operation. Only used for logging.\r\n * @param operation a function called with the lock held and the database open for write.\r\n * @returns A promise that resolves to the the return value of `operation`.\r\n * @see `SQLiteDb.withLockedContainer`\r\n * @note Most uses of `CloudSqliteDbAccess` require that the lock not be held by any operation for long. Make sure you don't\r\n * do any avoidable or time consuming work in your operation function.\r\n */\r\n public async withLockedDb<T>(args: { operationName: string, openMode?: OpenMode, user?: string }, operation: () => Promise<T>): Promise<T> {\r\n let nRetries = this.lockParams.nRetries;\r\n const cacheGuid = this.container.cache!.guid; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n const user = args.user ?? this.lockParams.user ?? cacheGuid;\r\n const timer = new StopWatch(undefined, true);\r\n const showMs = () => `(${timer.elapsed.milliseconds}ms)`;\r\n\r\n const busyHandler = async (lockedBy: string, expires: string): Promise<void | \"stop\"> => {\r\n if (--nRetries <= 0) {\r\n if (\"stop\" === await this.lockParams.onFailure?.(lockedBy, expires))\r\n return \"stop\";\r\n nRetries = this.lockParams.nRetries;\r\n }\r\n const delay = this.lockParams.retryDelayMs;\r\n logInfo(`lock retry for ${cacheGuid} after ${showMs()}, waiting ${delay}`);\r\n await BeDuration.fromMilliseconds(delay).wait();\r\n };\r\n\r\n this.closeDb(); // in case it is currently open for read.\r\n let lockObtained = false;\r\n const operationName = args.operationName;\r\n try {\r\n return await this._cloudDb.withLockedContainer({ user, dbName: this.dbName, container: this.container, busyHandler, openMode: args.openMode }, async () => {\r\n lockObtained = true;\r\n logInfo(`lock acquired by ${cacheGuid} for ${operationName} ${showMs()}`);\r\n return operation();\r\n });\r\n } finally {\r\n if (lockObtained)\r\n logInfo(`lock released by ${cacheGuid} after ${operationName} ${showMs()} `);\r\n else\r\n logError(`could not obtain lock for ${cacheGuid} to perform ${operationName} ${showMs()} `);\r\n }\r\n }\r\n\r\n /** get a method member, by name, from the database object. Throws if not a Function. */\r\n private getDbMethod(methodName: string): Function {\r\n const fn = (this._cloudDb as any)[methodName] as Function;\r\n if (typeof fn !== \"function\")\r\n throw new Error(`illegal method name ${methodName}`);\r\n return fn;\r\n }\r\n\r\n /**\r\n * A Proxy Object to call a writeable async method on the cloud database controlled by this `DbAccess`.\r\n *\r\n * Whenever a method is called through this Proxy, it will:\r\n * - attempt to acquire the write lock on the container\r\n * - open the database for write\r\n * - call the method\r\n * - close the database\r\n * - upload changes\r\n * - release the write lock.\r\n *\r\n * @see [[withLockedDb]]\r\n */\r\n public get writeLocker() {\r\n return this._writeLockProxy ??= new Proxy(this, {\r\n get(access, operationName: string) {\r\n const fn = access.getDbMethod(operationName);\r\n return async (...args: any[]) => access.withLockedDb({ operationName, user: RpcTrace.currentActivity?.user }, fn.bind(access._cloudDb, ...args));\r\n },\r\n }) as PickAsyncMethods<WriteMethods>;\r\n }\r\n\r\n /**\r\n * A Proxy Object to call a synchronous readonly method on the database controlled by this `DbAccess`.\r\n * Whenever a method is called through this Proxy, it will first ensure that the database is opened for at least read access.\r\n */\r\n public get reader() {\r\n return this._readerProxy ??= new Proxy(this, {\r\n get(access, methodName: string) {\r\n const fn = access.getDbMethod(methodName);\r\n return (...args: any[]) => fn.call(access.openForRead(), ...args);\r\n },\r\n }) as PickMethods<ReadMethods>;\r\n }\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-backend",
|
|
3
|
-
"version": "4.2.0-dev.
|
|
3
|
+
"version": "4.2.0-dev.15",
|
|
4
4
|
"description": "iTwin.js backend components",
|
|
5
5
|
"main": "lib/cjs/core-backend.js",
|
|
6
6
|
"typings": "lib/cjs/core-backend",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"url": "http://www.bentley.com"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@itwin/core-bentley": "^4.2.0-dev.
|
|
29
|
-
"@itwin/core-common": "^4.2.0-dev.
|
|
30
|
-
"@itwin/core-geometry": "^4.2.0-dev.
|
|
28
|
+
"@itwin/core-bentley": "^4.2.0-dev.15",
|
|
29
|
+
"@itwin/core-common": "^4.2.0-dev.15",
|
|
30
|
+
"@itwin/core-geometry": "^4.2.0-dev.15",
|
|
31
31
|
"@opentelemetry/api": "^1.0.4"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
|
@@ -66,12 +66,12 @@
|
|
|
66
66
|
"source-map-loader": "^4.0.0",
|
|
67
67
|
"typescript": "~5.0.2",
|
|
68
68
|
"webpack": "^5.76.0",
|
|
69
|
-
"@itwin/build-tools": "4.2.0-dev.
|
|
70
|
-
"@itwin/core-
|
|
71
|
-
"@itwin/core-
|
|
72
|
-
"@itwin/core-
|
|
73
|
-
"@itwin/core-webpack-tools": "4.2.0-dev.
|
|
74
|
-
"@itwin/ecsql-common": "4.2.0-dev.
|
|
69
|
+
"@itwin/build-tools": "4.2.0-dev.15",
|
|
70
|
+
"@itwin/core-common": "4.2.0-dev.15",
|
|
71
|
+
"@itwin/core-bentley": "4.2.0-dev.15",
|
|
72
|
+
"@itwin/core-geometry": "4.2.0-dev.15",
|
|
73
|
+
"@itwin/core-webpack-tools": "4.2.0-dev.15",
|
|
74
|
+
"@itwin/ecsql-common": "4.2.0-dev.15",
|
|
75
75
|
"internal-tools": "3.0.0-dev.69"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"reflect-metadata": "^0.1.13",
|
|
88
88
|
"semver": "^7.3.5",
|
|
89
89
|
"ws": "^7.5.3",
|
|
90
|
-
"@itwin/core-telemetry": "4.2.0-dev.
|
|
90
|
+
"@itwin/core-telemetry": "4.2.0-dev.15"
|
|
91
91
|
},
|
|
92
92
|
"nyc": {
|
|
93
93
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|