@itwin/core-backend 3.0.0-dev.98 → 3.1.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 (128) hide show
  1. package/CHANGELOG.md +82 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/AliCloudStorageService.d.ts +8 -2
  4. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
  5. package/lib/cjs/AliCloudStorageService.js +4 -5
  6. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  7. package/lib/cjs/BackendHubAccess.d.ts +9 -9
  8. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  9. package/lib/cjs/BackendHubAccess.js.map +1 -1
  10. package/lib/cjs/BriefcaseManager.js +4 -3
  11. package/lib/cjs/BriefcaseManager.js.map +1 -1
  12. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
  13. package/lib/cjs/ChangeSummaryManager.js +2 -0
  14. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  15. package/lib/cjs/ChangedElementsDb.d.ts +2 -0
  16. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  17. package/lib/cjs/ChangedElementsDb.js +1 -1
  18. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  19. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  20. package/lib/cjs/CheckpointManager.js +10 -7
  21. package/lib/cjs/CheckpointManager.js.map +1 -1
  22. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  23. package/lib/cjs/ClassRegistry.js +10 -3
  24. package/lib/cjs/ClassRegistry.js.map +1 -1
  25. package/lib/cjs/CloudStorageBackend.d.ts +2 -3
  26. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
  27. package/lib/cjs/CloudStorageBackend.js +5 -2
  28. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  29. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
  30. package/lib/cjs/ConcurrentQuery.js +7 -0
  31. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  32. package/lib/cjs/DevTools.d.ts +2 -2
  33. package/lib/cjs/DevTools.d.ts.map +1 -1
  34. package/lib/cjs/DevTools.js +2 -2
  35. package/lib/cjs/DevTools.js.map +1 -1
  36. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  37. package/lib/cjs/DisplayStyle.js +13 -45
  38. package/lib/cjs/DisplayStyle.js.map +1 -1
  39. package/lib/cjs/ECDb.d.ts +5 -9
  40. package/lib/cjs/ECDb.d.ts.map +1 -1
  41. package/lib/cjs/ECDb.js +11 -14
  42. package/lib/cjs/ECDb.js.map +1 -1
  43. package/lib/cjs/ECSchemaXmlContext.d.ts +1 -0
  44. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  45. package/lib/cjs/ECSchemaXmlContext.js +10 -4
  46. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  47. package/lib/cjs/ECSqlStatement.d.ts +8 -8
  48. package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
  49. package/lib/cjs/ECSqlStatement.js +24 -15
  50. package/lib/cjs/ECSqlStatement.js.map +1 -1
  51. package/lib/cjs/Element.js +1 -1
  52. package/lib/cjs/Element.js.map +1 -1
  53. package/lib/cjs/ElementAspect.js +2 -2
  54. package/lib/cjs/ElementAspect.js.map +1 -1
  55. package/lib/cjs/ElementGraphics.js +1 -1
  56. package/lib/cjs/ElementGraphics.js.map +1 -1
  57. package/lib/cjs/ExportGraphics.d.ts +1 -1
  58. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  59. package/lib/cjs/ExportGraphics.js +3 -0
  60. package/lib/cjs/ExportGraphics.js.map +1 -1
  61. package/lib/cjs/IModelDb.d.ts +44 -26
  62. package/lib/cjs/IModelDb.d.ts.map +1 -1
  63. package/lib/cjs/IModelDb.js +104 -25
  64. package/lib/cjs/IModelDb.js.map +1 -1
  65. package/lib/cjs/IModelHost.d.ts +40 -19
  66. package/lib/cjs/IModelHost.d.ts.map +1 -1
  67. package/lib/cjs/IModelHost.js +70 -20
  68. package/lib/cjs/IModelHost.js.map +1 -1
  69. package/lib/cjs/IModelJsFs.js +1 -1
  70. package/lib/cjs/IModelJsFs.js.map +1 -1
  71. package/lib/cjs/IpcHost.js +2 -1
  72. package/lib/cjs/IpcHost.js.map +1 -1
  73. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
  74. package/lib/cjs/LocalhostIpcHost.js +10 -3
  75. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  76. package/lib/cjs/Model.js +1 -1
  77. package/lib/cjs/Model.js.map +1 -1
  78. package/lib/cjs/NativeHost.d.ts +4 -22
  79. package/lib/cjs/NativeHost.d.ts.map +1 -1
  80. package/lib/cjs/NativeHost.js +4 -56
  81. package/lib/cjs/NativeHost.js.map +1 -1
  82. package/lib/cjs/Relationship.d.ts +7 -7
  83. package/lib/cjs/Relationship.js +4 -4
  84. package/lib/cjs/Relationship.js.map +1 -1
  85. package/lib/cjs/RpcBackend.d.ts +4 -0
  86. package/lib/cjs/RpcBackend.d.ts.map +1 -1
  87. package/lib/cjs/RpcBackend.js +7 -0
  88. package/lib/cjs/RpcBackend.js.map +1 -1
  89. package/lib/cjs/SQLiteDb.js +1 -1
  90. package/lib/cjs/SQLiteDb.js.map +1 -1
  91. package/lib/cjs/ServerBasedLocks.d.ts +4 -10
  92. package/lib/cjs/ServerBasedLocks.d.ts.map +1 -1
  93. package/lib/cjs/ServerBasedLocks.js +12 -20
  94. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  95. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  96. package/lib/cjs/SqliteStatement.js.map +1 -1
  97. package/lib/cjs/TxnManager.js +1 -1
  98. package/lib/cjs/TxnManager.js.map +1 -1
  99. package/lib/cjs/assets/Settings.schema.json +25 -0
  100. package/lib/cjs/core-backend.d.ts +8 -1
  101. package/lib/cjs/core-backend.d.ts.map +1 -1
  102. package/lib/cjs/core-backend.js +9 -1
  103. package/lib/cjs/core-backend.js.map +1 -1
  104. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
  105. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +33 -24
  106. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  107. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  108. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +10 -7
  109. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  110. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  111. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +11 -1
  112. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  113. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts.map +1 -1
  114. package/lib/cjs/rpc-impl/WipRpcImpl.js +3 -0
  115. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  116. package/lib/cjs/workspace/Settings.d.ts +182 -0
  117. package/lib/cjs/workspace/Settings.d.ts.map +1 -0
  118. package/lib/cjs/workspace/Settings.js +144 -0
  119. package/lib/cjs/workspace/Settings.js.map +1 -0
  120. package/lib/cjs/workspace/SettingsSpecRegistry.d.ts +68 -0
  121. package/lib/cjs/workspace/SettingsSpecRegistry.d.ts.map +1 -0
  122. package/lib/cjs/workspace/SettingsSpecRegistry.js +122 -0
  123. package/lib/cjs/workspace/SettingsSpecRegistry.js.map +1 -0
  124. package/lib/cjs/workspace/Workspace.d.ts +306 -0
  125. package/lib/cjs/workspace/Workspace.d.ts.map +1 -0
  126. package/lib/cjs/workspace/Workspace.js +372 -0
  127. package/lib/cjs/workspace/Workspace.js.map +1 -0
  128. package/package.json +33 -19
