@itwin/core-backend 4.1.0-dev.8 → 4.1.0-dev.80

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 (188) hide show
  1. package/CHANGELOG.md +99 -1
  2. package/lib/cjs/BackendHubAccess.js.map +1 -1
  3. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  4. package/lib/cjs/BisCoreSchema.js.map +1 -1
  5. package/lib/cjs/BlobContainerService.d.ts +38 -28
  6. package/lib/cjs/BlobContainerService.d.ts.map +1 -1
  7. package/lib/cjs/BlobContainerService.js.map +1 -1
  8. package/lib/cjs/BriefcaseManager.d.ts +8 -5
  9. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  10. package/lib/cjs/BriefcaseManager.js +9 -16
  11. package/lib/cjs/BriefcaseManager.js.map +1 -1
  12. package/lib/cjs/Category.d.ts +4 -16
  13. package/lib/cjs/Category.d.ts.map +1 -1
  14. package/lib/cjs/Category.js +0 -12
  15. package/lib/cjs/Category.js.map +1 -1
  16. package/lib/cjs/ChangeSummaryManager.js +2 -2
  17. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  18. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  19. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  20. package/lib/cjs/ChannelControl.d.ts +5 -1
  21. package/lib/cjs/ChannelControl.d.ts.map +1 -1
  22. package/lib/cjs/ChannelControl.js +10 -5
  23. package/lib/cjs/ChannelControl.js.map +1 -1
  24. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  25. package/lib/cjs/CheckpointManager.js +20 -9
  26. package/lib/cjs/CheckpointManager.js.map +1 -1
  27. package/lib/cjs/ClassRegistry.d.ts +2 -1
  28. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  29. package/lib/cjs/ClassRegistry.js +7 -6
  30. package/lib/cjs/ClassRegistry.js.map +1 -1
  31. package/lib/cjs/CloudSqlite.d.ts +57 -40
  32. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  33. package/lib/cjs/CloudSqlite.js +54 -39
  34. package/lib/cjs/CloudSqlite.js.map +1 -1
  35. package/lib/cjs/CodeService.js.map +1 -1
  36. package/lib/cjs/CodeSpecs.js.map +1 -1
  37. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  38. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  39. package/lib/cjs/DevTools.js.map +1 -1
  40. package/lib/cjs/DisplayStyle.d.ts +2 -5
  41. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  42. package/lib/cjs/DisplayStyle.js +0 -3
  43. package/lib/cjs/DisplayStyle.js.map +1 -1
  44. package/lib/cjs/ECDb.d.ts +6 -0
  45. package/lib/cjs/ECDb.d.ts.map +1 -1
  46. package/lib/cjs/ECDb.js +6 -0
  47. package/lib/cjs/ECDb.js.map +1 -1
  48. package/lib/cjs/ECSchemaXmlContext.d.ts +28 -1
  49. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  50. package/lib/cjs/ECSchemaXmlContext.js +28 -1
  51. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  52. package/lib/cjs/ECSqlStatement.js.map +1 -1
  53. package/lib/cjs/Element.d.ts +40 -97
  54. package/lib/cjs/Element.d.ts.map +1 -1
  55. package/lib/cjs/Element.js +0 -57
  56. package/lib/cjs/Element.js.map +1 -1
  57. package/lib/cjs/ElementAspect.d.ts +2 -4
  58. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  59. package/lib/cjs/ElementAspect.js +2 -4
  60. package/lib/cjs/ElementAspect.js.map +1 -1
  61. package/lib/cjs/ElementGraphics.js.map +1 -1
  62. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  63. package/lib/cjs/Entity.d.ts +5 -2
  64. package/lib/cjs/Entity.d.ts.map +1 -1
  65. package/lib/cjs/Entity.js +10 -2
  66. package/lib/cjs/Entity.js.map +1 -1
  67. package/lib/cjs/EntityReferences.js.map +1 -1
  68. package/lib/cjs/ExportGraphics.js.map +1 -1
  69. package/lib/cjs/ExternalSource.d.ts +4 -11
  70. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  71. package/lib/cjs/ExternalSource.js +0 -7
  72. package/lib/cjs/ExternalSource.js.map +1 -1
  73. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  74. package/lib/cjs/GeometrySummary.js +47 -47
  75. package/lib/cjs/GeometrySummary.js.map +1 -1
  76. package/lib/cjs/HubMock.js.map +1 -1
  77. package/lib/cjs/IModelCloneContext.js.map +1 -1
  78. package/lib/cjs/IModelDb.d.ts +61 -26
  79. package/lib/cjs/IModelDb.d.ts.map +1 -1
  80. package/lib/cjs/IModelDb.js +164 -83
  81. package/lib/cjs/IModelDb.js.map +1 -1
  82. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  83. package/lib/cjs/IModelHost.d.ts +1 -3
  84. package/lib/cjs/IModelHost.d.ts.map +1 -1
  85. package/lib/cjs/IModelHost.js +3 -5
  86. package/lib/cjs/IModelHost.js.map +1 -1
  87. package/lib/cjs/IModelJsFs.js.map +1 -1
  88. package/lib/cjs/IpcHost.js.map +1 -1
  89. package/lib/cjs/LineStyle.js.map +1 -1
  90. package/lib/cjs/LocalHub.js +1 -1
  91. package/lib/cjs/LocalHub.js.map +1 -1
  92. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  93. package/lib/cjs/Material.d.ts +0 -1
  94. package/lib/cjs/Material.d.ts.map +1 -1
  95. package/lib/cjs/Material.js +1 -2
  96. package/lib/cjs/Material.js.map +1 -1
  97. package/lib/cjs/Model.d.ts +4 -13
  98. package/lib/cjs/Model.d.ts.map +1 -1
  99. package/lib/cjs/Model.js +0 -9
  100. package/lib/cjs/Model.js.map +1 -1
  101. package/lib/cjs/NativeAppStorage.js.map +1 -1
  102. package/lib/cjs/NativeHost.js.map +1 -1
  103. package/lib/cjs/NavigationRelationship.js.map +1 -1
  104. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  105. package/lib/cjs/PropertyStore.d.ts +3 -3
  106. package/lib/cjs/PropertyStore.d.ts.map +1 -1
  107. package/lib/cjs/PropertyStore.js +2 -5
  108. package/lib/cjs/PropertyStore.js.map +1 -1
  109. package/lib/cjs/Relationship.d.ts +2 -5
  110. package/lib/cjs/Relationship.d.ts.map +1 -1
  111. package/lib/cjs/Relationship.js +0 -3
  112. package/lib/cjs/Relationship.js.map +1 -1
  113. package/lib/cjs/RpcBackend.js.map +1 -1
  114. package/lib/cjs/SQLiteDb.d.ts +1 -1
  115. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  116. package/lib/cjs/SQLiteDb.js +1 -1
  117. package/lib/cjs/SQLiteDb.js.map +1 -1
  118. package/lib/cjs/Schema.d.ts +0 -1
  119. package/lib/cjs/Schema.d.ts.map +1 -1
  120. package/lib/cjs/Schema.js +0 -1
  121. package/lib/cjs/Schema.js.map +1 -1
  122. package/lib/cjs/SchemaUtils.d.ts +19 -0
  123. package/lib/cjs/SchemaUtils.d.ts.map +1 -0
  124. package/lib/cjs/SchemaUtils.js +42 -0
  125. package/lib/cjs/SchemaUtils.js.map +1 -0
  126. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  127. package/lib/cjs/SqliteStatement.d.ts +13 -1
  128. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  129. package/lib/cjs/SqliteStatement.js +23 -1
  130. package/lib/cjs/SqliteStatement.js.map +1 -1
  131. package/lib/cjs/Texture.d.ts +3 -4
  132. package/lib/cjs/Texture.d.ts.map +1 -1
  133. package/lib/cjs/Texture.js +1 -2
  134. package/lib/cjs/Texture.js.map +1 -1
  135. package/lib/cjs/TileStorage.d.ts +3 -0
  136. package/lib/cjs/TileStorage.d.ts.map +1 -1
  137. package/lib/cjs/TileStorage.js +9 -1
  138. package/lib/cjs/TileStorage.js.map +1 -1
  139. package/lib/cjs/TxnManager.js.map +1 -1
  140. package/lib/cjs/ViewDefinition.d.ts +7 -28
  141. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  142. package/lib/cjs/ViewDefinition.js +0 -21
  143. package/lib/cjs/ViewDefinition.js.map +1 -1
  144. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  145. package/lib/cjs/ViewStore.d.ts +488 -0
  146. package/lib/cjs/ViewStore.d.ts.map +1 -0
  147. package/lib/cjs/ViewStore.js +1246 -0
  148. package/lib/cjs/ViewStore.js.map +1 -0
  149. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  150. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +44 -44
  151. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  152. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  153. package/lib/cjs/assets/Settings/backend.setting.json5 +132 -132
  154. package/lib/cjs/core-backend.d.ts +2 -0
  155. package/lib/cjs/core-backend.d.ts.map +1 -1
  156. package/lib/cjs/core-backend.js +2 -0
  157. package/lib/cjs/core-backend.js.map +1 -1
  158. package/lib/cjs/domains/FunctionalElements.d.ts +6 -12
  159. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
  160. package/lib/cjs/domains/FunctionalElements.js +0 -6
  161. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  162. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  163. package/lib/cjs/domains/GenericElements.js.map +1 -1
  164. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  165. package/lib/cjs/rpc/multipart.js.map +1 -1
  166. package/lib/cjs/rpc/tracing.js +2 -2
  167. package/lib/cjs/rpc/tracing.js.map +1 -1
  168. package/lib/cjs/rpc/web/logging.js.map +1 -1
  169. package/lib/cjs/rpc/web/request.js.map +1 -1
  170. package/lib/cjs/rpc/web/response.js.map +1 -1
  171. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  172. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +5 -3
  173. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
  174. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +53 -36
  175. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  176. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  177. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  178. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +0 -2
  179. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  180. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  181. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  182. package/lib/cjs/workspace/Settings.js.map +1 -1
  183. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  184. package/lib/cjs/workspace/Workspace.d.ts +1 -1
  185. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  186. package/lib/cjs/workspace/Workspace.js +4 -4
  187. package/lib/cjs/workspace/Workspace.js.map +1 -1
  188. package/package.json +21 -40
