@itwin/core-backend 3.3.0-dev.9 → 3.4.0-dev.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +32 -15
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js.map +1 -1
  5. package/lib/cjs/BisCoreSchema.d.ts +1 -1
  6. package/lib/cjs/BisCoreSchema.js +1 -1
  7. package/lib/cjs/BisCoreSchema.js.map +1 -1
  8. package/lib/cjs/BriefcaseManager.d.ts +10 -11
  9. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  10. package/lib/cjs/BriefcaseManager.js +10 -11
  11. package/lib/cjs/BriefcaseManager.js.map +1 -1
  12. package/lib/cjs/CheckpointManager.d.ts +28 -6
  13. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  14. package/lib/cjs/CheckpointManager.js +117 -22
  15. package/lib/cjs/CheckpointManager.js.map +1 -1
  16. package/lib/cjs/ClassRegistry.js +6 -6
  17. package/lib/cjs/ClassRegistry.js.map +1 -1
  18. package/lib/cjs/CodeSpecs.d.ts +1 -1
  19. package/lib/cjs/CodeSpecs.js +1 -1
  20. package/lib/cjs/CodeSpecs.js.map +1 -1
  21. package/lib/cjs/DisplayStyle.d.ts +2 -2
  22. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  23. package/lib/cjs/DisplayStyle.js +14 -17
  24. package/lib/cjs/DisplayStyle.js.map +1 -1
  25. package/lib/cjs/Element.d.ts +36 -25
  26. package/lib/cjs/Element.d.ts.map +1 -1
  27. package/lib/cjs/Element.js +54 -39
  28. package/lib/cjs/Element.js.map +1 -1
  29. package/lib/cjs/GeoCoordConfig.d.ts +14 -0
  30. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -0
  31. package/lib/cjs/GeoCoordConfig.js +74 -0
  32. package/lib/cjs/GeoCoordConfig.js.map +1 -0
  33. package/lib/cjs/HubMock.d.ts +94 -0
  34. package/lib/cjs/HubMock.d.ts.map +1 -0
  35. package/lib/cjs/HubMock.js +191 -0
  36. package/lib/cjs/HubMock.js.map +1 -0
  37. package/lib/cjs/IModelDb.d.ts +26 -15
  38. package/lib/cjs/IModelDb.d.ts.map +1 -1
  39. package/lib/cjs/IModelDb.js +44 -35
  40. package/lib/cjs/IModelDb.js.map +1 -1
  41. package/lib/cjs/IModelHost.d.ts +75 -33
  42. package/lib/cjs/IModelHost.d.ts.map +1 -1
  43. package/lib/cjs/IModelHost.js +66 -80
  44. package/lib/cjs/IModelHost.js.map +1 -1
  45. package/lib/cjs/IpcHost.d.ts +2 -2
  46. package/lib/cjs/IpcHost.d.ts.map +1 -1
  47. package/lib/cjs/IpcHost.js +1 -1
  48. package/lib/cjs/IpcHost.js.map +1 -1
  49. package/lib/cjs/LocalHub.d.ts +163 -0
  50. package/lib/cjs/LocalHub.d.ts.map +1 -0
  51. package/lib/cjs/LocalHub.js +588 -0
  52. package/lib/cjs/LocalHub.js.map +1 -0
  53. package/lib/cjs/LocalhostIpcHost.d.ts +2 -2
  54. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
  55. package/lib/cjs/LocalhostIpcHost.js +16 -0
  56. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  57. package/lib/cjs/RpcBackend.d.ts +3 -1
  58. package/lib/cjs/RpcBackend.d.ts.map +1 -1
  59. package/lib/cjs/RpcBackend.js +27 -3
  60. package/lib/cjs/RpcBackend.js.map +1 -1
  61. package/lib/cjs/SQLiteDb.d.ts +138 -30
  62. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  63. package/lib/cjs/SQLiteDb.js +110 -38
  64. package/lib/cjs/SQLiteDb.js.map +1 -1
  65. package/lib/cjs/SqliteStatement.d.ts +8 -0
  66. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  67. package/lib/cjs/SqliteStatement.js +10 -0
  68. package/lib/cjs/SqliteStatement.js.map +1 -1
  69. package/lib/cjs/ViewDefinition.d.ts +6 -6
  70. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  71. package/lib/cjs/ViewDefinition.js +20 -20
  72. package/lib/cjs/ViewDefinition.js.map +1 -1
  73. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +68 -0
  74. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +22 -0
  75. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +53 -0
  76. package/lib/cjs/assets/Settings/backend.setting.json5 +139 -0
  77. package/lib/cjs/core-backend.d.ts +9 -7
  78. package/lib/cjs/core-backend.d.ts.map +1 -1
  79. package/lib/cjs/core-backend.js +9 -7
  80. package/lib/cjs/core-backend.js.map +1 -1
  81. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +1 -1
  82. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  83. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +8 -12
  84. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  85. package/lib/cjs/workspace/Settings.d.ts +8 -3
  86. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  87. package/lib/cjs/workspace/Settings.js +9 -0
  88. package/lib/cjs/workspace/Settings.js.map +1 -1
  89. package/lib/cjs/workspace/SettingsSchemas.d.ts +76 -0
  90. package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -0
  91. package/lib/cjs/workspace/SettingsSchemas.js +192 -0
  92. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -0
  93. package/lib/cjs/workspace/Workspace.d.ts +240 -144
  94. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  95. package/lib/cjs/workspace/Workspace.js +258 -95
  96. package/lib/cjs/workspace/Workspace.js.map +1 -1
  97. package/package.json +26 -21
  98. package/lib/cjs/assets/Settings.schema.json +0 -25
  99. package/lib/cjs/workspace/SettingsSpecRegistry.d.ts +0 -68
  100. package/lib/cjs/workspace/SettingsSpecRegistry.d.ts.map +0 -1
  101. package/lib/cjs/workspace/SettingsSpecRegistry.js +0 -122
  102. package/lib/cjs/workspace/SettingsSpecRegistry.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module iModels
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.GeoCoordConfig = void 0;
11
+ // cspell:ignore customuri
12
+ const core_bentley_1 = require("@itwin/core-bentley");
13
+ const IModelHost_1 = require("./IModelHost");
14
+ const SQLiteDb_1 = require("./SQLiteDb");
15
+ const loggerCat = "GeoCoord";
16
+ /** Internal class to configure and load the gcs workspaces for an iModel. */
17
+ class GeoCoordConfig {
18
+ static addGcsWorkspace(gcsDbAlias) {
19
+ const ws = IModelHost_1.IModelHost.appWorkspace;
20
+ const dbProps = ws.resolveDatabase(gcsDbAlias);
21
+ const containerProps = ws.resolveContainer(dbProps.containerName);
22
+ const account = ws.resolveAccount(containerProps.accountName);
23
+ containerProps.syncOnConnect = true;
24
+ try {
25
+ const container = ws.getContainer(containerProps, account);
26
+ const cloudContainer = container.cloudContainer;
27
+ if (!(cloudContainer === null || cloudContainer === void 0 ? void 0 : cloudContainer.isConnected)) {
28
+ core_bentley_1.Logger.logInfo("GeoCoord", `could not load gcs database "${gcsDbAlias}"`);
29
+ return;
30
+ }
31
+ const gcsDbName = container.resolveDbFileName(dbProps);
32
+ const gcsDbProps = cloudContainer.queryDatabase(gcsDbName);
33
+ if (undefined === gcsDbProps)
34
+ throw new Error(`database "${gcsDbName}" not found in container "${containerProps.containerId}"`);
35
+ if (!IModelHost_1.IModelHost.platform.addGcsWorkspaceDb(gcsDbName, cloudContainer, dbProps.priority))
36
+ return; // already had this db
37
+ if (IModelHost_1.IModelHost.appWorkspace.settings.getBoolean("gcs/noLocalData", false))
38
+ IModelHost_1.IModelHost.platform.enableLocalGcsFiles(false);
39
+ core_bentley_1.Logger.logInfo(loggerCat, `loaded gcsDb "${gcsDbName}", from "${account.accessName}${containerProps.containerId}" size=${gcsDbProps.totalBlocks}, local=${gcsDbProps.localBlocks}`);
40
+ if (true === dbProps.prefetch)
41
+ SQLiteDb_1.SQLiteDb.startCloudPrefetch(cloudContainer, gcsDbName);
42
+ }
43
+ catch (e) {
44
+ core_bentley_1.Logger.logError(loggerCat, `Cannot load GCS workspace: ${core_bentley_1.BentleyError.getErrorMessage(e)}, account=${account.accessName}`);
45
+ }
46
+ }
47
+ static loadAll(settings, settingName) {
48
+ settings.resolveSetting(settingName, (val) => {
49
+ if (Array.isArray(val)) {
50
+ for (const entry of val) {
51
+ if (typeof entry === "string")
52
+ this.addGcsWorkspace(entry);
53
+ }
54
+ }
55
+ return undefined; // keep going through all dictionaries
56
+ });
57
+ }
58
+ static onStartup() {
59
+ this._defaultDbsLoaded = false;
60
+ }
61
+ static loadDefaultDatabases() {
62
+ if (!this._defaultDbsLoaded) {
63
+ this._defaultDbsLoaded = true;
64
+ this.loadAll(IModelHost_1.IModelHost.appWorkspace.settings, "gcs/default/databases");
65
+ }
66
+ }
67
+ static loadForImodel(settings) {
68
+ this.loadDefaultDatabases();
69
+ this.loadAll(settings, "gcs/databases");
70
+ }
71
+ }
72
+ exports.GeoCoordConfig = GeoCoordConfig;
73
+ GeoCoordConfig._defaultDbsLoaded = false;
74
+ //# sourceMappingURL=GeoCoordConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeoCoordConfig.js","sourceRoot":"","sources":["../../src/GeoCoordConfig.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,0BAA0B;AAE1B,sDAA2D;AAC3D,6CAA0C;AAC1C,yCAAsC;AAItC,MAAM,SAAS,GAAG,UAAU,CAAC;AAO7B,6EAA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oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC1C,CAAC;;AAhEH,wCAiEC;AAhBgB,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\n// cspell:ignore customuri\r\n\r\nimport { BentleyError, Logger } from \"@itwin/core-bentley\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { SQLiteDb } from \"./SQLiteDb\";\r\nimport { Settings } from \"./workspace/Settings\";\r\nimport { 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/** Internal class to configure and load the gcs workspaces for an iModel. */\r\nexport class GeoCoordConfig {\r\n\r\n private static addGcsWorkspace(gcsDbAlias: string) {\r\n const ws = IModelHost.appWorkspace;\r\n const dbProps = ws.resolveDatabase(gcsDbAlias) as GcsDbProps;\r\n const containerProps = ws.resolveContainer(dbProps.containerName);\r\n const account = ws.resolveAccount(containerProps.accountName);\r\n containerProps.syncOnConnect = true;\r\n try {\r\n const container = ws.getContainer(containerProps, account);\r\n const cloudContainer = container.cloudContainer;\r\n if (!cloudContainer?.isConnected) {\r\n Logger.logInfo(\"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 SQLiteDb.startCloudPrefetch(cloudContainer, gcsDbName);\r\n\r\n } catch (e: unknown) {\r\n Logger.logError(loggerCat, `Cannot load GCS workspace: ${BentleyError.getErrorMessage(e)}, account=${account.accessName}`);\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 }\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"]}
@@ -0,0 +1,94 @@
1
+ import { GuidString } from "@itwin/core-bentley";
2
+ import { ChangesetFileProps, ChangesetIndex, ChangesetIndexAndId, ChangesetProps, ChangesetRange, IModelVersion, LocalDirName } from "@itwin/core-common";
3
+ import { AcquireNewBriefcaseIdArg, BriefcaseDbArg, BriefcaseIdArg, ChangesetArg, CheckpointArg, CreateNewIModelProps, DownloadChangesetArg, DownloadChangesetRangeArg, IModelIdArg, IModelNameArg, LockMap, LockProps, V2CheckpointAccessProps } from "./BackendHubAccess";
4
+ import { CheckpointProps } from "./CheckpointManager";
5
+ import { LocalHub } from "./LocalHub";
6
+ /**
7
+ * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.
8
+ *
9
+ * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:
10
+ * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs
11
+ * - waste network and data center resources (i.e. $$$s),
12
+ * - interfere with other tests running on the same or other systems, and
13
+ * - (far worse) are the source of test flakiness outside of the api being tested.
14
+ *
15
+ * This class can be used to create tests that do not require authentication, are synchronous,
16
+ * 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
17
+ * 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.
18
+ *
19
+ * 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
20
+ * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to
21
+ * low level testing of the core apis only.
22
+ *
23
+ * 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
24
+ * 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
25
+ * 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
26
+ * 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
27
+ * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)
28
+ *
29
+ * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.
30
+ * They use mock (aka "bogus") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current
31
+ * computer.
32
+ *
33
+ * @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
34
+ * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.
35
+ *
36
+ * @internal
37
+ */
38
+ export declare class HubMock {
39
+ private static mockRoot;
40
+ private static hubs;
41
+ private static _saveHubAccess;
42
+ private static _iTwinId;
43
+ /** Determine whether a test us currently being run under HubMock */
44
+ static get isValid(): boolean;
45
+ static get iTwinId(): string;
46
+ /**
47
+ * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].
48
+ * @param mockName a unique name (e.g. "MyTest") for this HubMock to disambiguate tests when more than one is simultaneously active.
49
+ * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.
50
+ */
51
+ static startup(mockName: LocalDirName, outputDir: string): void;
52
+ /** Stop a HubMock that was previously started with [[startup]]
53
+ * @note this function throws an exception if any of the iModels used during the tests are left open.
54
+ */
55
+ static shutdown(): void;
56
+ static findLocalHub(iModelId: GuidString): LocalHub;
57
+ /** create a [[LocalHub]] for an iModel. */
58
+ static createNewIModel(arg: CreateNewIModelProps): Promise<GuidString>;
59
+ /** remove the [[LocalHub]] for an iModel */
60
+ static destroy(iModelId: GuidString): void;
61
+ /** All methods below are mocks of the [[BackendHubAccess]] interface */
62
+ static getChangesetFromNamedVersion(arg: IModelIdArg & {
63
+ versionName: string;
64
+ }): Promise<ChangesetProps>;
65
+ private static changesetIndexFromArg;
66
+ static getChangesetFromVersion(arg: IModelIdArg & {
67
+ version: IModelVersion;
68
+ }): Promise<ChangesetProps>;
69
+ static getLatestChangeset(arg: IModelIdArg): Promise<ChangesetProps>;
70
+ private static getAccessToken;
71
+ static getMyBriefcaseIds(arg: IModelIdArg): Promise<number[]>;
72
+ static acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<number>;
73
+ /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */
74
+ static releaseBriefcase(arg: BriefcaseIdArg): Promise<void>;
75
+ static downloadChangeset(arg: DownloadChangesetArg): Promise<ChangesetFileProps>;
76
+ static downloadChangesets(arg: DownloadChangesetRangeArg): Promise<ChangesetFileProps[]>;
77
+ static queryChangeset(arg: ChangesetArg): Promise<ChangesetProps>;
78
+ static queryChangesets(arg: IModelIdArg & {
79
+ range?: ChangesetRange;
80
+ }): Promise<ChangesetProps[]>;
81
+ static pushChangeset(arg: IModelIdArg & {
82
+ changesetProps: ChangesetFileProps;
83
+ }): Promise<ChangesetIndex>;
84
+ static queryV2Checkpoint(_arg: CheckpointProps): Promise<V2CheckpointAccessProps | undefined>;
85
+ static downloadV1Checkpoint(arg: CheckpointArg): Promise<ChangesetIndexAndId>;
86
+ static releaseAllLocks(arg: BriefcaseDbArg): Promise<void>;
87
+ static queryAllLocks(_arg: BriefcaseDbArg): Promise<LockProps[]>;
88
+ static acquireLocks(arg: BriefcaseDbArg, locks: LockMap): Promise<void>;
89
+ static queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined>;
90
+ static deleteIModel(arg: IModelIdArg & {
91
+ iTwinId: GuidString;
92
+ }): Promise<void>;
93
+ }
94
+ //# sourceMappingURL=HubMock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HubMock.d.ts","sourceRoot":"","sources":["../../src/HubMock.ts"],"names":[],"mappings":"AAMA,OAAO,EAAQ,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,kBAAkB,EAAE,cAAc,EAAE,mBAAmB,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EACrH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,wBAAwB,EACN,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,WAAW,EAAE,aAAa,EAChL,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAC5C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,O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,IAAI,CAAC;WAIpD,iBAAiB,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC;WAIzE,kBAAkB,CAAC,GAAG,EAAE,yBAAyB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;WAIjF,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;WAI1D,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG;QAAE,KAAK,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;CAG5F"}
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.HubMock = void 0;
8
+ const path_1 = require("path");
9
+ const core_bentley_1 = require("@itwin/core-bentley");
10
+ const IModelHost_1 = require("./IModelHost");
11
+ const IModelJsFs_1 = require("./IModelJsFs");
12
+ const LocalHub_1 = require("./LocalHub");
13
+ /**
14
+ * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.
15
+ *
16
+ * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:
17
+ * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs
18
+ * - waste network and data center resources (i.e. $$$s),
19
+ * - interfere with other tests running on the same or other systems, and
20
+ * - (far worse) are the source of test flakiness outside of the api being tested.
21
+ *
22
+ * This class can be used to create tests that do not require authentication, are synchronous,
23
+ * 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
24
+ * 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.
25
+ *
26
+ * 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
27
+ * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to
28
+ * low level testing of the core apis only.
29
+ *
30
+ * 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
31
+ * 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
32
+ * 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
33
+ * 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
34
+ * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)
35
+ *
36
+ * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.
37
+ * They use mock (aka "bogus") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current
38
+ * computer.
39
+ *
40
+ * @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
41
+ * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.
42
+ *
43
+ * @internal
44
+ */
45
+ class HubMock {
46
+ /** Determine whether a test us currently being run under HubMock */
47
+ static get isValid() { return undefined !== this.mockRoot; }
48
+ static get iTwinId() {
49
+ if (undefined === this._iTwinId)
50
+ 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");
51
+ return this._iTwinId;
52
+ }
53
+ /**
54
+ * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].
55
+ * @param mockName a unique name (e.g. "MyTest") for this HubMock to disambiguate tests when more than one is simultaneously active.
56
+ * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.
57
+ */
58
+ static startup(mockName, outputDir) {
59
+ if (this.isValid)
60
+ 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");
61
+ this.hubs.clear();
62
+ this.mockRoot = (0, path_1.join)(outputDir, "HubMock", mockName);
63
+ IModelJsFs_1.IModelJsFs.recursiveMkDirSync(this.mockRoot);
64
+ IModelJsFs_1.IModelJsFs.purgeDirSync(this.mockRoot);
65
+ this._saveHubAccess = IModelHost_1.IModelHost.getHubAccess();
66
+ IModelHost_1.IModelHost.setHubAccess(this);
67
+ HubMock._iTwinId = core_bentley_1.Guid.createValue(); // all iModels for this test get the same "iTwinId"
68
+ }
69
+ /** Stop a HubMock that was previously started with [[startup]]
70
+ * @note this function throws an exception if any of the iModels used during the tests are left open.
71
+ */
72
+ static shutdown() {
73
+ if (!this.isValid)
74
+ return;
75
+ HubMock._iTwinId = undefined;
76
+ for (const hub of this.hubs)
77
+ hub[1].cleanup();
78
+ this.hubs.clear();
79
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
80
+ IModelJsFs_1.IModelJsFs.purgeDirSync(this.mockRoot);
81
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
82
+ IModelJsFs_1.IModelJsFs.removeSync(this.mockRoot);
83
+ IModelHost_1.IModelHost.setHubAccess(this._saveHubAccess);
84
+ this.mockRoot = undefined;
85
+ }
86
+ static findLocalHub(iModelId) {
87
+ const hub = this.hubs.get(iModelId);
88
+ if (!hub)
89
+ throw new Error(`local hub for iModel ${iModelId} not created`);
90
+ return hub;
91
+ }
92
+ /** create a [[LocalHub]] for an iModel. */
93
+ static async createNewIModel(arg) {
94
+ if (!this.mockRoot)
95
+ throw new Error("call startup first");
96
+ const props = { ...arg, iModelId: core_bentley_1.Guid.createValue() };
97
+ const mock = new LocalHub_1.LocalHub((0, path_1.join)(this.mockRoot, props.iModelId), props);
98
+ this.hubs.set(props.iModelId, mock);
99
+ return props.iModelId;
100
+ }
101
+ /** remove the [[LocalHub]] for an iModel */
102
+ static destroy(iModelId) {
103
+ this.findLocalHub(iModelId).cleanup();
104
+ this.hubs.delete(iModelId);
105
+ }
106
+ /** All methods below are mocks of the [[BackendHubAccess]] interface */
107
+ static async getChangesetFromNamedVersion(arg) {
108
+ return this.findLocalHub(arg.iModelId).findNamedVersion(arg.versionName);
109
+ }
110
+ static changesetIndexFromArg(arg) {
111
+ return (undefined !== arg.changeset.index) ? arg.changeset.index : this.findLocalHub(arg.iModelId).getChangesetIndex(arg.changeset.id);
112
+ }
113
+ static async getChangesetFromVersion(arg) {
114
+ const hub = this.findLocalHub(arg.iModelId);
115
+ const version = arg.version;
116
+ if (version.isFirst)
117
+ return hub.getChangesetByIndex(0);
118
+ const asOf = version.getAsOfChangeSet();
119
+ if (asOf)
120
+ return hub.getChangesetById(asOf);
121
+ const versionName = version.getName();
122
+ if (versionName)
123
+ return hub.findNamedVersion(versionName);
124
+ return hub.getLatestChangeset();
125
+ }
126
+ static async getLatestChangeset(arg) {
127
+ return this.findLocalHub(arg.iModelId).getLatestChangeset();
128
+ }
129
+ static async getAccessToken(arg) {
130
+ var _a;
131
+ return (_a = arg.accessToken) !== null && _a !== void 0 ? _a : await IModelHost_1.IModelHost.getAccessToken();
132
+ }
133
+ static async getMyBriefcaseIds(arg) {
134
+ const accessToken = await this.getAccessToken(arg);
135
+ return this.findLocalHub(arg.iModelId).getBriefcaseIds(accessToken);
136
+ }
137
+ static async acquireNewBriefcaseId(arg) {
138
+ const accessToken = await this.getAccessToken(arg);
139
+ return this.findLocalHub(arg.iModelId).acquireNewBriefcaseId(accessToken, arg.briefcaseAlias);
140
+ }
141
+ /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */
142
+ static async releaseBriefcase(arg) {
143
+ return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);
144
+ }
145
+ static async downloadChangeset(arg) {
146
+ return this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });
147
+ }
148
+ static async downloadChangesets(arg) {
149
+ return this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });
150
+ }
151
+ static async queryChangeset(arg) {
152
+ return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));
153
+ }
154
+ static async queryChangesets(arg) {
155
+ return this.findLocalHub(arg.iModelId).queryChangesets(arg.range);
156
+ }
157
+ static async pushChangeset(arg) {
158
+ return this.findLocalHub(arg.iModelId).addChangeset(arg.changesetProps);
159
+ }
160
+ static async queryV2Checkpoint(_arg) {
161
+ return undefined;
162
+ }
163
+ // eslint-disable-next-line deprecation/deprecation
164
+ static async downloadV1Checkpoint(arg) {
165
+ return this.findLocalHub(arg.checkpoint.iModelId).downloadCheckpoint({ changeset: arg.checkpoint.changeset, targetFile: arg.localFile });
166
+ }
167
+ static async releaseAllLocks(arg) {
168
+ const hub = this.findLocalHub(arg.iModelId);
169
+ hub.releaseAllLocks({ briefcaseId: arg.briefcaseId, changesetIndex: hub.getIndexFromChangeset(arg.changeset) });
170
+ }
171
+ static async queryAllLocks(_arg) {
172
+ return [];
173
+ }
174
+ static async acquireLocks(arg, locks) {
175
+ this.findLocalHub(arg.iModelId).acquireLocks(locks, arg);
176
+ }
177
+ static async queryIModelByName(arg) {
178
+ for (const hub of this.hubs) {
179
+ const localHub = hub[1];
180
+ if (localHub.iTwinId === arg.iTwinId && localHub.iModelName === arg.iModelName)
181
+ return localHub.iModelId;
182
+ }
183
+ return undefined;
184
+ }
185
+ static async deleteIModel(arg) {
186
+ return this.destroy(arg.iModelId);
187
+ }
188
+ }
189
+ exports.HubMock = HubMock;
190
+ HubMock.hubs = new Map();
191
+ //# sourceMappingURL=HubMock.js.map
@@ -0,0 +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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,OAAO;IAMlB,oEAAoE;IAC7D,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE5D,MAAM,KAAK,OAAO;QACvB,IAAI,SAAS,KAAK,IAAI,CAAC,QAAQ;YAC7B,MAAM,IAAI,KAAK,CAAC,0JAA0J,CAAC,CAAC;QAC9K,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,uB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,SAAS,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,GAA0C;QACzE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;;AArLH,0BAsLC;AApLgB,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\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\r\n public static get iTwinId() {\r\n if (undefined === this._iTwinId)\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 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.isValid)\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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\r\n IModelJsFs.purgeDirSync(this.mockRoot!);\r\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\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 if (!this.mockRoot)\r\n throw new Error(\"call startup first\");\r\n\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"]}
@@ -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, CodeSpec, CreateEmptySnapshotIModelProps, CreateEmptyStandaloneIModelProps, CreateSnapshotIModelProps, EcefLocation, 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, RpcActivity, SchemaState, SnapRequestProps, SnapResponseProps, SnapshotOpenOptions, StandaloneOpenOptions, TextureData, TextureLoadProps, ThumbnailProps, UpgradeOptions, ViewDefinitionProps, ViewQueryParams, ViewStateLoadProps, ViewStateProps } from "@itwin/core-common";
6
+ import { AxisAlignedBox3d, BRepGeometryCreate, BriefcaseId, ChangesetIdWithIndex, Code, CodeSpec, CreateEmptySnapshotIModelProps, CreateEmptyStandaloneIModelProps, CreateSnapshotIModelProps, EcefLocation, 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, 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";
@@ -21,6 +21,7 @@ import { TxnManager } from "./TxnManager";
21
21
  import { ViewDefinition } from "./ViewDefinition";
22
22
  import { SettingDictionary } from "./workspace/Settings";
23
23
  import { Workspace } from "./workspace/Workspace";
24
+ import { SQLiteDb } from "./SQLiteDb";
24
25
  /** Options for [[IModelDb.Models.updateModel]]
25
26
  * @note To mark *only* the geometry as changed, use [[IModelDb.Models.updateGeometryGuid]] instead.
26
27
  * @public
@@ -135,7 +136,7 @@ export declare abstract class IModelDb extends IModel {
135
136
  private _classMetaDataRegistry?;
136
137
  protected _fontMap?: FontMap;
137
138
  /** @internal */
138
- protected _workspace: Workspace;
139
+ private _workspace?;
139
140
  private readonly _snaps;
140
141
  private static _shutdownListener;
141
142
  /** @internal */
@@ -193,7 +194,7 @@ export declare abstract class IModelDb extends IModel {
193
194
  /** Close this IModel, if it is currently open. */
194
195
  close(): void;
195
196
  /** @internal */
196
- reattachDaemon(_accessToken: AccessToken): Promise<void>;
197
+ refreshContainerSas(_userAccessToken: AccessToken): Promise<void>;
197
198
  /** Event called when the iModel is about to be closed. */
198
199
  readonly onBeforeClose: BeEvent<() => void>;
199
200
  /**
@@ -424,7 +425,7 @@ export declare abstract class IModelDb extends IModel {
424
425
  static openDgnDb(file: {
425
426
  path: LocalFileName;
426
427
  key?: string;
427
- }, openMode: OpenMode, upgradeOptions?: UpgradeOptions, props?: SnapshotOpenOptions): IModelJsNative.DgnDb;
428
+ }, openMode: OpenMode, upgradeOptions?: UpgradeOptions, props?: SnapshotOpenOptions & CloudContainerArgs): IModelJsNative.DgnDb;
428
429
  /**
429
430
  * Determines if the schemas in the Db must or can be upgraded by comparing them with those included in the
430
431
  * current version of the software.
@@ -730,7 +731,7 @@ export declare namespace IModelDb {
730
731
  */
731
732
  getElementJson<T extends ElementProps>(elementId: ElementLoadProps): T;
732
733
  /** Read element data from the iModel as JSON
733
- * @param elementIdArg a json string with the identity of the element to load. Must have one of "id", "federationGuid", or "code".
734
+ * @param loadProps - a json string with the identity of the element to load. Must have one of "id", "federationGuid", or "code".
734
735
  * @returns The JSON properties of the element or `undefined` if the element is not found.
735
736
  * @throws [[IModelError]] if the element exists, but cannot be loaded.
736
737
  * @see getElementJson
@@ -937,13 +938,23 @@ export interface TokenArg {
937
938
  /** If present, the access token for the requested operation. If not present, use [[IModelHost.getAccessToken]] */
938
939
  readonly accessToken?: AccessToken;
939
940
  }
941
+ /** Augments a [[SnapshotDbOpenArgs]] or [[OpenBriefcaseArgs]] with a [CloudContainer]($docs/learning/backend/Workspace.md).
942
+ * The properties are this interface are reserved for internal use only.
943
+ * @public
944
+ */
945
+ export interface CloudContainerArgs {
946
+ /** @internal */
947
+ container?: SQLiteDb.CloudContainer;
948
+ }
949
+ /** Options to open a [SnapshotDb]($backend).
950
+ * @public
951
+ */
952
+ export declare type SnapshotDbOpenArgs = SnapshotOpenOptions & CloudContainerArgs;
940
953
  /**
941
954
  * Arguments to open a BriefcaseDb
942
955
  * @public
943
956
  */
944
- export declare type OpenBriefcaseArgs = OpenBriefcaseProps & {
945
- rpcActivity?: RpcActivity;
946
- };
957
+ export declare type OpenBriefcaseArgs = OpenBriefcaseProps & CloudContainerArgs;
947
958
  /**
948
959
  * A local copy of an iModel from iModelHub that can pull and potentially push changesets.
949
960
  * BriefcaseDb raises a set of events to allow apps and subsystems to track its object life cycle, including [[onOpen]] and [[onOpened]].
@@ -1023,7 +1034,7 @@ export declare class BriefcaseDb extends IModelDb {
1023
1034
  */
1024
1035
  export declare class SnapshotDb extends IModelDb {
1025
1036
  get isSnapshot(): boolean;
1026
- private _daemonReattach;
1037
+ private _refreshSas;
1027
1038
  private _createClassViewsOnClose?;
1028
1039
  private constructor();
1029
1040
  static findByKey(key: string): SnapshotDb;
@@ -1050,14 +1061,14 @@ export declare class SnapshotDb extends IModelDb {
1050
1061
  /** open this SnapshotDb read/write, strictly to apply incoming changesets. Used for creating new checkpoints.
1051
1062
  * @internal
1052
1063
  */
1053
- static openForApplyChangesets(path: LocalFileName, props?: SnapshotOpenOptions): SnapshotDb;
1064
+ static openForApplyChangesets(path: LocalFileName, props?: SnapshotDbOpenArgs): SnapshotDb;
1054
1065
  /** Open a read-only iModel *snapshot*.
1055
1066
  * @param path the full path of the snapshot iModel file to open.
1056
1067
  * @param props options for opening snapshot
1057
1068
  * @see [[close]]
1058
1069
  * @throws [[IModelError]] If the file is not found or is not a valid *snapshot*.
1059
1070
  */
1060
- static openFile(path: LocalFileName, opts?: SnapshotOpenOptions): SnapshotDb;
1071
+ static openFile(path: LocalFileName, opts?: SnapshotDbOpenArgs): SnapshotDb;
1061
1072
  /** Open a previously downloaded V1 checkpoint file.
1062
1073
  * @note The key is generated by this call is predictable and is formed from the IModelId and ChangeSetId.
1063
1074
  * This is so every backend working on the same checkpoint will use the same key, to permit multiple backends
@@ -1068,17 +1079,17 @@ export declare class SnapshotDb extends IModelDb {
1068
1079
  /** Open a V2 *checkpoint*, a special form of snapshot iModel that represents a read-only snapshot of an iModel from iModelHub at a particular point in time.
1069
1080
  * > Note: The checkpoint daemon must already be running and a checkpoint must already exist in iModelHub's storage *before* this function is called.
1070
1081
  * @param checkpoint The checkpoint to open
1071
- * @note The key is generated by this call is predictable and is formed from the IModelId and ChangeSetId.
1082
+ * @note The key generated by this call is predictable and is formed from the IModelId and ChangeSetId.
1072
1083
  * This is so every backend working on the same checkpoint will use the same key, to permit multiple backends
1073
1084
  * servicing the same checkpoint.
1074
1085
  * @throws [[IModelError]] If the checkpoint is not found in iModelHub or the checkpoint daemon is not supported in the current environment.
1075
1086
  * @internal
1076
1087
  */
1077
1088
  static openCheckpointV2(checkpoint: CheckpointProps): Promise<SnapshotDb>;
1078
- /** Used to refresh the daemon's accessToken if this is a V2 checkpoint.
1089
+ /** Used to refresh the container sasToken using the current user's accessToken
1079
1090
  * @internal
1080
1091
  */
1081
- reattachDaemon(accessToken: AccessToken): Promise<void>;
1092
+ refreshContainerSas(userAccessToken: AccessToken): Promise<void>;
1082
1093
  /** @internal */
1083
1094
  beforeClose(): void;
1084
1095
  }
@@ -1123,6 +1134,6 @@ export declare class StandaloneDb extends BriefcaseDb {
1123
1134
  * @throws [[IModelError]] if the file is not a standalone iModel.
1124
1135
  * @see [BriefcaseConnection.openStandalone]($frontend) to open a StandaloneDb from the frontend
1125
1136
  */
1126
- static openFile(filePath: LocalFileName, openMode?: OpenMode, options?: StandaloneOpenOptions): StandaloneDb;
1137
+ static openFile(filePath: LocalFileName, openMode?: OpenMode, options?: SnapshotDbOpenArgs): StandaloneDb;
1127
1138
  }
1128
1139
  //# sourceMappingURL=IModelDb.d.ts.map