@@ -31,6 +31,8 @@ const ServerBasedLocks_1 = require("./ServerBasedLocks");
31
31
  const SqliteStatement_1 = require("./SqliteStatement");
32
32
  const TxnManager_1 = require("./TxnManager");
33
33
  const ViewDefinition_1 = require("./ViewDefinition");
34
+ const Settings_1 = require("./workspace/Settings");
35
+ const Workspace_1 = require("./workspace/Workspace");
34
36
  const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.IModelDb;
35
37
  /** A null-implementation of LockControl that does not attempt to limit access between briefcases. This relies on change-merging to resolve conflicts. */
36
38
  class NoLocks {
@@ -42,8 +44,7 @@ class NoLocks {
42
44
  checkExclusiveLock() { }
43
45
  checkSharedLock() { }
44
46
  elementWasCreated() { }
45
- async acquireExclusiveLock() { }
46
- async acquireSharedLock() { }
47
+ async acquireLocks() { }
47
48
  async releaseAllLocks() { }
48
49
  }
49
50
  /** @internal */
@@ -62,6 +63,21 @@ const withBriefcaseDb = async (briefcase, fn) => {
62
63
  db.close();
63
64
  }
64
65
  };
66
+ /**
67
+ * Settings for an individual iModel. May only include settings priority for iModel, iTwin and organization.
68
+ * @note if there is more than one iModel for an iTwin or organization, they will *each* hold a copy of the settings for those priorities.
69
+ */
70
+ class IModelSettings extends Settings_1.BaseSettings {
71
+ verifyPriority(priority) {
72
+ if (priority <= Settings_1.SettingsPriority.application)
73
+ throw new Error("Use IModelHost.appSettings");
74
+ }
75
+ // attempt to resolve a setting from this iModel's settings, otherwise use appWorkspace's settings, otherwise defaultValue.
76
+ resolveSetting(name, resolver, defaultValue) {
77
+ var _a;
78
+ return (_a = super.resolveSetting(name, resolver)) !== null && _a !== void 0 ? _a : IModelHost_1.IModelHost.appWorkspace.settings.resolveSetting(name, resolver, defaultValue);
79
+ }
80
+ }
65
81
  /** An iModel database file. The database file can either be a briefcase or a snapshot.
66
82
  * @see [Accessing iModels]($docs/learning/backend/AccessingIModels.md)
67
83
  * @see [About IModelDb]($docs/learning/backend/IModelDb.md)
@@ -78,7 +94,6 @@ class IModelDb extends core_common_1.IModel {
78
94
  this.tiles = new IModelDb.Tiles(this);
79
95
  this._statementCache = new SqliteStatement_1.StatementCache();
80
96
  this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
81
- this._concurrentQueryStats = { resetTimerHandle: null, logTimerHandle: null, lastActivityTime: Date.now(), dispose: () => { } };
82
97
  this._snaps = new Map();
83
98
  /** @internal */