@@ -9,13 +9,16 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.StandaloneDb = exports.SnapshotDb = exports.BriefcaseDb = exports.IModelDb = exports.BriefcaseLocalValue = void 0;
11
11
  const path_1 = require("path");
12
+ const fs = require("fs");
12
13
  const core_bentley_1 = require("@itwin/core-bentley");
13
14
  const core_common_1 = require("@itwin/core-common");
14
15
  const core_geometry_1 = require("@itwin/core-geometry");
15
16
  const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
16
17
  const BriefcaseManager_1 = require("./BriefcaseManager");
18
+ const ChannelControl_1 = require("./ChannelControl");
17
19
  const CheckpointManager_1 = require("./CheckpointManager");
18
20
  const ClassRegistry_1 = require("./ClassRegistry");
21
+ const CloudSqlite_1 = require("./CloudSqlite");
19
22
  const CodeService_1 = require("./CodeService");
20
23
  const CodeSpecs_1 = require("./CodeSpecs");
21
24
  const ConcurrentQuery_1 = require("./ConcurrentQuery");
@@ -23,6 +26,7 @@ const ECSqlStatement_1 = require("./ECSqlStatement");
23
26
  const Element_1 = require("./Element");
24
27
  const ElementAspect_1 = require("./ElementAspect");
