@itwin/core-backend 3.5.0-dev.8 → 3.5.0
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/CHANGELOG.md +107 -1
- package/lib/cjs/BriefcaseManager.d.ts +7 -2
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +11 -3
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
- package/lib/cjs/ChangeSummaryManager.js +2 -0
- package/lib/cjs/ChangeSummaryManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts +8 -0
- package/lib/cjs/ClassRegistry.d.ts.map +1 -1
- package/lib/cjs/ClassRegistry.js +47 -13
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +1 -0
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +1 -0
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/ConcurrentQuery.d.ts +3 -1
- package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
- package/lib/cjs/ConcurrentQuery.js +6 -0
- package/lib/cjs/ConcurrentQuery.js.map +1 -1
- package/lib/cjs/CustomViewState3dCreator.d.ts +3 -14
- package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
- package/lib/cjs/CustomViewState3dCreator.js +11 -43
- package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +9 -9
- package/lib/cjs/DisplayStyle.d.ts.map +1 -1
- package/lib/cjs/DisplayStyle.js +12 -12
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/Element.d.ts +23 -30
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +42 -46
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +24 -4
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +35 -2
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/Entity.d.ts +31 -1
- package/lib/cjs/Entity.d.ts.map +1 -1
- package/lib/cjs/Entity.js +52 -0
- package/lib/cjs/Entity.js.map +1 -1
- package/lib/cjs/EntityReferences.d.ts +50 -0
- package/lib/cjs/EntityReferences.d.ts.map +1 -0
- package/lib/cjs/EntityReferences.js +96 -0
- package/lib/cjs/EntityReferences.js.map +1 -0
- package/lib/cjs/ExternalSource.d.ts +3 -1
- package/lib/cjs/ExternalSource.d.ts.map +1 -1
- package/lib/cjs/ExternalSource.js +6 -0
- package/lib/cjs/ExternalSource.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
- package/lib/cjs/GeoCoordConfig.js +10 -7
- package/lib/cjs/GeoCoordConfig.js.map +1 -1
- package/lib/cjs/HubMock.d.ts +1 -0
- package/lib/cjs/HubMock.d.ts.map +1 -1
- package/lib/cjs/HubMock.js +34 -2
- package/lib/cjs/HubMock.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +5 -82
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +7 -142
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +21 -2
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +64 -14
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelElementCloneContext.d.ts +90 -0
- package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -0
- package/lib/cjs/IModelElementCloneContext.js +160 -0
- package/lib/cjs/IModelElementCloneContext.js.map +1 -0
- package/lib/cjs/IModelHost.d.ts +9 -0
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +9 -2
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts +6 -0
- package/lib/cjs/IpcHost.d.ts.map +1 -1
- package/lib/cjs/IpcHost.js +47 -3
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/Model.d.ts +8 -2
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +15 -1
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/NativeHost.d.ts.map +1 -1
- package/lib/cjs/NativeHost.js +10 -15
- package/lib/cjs/NativeHost.js.map +1 -1
- package/lib/cjs/PromiseMemoizer.d.ts +4 -4
- package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
- package/lib/cjs/PromiseMemoizer.js +44 -44
- package/lib/cjs/PromiseMemoizer.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +18 -2
- package/lib/cjs/Relationship.d.ts.map +1 -1
- package/lib/cjs/Relationship.js +30 -1
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/RpcBackend.d.ts +0 -23
- package/lib/cjs/RpcBackend.d.ts.map +1 -1
- package/lib/cjs/RpcBackend.js +13 -108
- package/lib/cjs/RpcBackend.js.map +1 -1
- package/lib/cjs/SqliteStatement.d.ts +81 -4
- package/lib/cjs/SqliteStatement.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js +163 -25
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +14 -10
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +31 -20
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/ViewStateHydrator.js +2 -2
- package/lib/cjs/ViewStateHydrator.js.map +1 -1
- package/lib/cjs/core-backend.d.ts +4 -2
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +4 -2
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/rpc/multipart.d.ts +12 -0
- package/lib/cjs/rpc/multipart.d.ts.map +1 -0
- package/lib/cjs/rpc/multipart.js +71 -0
- package/lib/cjs/rpc/multipart.js.map +1 -0
- package/lib/cjs/rpc/tracing.d.ts +29 -0
- package/lib/cjs/rpc/tracing.d.ts.map +1 -0
- package/lib/cjs/rpc/tracing.js +74 -0
- package/lib/cjs/rpc/tracing.js.map +1 -0
- package/lib/cjs/rpc/web/logging.d.ts +10 -0
- package/lib/cjs/rpc/web/logging.d.ts.map +1 -0
- package/lib/cjs/rpc/web/logging.js +43 -0
- package/lib/cjs/rpc/web/logging.js.map +1 -0
- package/lib/cjs/rpc/web/request.d.ts +7 -0
- package/lib/cjs/rpc/web/request.d.ts.map +1 -0
- package/lib/cjs/rpc/web/request.js +74 -0
- package/lib/cjs/rpc/web/request.js.map +1 -0
- package/lib/cjs/rpc/web/response.d.ts +7 -0
- package/lib/cjs/rpc/web/response.d.ts.map +1 -0
- package/lib/cjs/rpc/web/response.js +106 -0
- package/lib/cjs/rpc/web/response.js.map +1 -0
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +4 -2
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +80 -51
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +13 -15
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +1 -1
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +2 -2
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeoCoordConfig.js","sourceRoot":"","sources":["../../src/GeoCoordConfig.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA2D;AAC3D,+CAA4C;AAC5C,6CAA0C;AAI1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,CAAC,QAAQ,EAAE,CAAC;YAC9K,qBAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,MAAM,CAAC,OAAO,CAAC,QAAkB,EAAE,WAAmB;QAC5D,QAAQ,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACtB,KAAK,MAAM,KAAK,IAAI,GAAG,EAAE;oBACvB,IAAI,OAAO,KAAK,KAAK,QAAQ;wBAC3B,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;iBAC/B;aACF;YACD,OAAO,SAAS,CAAC,CAAC,sCAAsC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC;IAGM,MAAM,CAAC,SAAS;QACrB,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IAC7B,CAAC;IAEM,MAAM,CAAC,oBAAoB;QAChC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAC3B,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;YAC9B,IAAI,CAAC,OAAO,CAAC,uBAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAC;SACzE;IACH,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,QAAkB;QAC5C,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC1C,CAAC;;AA3EH,wCA4EC;AA3EC,gFAAgF;AACzD,yBAAU,GAAgC,EAAE,CAAC;AAyDrD,gCAAiB,GAAG,KAAK,CAAC","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\nimport { BentleyError, Logger } from \"@itwin/core-bentley\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { Settings } from \"./workspace/Settings\";\r\nimport { WorkspaceAccount, WorkspaceContainer, WorkspaceDb } from \"./workspace/Workspace\";\r\n\r\nconst loggerCat = \"GeoCoord\";\r\n\r\ninterface GcsDbProps extends WorkspaceDb.Props, WorkspaceContainer.Alias {\r\n prefetch?: boolean;\r\n priority?: number;\r\n}\r\n\r\n/**\r\n * Internal class to configure and load the gcs workspaces for an iModel.\r\n * @internal\r\n */\r\nexport class GeoCoordConfig {\r\n /** array of cloud prefetch tasks that may be awaited to permit offline usage */\r\n public static readonly prefetches: CloudSqlite.CloudPrefetch[] = [];\r\n\r\n private static addGcsWorkspace(gcsDbAlias: string) {\r\n // override to disable loading GCS data from workspaces\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"gcs/disableWorkspaces\", false))\r\n return;\r\n\r\n let account: CloudSqlite.AccountAccessProps | undefined;\r\n let containerProps: WorkspaceContainer.Props & WorkspaceAccount.Alias | undefined;\r\n try {\r\n const ws = IModelHost.appWorkspace;\r\n const dbProps = ws.resolveDatabase(gcsDbAlias) as GcsDbProps;\r\n containerProps = ws.resolveContainer(dbProps.containerName);\r\n account = ws.resolveAccount(containerProps.accountName);\r\n const container = ws.getContainer(containerProps, account);\r\n const cloudContainer = container.cloudContainer;\r\n if (!cloudContainer?.isConnected) {\r\n Logger.logError(\"GeoCoord\", `could not load gcs database \"${gcsDbAlias}\"`);\r\n return;\r\n }\r\n\r\n const gcsDbName = container.resolveDbFileName(dbProps);\r\n const gcsDbProps = cloudContainer.queryDatabase(gcsDbName);\r\n if (undefined === gcsDbProps)\r\n throw new Error(`database \"${gcsDbName}\" not found in container \"${containerProps.containerId}\"`);\r\n\r\n if (!IModelHost.platform.addGcsWorkspaceDb(gcsDbName, cloudContainer, dbProps.priority))\r\n return; // already had this db\r\n\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"gcs/noLocalData\", false))\r\n IModelHost.platform.enableLocalGcsFiles(false);\r\n\r\n Logger.logInfo(loggerCat, `loaded gcsDb \"${gcsDbName}\", from \"${account.accessName}/${containerProps.containerId}\" size=${gcsDbProps.totalBlocks}, local=${gcsDbProps.localBlocks}`);\r\n\r\n if (true === dbProps.prefetch)\r\n this.prefetches.push(CloudSqlite.startCloudPrefetch(cloudContainer, gcsDbName));\r\n\r\n } catch (e: any) {\r\n let msg = `Cannot load GCS workspace (${e.errorNumber}): ${BentleyError.getErrorMessage(e)}`;\r\n if (account && containerProps)\r\n msg += `,container=${account.accessName}/${containerProps.containerId}, storage=${account.storageType}, public=${containerProps.isPublic}, cacheDir=${IModelHost.cacheDir}`;\r\n Logger.logError(loggerCat, msg);\r\n }\r\n }\r\n\r\n private static loadAll(settings: Settings, settingName: string) {\r\n settings.resolveSetting(settingName, (val) => {\r\n if (Array.isArray(val)) {\r\n for (const entry of val) {\r\n if (typeof entry === \"string\")\r\n this.addGcsWorkspace(entry);\r\n }\r\n }\r\n return undefined; // keep going through all dictionaries\r\n });\r\n }\r\n\r\n private static _defaultDbsLoaded = false;\r\n public static onStartup() {\r\n this._defaultDbsLoaded = false;\r\n this.prefetches.length = 0;\r\n }\r\n\r\n public static loadDefaultDatabases(): void {\r\n if (!this._defaultDbsLoaded) {\r\n this._defaultDbsLoaded = true;\r\n this.loadAll(IModelHost.appWorkspace.settings, \"gcs/default/databases\");\r\n }\r\n }\r\n\r\n public static loadForImodel(settings: Settings) {\r\n this.loadDefaultDatabases();\r\n this.loadAll(settings, \"gcs/databases\");\r\n }\r\n}\r\n"]}
|
package/lib/cjs/HubMock.d.ts
CHANGED
package/lib/cjs/HubMock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HubMock.d.ts","sourceRoot":"","sources":["../../src/HubMock.ts"],"names":[],"m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CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;WAIzF,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG;QAAE,cAAc,EAAE,kBAAkB,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;WAIjG,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC;WAKtF,oBAAoB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;WAItE,eAAe,CAAC,GAAG,EAAE,cAAc;WAKnC,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;WAIzD,YAAY,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;WAIhE,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;WAStE,YAAY,CAAC,GAAG,EAAE,WAAW,GAAG;QAAE,OAAO,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;mBAItE,qBAAqB;CAqB3C"}
|
package/lib/cjs/HubMock.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.HubMock = void 0;
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
10
|
+
const CheckpointManager_1 = require("./CheckpointManager");
|
|
10
11
|
const IModelHost_1 = require("./IModelHost");
|
|
11
12
|
const IModelJsFs_1 = require("./IModelJsFs");
|
|
12
13
|
const LocalHub_1 = require("./LocalHub");
|
|
@@ -143,10 +144,22 @@ class HubMock {
|
|
|
143
144
|
return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);
|
|
144
145
|
}
|
|
145
146
|
static async downloadChangeset(arg) {
|
|
146
|
-
|
|
147
|
+
var _a;
|
|
148
|
+
const changesetProps = this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });
|
|
149
|
+
if (arg.progressCallback) {
|
|
150
|
+
const totalSize = (_a = IModelJsFs_1.IModelJsFs.lstatSync(changesetProps.pathname)) === null || _a === void 0 ? void 0 : _a.size;
|
|
151
|
+
if (totalSize)
|
|
152
|
+
await HubMock.mockProgressReporting(arg.progressCallback, totalSize);
|
|
153
|
+
}
|
|
154
|
+
return changesetProps;
|
|
147
155
|
}
|
|
148
156
|
static async downloadChangesets(arg) {
|
|
149
|
-
|
|
157
|
+
const changesetProps = this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });
|
|
158
|
+
if (arg.progressCallback) {
|
|
159
|
+
const totalSize = changesetProps.reduce((sum, props) => { var _a, _b; return sum + ((_b = (_a = IModelJsFs_1.IModelJsFs.lstatSync(props.pathname)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0); }, 0);
|
|
160
|
+
await HubMock.mockProgressReporting(arg.progressCallback, totalSize);
|
|
161
|
+
}
|
|
162
|
+
return changesetProps;
|
|
150
163
|
}
|
|
151
164
|
static async queryChangeset(arg) {
|
|
152
165
|
return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));
|
|
@@ -185,6 +198,25 @@ class HubMock {
|
|
|
185
198
|
static async deleteIModel(arg) {
|
|
186
199
|
return this.destroy(arg.iModelId);
|
|
187
200
|
}
|
|
201
|
+
static async mockProgressReporting(progressCallback, totalSize) {
|
|
202
|
+
await new Promise((resolve, reject) => {
|
|
203
|
+
let rejected = false;
|
|
204
|
+
const mockProgress = (index) => {
|
|
205
|
+
const bytesDownloaded = Math.floor(totalSize * (index / 4));
|
|
206
|
+
if (!rejected && progressCallback(bytesDownloaded, totalSize) === CheckpointManager_1.ProgressStatus.Abort) {
|
|
207
|
+
rejected = true;
|
|
208
|
+
reject(new Error("AbortError"));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
mockProgress(1);
|
|
212
|
+
setTimeout(() => mockProgress(2), 50);
|
|
213
|
+
setTimeout(() => mockProgress(3), 100);
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
mockProgress(4);
|
|
216
|
+
resolve(undefined);
|
|
217
|
+
}, 150);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
188
220
|
}
|
|
189
221
|
exports.HubMock = HubMock;
|
|
190
222
|
HubMock.hubs = new Map();
|
package/lib/cjs/HubMock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HubMock.js","sourceRoot":"","sources":["../../src/HubMock.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,+BAA4B;AAC5B,sDAAuD;AAUvD,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAsC;AAGtC,SAAS,UAAU,CAAC,GAAuB;IACzC,IAAI,SAAS,KAAK,GAAG;QACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,OAAO;IAMlB,oEAAoE;IAC7D,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,MAAM,KAAK,OAAO;QACvB,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,QAAsB,EAAE,SAAiB;QAC7D,IAAI,IAAI,CAAC,OAAO;YACd,MAAM,IAAI,KAAK,CAAC,0JAA0J,CAAC,CAAC;QAE9K,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,S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nB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,GAA0C;QACzE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;;AA/KH,0BAgLC;AA9KgB,YAAI,GAAG,IAAI,GAAG,EAAoB,CAAC","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\r\nimport { join } from \"path\";\r\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\r\nimport {\r\n ChangesetFileProps, ChangesetIndex, ChangesetIndexAndId, ChangesetProps, ChangesetRange, IModelVersion, LocalDirName,\r\n} from \"@itwin/core-common\";\r\nimport {\r\n AcquireNewBriefcaseIdArg,\r\n BackendHubAccess, BriefcaseDbArg, BriefcaseIdArg, ChangesetArg, CheckpointArg, CreateNewIModelProps, DownloadChangesetArg, DownloadChangesetRangeArg, IModelIdArg, IModelNameArg,\r\n LockMap, LockProps, V2CheckpointAccessProps,\r\n} from \"./BackendHubAccess\";\r\nimport { CheckpointProps } from \"./CheckpointManager\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { LocalHub } from \"./LocalHub\";\r\nimport { TokenArg } from \"./IModelDb\";\r\n\r\nfunction wasStarted(val: string | undefined): asserts val is string {\r\n if (undefined === val)\r\n throw new Error(\"Call HubMock.startup first\");\r\n}\r\n\r\n/**\r\n * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.\r\n *\r\n * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:\r\n * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs\r\n * - waste network and data center resources (i.e. $$$s),\r\n * - interfere with other tests running on the same or other systems, and\r\n * - (far worse) are the source of test flakiness outside of the api being tested.\r\n *\r\n * This class can be used to create tests that do not require authentication, are synchronous,\r\n * are guaranteed to be self-contained (i.e. do not interfere with other tests running at the same time or later), and do not fail for reasons outside\r\n * of the control of the test itself. As a bonus, in addition to making tests more reliable, mocking IModelHub generally makes tests run *much* faster.\r\n *\r\n * On the other hand, tests that expect to find an existing iModels, checkpoints, changesets, etc. in IModelHub cannot be mocked. In that case, those tests\r\n * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to\r\n * low level testing of the core apis only.\r\n *\r\n * To initialize HubMock, call [[startup]] at the beginning of your test, usually in `describe.before`. Thereafter, all access to iModelHub for an iModel will be\r\n * directed to a [[LocalHub]] - your test code does not change. After the test(s) complete, call [[shutdown]] (usually in `describe.after`) to stop mocking IModelHub and clean\r\n * up any resources used by the test(s). If you want to mock a single test, call [[startup]] as the first line and [[shutdown]] as the last. If you wish to run the\r\n * test against a \"real\" IModelHub, you can simply comment off the call [[startup]], though in that case you should make sure the name of your\r\n * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)\r\n *\r\n * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.\r\n * They use mock (aka \"bogus\") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current\r\n * computer.\r\n *\r\n * @note Only one HubMock at a time, *running in a single process*, may be active. The comments above about multiple simultaneous tests refer to tests\r\n * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.\r\n *\r\n * @internal\r\n */\r\nexport class HubMock {\r\n private static mockRoot: LocalDirName | undefined;\r\n private static hubs = new Map<string, LocalHub>();\r\n private static _saveHubAccess: BackendHubAccess | undefined;\r\n private static _iTwinId: GuidString | undefined;\r\n\r\n /** Determine whether a test us currently being run under HubMock */\r\n public static get isValid() { return undefined !== this.mockRoot; }\r\n public static get iTwinId() {\r\n wasStarted(this._iTwinId);\r\n return this._iTwinId;\r\n }\r\n\r\n /**\r\n * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].\r\n * @param mockName a unique name (e.g. \"MyTest\") for this HubMock to disambiguate tests when more than one is simultaneously active.\r\n * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.\r\n */\r\n public static startup(mockName: LocalDirName, outputDir: string) {\r\n if (this.isValid)\r\n throw new Error(\"Either a previous test did not call HubMock.shutdown() properly, or more than one test is simultaneously attempting to use HubMock, which is not allowed\");\r\n\r\n this.hubs.clear();\r\n this.mockRoot = join(outputDir, \"HubMock\", mockName);\r\n IModelJsFs.recursiveMkDirSync(this.mockRoot);\r\n IModelJsFs.purgeDirSync(this.mockRoot);\r\n this._saveHubAccess = IModelHost.getHubAccess();\r\n\r\n IModelHost.setHubAccess(this);\r\n HubMock._iTwinId = Guid.createValue(); // all iModels for this test get the same \"iTwinId\"\r\n }\r\n\r\n /** Stop a HubMock that was previously started with [[startup]]\r\n * @note this function throws an exception if any of the iModels used during the tests are left open.\r\n */\r\n public static shutdown() {\r\n if (this.mockRoot === undefined)\r\n return;\r\n\r\n HubMock._iTwinId = undefined;\r\n for (const hub of this.hubs)\r\n hub[1].cleanup();\r\n\r\n this.hubs.clear();\r\n IModelJsFs.purgeDirSync(this.mockRoot);\r\n IModelJsFs.removeSync(this.mockRoot);\r\n IModelHost.setHubAccess(this._saveHubAccess);\r\n this.mockRoot = undefined;\r\n }\r\n\r\n public static findLocalHub(iModelId: GuidString): LocalHub {\r\n const hub = this.hubs.get(iModelId);\r\n if (!hub)\r\n throw new Error(`local hub for iModel ${iModelId} not created`);\r\n return hub;\r\n }\r\n\r\n /** create a [[LocalHub]] for an iModel. */\r\n public static async createNewIModel(arg: CreateNewIModelProps): Promise<GuidString> {\r\n wasStarted(this.mockRoot);\r\n const props = { ...arg, iModelId: Guid.createValue() };\r\n const mock = new LocalHub(join(this.mockRoot, props.iModelId), props);\r\n this.hubs.set(props.iModelId, mock);\r\n return props.iModelId;\r\n }\r\n\r\n /** remove the [[LocalHub]] for an iModel */\r\n public static destroy(iModelId: GuidString) {\r\n this.findLocalHub(iModelId).cleanup();\r\n this.hubs.delete(iModelId);\r\n }\r\n\r\n /** All methods below are mocks of the [[BackendHubAccess]] interface */\r\n\r\n public static async getChangesetFromNamedVersion(arg: IModelIdArg & { versionName: string }): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).findNamedVersion(arg.versionName);\r\n }\r\n\r\n private static changesetIndexFromArg(arg: ChangesetArg) {\r\n return (undefined !== arg.changeset.index) ? arg.changeset.index : this.findLocalHub(arg.iModelId).getChangesetIndex(arg.changeset.id);\r\n }\r\n\r\n public static async getChangesetFromVersion(arg: IModelIdArg & { version: IModelVersion }): Promise<ChangesetProps> {\r\n const hub = this.findLocalHub(arg.iModelId);\r\n const version = arg.version;\r\n if (version.isFirst)\r\n return hub.getChangesetByIndex(0);\r\n\r\n const asOf = version.getAsOfChangeSet();\r\n if (asOf)\r\n return hub.getChangesetById(asOf);\r\n\r\n const versionName = version.getName();\r\n if (versionName)\r\n return hub.findNamedVersion(versionName);\r\n\r\n return hub.getLatestChangeset();\r\n }\r\n\r\n public static async getLatestChangeset(arg: IModelIdArg): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).getLatestChangeset();\r\n }\r\n\r\n private static async getAccessToken(arg: TokenArg) {\r\n return arg.accessToken ?? await IModelHost.getAccessToken();\r\n }\r\n\r\n public static async getMyBriefcaseIds(arg: IModelIdArg): Promise<number[]> {\r\n const accessToken = await this.getAccessToken(arg);\r\n return this.findLocalHub(arg.iModelId).getBriefcaseIds(accessToken);\r\n }\r\n\r\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<number> {\r\n const accessToken = await this.getAccessToken(arg);\r\n return this.findLocalHub(arg.iModelId).acquireNewBriefcaseId(accessToken, arg.briefcaseAlias);\r\n }\r\n\r\n /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */\r\n public static async releaseBriefcase(arg: BriefcaseIdArg): Promise<void> {\r\n return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);\r\n }\r\n\r\n public static async downloadChangeset(arg: DownloadChangesetArg): Promise<ChangesetFileProps> {\r\n return this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });\r\n }\r\n\r\n public static async downloadChangesets(arg: DownloadChangesetRangeArg): Promise<ChangesetFileProps[]> {\r\n return this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });\r\n }\r\n\r\n public static async queryChangeset(arg: ChangesetArg): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));\r\n }\r\n\r\n public static async queryChangesets(arg: IModelIdArg & { range?: ChangesetRange }): Promise<ChangesetProps[]> {\r\n return this.findLocalHub(arg.iModelId).queryChangesets(arg.range);\r\n }\r\n\r\n public static async pushChangeset(arg: IModelIdArg & { changesetProps: ChangesetFileProps }): Promise<ChangesetIndex> {\r\n return this.findLocalHub(arg.iModelId).addChangeset(arg.changesetProps);\r\n }\r\n\r\n public static async queryV2Checkpoint(_arg: CheckpointProps): Promise<V2CheckpointAccessProps | undefined> {\r\n return undefined;\r\n }\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n public static async downloadV1Checkpoint(arg: CheckpointArg): Promise<ChangesetIndexAndId> {\r\n return this.findLocalHub(arg.checkpoint.iModelId).downloadCheckpoint({ changeset: arg.checkpoint.changeset, targetFile: arg.localFile });\r\n }\r\n\r\n public static async releaseAllLocks(arg: BriefcaseDbArg) {\r\n const hub = this.findLocalHub(arg.iModelId);\r\n hub.releaseAllLocks({ briefcaseId: arg.briefcaseId, changesetIndex: hub.getIndexFromChangeset(arg.changeset) });\r\n }\r\n\r\n public static async queryAllLocks(_arg: BriefcaseDbArg): Promise<LockProps[]> {\r\n return [];\r\n }\r\n\r\n public static async acquireLocks(arg: BriefcaseDbArg, locks: LockMap): Promise<void> {\r\n this.findLocalHub(arg.iModelId).acquireLocks(locks, arg);\r\n }\r\n\r\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\r\n for (const hub of this.hubs) {\r\n const localHub = hub[1];\r\n if (localHub.iTwinId === arg.iTwinId && localHub.iModelName === arg.iModelName)\r\n return localHub.iModelId;\r\n }\r\n return undefined;\r\n }\r\n\r\n public static async deleteIModel(arg: IModelIdArg & { iTwinId: GuidString }): Promise<void> {\r\n return this.destroy(arg.iModelId);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"HubMock.js","sourceRoot":"","sources":["../../src/HubMock.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,+BAA4B;AAC5B,sDAAuD;AASvD,2DAAwF;AACxF,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAsC;AAGtC,SAAS,UAAU,CAAC,GAAuB;IACzC,IAAI,SAAS,KAAK,GAAG;QACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,OAAO;IAMlB,oEAAoE;IAC7D,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,MAAM,KAAK,OAAO;QACvB,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,QAAsB,EAAE,SAAiB;QAC7D,IAAI,IAAI,CAAC,OAAO;YACd,MAAM,IAAI,KAAK,CAAC,0JAA0J,CAAC,CAAC;QAE9K,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACrD,uBAAU,CAAC,kBAAk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oBAChB,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;iBACjC;YACH,CAAC,CAAC;YAEF,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtC,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACvC,UAAU,CAAC,GAAG,EAAE;gBACd,YAAY,CAAC,CAAC,CAAC,CAAC;gBAChB,OAAO,CAAC,SAAS,CAAC,CAAC;YACrB,CAAC,EAAE,GAAG,CAAC,CAAC;QACV,CAAC,CAAC,CAAC;IACL,CAAC;;AApNH,0BAqNC;AAnNgB,YAAI,GAAG,IAAI,GAAG,EAAoB,CAAC","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\r\nimport { join } from \"path\";\r\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\r\nimport {\r\n ChangesetFileProps, ChangesetIndex, ChangesetIndexAndId, ChangesetProps, ChangesetRange, IModelVersion, LocalDirName,\r\n} from \"@itwin/core-common\";\r\nimport {\r\n AcquireNewBriefcaseIdArg,\r\n BackendHubAccess, BriefcaseDbArg, BriefcaseIdArg, ChangesetArg, CheckpointArg, CreateNewIModelProps, DownloadChangesetArg, DownloadChangesetRangeArg, IModelIdArg, IModelNameArg,\r\n LockMap, LockProps, V2CheckpointAccessProps,\r\n} from \"./BackendHubAccess\";\r\nimport { CheckpointProps, ProgressFunction, ProgressStatus } from \"./CheckpointManager\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { LocalHub } from \"./LocalHub\";\r\nimport { TokenArg } from \"./IModelDb\";\r\n\r\nfunction wasStarted(val: string | undefined): asserts val is string {\r\n if (undefined === val)\r\n throw new Error(\"Call HubMock.startup first\");\r\n}\r\n\r\n/**\r\n * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.\r\n *\r\n * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:\r\n * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs\r\n * - waste network and data center resources (i.e. $$$s),\r\n * - interfere with other tests running on the same or other systems, and\r\n * - (far worse) are the source of test flakiness outside of the api being tested.\r\n *\r\n * This class can be used to create tests that do not require authentication, are synchronous,\r\n * are guaranteed to be self-contained (i.e. do not interfere with other tests running at the same time or later), and do not fail for reasons outside\r\n * of the control of the test itself. As a bonus, in addition to making tests more reliable, mocking IModelHub generally makes tests run *much* faster.\r\n *\r\n * On the other hand, tests that expect to find an existing iModels, checkpoints, changesets, etc. in IModelHub cannot be mocked. In that case, those tests\r\n * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to\r\n * low level testing of the core apis only.\r\n *\r\n * To initialize HubMock, call [[startup]] at the beginning of your test, usually in `describe.before`. Thereafter, all access to iModelHub for an iModel will be\r\n * directed to a [[LocalHub]] - your test code does not change. After the test(s) complete, call [[shutdown]] (usually in `describe.after`) to stop mocking IModelHub and clean\r\n * up any resources used by the test(s). If you want to mock a single test, call [[startup]] as the first line and [[shutdown]] as the last. If you wish to run the\r\n * test against a \"real\" IModelHub, you can simply comment off the call [[startup]], though in that case you should make sure the name of your\r\n * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)\r\n *\r\n * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.\r\n * They use mock (aka \"bogus\") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current\r\n * computer.\r\n *\r\n * @note Only one HubMock at a time, *running in a single process*, may be active. The comments above about multiple simultaneous tests refer to tests\r\n * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.\r\n *\r\n * @internal\r\n */\r\nexport class HubMock {\r\n private static mockRoot: LocalDirName | undefined;\r\n private static hubs = new Map<string, LocalHub>();\r\n private static _saveHubAccess: BackendHubAccess | undefined;\r\n private static _iTwinId: GuidString | undefined;\r\n\r\n /** Determine whether a test us currently being run under HubMock */\r\n public static get isValid() { return undefined !== this.mockRoot; }\r\n public static get iTwinId() {\r\n wasStarted(this._iTwinId);\r\n return this._iTwinId;\r\n }\r\n\r\n /**\r\n * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].\r\n * @param mockName a unique name (e.g. \"MyTest\") for this HubMock to disambiguate tests when more than one is simultaneously active.\r\n * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.\r\n */\r\n public static startup(mockName: LocalDirName, outputDir: string) {\r\n if (this.isValid)\r\n throw new Error(\"Either a previous test did not call HubMock.shutdown() properly, or more than one test is simultaneously attempting to use HubMock, which is not allowed\");\r\n\r\n this.hubs.clear();\r\n this.mockRoot = join(outputDir, \"HubMock\", mockName);\r\n IModelJsFs.recursiveMkDirSync(this.mockRoot);\r\n IModelJsFs.purgeDirSync(this.mockRoot);\r\n this._saveHubAccess = IModelHost.getHubAccess();\r\n\r\n IModelHost.setHubAccess(this);\r\n HubMock._iTwinId = Guid.createValue(); // all iModels for this test get the same \"iTwinId\"\r\n }\r\n\r\n /** Stop a HubMock that was previously started with [[startup]]\r\n * @note this function throws an exception if any of the iModels used during the tests are left open.\r\n */\r\n public static shutdown() {\r\n if (this.mockRoot === undefined)\r\n return;\r\n\r\n HubMock._iTwinId = undefined;\r\n for (const hub of this.hubs)\r\n hub[1].cleanup();\r\n\r\n this.hubs.clear();\r\n IModelJsFs.purgeDirSync(this.mockRoot);\r\n IModelJsFs.removeSync(this.mockRoot);\r\n IModelHost.setHubAccess(this._saveHubAccess);\r\n this.mockRoot = undefined;\r\n }\r\n\r\n public static findLocalHub(iModelId: GuidString): LocalHub {\r\n const hub = this.hubs.get(iModelId);\r\n if (!hub)\r\n throw new Error(`local hub for iModel ${iModelId} not created`);\r\n return hub;\r\n }\r\n\r\n /** create a [[LocalHub]] for an iModel. */\r\n public static async createNewIModel(arg: CreateNewIModelProps): Promise<GuidString> {\r\n wasStarted(this.mockRoot);\r\n const props = { ...arg, iModelId: Guid.createValue() };\r\n const mock = new LocalHub(join(this.mockRoot, props.iModelId), props);\r\n this.hubs.set(props.iModelId, mock);\r\n return props.iModelId;\r\n }\r\n\r\n /** remove the [[LocalHub]] for an iModel */\r\n public static destroy(iModelId: GuidString) {\r\n this.findLocalHub(iModelId).cleanup();\r\n this.hubs.delete(iModelId);\r\n }\r\n\r\n /** All methods below are mocks of the [[BackendHubAccess]] interface */\r\n\r\n public static async getChangesetFromNamedVersion(arg: IModelIdArg & { versionName: string }): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).findNamedVersion(arg.versionName);\r\n }\r\n\r\n private static changesetIndexFromArg(arg: ChangesetArg) {\r\n return (undefined !== arg.changeset.index) ? arg.changeset.index : this.findLocalHub(arg.iModelId).getChangesetIndex(arg.changeset.id);\r\n }\r\n\r\n public static async getChangesetFromVersion(arg: IModelIdArg & { version: IModelVersion }): Promise<ChangesetProps> {\r\n const hub = this.findLocalHub(arg.iModelId);\r\n const version = arg.version;\r\n if (version.isFirst)\r\n return hub.getChangesetByIndex(0);\r\n\r\n const asOf = version.getAsOfChangeSet();\r\n if (asOf)\r\n return hub.getChangesetById(asOf);\r\n\r\n const versionName = version.getName();\r\n if (versionName)\r\n return hub.findNamedVersion(versionName);\r\n\r\n return hub.getLatestChangeset();\r\n }\r\n\r\n public static async getLatestChangeset(arg: IModelIdArg): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).getLatestChangeset();\r\n }\r\n\r\n private static async getAccessToken(arg: TokenArg) {\r\n return arg.accessToken ?? await IModelHost.getAccessToken();\r\n }\r\n\r\n public static async getMyBriefcaseIds(arg: IModelIdArg): Promise<number[]> {\r\n const accessToken = await this.getAccessToken(arg);\r\n return this.findLocalHub(arg.iModelId).getBriefcaseIds(accessToken);\r\n }\r\n\r\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<number> {\r\n const accessToken = await this.getAccessToken(arg);\r\n return this.findLocalHub(arg.iModelId).acquireNewBriefcaseId(accessToken, arg.briefcaseAlias);\r\n }\r\n\r\n /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */\r\n public static async releaseBriefcase(arg: BriefcaseIdArg): Promise<void> {\r\n return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);\r\n }\r\n\r\n public static async downloadChangeset(arg: DownloadChangesetArg): Promise<ChangesetFileProps> {\r\n const changesetProps = this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });\r\n\r\n if (arg.progressCallback) {\r\n const totalSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\r\n if (totalSize)\r\n await HubMock.mockProgressReporting(arg.progressCallback, totalSize);\r\n }\r\n\r\n return changesetProps;\r\n }\r\n\r\n public static async downloadChangesets(arg: DownloadChangesetRangeArg): Promise<ChangesetFileProps[]> {\r\n const changesetProps = this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });\r\n\r\n if (arg.progressCallback) {\r\n const totalSize = changesetProps.reduce((sum, props) => sum + (IModelJsFs.lstatSync(props.pathname)?.size ?? 0), 0);\r\n await HubMock.mockProgressReporting(arg.progressCallback, totalSize);\r\n }\r\n\r\n return changesetProps;\r\n }\r\n\r\n public static async queryChangeset(arg: ChangesetArg): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));\r\n }\r\n\r\n public static async queryChangesets(arg: IModelIdArg & { range?: ChangesetRange }): Promise<ChangesetProps[]> {\r\n return this.findLocalHub(arg.iModelId).queryChangesets(arg.range);\r\n }\r\n\r\n public static async pushChangeset(arg: IModelIdArg & { changesetProps: ChangesetFileProps }): Promise<ChangesetIndex> {\r\n return this.findLocalHub(arg.iModelId).addChangeset(arg.changesetProps);\r\n }\r\n\r\n public static async queryV2Checkpoint(_arg: CheckpointProps): Promise<V2CheckpointAccessProps | undefined> {\r\n return undefined;\r\n }\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n public static async downloadV1Checkpoint(arg: CheckpointArg): Promise<ChangesetIndexAndId> {\r\n return this.findLocalHub(arg.checkpoint.iModelId).downloadCheckpoint({ changeset: arg.checkpoint.changeset, targetFile: arg.localFile });\r\n }\r\n\r\n public static async releaseAllLocks(arg: BriefcaseDbArg) {\r\n const hub = this.findLocalHub(arg.iModelId);\r\n hub.releaseAllLocks({ briefcaseId: arg.briefcaseId, changesetIndex: hub.getIndexFromChangeset(arg.changeset) });\r\n }\r\n\r\n public static async queryAllLocks(_arg: BriefcaseDbArg): Promise<LockProps[]> {\r\n return [];\r\n }\r\n\r\n public static async acquireLocks(arg: BriefcaseDbArg, locks: LockMap): Promise<void> {\r\n this.findLocalHub(arg.iModelId).acquireLocks(locks, arg);\r\n }\r\n\r\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\r\n for (const hub of this.hubs) {\r\n const localHub = hub[1];\r\n if (localHub.iTwinId === arg.iTwinId && localHub.iModelName === arg.iModelName)\r\n return localHub.iModelId;\r\n }\r\n return undefined;\r\n }\r\n\r\n public static async deleteIModel(arg: IModelIdArg & { iTwinId: GuidString }): Promise<void> {\r\n return this.destroy(arg.iModelId);\r\n }\r\n\r\n private static async mockProgressReporting(progressCallback: ProgressFunction, totalSize: number): Promise<void> {\r\n await new Promise((resolve, reject) => {\r\n let rejected = false;\r\n\r\n const mockProgress = (index: number) => {\r\n const bytesDownloaded = Math.floor(totalSize * (index / 4));\r\n if (!rejected && progressCallback(bytesDownloaded, totalSize) === ProgressStatus.Abort){\r\n rejected = true;\r\n reject(new Error(\"AbortError\"));\r\n }\r\n };\r\n\r\n mockProgress(1);\r\n setTimeout(() => mockProgress(2), 50);\r\n setTimeout(() => mockProgress(3), 100);\r\n setTimeout(() => {\r\n mockProgress(4);\r\n resolve(undefined);\r\n }, 150);\r\n });\r\n }\r\n}\r\n"]}
|
|
@@ -1,86 +1,9 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module iModels
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { SQLiteDb } from "./SQLiteDb";
|
|
10
|
-
/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.
|
|
11
|
-
* @beta
|
|
12
|
-
*/
|
|
13
|
-
export declare class IModelCloneContext {
|
|
14
|
-
/** The source IModelDb. */
|
|
15
|
-
readonly sourceDb: IModelDb;
|
|
16
|
-
/** The target IModelDb. */
|
|
17
|
-
readonly targetDb: IModelDb;
|
|
18
|
-
/** The native import context */
|
|
19
|
-
private _nativeContext;
|
|
20
|
-
/** Construct a new IModelCloneContext.
|
|
21
|
-
* @param sourceDb The source IModelDb.
|
|
22
|
-
* @param targetDb If provided the target IModelDb. If not provided, the source and target are the same IModelDb.
|
|
23
|
-
*/
|
|
24
|
-
constructor(sourceDb: IModelDb, targetDb?: IModelDb);
|
|
25
|
-
/** Returns `true` if this context is for transforming between 2 iModels and `false` if it for transforming within the same iModel. */
|
|
26
|
-
get isBetweenIModels(): boolean;
|
|
27
|
-
/** Dispose any native resources associated with this IModelCloneContext. */
|
|
28
|
-
dispose(): void;
|
|
29
|
-
/** Debugging aid that dumps the Id remapping details and other information to the specified output file.
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
dump(outputFileName: string): void;
|
|
33
|
-
/** Add a rule that remaps the specified source [CodeSpec]($common) to the specified target [CodeSpec]($common).
|
|
34
|
-
* @param sourceCodeSpecName The name of the CodeSpec from the source iModel.
|
|
35
|
-
* @param targetCodeSpecName The name of the CodeSpec from the target iModel.
|
|
36
|
-
* @throws [[IModelError]] if either CodeSpec could not be found.
|
|
37
|
-
*/
|
|
38
|
-
remapCodeSpec(sourceCodeSpecName: string, targetCodeSpecName: string): void;
|
|
39
|
-
/** Add a rule that remaps the specified source class to the specified target class. */
|
|
40
|
-
remapElementClass(sourceClassFullName: string, targetClassFullName: string): void;
|
|
41
|
-
/** Add a rule that remaps the specified source Element to the specified target Element. */
|
|
42
|
-
remapElement(sourceId: Id64String, targetId: Id64String): void;
|
|
43
|
-
/** Remove a rule that remaps the specified source Element. */
|
|
44
|
-
removeElement(sourceId: Id64String): void;
|
|
45
|
-
/** Look up a target CodeSpecId from the source CodeSpecId.
|
|
46
|
-
* @returns the target CodeSpecId or [Id64.invalid]($bentley) if a mapping not found.
|
|
47
|
-
*/
|
|
48
|
-
findTargetCodeSpecId(sourceId: Id64String): Id64String;
|
|
49
|
-
/** Look up a target ElementId from the source ElementId.
|
|
50
|
-
* @returns the target ElementId or [Id64.invalid]($bentley) if a mapping not found.
|
|
51
|
-
*/
|
|
52
|
-
findTargetElementId(sourceElementId: Id64String): Id64String;
|
|
53
|
-
/** Filter out geometry entries in the specified SubCategory from GeometryStreams in the target iModel.
|
|
54
|
-
* @note It is not possible to filter out a *default* SubCategory. A request to do so will be ignored.
|
|
55
|
-
* @see [SubCategory.isDefaultSubCategory]($backend)
|
|
56
|
-
*/
|
|
57
|
-
filterSubCategory(sourceSubCategoryId: Id64String): void;
|
|
58
|
-
/** Returns `true` if there are any SubCategories being filtered. */
|
|
59
|
-
get hasSubCategoryFilter(): boolean;
|
|
60
|
-
/** Returns `true` if this SubCategory is being filtered. */
|
|
61
|
-
isSubCategoryFiltered(subCategoryId: Id64String): boolean;
|
|
62
|
-
/** Import the specified font from the source iModel into the target iModel.
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
importFont(sourceFontNumber: number): void;
|
|
66
|
-
/** Import a single CodeSpec from the source iModel into the target iModel.
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
importCodeSpec(sourceCodeSpecId: Id64String): void;
|
|
70
|
-
/** Clone the specified source Element into ElementProps for the target iModel.
|
|
71
|
-
* @internal
|
|
72
|
-
*/
|
|
73
|
-
cloneElement(sourceElement: Element, cloneOptions?: IModelJsNative.CloneElementOptions): ElementProps;
|
|
74
|
-
/**
|
|
75
|
-
* serialize state to a sqlite database at a given path
|
|
76
|
-
* assumes the database has not already had any context state serialized to it
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
saveStateToDb(db: SQLiteDb): void;
|
|
80
|
-
/**
|
|
81
|
-
* load state from a sqlite database at a given path
|
|
82
|
-
* @internal
|
|
83
|
-
*/
|
|
84
|
-
loadStateFromDb(db: SQLiteDb): void;
|
|
85
|
-
}
|
|
4
|
+
import { IModelElementCloneContext } from "./IModelElementCloneContext";
|
|
5
|
+
/** @deprecated use [[IModelElementCloneContext]] instead, @beta */
|
|
6
|
+
export declare const IModelCloneContext: typeof IModelElementCloneContext;
|
|
7
|
+
/** @deprecated use [[IModelElementCloneContext]] instead, @beta */
|
|
8
|
+
export declare type IModelCloneContext = IModelElementCloneContext;
|
|
86
9
|
//# sourceMappingURL=IModelCloneContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelCloneContext.d.ts","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"IModelCloneContext.d.ts","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAIxE,mEAAmE;AAEnE,eAAO,MAAM,kBAAkB,kCAA4B,CAAC;AAC5D,mEAAmE;AAEnE,oBAAY,kBAAkB,GAAG,yBAAyB,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IModelCloneContext = void 0;
|
|
4
2
|
/*---------------------------------------------------------------------------------------------
|
|
5
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -8,144 +6,11 @@ exports.IModelCloneContext = void 0;
|
|
|
8
6
|
/** @packageDocumentation
|
|
9
7
|
* @module iModels
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class IModelCloneContext {
|
|
19
|
-
/** Construct a new IModelCloneContext.
|
|
20
|
-
* @param sourceDb The source IModelDb.
|
|
21
|
-
* @param targetDb If provided the target IModelDb. If not provided, the source and target are the same IModelDb.
|
|
22
|
-
*/
|
|
23
|
-
constructor(sourceDb, targetDb) {
|
|
24
|
-
this.sourceDb = sourceDb;
|
|
25
|
-
this.targetDb = (undefined !== targetDb) ? targetDb : sourceDb;
|
|
26
|
-
this._nativeContext = new IModelHost_1.IModelHost.platform.ImportContext(this.sourceDb.nativeDb, this.targetDb.nativeDb);
|
|
27
|
-
}
|
|
28
|
-
/** Returns `true` if this context is for transforming between 2 iModels and `false` if it for transforming within the same iModel. */
|
|
29
|
-
get isBetweenIModels() { return this.sourceDb !== this.targetDb; }
|
|
30
|
-
/** Dispose any native resources associated with this IModelCloneContext. */
|
|
31
|
-
dispose() { this._nativeContext.dispose(); }
|
|
32
|
-
/** Debugging aid that dumps the Id remapping details and other information to the specified output file.
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
dump(outputFileName) { this._nativeContext.dump(outputFileName); }
|
|
36
|
-
/** Add a rule that remaps the specified source [CodeSpec]($common) to the specified target [CodeSpec]($common).
|
|
37
|
-
* @param sourceCodeSpecName The name of the CodeSpec from the source iModel.
|
|
38
|
-
* @param targetCodeSpecName The name of the CodeSpec from the target iModel.
|
|
39
|
-
* @throws [[IModelError]] if either CodeSpec could not be found.
|
|
40
|
-
*/
|
|
41
|
-
remapCodeSpec(sourceCodeSpecName, targetCodeSpecName) {
|
|
42
|
-
const sourceCodeSpec = this.sourceDb.codeSpecs.getByName(sourceCodeSpecName);
|
|
43
|
-
const targetCodeSpec = this.targetDb.codeSpecs.getByName(targetCodeSpecName);
|
|
44
|
-
this._nativeContext.addCodeSpecId(sourceCodeSpec.id, targetCodeSpec.id);
|
|
45
|
-
}
|
|
46
|
-
/** Add a rule that remaps the specified source class to the specified target class. */
|
|
47
|
-
remapElementClass(sourceClassFullName, targetClassFullName) {
|
|
48
|
-
this._nativeContext.addClass(sourceClassFullName, targetClassFullName);
|
|
49
|
-
}
|
|
50
|
-
/** Add a rule that remaps the specified source Element to the specified target Element. */
|
|
51
|
-
remapElement(sourceId, targetId) {
|
|
52
|
-
this._nativeContext.addElementId(sourceId, targetId);
|
|
53
|
-
}
|
|
54
|
-
/** Remove a rule that remaps the specified source Element. */
|
|
55
|
-
removeElement(sourceId) {
|
|
56
|
-
this._nativeContext.removeElementId(sourceId);
|
|
57
|
-
}
|
|
58
|
-
/** Look up a target CodeSpecId from the source CodeSpecId.
|
|
59
|
-
* @returns the target CodeSpecId or [Id64.invalid]($bentley) if a mapping not found.
|
|
60
|
-
*/
|
|
61
|
-
findTargetCodeSpecId(sourceId) {
|
|
62
|
-
if (core_bentley_1.Id64.invalid === sourceId) {
|
|
63
|
-
return core_bentley_1.Id64.invalid;
|
|
64
|
-
}
|
|
65
|
-
return this._nativeContext.findCodeSpecId(sourceId);
|
|
66
|
-
}
|
|
67
|
-
/** Look up a target ElementId from the source ElementId.
|
|
68
|
-
* @returns the target ElementId or [Id64.invalid]($bentley) if a mapping not found.
|
|
69
|
-
*/
|
|
70
|
-
findTargetElementId(sourceElementId) {
|
|
71
|
-
if (core_bentley_1.Id64.invalid === sourceElementId) {
|
|
72
|
-
return core_bentley_1.Id64.invalid;
|
|
73
|
-
}
|
|
74
|
-
return this._nativeContext.findElementId(sourceElementId);
|
|
75
|
-
}
|
|
76
|
-
/** Filter out geometry entries in the specified SubCategory from GeometryStreams in the target iModel.
|
|
77
|
-
* @note It is not possible to filter out a *default* SubCategory. A request to do so will be ignored.
|
|
78
|
-
* @see [SubCategory.isDefaultSubCategory]($backend)
|
|
79
|
-
*/
|
|
80
|
-
filterSubCategory(sourceSubCategoryId) {
|
|
81
|
-
const sourceSubCategory = this.sourceDb.elements.tryGetElement(sourceSubCategoryId, Category_1.SubCategory);
|
|
82
|
-
if (sourceSubCategory && !sourceSubCategory.isDefaultSubCategory) {
|
|
83
|
-
this._nativeContext.filterSubCategoryId(sourceSubCategoryId);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/** Returns `true` if there are any SubCategories being filtered. */
|
|
87
|
-
get hasSubCategoryFilter() {
|
|
88
|
-
return this._nativeContext.hasSubCategoryFilter();
|
|
89
|
-
}
|
|
90
|
-
/** Returns `true` if this SubCategory is being filtered. */
|
|
91
|
-
isSubCategoryFiltered(subCategoryId) {
|
|
92
|
-
return this._nativeContext.isSubCategoryFiltered(subCategoryId);
|
|
93
|
-
}
|
|
94
|
-
/** Import the specified font from the source iModel into the target iModel.
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
importFont(sourceFontNumber) {
|
|
98
|
-
this.targetDb.clearFontMap(); // so it will be reloaded with new font info
|
|
99
|
-
this._nativeContext.importFont(sourceFontNumber);
|
|
100
|
-
}
|
|
101
|
-
/** Import a single CodeSpec from the source iModel into the target iModel.
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
importCodeSpec(sourceCodeSpecId) {
|
|
105
|
-
this._nativeContext.importCodeSpec(sourceCodeSpecId);
|
|
106
|
-
}
|
|
107
|
-
/** Clone the specified source Element into ElementProps for the target iModel.
|
|
108
|
-
* @internal
|
|
109
|
-
*/
|
|
110
|
-
cloneElement(sourceElement, cloneOptions) {
|
|
111
|
-
const targetElementProps = this._nativeContext.cloneElement(sourceElement.id, cloneOptions);
|
|
112
|
-
// Ensure that all NavigationProperties in targetElementProps have a defined value so "clearing" changes will be part of the JSON used for update
|
|
113
|
-
sourceElement.forEachProperty((propertyName, meta) => {
|
|
114
|
-
if ((meta.isNavigation) && (undefined === sourceElement[propertyName])) {
|
|
115
|
-
targetElementProps[propertyName] = core_common_1.RelatedElement.none;
|
|
116
|
-
}
|
|
117
|
-
}, false); // exclude custom because C++ has already handled them
|
|
118
|
-
if (this.isBetweenIModels) {
|
|
119
|
-
// The native C++ cloneElement strips off federationGuid, want to put it back if transformation is between iModels
|
|
120
|
-
targetElementProps.federationGuid = sourceElement.federationGuid;
|
|
121
|
-
if (core_common_1.CodeScopeSpec.Type.Repository === this.targetDb.codeSpecs.getById(targetElementProps.code.spec).scopeType) {
|
|
122
|
-
targetElementProps.code.scope = core_common_1.IModel.rootSubjectId;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// unlike other references, code cannot be null. If it is null, use an empty code instead
|
|
126
|
-
if (targetElementProps.code.scope === core_bentley_1.Id64.invalid || targetElementProps.code.spec === core_bentley_1.Id64.invalid) {
|
|
127
|
-
targetElementProps.code = core_common_1.Code.createEmpty();
|
|
128
|
-
}
|
|
129
|
-
const jsClass = this.sourceDb.getJsClass(sourceElement.classFullName);
|
|
130
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
131
|
-
jsClass["onCloned"](this, sourceElement.toJSON(), targetElementProps);
|
|
132
|
-
return targetElementProps;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* serialize state to a sqlite database at a given path
|
|
136
|
-
* assumes the database has not already had any context state serialized to it
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
saveStateToDb(db) {
|
|
140
|
-
this._nativeContext.saveStateToDb(db.nativeDb);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* load state from a sqlite database at a given path
|
|
144
|
-
* @internal
|
|
145
|
-
*/
|
|
146
|
-
loadStateFromDb(db) {
|
|
147
|
-
this._nativeContext.loadStateFromDb(db.nativeDb);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.IModelCloneContext = IModelCloneContext;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.IModelCloneContext = void 0;
|
|
11
|
+
const IModelElementCloneContext_1 = require("./IModelElementCloneContext");
|
|
12
|
+
// re-export both the type and the value of the class, and deprecate both
|
|
13
|
+
/** @deprecated use [[IModelElementCloneContext]] instead, @beta */
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
15
|
+
exports.IModelCloneContext = IModelElementCloneContext_1.IModelElementCloneContext;
|
|
151
16
|
//# sourceMappingURL=IModelCloneContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelCloneContext.js","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,sDAAuD;AACvD,oDAA2H;AAE3H,yCAAyC;AAGzC,6CAA0C;AAG1C;;GAEG;AACH,MAAa,kBAAkB;IAQ7B;;;OAGG;IACH,YAAmB,QAAkB,EAAE,QAAmB;QACxD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC/D,IAAI,CAAC,cAAc,GAAG,IAAI,uBAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC9G,CAAC;IAED,sIAAsI;IACtI,IAAW,gBAAgB,KAAc,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAElF,4EAA4E;IACrE,OAAO,KAAW,IAA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JC","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\nimport { Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { Code, CodeScopeSpec, CodeSpec, ElementProps, IModel, PropertyMetaData, RelatedElement } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { SubCategory } from \"./Category\";\r\nimport { Element } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { SQLiteDb } from \"./SQLiteDb\";\r\n\r\n/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.\r\n * @beta\r\n */\r\nexport class IModelCloneContext {\r\n /** The source IModelDb. */\r\n public readonly sourceDb: IModelDb;\r\n /** The target IModelDb. */\r\n public readonly targetDb: IModelDb;\r\n /** The native import context */\r\n private _nativeContext: IModelJsNative.ImportContext;\r\n\r\n /** Construct a new IModelCloneContext.\r\n * @param sourceDb The source IModelDb.\r\n * @param targetDb If provided the target IModelDb. If not provided, the source and target are the same IModelDb.\r\n */\r\n public constructor(sourceDb: IModelDb, targetDb?: IModelDb) {\r\n this.sourceDb = sourceDb;\r\n this.targetDb = (undefined !== targetDb) ? targetDb : sourceDb;\r\n this._nativeContext = new IModelHost.platform.ImportContext(this.sourceDb.nativeDb, this.targetDb.nativeDb);\r\n }\r\n\r\n /** Returns `true` if this context is for transforming between 2 iModels and `false` if it for transforming within the same iModel. */\r\n public get isBetweenIModels(): boolean { return this.sourceDb !== this.targetDb; }\r\n\r\n /** Dispose any native resources associated with this IModelCloneContext. */\r\n public dispose(): void { this._nativeContext.dispose(); }\r\n\r\n /** Debugging aid that dumps the Id remapping details and other information to the specified output file.\r\n * @internal\r\n */\r\n public dump(outputFileName: string): void { this._nativeContext.dump(outputFileName); }\r\n\r\n /** Add a rule that remaps the specified source [CodeSpec]($common) to the specified target [CodeSpec]($common).\r\n * @param sourceCodeSpecName The name of the CodeSpec from the source iModel.\r\n * @param targetCodeSpecName The name of the CodeSpec from the target iModel.\r\n * @throws [[IModelError]] if either CodeSpec could not be found.\r\n */\r\n public remapCodeSpec(sourceCodeSpecName: string, targetCodeSpecName: string): void {\r\n const sourceCodeSpec: CodeSpec = this.sourceDb.codeSpecs.getByName(sourceCodeSpecName);\r\n const targetCodeSpec: CodeSpec = this.targetDb.codeSpecs.getByName(targetCodeSpecName);\r\n this._nativeContext.addCodeSpecId(sourceCodeSpec.id, targetCodeSpec.id);\r\n }\r\n\r\n /** Add a rule that remaps the specified source class to the specified target class. */\r\n public remapElementClass(sourceClassFullName: string, targetClassFullName: string): void {\r\n this._nativeContext.addClass(sourceClassFullName, targetClassFullName);\r\n }\r\n\r\n /** Add a rule that remaps the specified source Element to the specified target Element. */\r\n public remapElement(sourceId: Id64String, targetId: Id64String): void {\r\n this._nativeContext.addElementId(sourceId, targetId);\r\n }\r\n\r\n /** Remove a rule that remaps the specified source Element. */\r\n public removeElement(sourceId: Id64String): void {\r\n this._nativeContext.removeElementId(sourceId);\r\n }\r\n\r\n /** Look up a target CodeSpecId from the source CodeSpecId.\r\n * @returns the target CodeSpecId or [Id64.invalid]($bentley) if a mapping not found.\r\n */\r\n public findTargetCodeSpecId(sourceId: Id64String): Id64String {\r\n if (Id64.invalid === sourceId) {\r\n return Id64.invalid;\r\n }\r\n return this._nativeContext.findCodeSpecId(sourceId);\r\n }\r\n\r\n /** Look up a target ElementId from the source ElementId.\r\n * @returns the target ElementId or [Id64.invalid]($bentley) if a mapping not found.\r\n */\r\n public findTargetElementId(sourceElementId: Id64String): Id64String {\r\n if (Id64.invalid === sourceElementId) {\r\n return Id64.invalid;\r\n }\r\n return this._nativeContext.findElementId(sourceElementId);\r\n }\r\n\r\n /** Filter out geometry entries in the specified SubCategory from GeometryStreams in the target iModel.\r\n * @note It is not possible to filter out a *default* SubCategory. A request to do so will be ignored.\r\n * @see [SubCategory.isDefaultSubCategory]($backend)\r\n */\r\n public filterSubCategory(sourceSubCategoryId: Id64String): void {\r\n const sourceSubCategory = this.sourceDb.elements.tryGetElement<SubCategory>(sourceSubCategoryId, SubCategory);\r\n if (sourceSubCategory && !sourceSubCategory.isDefaultSubCategory) {\r\n this._nativeContext.filterSubCategoryId(sourceSubCategoryId);\r\n }\r\n }\r\n\r\n /** Returns `true` if there are any SubCategories being filtered. */\r\n public get hasSubCategoryFilter(): boolean {\r\n return this._nativeContext.hasSubCategoryFilter();\r\n }\r\n\r\n /** Returns `true` if this SubCategory is being filtered. */\r\n public isSubCategoryFiltered(subCategoryId: Id64String): boolean {\r\n return this._nativeContext.isSubCategoryFiltered(subCategoryId);\r\n }\r\n\r\n /** Import the specified font from the source iModel into the target iModel.\r\n * @internal\r\n */\r\n public importFont(sourceFontNumber: number): void {\r\n this.targetDb.clearFontMap(); // so it will be reloaded with new font info\r\n this._nativeContext.importFont(sourceFontNumber);\r\n }\r\n\r\n /** Import a single CodeSpec from the source iModel into the target iModel.\r\n * @internal\r\n */\r\n public importCodeSpec(sourceCodeSpecId: Id64String): void {\r\n this._nativeContext.importCodeSpec(sourceCodeSpecId);\r\n }\r\n\r\n /** Clone the specified source Element into ElementProps for the target iModel.\r\n * @internal\r\n */\r\n public cloneElement(sourceElement: Element, cloneOptions?: IModelJsNative.CloneElementOptions): ElementProps {\r\n const targetElementProps: ElementProps = this._nativeContext.cloneElement(sourceElement.id, cloneOptions);\r\n // Ensure that all NavigationProperties in targetElementProps have a defined value so \"clearing\" changes will be part of the JSON used for update\r\n sourceElement.forEachProperty((propertyName: string, meta: PropertyMetaData) => {\r\n if ((meta.isNavigation) && (undefined === (sourceElement as any)[propertyName])) {\r\n (targetElementProps as any)[propertyName] = RelatedElement.none;\r\n }\r\n }, false); // exclude custom because C++ has already handled them\r\n if (this.isBetweenIModels) {\r\n // The native C++ cloneElement strips off federationGuid, want to put it back if transformation is between iModels\r\n targetElementProps.federationGuid = sourceElement.federationGuid;\r\n if (CodeScopeSpec.Type.Repository === this.targetDb.codeSpecs.getById(targetElementProps.code.spec).scopeType) {\r\n targetElementProps.code.scope = IModel.rootSubjectId;\r\n }\r\n }\r\n // unlike other references, code cannot be null. If it is null, use an empty code instead\r\n if (targetElementProps.code.scope === Id64.invalid || targetElementProps.code.spec === Id64.invalid) {\r\n targetElementProps.code = Code.createEmpty();\r\n }\r\n const jsClass = this.sourceDb.getJsClass<typeof Element>(sourceElement.classFullName);\r\n // eslint-disable-next-line @typescript-eslint/dot-notation\r\n jsClass[\"onCloned\"](this, sourceElement.toJSON(), targetElementProps);\r\n return targetElementProps;\r\n }\r\n\r\n /**\r\n * serialize state to a sqlite database at a given path\r\n * assumes the database has not already had any context state serialized to it\r\n * @internal\r\n */\r\n public saveStateToDb(db: SQLiteDb): void {\r\n this._nativeContext.saveStateToDb(db.nativeDb);\r\n }\r\n\r\n /**\r\n * load state from a sqlite database at a given path\r\n * @internal\r\n */\r\n public loadStateFromDb(db: SQLiteDb): void {\r\n this._nativeContext.loadStateFromDb(db.nativeDb);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"IModelCloneContext.js","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2EAAwE;AAExE,yEAAyE;AAEzE,mEAAmE;AACnE,gEAAgE;AACnD,QAAA,kBAAkB,GAAG,qDAAyB,CAAC","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\nimport { IModelElementCloneContext } from \"./IModelElementCloneContext\";\r\n\r\n// re-export both the type and the value of the class, and deprecate both\r\n\r\n/** @deprecated use [[IModelElementCloneContext]] instead, @beta */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport const IModelCloneContext = IModelElementCloneContext;\r\n/** @deprecated use [[IModelElementCloneContext]] instead, @beta */\r\n// eslint-disable-next-line @typescript-eslint/no-redeclare\r\nexport type IModelCloneContext = IModelElementCloneContext;\r\n"]}
|
package/lib/cjs/IModelDb.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { IModelJsNative } from "@bentley/imodeljs-native";
|
|
5
5
|
import { AccessToken, BeEvent, DbResult, GuidString, Id64Arg, Id64Array, Id64Set, Id64String, IModelStatus, OpenMode } from "@itwin/core-bentley";
|
|
6
|
-
import { AxisAlignedBox3d, BRepGeometryCreate, BriefcaseId, ChangesetIdWithIndex, Code, CodeProps, CodeSpec, CreateEmptySnapshotIModelProps, CreateEmptyStandaloneIModelProps, CreateSnapshotIModelProps, EcefLocation, ECSchemaProps, ECSqlReader, ElementAspectProps, ElementGeometryRequest, ElementGraphicsRequestProps, ElementLoadProps, ElementProps, EntityMetaData, EntityProps, EntityQueryParams, FilePropertyProps, FontId, FontMap, FontType, GeoCoordinatesRequestProps, GeoCoordinatesResponseProps, GeometryContainmentRequestProps, GeometryContainmentResponseProps, IModel, IModelCoordinatesRequestProps, IModelCoordinatesResponseProps, IModelTileTreeProps, LocalFileName, MassPropertiesRequestProps, MassPropertiesResponseProps, ModelLoadProps, ModelProps, OpenBriefcaseProps, PropertyCallback, QueryBinder, QueryOptions, SchemaState, SnapRequestProps, SnapResponseProps, SnapshotOpenOptions, SubCategoryResultRow, TextureData, TextureLoadProps, ThumbnailProps, UpgradeOptions, ViewDefinitionProps, ViewQueryParams, ViewStateLoadProps, ViewStateProps } from "@itwin/core-common";
|
|
6
|
+
import { AxisAlignedBox3d, BRepGeometryCreate, BriefcaseId, ChangesetIdWithIndex, Code, CodeProps, CodeSpec, CreateEmptySnapshotIModelProps, CreateEmptyStandaloneIModelProps, CreateSnapshotIModelProps, EcefLocation, ECSchemaProps, ECSqlReader, ElementAspectProps, ElementGeometryRequest, ElementGraphicsRequestProps, ElementLoadProps, ElementProps, EntityMetaData, EntityProps, EntityQueryParams, FilePropertyProps, FontId, FontMap, FontType, GeoCoordinatesRequestProps, GeoCoordinatesResponseProps, GeometryContainmentRequestProps, GeometryContainmentResponseProps, IModel, IModelCoordinatesRequestProps, IModelCoordinatesResponseProps, IModelTileTreeProps, LocalFileName, MassPropertiesRequestProps, MassPropertiesResponseProps, ModelExtentsProps, ModelLoadProps, ModelProps, OpenBriefcaseProps, PropertyCallback, QueryBinder, QueryOptions, SchemaState, SnapRequestProps, SnapResponseProps, SnapshotOpenOptions, SubCategoryResultRow, TextureData, TextureLoadProps, ThumbnailProps, UpgradeOptions, ViewDefinitionProps, ViewQueryParams, ViewStateLoadProps, ViewStateProps } from "@itwin/core-common";
|
|
7
7
|
import { Range3d } from "@itwin/core-geometry";
|
|
8
8
|
import { PullChangesArgs, PushChangesArgs } from "./BriefcaseManager";
|
|
9
9
|
import { CheckpointProps } from "./CheckpointManager";
|
|
@@ -732,6 +732,18 @@ export declare namespace IModelDb {
|
|
|
732
732
|
* @throws [[IModelError]]
|
|
733
733
|
*/
|
|
734
734
|
deleteModel(ids: Id64Arg): void;
|
|
735
|
+
/** For each specified [[GeometricModel]], attempts to obtain the union of the volumes of all geometric elements within that model.
|
|
736
|
+
* @param ids The Id or Ids of the [[GeometricModel]]s for which to obtain the extents.
|
|
737
|
+
* @returns An array of results, one per supplied Id, in the order in which the Ids were supplied. If the extents could not be obtained, the
|
|
738
|
+
* corresponding results entry's `extents` will be a "null" range (@see [Range3d.isNull]($geometry)) and its `status` will indicate
|
|
739
|
+
* why the extents could not be obtained (e.g., because the Id did not identify a [[GeometricModel]]).
|
|
740
|
+
* @see [[queryRange]] to obtain the union of all of the models' extents.
|
|
741
|
+
*/
|
|
742
|
+
queryExtents(ids: Id64String | Id64String[]): Promise<ModelExtentsProps[]>;
|
|
743
|
+
/** Computes the union of the volumes of all geoemtric elements within any number of [[GeometricModel]]s, specified by model Id.
|
|
744
|
+
* @see [[queryExtents]] to obtain discrete volumes for each model.
|
|
745
|
+
*/
|
|
746
|
+
queryRange(ids: Id64String | Id64String[]): Promise<AxisAlignedBox3d>;
|
|
735
747
|
}
|
|
736
748
|
/** The collection of elements in an [[IModelDb]].
|
|
737
749
|
* @public
|
|
@@ -875,8 +887,11 @@ export declare namespace IModelDb {
|
|
|
875
887
|
/** Insert a new ElementAspect into the iModel.
|
|
876
888
|
* @param aspectProps The properties of the new ElementAspect.
|
|
877
889
|
* @throws [[IModelError]] if unable to insert the ElementAspect.
|
|
890
|
+
* @returns the id of the newly inserted aspect.
|
|
891
|
+
* @note Aspect Ids may collide with element Ids, so don't put both in a container like Set or Map
|
|
892
|
+
* use [EntityReference]($common) for that instead.
|
|
878
893
|
*/
|
|
879
|
-
insertAspect(aspectProps: ElementAspectProps):
|
|
894
|
+
insertAspect(aspectProps: ElementAspectProps): Id64String;
|
|
880
895
|
/** Update an exist ElementAspect within the iModel.
|
|
881
896
|
* @param aspectProps The properties to use to update the ElementAspect.
|
|
882
897
|
* @throws [[IModelError]] if unable to update the ElementAspect.
|
|
@@ -913,7 +928,11 @@ export declare namespace IModelDb {
|
|
|
913
928
|
* ```
|
|
914
929
|
*/
|
|
915
930
|
iterateViews(params: ViewQueryParams, callback: (view: ViewDefinition) => boolean): boolean;
|
|
931
|
+
private loadViewStateProps;
|
|
932
|
+
/** @deprecated use [[getViewStateProps]]. */
|
|
916
933
|
getViewStateData(viewDefinitionId: string, options?: ViewStateLoadProps): ViewStateProps;
|
|
934
|
+
/** Obtain a [ViewStateProps]($common) for a [[ViewDefinition]] specified by element Id. */
|
|
935
|
+
getViewStateProps(viewDefinitionId: string, options?: ViewStateLoadProps): Promise<ViewStateProps>;
|
|
917
936
|
private getViewThumbnailArg;
|
|
918
937
|
/** Get the thumbnail for a view.
|
|
919
938
|
* @param viewDefinitionId The Id of the view for thumbnail
|