84
99
  this._locks = new NoLocks();
@@ -90,6 +105,8 @@ class IModelDb extends core_common_1.IModel {
90
105
  this.nativeDb.setIModelDb(this);
91
106
  this.initializeIModelDb();
92
107
  IModelDb._openDbs.set(this._fileKey, this);
108
+ this._workspace = new Workspace_1.ITwinWorkspace(new IModelSettings(), IModelHost_1.IModelHost.appWorkspace);
109
+ this.loadSettingDictionaries();
93
110
  if (undefined === IModelDb._shutdownListener) { // the first time we create an IModelDb, add a listener to close any orphan files at shutdown.
94
111
  IModelDb._shutdownListener = IModelHost_1.IModelHost.onBeforeShutdown.addListener(() => {
95
112
  IModelDb._openDbs.forEach((db) => {
@@ -103,16 +120,21 @@ class IModelDb extends core_common_1.IModel {
103
120
  }
104
121
  }
105
122
  /**
106
- * Get the lock control for this iModel.
123
+ * Get the [[LockControl]] for this iModel.
124
+ * @beta
125
+ */
126
+ get locks() { return this._locks; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
127
+ /**
128
+ * Get the [[Workspace]] for this iModel.
107
129
  * @beta
108
130
  */
109
- get locks() { return this._locks; }
131
+ get workspace() { return this._workspace; }
110
132
  /** Acquire the exclusive schema lock on this iModel.
111
133
  * > Note: To acquire the schema lock, all other briefcases must first release *all* their locks. No other briefcases
112
134
  * will be able to acquire *any* locks while the schema lock is held.
113
135
  */
114
136
  async acquireSchemaLock() {
115
- return this.locks.acquireExclusiveLock(core_common_1.IModel.repositoryModelId);
137
+ return this.locks.acquireLocks({ exclusive: core_common_1.IModel.repositoryModelId });
116
138
  }
117
139
  /** determine whether the schema lock is currently held for this iModel. */
118
140
  get holdsSchemaLock() {
@@ -124,13 +146,17 @@ class IModelDb extends core_common_1.IModel {
124
146
  this.onChangesetApplied.raiseEvent();
125
147
  }
126
148
  get fontMap() { var _a; return (_a = this._fontMap) !== null && _a !== void 0 ? _a : (this._fontMap = new core_common_1.FontMap(this.nativeDb.readFontMap())); }
149
+ /** @internal */
127
150
  embedFont(prop) { this._fontMap = undefined; return this.nativeDb.embedFont(prop); }
128
151
  /** Check if this iModel has been opened read-only or not. */
129
152
  get isReadonly() { return this.openMode === core_bentley_1.OpenMode.Readonly; }
130
153
  /** The Guid that identifies this iModel. */
131
- get iModelId() { return super.iModelId; } // GuidString | undefined for the IModel superclass, but required for all IModelDb subclasses
154
+ get iModelId() {
155
+ (0, core_bentley_1.assert)(undefined !== super.iModelId);
156
+ return super.iModelId;
157
+ } // GuidString | undefined for the IModel superclass, but required for all IModelDb subclasses
132
158
  /** @internal*/
133
- get nativeDb() { return this._nativeDb; }
159
+ get nativeDb() { return this._nativeDb; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
134
160
  /** Get the full path fileName of this iModelDb
135
161
  * @note this member is only valid while the iModel is opened.
136
162
  */
@@ -141,6 +167,7 @@ class IModelDb extends core_common_1.IModel {
141
167
  return; // don't continue if already closed
142
168
  this.beforeClose();
143
169
  IModelDb._openDbs.delete(this._fileKey);
170
+ this._workspace.close();
144
171
  this.locks.close();
145
172
  this._locks = undefined;
146
173
  this.nativeDb.closeIModel();
@@ -155,7 +182,6 @@ class IModelDb extends core_common_1.IModel {
155
182
  beforeClose() {
156
183
  this.onBeforeClose.raiseEvent();
157
184
  this.clearCaches();
158
- this._concurrentQueryStats.dispose();
159
185
  }
160
186
  /** @internal */
161
187
  initializeIModelDb() {
@@ -274,7 +300,7 @@ class IModelDb extends core_common_1.IModel {
274
300
  }
275
301
  const executor = {
276
302
  execute: async (request) => {
277
- return ConcurrentQuery_1.ConcurrentQuery.executeQueryRequest(this._nativeDb, request);
303
+ return ConcurrentQuery_1.ConcurrentQuery.executeQueryRequest(this.nativeDb, request);
278
304
  },
279
305
  };
280
306
  return new core_common_1.ECSqlReader(executor, ecsql, params, config);
@@ -289,20 +315,16 @@ class IModelDb extends core_common_1.IModel {
289
315
  *
290
316
  * @param ecsql The ECSQL statement to execute
291
317
  * @param params The values to bind to the parameters (if the ECSQL has any).
292
- * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*
293
318
  * @param options Allow to specify certain flags which control how query is executed.
294
319
  * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.
295
320
  * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.
296
321
  * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query
297
322
  */
298
- async *query(ecsql, params, rowFormat = core_common_1.QueryRowFormat.UseArrayIndexes, options) {
323
+ async *query(ecsql, params, options) {
299
324
  const builder = new core_common_1.QueryOptionsBuilder(options);
300
- if (rowFormat === core_common_1.QueryRowFormat.UseJsPropertyNames) {
301
- builder.setConvertClassIdsToNames(true);
302
- }
303
325
  const reader = this.createQueryReader(ecsql, params, builder.getOptions());
304
326
  while (await reader.step())
305
- yield reader.formatCurrentRow(rowFormat);
327
+ yield reader.formatCurrentRow();
306
328
  }
307
329
  /** Compute number of rows that would be returned by the ECSQL.
308
330
  *
@@ -312,7 +334,7 @@ class IModelDb extends core_common_1.IModel {
312
334
  *
313
335
  * @param ecsql The ECSQL statement to execute
314
336
  * @param params The values to bind to the parameters (if the ECSQL has any).
315
- * See "[iModel.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" for details.
337
+ * See "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" for details.
316
338
  * @returns Return row count.
317
339
  * @throws [IModelError]($common) If the statement is invalid
318
340
  */
@@ -334,14 +356,13 @@ class IModelDb extends core_common_1.IModel {
334
356
  * @param token None empty restart token. The previous query with same token would be cancelled. This would cause
335
357
  * exception which user code must handle.
336
358
  * @param params The values to bind to the parameters (if the ECSQL has any).
337
- * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*
338
359
  * @param options Allow to specify certain flags which control how query is executed.
339
360
  * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.
340
361
  * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.
341
362
  * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query
342
363
  */
343
- async *restartQuery(token, ecsql, params, rowFormat = core_common_1.QueryRowFormat.UseArrayIndexes, options) {
344
- for await (const row of this.query(ecsql, params, rowFormat, new core_common_1.QueryOptionsBuilder(options).setRestartToken(token).getOptions())) {
364
+ async *restartQuery(token, ecsql, params, options) {
365
+ for await (const row of this.query(ecsql, params, new core_common_1.QueryOptionsBuilder(options).setRestartToken(token).getOptions())) {
345
366
  yield row;
346
367
  }
347
368
  }
@@ -762,6 +783,7 @@ class IModelDb extends core_common_1.IModel {
762
783
  const val = this.nativeDb.getECClassMetaData(className[0], className[1]);
763
784
  if (val.error)
764
785
  throw new core_common_1.IModelError(val.error.status, `Error getting class meta data for: ${classFullName}`);
786
+ (0, core_bentley_1.assert)(undefined !== val.result);
765
787
  const metaData = new core_common_1.EntityMetaData(JSON.parse(val.result));
766
788
  this.classMetaDataRegistry.add(classFullName, metaData);
767
789
  // Recursive, to make sure that base classes are cached.
@@ -917,7 +939,7 @@ class IModelDb extends core_common_1.IModel {
917
939
  * that list.
918
940
  * * The results of changing [ExportPartGraphicsOptions]($core-backend) during the
919
941
  * [ExportPartGraphicsOptions.onPartGraphics]($core-backend) callback are not defined.
920
- * * See export-gltf under test-apps in the iModel.js monorepo for a working reference.
942
+ * * See export-gltf under test-apps in the iTwin.js monorepo for a working reference.
921
943
  * @returns 0 is successful, status otherwise
922
944
  * @public
923
945
  */
@@ -953,12 +975,61 @@ class IModelDb extends core_common_1.IModel {
953
975
  async generateElementGraphics(request) {
954
976
  return (0, ElementGraphics_1.generateElementGraphics)(request, this);
955
977
  }
978
+ /** Save a `SettingDictionary` in this iModel that will be loaded into [[workspace.settings]] every time this iModel is opened in future sessions.
979
+ * @param name The name for the SettingDictionary. If a dictionary by that name already exists in the iModel, its value is replaced.
980
+ * @param dict The SettingDictionary object to stringify and save.
981
+ * @note All saved `SettingDictionary`s are loaded into [[workspace.settings]] every time an iModel is opened.
982
+ * @beta
983
+ */
984
+ saveSettingDictionary(name, dict) {
985
+ this.withSqliteStatement("REPLACE INTO be_Prop(id,SubId,TxnMode,Namespace,Name,strData) VALUES(0,0,0,?,?,?)", (stmt) => {
986
+ stmt.bindString(1, IModelDb._settingPropNamespace);
987
+ stmt.bindString(2, name);
988
+ stmt.bindString(3, JSON.stringify(dict));
989
+ const rc = stmt.step();
990
+ if (rc !== core_bentley_1.DbResult.BE_SQLITE_DONE)
991
+ throw new core_common_1.IModelError(rc, "cannot save setting");
992
+ });
993
+ this.saveChanges("add settings");
994
+ }
995
+ /** Delete a SettingDictionary, previously added with [[saveSettingDictionary]], from this iModel.
996
+ * @param name The name of the dictionary to delete.
997
+ * @beta
998
+ */
999
+ deleteSettingDictionary(name) {
1000
+ this.withSqliteStatement("DELETE FROM be_Prop WHERE Namespace=? AND Name=?", (stmt) => {
1001
+ stmt.bindString(1, IModelDb._settingPropNamespace);
1002
+ stmt.bindString(2, name);
1003
+ const rc = stmt.step();
1004
+ if (rc !== core_bentley_1.DbResult.BE_SQLITE_DONE)
1005
+ throw new core_common_1.IModelError(rc, "cannot delete setting");
1006
+ });
1007
+ this.saveChanges("delete settings");
1008
+ }
1009
+ /** Load all setting dictionaries in this iModel into `this.workspace.settings` */
1010
+ loadSettingDictionaries() {
1011
+ if (!this.nativeDb.isOpen())
1012
+ return;
1013
+ this.withSqliteStatement("SELECT Name,StrData FROM be_Prop WHERE Namespace=?", (stmt) => {
1014
+ stmt.bindString(1, IModelDb._settingPropNamespace);
1015
+ while (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW) {
1016
+ try {
1017
+ const dict = JSON.parse(stmt.getValueString(1));
1018
+ this.workspace.settings.addDictionary(stmt.getValueString(0), Settings_1.SettingsPriority.iModel, dict);
1019
+ }
1020
+ catch (e) {
1021
+ core_bentley_1.UnexpectedErrors.handle(e);
1022
+ }
1023
+ }
1024
+ });
1025
+ }
956
1026
  }
957
1027
  exports.IModelDb = IModelDb;
958
1028
  /** Keep track of open imodels to support `tryFind` for RPC purposes */
959
1029
  IModelDb._openDbs = new Map();
960
1030
  IModelDb.defaultLimit = 1000; // default limit for batching queries
961
1031
  IModelDb.maxLimit = 10000; // maximum limit for batching queries
1032
+ IModelDb._settingPropNamespace = "settings";
962
1033
  /** @public */
963
1034
  (function (IModelDb) {
964
1035
  /** The collection of models in an [[IModelDb]].
@@ -1068,7 +1139,7 @@ IModelDb.maxLimit = 10000; // maximum limit for batching queries
1068
1139
  */
1069
1140
  getSubModel(modeledElementId, modelClass) {
1070
1141
  const modeledElementProps = this._iModel.elements.getElementProps(modeledElementId);
1071
- if (modeledElementProps.id === core_common_1.IModel.rootSubjectId)
1142
+ if (undefined === modeledElementProps.id || modeledElementProps.id === core_common_1.IModel.rootSubjectId)
1072
1143
  throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, "Root subject does not have a sub-model");
1073
1144
  return this.getModel(modeledElementProps.id, modelClass);
1074
1145
  }
@@ -1081,7 +1152,7 @@ IModelDb.maxLimit = 10000; // maximum limit for batching queries
1081
1152
  */
1082
1153
  tryGetSubModel(modeledElementId, modelClass) {
1083
1154
  const modeledElementProps = this._iModel.elements.tryGetElementProps(modeledElementId);
1084
- if ((undefined === modeledElementProps) || (core_common_1.IModel.rootSubjectId === modeledElementProps.id))
1155
+ if (undefined === (modeledElementProps === null || modeledElementProps === void 0 ? void 0 : modeledElementProps.id) || (core_common_1.IModel.rootSubjectId === modeledElementProps.id))
1085
1156
  return undefined;
1086
1157
  return this.tryGetModel(modeledElementProps.id, modelClass);
1087
1158
  }
@@ -1760,6 +1831,7 @@ IModelDb.maxLimit = 10000; // maximum limit for batching queries
1760
1831
  if (undefined !== ret.error) {
1761
1832
  throw new core_common_1.IModelError(ret.error.status, `TreeId=${treeId} TileId=${tileId}`);
1762
1833
  }
1834
+ (0, core_bentley_1.assert)(undefined !== ret.result);
1763
1835
  return ret.result;
1764
1836
  }
1765
1837
  }
@@ -1789,8 +1861,11 @@ class BriefcaseDb extends IModelDb {
1789
1861
  const db = super.tryFindByKey(key);
1790
1862
  return (db === null || db === void 0 ? void 0 : db.isBriefcaseDb()) ? db : undefined;
1791
1863
  }
1792
- /** The Guid that identifies the *context* that owns this iModel. */
1793
- get iTwinId() { return super.iTwinId; } // GuidString | undefined for the superclass, but required for BriefcaseDb
1864
+ /**
1865
+ * The Guid that identifies the *context* that owns this iModel.
1866
+ * GuidString | undefined for the superclass, but required for BriefcaseDb
1867
+ * */
1868
+ get iTwinId() { return super.iTwinId; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
1794
1869
  /**
1795
1870
  * Determine whether this BriefcaseDb should use a lock server.
1796
1871
  * All must be true:
@@ -1919,6 +1994,7 @@ class DaemonReattach {
1919
1994
  core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.BackendLoggerCategory.Authorization, "attempting to reattach checkpoint");
1920
1995
  try {
1921
1996
  // this exchanges the supplied user accessToken for an expiring blob-store token to read the checkpoint.
1997
+ (0, core_bentley_1.assert)(undefined !== iModel.iTwinId);
1922
1998
  const response = await CheckpointManager_1.V2CheckpointManager.attach({ accessToken, iTwinId: iModel.iTwinId, iModelId: iModel.iModelId, changeset: iModel.changeset });
1923
1999
  core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.BackendLoggerCategory.Authorization, "reattached checkpoint successfully");
1924
2000
  this.setTimestamp(response.expiryTimestamp);
@@ -2012,6 +2088,7 @@ class SnapshotDb extends IModelDb {
2012
2088
  static openForApplyChangesets(path, props) {
2013
2089
  const file = { path, key: props === null || props === void 0 ? void 0 : props.key };
2014
2090
  const nativeDb = this.openDgnDb(file, core_bentley_1.OpenMode.ReadWrite, undefined, props);
2091
+ (0, core_bentley_1.assert)(undefined !== file.key);
2015
2092
  return new SnapshotDb(nativeDb, file.key);
2016
2093
  }
2017
2094
  /** Open a read-only iModel *snapshot*.
@@ -2023,6 +2100,7 @@ class SnapshotDb extends IModelDb {
2023
2100
  static openFile(path, opts) {
2024
2101
  const file = { path, key: opts === null || opts === void 0 ? void 0 : opts.key };
2025
2102
  const nativeDb = this.openDgnDb(file, core_bentley_1.OpenMode.Readonly, undefined, opts);
2103
+ (0, core_bentley_1.assert)(undefined !== file.key);
2026
2104
  return new SnapshotDb(nativeDb, file.key);
2027
2105
  }
2028
2106
  /** Open a previously downloaded V1 checkpoint file.
@@ -2149,6 +2227,7 @@ class StandaloneDb extends BriefcaseDb {
2149
2227
  const iTwinId = nativeDb.getITwinId();
2150
2228
  if (iTwinId !== core_bentley_1.Guid.empty) // a "standalone" iModel means it is not associated with an iTwin
2151
2229
  throw new core_common_1.IModelError(core_bentley_1.IModelStatus.WrongIModel, `${filePath} is not a Standalone iModel. iTwinId=${iTwinId}`);
2230
+ (0, core_bentley_1.assert)(undefined !== file.key);
2152
2231
  return new StandaloneDb({ nativeDb, key: file.key, openMode, briefcaseId: core_common_1.BriefcaseIdValue.Unassigned });
2153
2232
  }
2154
2233
  catch (error) {