25
28
  const ElementGraphics_1 = require("./ElementGraphics");
29
+ const Entity_1 = require("./Entity");
26
30
  const GeoCoordConfig_1 = require("./GeoCoordConfig");
27
31
  const IModelHost_1 = require("./IModelHost");
28
32
  const IModelJsFs_1 = require("./IModelJsFs");
@@ -33,9 +37,9 @@ const ServerBasedLocks_1 = require("./ServerBasedLocks");
33
37
  const SqliteStatement_1 = require("./SqliteStatement");
34
38
  const TxnManager_1 = require("./TxnManager");
35
39
  const ViewDefinition_1 = require("./ViewDefinition");
40
+ const ViewStore_1 = require("./ViewStore");
36
41
  const Settings_1 = require("./workspace/Settings");
37
42
  const Workspace_1 = require("./workspace/Workspace");
38
- const ChannelControl_1 = require("./ChannelControl");
39
43
  // spell:ignore fontid fontmap
40
44
  const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.IModelDb;
41
45
  /** A null-implementation of LockControl that does not attempt to limit access between briefcases. This relies on change-merging to resolve conflicts. */
@@ -247,9 +251,7 @@ class IModelDb extends core_common_1.IModel {
247
251
  * @internal
248
252
  */
249
253
  get isStandalone() { return false; }
250
- /** Type guard for instanceof [[StandaloneDb]]
251
- * @internal
252
- */
254
+ /** Type guard for instanceof [[StandaloneDb]]. */
253
255
  isStandaloneDb() { return this.isStandalone; }
254
256
  /** Return `true` if the underlying nativeDb is open and valid.
255
257
  * @internal
@@ -318,6 +320,12 @@ class IModelDb extends core_common_1.IModel {
318
320
  }
319
321
  }
320
322
  /** Allow to execute query and read results along with meta data. The result are streamed.
323
+ *
324
+ * See also:
325
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
326
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
327
+ * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)
328
+ *
321
329
  * @param params The values to bind to the parameters (if the ECSQL has any).
322
330
  * @param config Allow to specify certain flags which control how query is executed.
323
331
  * @returns Returns an [ECSqlReader]($common) which helps iterate over the result set and also give access to metadata.
@@ -744,7 +752,7 @@ class IModelDb extends core_common_1.IModel {
744
752
  }
745
753
  return schemaState;
746
754
  }
747
- /** Get the ClassMetaDataRegistry for this iModel.
755
+ /** The registry of entity metadata for this iModel.
748
756
  * @internal
749
757
  */
750
758
  get classMetaDataRegistry() {
@@ -784,7 +792,7 @@ class IModelDb extends core_common_1.IModel {
784
792
  */
785
793
  constructEntity(props) {
786
794
  const jsClass = this.getJsClass(props.classFullName);
787
- return new jsClass(props, this);
795
+ return Entity_1.Entity.instantiate(jsClass, props, this);
788
796
  }
789
797
  /** Get the JavaScript class that handles a given entity class. */
790
798
  getJsClass(classFullName) {
@@ -1023,7 +1031,7 @@ class IModelDb extends core_common_1.IModel {
1023
1031
  }
1024
1032
  /** Request geometry stream information from an element in binary format instead of json.
1025
1033
  * @returns IModelStatus.Success if successful
1026
- * @alpha
1034
+ * @beta
1027
1035
  */
1028
1036
  elementGeometryRequest(requestProps) {
1029
1037
  return this.nativeDb.processGeometryStream(requestProps);
@@ -1053,9 +1061,7 @@ class IModelDb extends core_common_1.IModel {
1053
1061
  stmt.bindString(1, IModelDb._settingPropNamespace);
1054
1062
  stmt.bindString(2, name);
1055
1063
  stmt.bindString(3, JSON.stringify(dict));
1056
- const rc = stmt.step();
1057
- if (rc !== core_bentley_1.DbResult.BE_SQLITE_DONE)
1058
- throw new core_common_1.IModelError(rc, "cannot save setting");
1064
+ stmt.stepForWrite();
1059
1065
  });
1060
1066
  this.saveChanges("add settings");
1061
1067
  }
@@ -1067,9 +1073,7 @@ class IModelDb extends core_common_1.IModel {
1067
1073
  this.withSqliteStatement("DELETE FROM be_Prop WHERE Namespace=? AND Name=?", (stmt) => {
1068
1074
  stmt.bindString(1, IModelDb._settingPropNamespace);
1069
1075
  stmt.bindString(2, name);
1070
- const rc = stmt.step();
1071
- if (rc !== core_bentley_1.DbResult.BE_SQLITE_DONE)
1072
- throw new core_common_1.IModelError(rc, "cannot delete setting");
1076
+ stmt.stepForWrite();
1073
1077
  });
1074
1078
  this.saveChanges("delete settings");
1075
1079
  }
@@ -1079,7 +1083,7 @@ class IModelDb extends core_common_1.IModel {
1079
1083
  return;
1080
1084
  this.withSqliteStatement("SELECT Name,StrData FROM be_Prop WHERE Namespace=?", (stmt) => {
1081
1085
  stmt.bindString(1, IModelDb._settingPropNamespace);
1082
- while (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW) {
1086
+ while (stmt.nextRow()) {
1083
1087
  try {
1084
1088
  const dict = JSON.parse(stmt.getValueString(1));
1085
1089
  this.workspace.settings.addDictionary(stmt.getValueString(0), Settings_1.SettingsPriority.iModel, dict);
@@ -1125,8 +1129,9 @@ exports.IModelDb = IModelDb;
1125
1129
  tryGetModelProps(id) {
1126
1130
  return this.tryGetModelJson({ id });
1127
1131
  }
1128
- /** Query for the last modified time of the specified Model.
1129
- * @internal
1132
+ /** Query for the last modified time for a [[Model]].
1133
+ * @param modelId The Id of the model.
1134
+ * @throws IModelError if `modelId` does not identify a model in the iModel.
1130
1135
  */
1131
1136
  queryLastModifiedTime(modelId) {
1132
1137
  const sql = `SELECT LastMod FROM ${Model_1.Model.classFullName} WHERE ECInstanceId=:modelId`;
@@ -1313,6 +1318,18 @@ exports.IModelDb = IModelDb;
1313
1318
  constructor(_iModel) {
1314
1319
  this._iModel = _iModel;
1315
1320
  }
1321
+ getFederationGuidFromId(id) {
1322
+ return this._iModel.withPreparedSqliteStatement(`SELECT FederationGuid FROM bis_Element WHERE Id=?`, (stmt) => {
1323
+ stmt.bindId(1, id);
1324
+ return stmt.nextRow() ? stmt.getValueGuid(0) : undefined;
1325
+ });
1326
+ }
1327
+ getIdFromFederationGuid(guid) {
1328
+ return guid ? this._iModel.withPreparedSqliteStatement(`SELECT Id FROM bis_Element WHERE FederationGuid=?`, (stmt) => {
1329
+ stmt.bindGuid(1, guid);
1330
+ return !stmt.nextRow() ? undefined : stmt.getValueId(0);
1331
+ }) : undefined;
1332
+ }
1316
1333
  /** Read element data from the iModel as JSON
1317
1334
  * @param elementIdArg a json string with the identity of the element to load. Must have one of "id", "federationGuid", or "code".
1318
1335
  * @returns The JSON properties of the element.
@@ -1433,8 +1450,9 @@ exports.IModelDb = IModelDb;
1433
1450
  return stmt.getValue(0).getId();
1434
1451
  });
1435
1452
  }
1436
- /** Query for the last modified time of the specified element.
1437
- * @internal
1453
+ /** Query for an [[Element]]'s last modified time.
1454
+ * @param elementId The Id of the element.
1455
+ * @throws IModelError if `elementId` does not identify an element in the iModel.
1438
1456
  */
1439
1457
  queryLastModifiedTime(elementId) {
1440
1458
  const sql = "SELECT LastMod FROM BisCore:Element WHERE ECInstanceId=:elementId";
@@ -1740,6 +1758,37 @@ exports.IModelDb = IModelDb;
1740
1758
  constructor(_iModel) {
1741
1759
  this._iModel = _iModel;
1742
1760
  }
1761
+ get hasViewStore() { return undefined !== this._viewStore; }
1762
+ /** @beta */
1763
+ get viewStore() {
1764
+ if (undefined === this._viewStore)
1765
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, "No ViewStore available");
1766
+ return this._viewStore;
1767
+ }
1768
+ set viewStore(viewStore) {
1769
+ this._viewStore = viewStore;
1770
+ }
1771
+ /** @beta */
1772
+ async accessViewStore(args) {
1773
+ let props = args.props;
1774
+ if (undefined === props) {
1775
+ const propsString = this._iModel.queryFilePropertyString(Views.viewStoreProperty);
1776
+ if (!propsString)
1777
+ throw new Error("iModel does not have a default ViewStore");
1778
+ props = JSON.parse(propsString);
1779
+ }
1780
+ const accessToken = await CloudSqlite_1.CloudSqlite.requestToken(props);
1781
+ if (!this._viewStore)
1782
+ this._viewStore = new ViewStore_1.ViewStore.CloudAccess({ ...props, accessToken, iModel: this._iModel });
1783
+ this._viewStore.container.accessToken = accessToken;
1784
+ return this._viewStore;
1785
+ }
1786
+ /** @beta */
1787
+ saveDefaultViewStore(arg) {
1788
+ const props = { baseUri: arg.baseUri, containerId: arg.containerId, storageType: arg.storageType }; // sanitize to only known properties
1789
+ this._iModel.saveFileProperty(Views.viewStoreProperty, JSON.stringify(props));
1790
+ this._iModel.saveChanges("update default ViewStore");
1791
+ }
1743
1792
  /** Query for the array of ViewDefinitionProps of the specified class and matching the specified IsPrivate setting.
1744
1793
  * @param className Query for view definitions of this class.
1745
1794
  * @param wantPrivate If true, include private view definitions.
@@ -1761,11 +1810,6 @@ exports.IModelDb = IModelDb;
1761
1810
  * @param params Specifies the query by which views are selected.
1762
1811
  * @param callback Function invoked for each ViewDefinition matching the query. Return false to terminate iteration, true to continue.
1763
1812
  * @returns true if all views were iterated, false if iteration was terminated early due to callback returning false.
1764
- *
1765
- * **Example: Finding all views of a specific DrawingModel**
1766
- * ``` ts
1767
- * [[include:IModelDb.Views.iterateViews]]
1768
- * ```
1769
1813
  */
1770
1814
  iterateViews(params, callback) {
1771
1815
  const ids = this._iModel.queryEntityIds(params);
@@ -1783,75 +1827,81 @@ exports.IModelDb = IModelDb;
1783
1827
  }
1784
1828
  return finished;
1785
1829
  }
1786
- loadViewStateProps(viewDefinitionElement, options, drawingExtents) {
1787
- const elements = this._iModel.elements;
1788
- const viewDefinitionProps = viewDefinitionElement.toJSON();
1789
- const categorySelectorProps = elements.getElementProps(viewDefinitionProps.categorySelectorId);
1790
- const displayStyleProps = elements.getElementProps({
1791
- id: viewDefinitionProps.displayStyleId,
1792
- displayStyle: options?.displayStyle,
1793
- });
1794
- const viewStateData = {
1795
- viewDefinitionProps,
1796
- displayStyleProps,
1797
- categorySelectorProps,
1798
- };
1799
- const modelSelectorId = viewDefinitionProps.modelSelectorId;
1800
- if (modelSelectorId !== undefined) {
1801
- viewStateData.modelSelectorProps = elements.getElementProps(modelSelectorId);
1802
- }
1803
- else if (viewDefinitionElement instanceof ViewDefinition_1.SheetViewDefinition) {
1804
- viewStateData.sheetProps = elements.getElementProps(viewDefinitionElement.baseModelId);
1805
- viewStateData.sheetAttachments = Array.from(this._iModel.queryEntityIds({
1830
+ loadViewData(viewId, options) {
1831
+ const iModel = this._iModel;
1832
+ const elements = iModel.elements;
1833
+ const loader = (() => {
1834
+ if (core_common_1.ViewStoreRpc.isViewStoreId(viewId)) {
1835
+ const reader = this.viewStore.reader;
1836
+ return {
1837
+ loadView: () => reader.getViewDefinitionSync({ viewId }),
1838
+ loadCategorySelector: (id) => reader.getCategorySelectorSync({ id, bindings: options?.queryBindings?.categorySelector }),
1839
+ loadDisplayStyle: (id) => reader.getDisplayStyleSync({ id, opts: options?.displayStyle }),
1840
+ loadModelSelector: (id) => reader.getModelSelectorSync({ id, bindings: options?.queryBindings?.modelSelector }),
1841
+ };
1842
+ }
1843
+ return {
1844
+ loadView: () => elements.getElementProps(viewId),
1845
+ loadCategorySelector: (id) => elements.getElementProps(id),
1846
+ loadDisplayStyle: (id) => elements.getElementProps({ id, displayStyle: options?.displayStyle }),
1847
+ loadModelSelector: (id) => elements.getElementProps(id),
1848
+ };
1849
+ })();
1850
+ const props = {};
1851
+ props.viewDefinitionProps = loader.loadView();
1852
+ props.categorySelectorProps = loader.loadCategorySelector(props.viewDefinitionProps.categorySelectorId);
1853
+ props.displayStyleProps = loader.loadDisplayStyle(props.viewDefinitionProps.displayStyleId);
1854
+ const modelSelectorId = props.viewDefinitionProps.modelSelectorId;
1855
+ if (modelSelectorId !== undefined)
1856
+ props.modelSelectorProps = loader.loadModelSelector(modelSelectorId);
1857
+ const viewClass = iModel.getJsClass(props.viewDefinitionProps.classFullName);
1858
+ const baseModelId = props.viewDefinitionProps.baseModelId;
1859
+ if (viewClass.is(ViewDefinition_1.SheetViewDefinition)) {
1860
+ props.sheetProps = elements.getElementProps(baseModelId);
1861
+ props.sheetAttachments = Array.from(iModel.queryEntityIds({
1806
1862
  from: "BisCore.ViewAttachment",
1807
- where: `Model.Id=${viewDefinitionElement.baseModelId}`,
1863
+ where: `Model.Id=${baseModelId}`,
1808
1864
  }));
1809
1865
  }
1810
- else if (viewDefinitionElement instanceof ViewDefinition_1.DrawingViewDefinition) {
1811
- // Ensure view has known extents
1812
- if (drawingExtents && !drawingExtents.isNull)
1813
- viewStateData.modelExtents = drawingExtents.toJSON();
1866
+ else if (viewClass.is(ViewDefinition_1.DrawingViewDefinition)) {
1814
1867
  // Include information about the associated [[SectionDrawing]], if any.
1815
1868
  // NB: The SectionDrawing ECClass may not exist in the iModel's version of the BisCore ECSchema.
1816
- try {
1817
- const sectionDrawing = this._iModel.elements.tryGetElement(viewDefinitionElement.baseModelId);
1818
- if (sectionDrawing && sectionDrawing.spatialView && core_bentley_1.Id64.isValidId64(sectionDrawing.spatialView.id)) {
1819
- viewStateData.sectionDrawing = {
1820
- spatialView: sectionDrawing.spatialView.id,
1821
- displaySpatialView: true === sectionDrawing.jsonProperties.displaySpatialView,
1822
- drawingToSpatialTransform: sectionDrawing.jsonProperties.drawingToSpatialTransform,
1823
- };
1824
- }
1825
- }
1826
- catch {
1827
- //
1869
+ const sectionDrawing = iModel.elements.tryGetElement(baseModelId);
1870
+ if (sectionDrawing && sectionDrawing.spatialView && core_bentley_1.Id64.isValidId64(sectionDrawing.spatialView.id)) {
1871
+ props.sectionDrawing = {
1872
+ spatialView: sectionDrawing.spatialView.id,
1873
+ displaySpatialView: true === sectionDrawing.jsonProperties.displaySpatialView,
1874
+ drawingToSpatialTransform: sectionDrawing.jsonProperties.drawingToSpatialTransform,
1875
+ };
1828
1876
  }
1829
1877
  }
1830
- return viewStateData;
1878
+ return props;
1831
1879
  }
1832
1880
  /** @deprecated in 3.x. use [[getViewStateProps]]. */
1833
1881
  getViewStateData(viewDefinitionId, options) {
1834
- const view = this._iModel.elements.getElement(viewDefinitionId);
1835
- let drawingExtents;
1836
- if (view instanceof ViewDefinition_1.DrawingViewDefinition) {
1837
- try {
1838
- drawingExtents = core_geometry_1.Range3d.fromJSON(this._iModel.nativeDb.queryModelExtents({ id: view.baseModelId }).modelExtents);
1839
- }
1840
- catch {
1841
- //
1842
- }
1882
+ const viewStateData = this.loadViewData(viewDefinitionId, options);
1883
+ const baseModelId = viewStateData.viewDefinitionProps.baseModelId;
1884
+ if (baseModelId) {
1885
+ const drawingExtents = core_geometry_1.Range3d.fromJSON(this._iModel.nativeDb.queryModelExtents({ id: baseModelId }).modelExtents);
1886
+ if (!drawingExtents.isNull)
1887
+ viewStateData.modelExtents = drawingExtents.toJSON();
1843
1888
  }
1844
- return this.loadViewStateProps(view, options, drawingExtents);
1889
+ return viewStateData;
1845
1890
  }
1846
- /** Obtain a [ViewStateProps]($common) for a [[ViewDefinition]] specified by element Id. */
1891
+ /** Obtain a [ViewStateProps]($common) for a [[ViewDefinition]] specified by ViewIdString. */
1847
1892
  async getViewStateProps(viewDefinitionId, options) {
1848
- const view = this._iModel.elements.getElement(viewDefinitionId);
1849
- let drawingExtents;
1850
- if (view instanceof ViewDefinition_1.DrawingViewDefinition)
1851
- drawingExtents = (await this._iModel.models.queryRange(view.baseModelId));
1852
- return this.loadViewStateProps(view, options, drawingExtents);
1893
+ const viewStateData = this.loadViewData(viewDefinitionId, options);
1894
+ const baseModelId = viewStateData.viewDefinitionProps.baseModelId;
1895
+ if (baseModelId) {
1896
+ const drawingExtents = await this._iModel.models.queryRange(baseModelId);
1897
+ if (!drawingExtents.isNull)
1898
+ viewStateData.modelExtents = drawingExtents.toJSON();
1899
+ }
1900
+ return viewStateData;
1853
1901
  }
1854
1902
  getViewThumbnailArg(viewDefinitionId) {
1903
+ if (!core_bentley_1.Id64.isValid(viewDefinitionId))
1904
+ throw new Error("illegal thumbnail id");
1855
1905
  return { namespace: "dgn_View", name: "Thumbnail", id: viewDefinitionId };
1856
1906
  }
1857
1907
  /** Get the thumbnail for a view.
@@ -1890,13 +1940,14 @@ exports.IModelDb = IModelDb;
1890
1940
  this._iModel.saveFileProperty(spec, undefined, blob8);
1891
1941
  }
1892
1942
  }
1943
+ Views.viewStoreProperty = { namespace: "itwinjs", name: "DefaultViewStore" };
1893
1944
  /** Default parameters for iterating/querying ViewDefinitions. Includes all subclasses of ViewDefinition, excluding only those marked 'private'. */
1894
1945
  Views.defaultQueryParams = { from: "BisCore.ViewDefinition", where: "IsPrivate=FALSE" };
1895
1946
  IModelDb.Views = Views;
1896
1947
  /** Represents the current state of a pollable tile content request.
1897
- * Note: lack of a "completed" state because polling a completed request returns the content as a Uint8Array.
1898
- * @internal
1899
- */
1948
+ * Note: lack of a "completed" state because polling a completed request returns the content as a Uint8Array.
1949
+ * @internal
1950
+ */
1900
1951
  let TileContentState;
1901
1952
  (function (TileContentState) {
1902
1953
  TileContentState[TileContentState["New"] = 0] = "New";
@@ -2008,6 +2059,8 @@ class BriefcaseDb extends IModelDb {
2008
2059
  super({ ...args, changeset: args.nativeDb.getCurrentChangeset() });
2009
2060
  /** Manages local changes to this briefcase. */
2010
2061
  this.txns = new TxnManager_1.TxnManager(this);
2062
+ /** Event raised after a BriefcaseDb has been closed. */
2063
+ this.onClosed = new core_bentley_1.BeEvent();
2011
2064
  this._openMode = args.openMode;
2012
2065
  this.briefcaseId = args.briefcaseId;
2013
2066
  if (this.useLockServer) // if the iModel uses a lock server, create a ServerBasedLocks LockControl for this BriefcaseDb.
@@ -2054,9 +2107,16 @@ class BriefcaseDb extends IModelDb {
2054
2107
  static async open(args) {
2055
2108
  this.onOpen.raiseEvent(args);
2056
2109
  const file = { path: args.fileName, key: args.key };
2057
- const openMode = args.readonly ? core_bentley_1.OpenMode.Readonly : core_bentley_1.OpenMode.ReadWrite;
2110
+ const openMode = (args.readonly || args.watchForChanges) ? core_bentley_1.OpenMode.Readonly : core_bentley_1.OpenMode.ReadWrite;
2058
2111
  const nativeDb = this.openDgnDb(file, openMode, undefined, args);
2059
2112
  const briefcaseDb = new BriefcaseDb({ nativeDb, key: file.key ?? core_bentley_1.Guid.createValue(), openMode, briefcaseId: nativeDb.getBriefcaseId() });
2113
+ // If they asked to watch for changes, set an fs.watch on the "-wal" file (only it is modified while we hold this connection.)
2114
+ // Whenever there are changes, restart our defaultTxn. That loads the changes from the other connection and sends
2115
+ // notifications as if they happened on this connection. Note: the watcher is called only when the backend event loop cycles.
2116
+ if (args.watchForChanges && undefined === args.container) {
2117
+ const watcher = fs.watch(`${file.path}-wal`, { persistent: false }, () => nativeDb.restartDefaultTxn());
2118
+ briefcaseDb.onBeforeClose.addOnce(() => watcher.close()); // Stop the watcher when we close this connection.
2119
+ }
2060
2120
  if (openMode === core_bentley_1.OpenMode.ReadWrite && CodeService_1.CodeService.createForIModel) {
2061
2121
  try {
2062
2122
  briefcaseDb._codeService = await CodeService_1.CodeService.createForIModel(briefcaseDb);
@@ -2067,7 +2127,6 @@ class BriefcaseDb extends IModelDb {
2067
2127
  throw e;
2068
2128
  }
2069
2129
  }
2070
- BriefcaseManager_1.BriefcaseManager.logUsage(briefcaseDb);
2071
2130
  this.onOpened.raiseEvent(briefcaseDb, args);
2072
2131
  return briefcaseDb;
2073
2132
  }
@@ -2103,6 +2162,10 @@ class BriefcaseDb extends IModelDb {
2103
2162
  const changeset = this.changeset;
2104
2163
  IpcHost_1.IpcHost.notifyTxns(this, "notifyPushedChanges", changeset);
2105
2164
  }
2165
+ close() {
2166
+ super.close();
2167
+ this.onClosed.raiseEvent();
2168
+ }
2106
2169
  }
2107
2170
  /**
2108
2171
  * Event raised just before a BriefcaseDb is opened. Supplies the arguments that will be used to open the BriefcaseDb.
@@ -2250,10 +2313,13 @@ class SnapshotDb extends IModelDb {
2250
2313
  * @throws [[IModelError]] If the file is not found or is not a valid *snapshot*.
2251
2314
  */
2252
2315
  static openFile(path, opts) {
2316
+ this.onOpen.raiseEvent(path, opts);
2253
2317
  const file = { path, key: opts?.key };
2254
2318
  const nativeDb = this.openDgnDb(file, core_bentley_1.OpenMode.Readonly, undefined, opts);
2255
2319
  (0, core_bentley_1.assert)(undefined !== file.key);
2256
- return new SnapshotDb(nativeDb, file.key);
2320
+ const db = new SnapshotDb(nativeDb, file.key);
2321
+ this.onOpened.raiseEvent(db);
2322
+ return db;
2257
2323
  }
2258
2324
  /** Open a previously downloaded V1 checkpoint file.
2259
2325
  * @note The key is generated by this call is predictable and is formed from the IModelId and ChangeSetId.
@@ -2310,6 +2376,8 @@ class SnapshotDb extends IModelDb {
2310
2376
  }
2311
2377
  }
2312
2378
  }
2379
+ SnapshotDb.onOpen = new core_bentley_1.BeEvent();
2380
+ SnapshotDb.onOpened = new core_bentley_1.BeEvent();
2313
2381
  exports.SnapshotDb = SnapshotDb;
2314
2382
  /**
2315
2383
  * Standalone iModels are read/write files that are not associated with an iTwin or managed by iModelHub.
@@ -2364,6 +2432,19 @@ class StandaloneDb extends BriefcaseDb {
2364
2432
  nativeDb = this.openDgnDb({ path: filePath }, core_bentley_1.OpenMode.ReadWrite, { domain: core_common_1.DomainOptions.Upgrade, schemaLockHeld: true });
2365
2433
  nativeDb.closeIModel();
2366
2434
  }
2435
+ /** Creates or updates views in the iModel to permit visualizing the EC content as ECClasses and ECProperties rather than raw database tables and columns.
2436
+ * This can be helpful when debugging the EC data, especially when the raw tables make use of shared columns or spread data across multiple tables.
2437
+ * @throws IModelError if view creation failed.
2438
+ * @note The views are strictly intended for developers and debugging purposes only - they should not be used in application code.
2439
+ * @beta
2440
+ */
2441
+ createClassViews() {
2442
+ const result = this.nativeDb.createClassViewsInDb();
2443
+ if (core_bentley_1.BentleyStatus.SUCCESS !== result)
2444
+ throw new core_common_1.IModelError(result, "Error creating class views");
2445
+ else
2446
+ this.saveChanges();
2447
+ }
2367
2448
  /** Open a standalone iModel file.
2368
2449
  * @param filePath The path of the standalone iModel file.
2369
2450
  * @param openMode Optional open mode for the standalone iModel. The default is read/write.