@itwin/core-backend 5.0.0-dev.11 → 5.0.0-dev.111

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 (1102) hide show
  1. package/CHANGELOG.md +90 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +15 -35
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +2 -0
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  7. package/lib/cjs/BisCoreSchema.d.ts.map +1 -1
  8. package/lib/cjs/BisCoreSchema.js +2 -0
  9. package/lib/cjs/BisCoreSchema.js.map +1 -1
  10. package/lib/cjs/BlobContainerService.d.ts +4 -4
  11. package/lib/cjs/BlobContainerService.d.ts.map +1 -1
  12. package/lib/cjs/BlobContainerService.js.map +1 -1
  13. package/lib/cjs/BriefcaseManager.d.ts +10 -0
  14. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  15. package/lib/cjs/BriefcaseManager.js +63 -20
  16. package/lib/cjs/BriefcaseManager.js.map +1 -1
  17. package/lib/cjs/CatalogDb.d.ts +103 -0
  18. package/lib/cjs/CatalogDb.d.ts.map +1 -0
  19. package/lib/cjs/CatalogDb.js +271 -0
  20. package/lib/cjs/CatalogDb.js.map +1 -0
  21. package/lib/cjs/Category.d.ts +37 -0
  22. package/lib/cjs/Category.d.ts.map +1 -1
  23. package/lib/cjs/Category.js +79 -1
  24. package/lib/cjs/Category.js.map +1 -1
  25. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
  26. package/lib/cjs/ChangeSummaryManager.js +104 -29
  27. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  28. package/lib/cjs/ChangedElementsDb.d.ts +3 -3
  29. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  30. package/lib/cjs/ChangedElementsDb.js +8 -7
  31. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  32. package/lib/cjs/ChangesetECAdaptor.d.ts +3 -3
  33. package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
  34. package/lib/cjs/ChangesetECAdaptor.js +274 -261
  35. package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
  36. package/lib/cjs/ChannelControl.js.map +1 -1
  37. package/lib/cjs/CheckpointManager.d.ts +12 -17
  38. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  39. package/lib/cjs/CheckpointManager.js +40 -92
  40. package/lib/cjs/CheckpointManager.js.map +1 -1
  41. package/lib/cjs/ClassRegistry.d.ts +46 -2
  42. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  43. package/lib/cjs/ClassRegistry.js +98 -42
  44. package/lib/cjs/ClassRegistry.js.map +1 -1
  45. package/lib/cjs/CloudSqlite.d.ts +104 -20
  46. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  47. package/lib/cjs/CloudSqlite.js +172 -54
  48. package/lib/cjs/CloudSqlite.js.map +1 -1
  49. package/lib/cjs/CodeService.d.ts +2 -0
  50. package/lib/cjs/CodeService.d.ts.map +1 -1
  51. package/lib/cjs/CodeService.js +4 -0
  52. package/lib/cjs/CodeService.js.map +1 -1
  53. package/lib/cjs/CodeSpecs.js +3 -2
  54. package/lib/cjs/CodeSpecs.js.map +1 -1
  55. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  56. package/lib/cjs/CustomViewState3dCreator.js +7 -6
  57. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  58. package/lib/cjs/DevTools.js +16 -16
  59. package/lib/cjs/DevTools.js.map +1 -1
  60. package/lib/cjs/DisplayStyle.d.ts +5 -0
  61. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  62. package/lib/cjs/DisplayStyle.js +29 -0
  63. package/lib/cjs/DisplayStyle.js.map +1 -1
  64. package/lib/cjs/ECDb.d.ts +53 -60
  65. package/lib/cjs/ECDb.d.ts.map +1 -1
  66. package/lib/cjs/ECDb.js +115 -73
  67. package/lib/cjs/ECDb.js.map +1 -1
  68. package/lib/cjs/ECSchemaXmlContext.d.ts +1 -1
  69. package/lib/cjs/ECSchemaXmlContext.js +2 -1
  70. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  71. package/lib/cjs/ECSqlStatement.d.ts +185 -4
  72. package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
  73. package/lib/cjs/ECSqlStatement.js +237 -9
  74. package/lib/cjs/ECSqlStatement.js.map +1 -1
  75. package/lib/cjs/Element.d.ts +194 -35
  76. package/lib/cjs/Element.d.ts.map +1 -1
  77. package/lib/cjs/Element.js +683 -57
  78. package/lib/cjs/Element.js.map +1 -1
  79. package/lib/cjs/ElementAspect.d.ts +0 -5
  80. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  81. package/lib/cjs/ElementAspect.js +25 -16
  82. package/lib/cjs/ElementAspect.js.map +1 -1
  83. package/lib/cjs/ElementGraphics.js.map +1 -1
  84. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  85. package/lib/cjs/ElementTreeWalker.js +17 -12
  86. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  87. package/lib/cjs/Entity.d.ts +91 -11
  88. package/lib/cjs/Entity.d.ts.map +1 -1
  89. package/lib/cjs/Entity.js +137 -16
  90. package/lib/cjs/Entity.js.map +1 -1
  91. package/lib/cjs/EntityReferences.js.map +1 -1
  92. package/lib/cjs/ExportGraphics.js +4 -0
  93. package/lib/cjs/ExportGraphics.js.map +1 -1
  94. package/lib/cjs/ExternalSource.js +22 -0
  95. package/lib/cjs/ExternalSource.js.map +1 -1
  96. package/lib/cjs/FontFile.d.ts +68 -0
  97. package/lib/cjs/FontFile.d.ts.map +1 -0
  98. package/lib/cjs/FontFile.js +36 -0
  99. package/lib/cjs/FontFile.js.map +1 -0
  100. package/lib/cjs/GeoCoordConfig.js +8 -8
  101. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  102. package/lib/cjs/GeographicCRSServices.js.map +1 -1
  103. package/lib/cjs/GeometrySummary.js +53 -50
  104. package/lib/cjs/GeometrySummary.js.map +1 -1
  105. package/lib/cjs/IModelDb.d.ts +231 -108
  106. package/lib/cjs/IModelDb.d.ts.map +1 -1
  107. package/lib/cjs/IModelDb.js +516 -249
  108. package/lib/cjs/IModelDb.js.map +1 -1
  109. package/lib/cjs/IModelDbFonts.d.ts +54 -0
  110. package/lib/cjs/IModelDbFonts.d.ts.map +1 -0
  111. package/lib/cjs/{IModelCloneContext.js → IModelDbFonts.js} +2 -7
  112. package/lib/cjs/IModelDbFonts.js.map +1 -0
  113. package/lib/cjs/IModelElementCloneContext.d.ts +2 -0
  114. package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -1
  115. package/lib/cjs/IModelElementCloneContext.js +12 -1
  116. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  117. package/lib/cjs/IModelHost.d.ts +28 -15
  118. package/lib/cjs/IModelHost.d.ts.map +1 -1
  119. package/lib/cjs/IModelHost.js +82 -43
  120. package/lib/cjs/IModelHost.js.map +1 -1
  121. package/lib/cjs/IModelJsFs.d.ts.map +1 -1
  122. package/lib/cjs/IModelJsFs.js +17 -1
  123. package/lib/cjs/IModelJsFs.js.map +1 -1
  124. package/lib/cjs/ImageSourceConversion.d.ts +49 -0
  125. package/lib/cjs/ImageSourceConversion.d.ts.map +1 -0
  126. package/lib/cjs/ImageSourceConversion.js +37 -0
  127. package/lib/cjs/ImageSourceConversion.js.map +1 -0
  128. package/lib/cjs/IpcHost.d.ts.map +1 -1
  129. package/lib/cjs/IpcHost.js +19 -33
  130. package/lib/cjs/IpcHost.js.map +1 -1
  131. package/lib/cjs/LineStyle.js.map +1 -1
  132. package/lib/cjs/LocalHub.js +9 -3
  133. package/lib/cjs/LocalHub.js.map +1 -1
  134. package/lib/cjs/LocalhostIpcHost.js +5 -6
  135. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  136. package/lib/cjs/LockControl.js.map +1 -1
  137. package/lib/cjs/Material.d.ts +19 -0
  138. package/lib/cjs/Material.d.ts.map +1 -1
  139. package/lib/cjs/Material.js +69 -0
  140. package/lib/cjs/Material.js.map +1 -1
  141. package/lib/cjs/Model.d.ts +43 -7
  142. package/lib/cjs/Model.d.ts.map +1 -1
  143. package/lib/cjs/Model.js +120 -7
  144. package/lib/cjs/Model.js.map +1 -1
  145. package/lib/cjs/NativeAppStorage.js +5 -3
  146. package/lib/cjs/NativeAppStorage.js.map +1 -1
  147. package/lib/cjs/NativeHost.d.ts.map +1 -1
  148. package/lib/cjs/NativeHost.js +10 -4
  149. package/lib/cjs/NativeHost.js.map +1 -1
  150. package/lib/cjs/NavigationRelationship.js +25 -25
  151. package/lib/cjs/NavigationRelationship.js.map +1 -1
  152. package/lib/cjs/PromiseMemoizer.d.ts +2 -3
  153. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  154. package/lib/cjs/PromiseMemoizer.js +12 -5
  155. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  156. package/lib/cjs/PropertyStore.js +1 -4
  157. package/lib/cjs/PropertyStore.js.map +1 -1
  158. package/lib/cjs/Relationship.d.ts.map +1 -1
  159. package/lib/cjs/Relationship.js +15 -1
  160. package/lib/cjs/Relationship.js.map +1 -1
  161. package/lib/cjs/RpcBackend.js.map +1 -1
  162. package/lib/cjs/SQLiteDb.d.ts +6 -4
  163. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  164. package/lib/cjs/SQLiteDb.js +79 -19
  165. package/lib/cjs/SQLiteDb.js.map +1 -1
  166. package/lib/cjs/Schema.d.ts +25 -1
  167. package/lib/cjs/Schema.d.ts.map +1 -1
  168. package/lib/cjs/Schema.js +44 -8
  169. package/lib/cjs/Schema.js.map +1 -1
  170. package/lib/cjs/SchemaSync.js +1 -4
  171. package/lib/cjs/SchemaSync.js.map +1 -1
  172. package/lib/cjs/SchemaUtils.js.map +1 -1
  173. package/lib/cjs/SheetIndex.js +6 -0
  174. package/lib/cjs/SheetIndex.js.map +1 -1
  175. package/lib/cjs/SqliteChangesetReader.d.ts +11 -3
  176. package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
  177. package/lib/cjs/SqliteChangesetReader.js +21 -5
  178. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  179. package/lib/cjs/SqliteStatement.d.ts +4 -2
  180. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  181. package/lib/cjs/SqliteStatement.js +13 -1
  182. package/lib/cjs/SqliteStatement.js.map +1 -1
  183. package/lib/cjs/TextAnnotationElement.js.map +1 -1
  184. package/lib/cjs/TextAnnotationGeometry.d.ts.map +1 -1
  185. package/lib/cjs/TextAnnotationGeometry.js +38 -11
  186. package/lib/cjs/TextAnnotationGeometry.js.map +1 -1
  187. package/lib/cjs/TextAnnotationLayout.d.ts +10 -3
  188. package/lib/cjs/TextAnnotationLayout.d.ts.map +1 -1
  189. package/lib/cjs/TextAnnotationLayout.js +56 -18
  190. package/lib/cjs/TextAnnotationLayout.js.map +1 -1
  191. package/lib/cjs/Texture.js +3 -0
  192. package/lib/cjs/Texture.js.map +1 -1
  193. package/lib/cjs/TileStorage.js +6 -1
  194. package/lib/cjs/TileStorage.js.map +1 -1
  195. package/lib/cjs/TxnManager.d.ts +55 -4
  196. package/lib/cjs/TxnManager.d.ts.map +1 -1
  197. package/lib/cjs/TxnManager.js +235 -58
  198. package/lib/cjs/TxnManager.js.map +1 -1
  199. package/lib/cjs/ViewDefinition.d.ts +106 -6
  200. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  201. package/lib/cjs/ViewDefinition.js +289 -26
  202. package/lib/cjs/ViewDefinition.js.map +1 -1
  203. package/lib/cjs/ViewStateHydrator.d.ts +0 -1
  204. package/lib/cjs/ViewStateHydrator.d.ts.map +1 -1
  205. package/lib/cjs/ViewStateHydrator.js +4 -14
  206. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  207. package/lib/cjs/ViewStore.d.ts.map +1 -1
  208. package/lib/cjs/ViewStore.js +32 -29
  209. package/lib/cjs/ViewStore.js.map +1 -1
  210. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  211. package/lib/cjs/assets/Settings/Schemas/Base.Schema.json +32 -32
  212. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +27 -27
  213. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +94 -94
  214. package/lib/cjs/assets/Settings/backend.setting.json5 +21 -21
  215. package/lib/cjs/core-backend.d.ts +8 -2
  216. package/lib/cjs/core-backend.d.ts.map +1 -1
  217. package/lib/cjs/core-backend.js +8 -2
  218. package/lib/cjs/core-backend.js.map +1 -1
  219. package/lib/cjs/domains/FunctionalElements.js +1 -1
  220. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  221. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  222. package/lib/cjs/domains/GenericElements.js.map +1 -1
  223. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  224. package/lib/cjs/internal/ChangesetConflictArgs.d.ts +40 -2
  225. package/lib/cjs/internal/ChangesetConflictArgs.d.ts.map +1 -1
  226. package/lib/cjs/internal/ChangesetConflictArgs.js +101 -0
  227. package/lib/cjs/internal/ChangesetConflictArgs.js.map +1 -1
  228. package/lib/cjs/internal/ChannelAdmin.d.ts +1 -1
  229. package/lib/cjs/internal/ChannelAdmin.d.ts.map +1 -1
  230. package/lib/cjs/internal/ChannelAdmin.js +16 -13
  231. package/lib/cjs/internal/ChannelAdmin.js.map +1 -1
  232. package/lib/cjs/internal/ElementLRUCache.d.ts +28 -0
  233. package/lib/cjs/internal/ElementLRUCache.d.ts.map +1 -0
  234. package/lib/cjs/internal/ElementLRUCache.js +120 -0
  235. package/lib/cjs/internal/ElementLRUCache.js.map +1 -0
  236. package/lib/cjs/internal/FontFileImpl.d.ts +34 -0
  237. package/lib/cjs/internal/FontFileImpl.d.ts.map +1 -0
  238. package/lib/cjs/internal/FontFileImpl.js +143 -0
  239. package/lib/cjs/internal/FontFileImpl.js.map +1 -0
  240. package/lib/cjs/{HubMock.d.ts → internal/HubMock.d.ts} +6 -7
  241. package/lib/cjs/internal/HubMock.d.ts.map +1 -0
  242. package/lib/cjs/{HubMock.js → internal/HubMock.js} +40 -15
  243. package/lib/cjs/internal/HubMock.js.map +1 -0
  244. package/lib/cjs/internal/IModelDbFontsImpl.d.ts +7 -0
  245. package/lib/cjs/internal/IModelDbFontsImpl.d.ts.map +1 -0
  246. package/lib/cjs/internal/IModelDbFontsImpl.js +186 -0
  247. package/lib/cjs/internal/IModelDbFontsImpl.js.map +1 -0
  248. package/lib/cjs/internal/NativePlatform.js.map +1 -1
  249. package/lib/cjs/internal/NoLocks.js +2 -5
  250. package/lib/cjs/internal/NoLocks.js.map +1 -1
  251. package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -1
  252. package/lib/cjs/internal/ServerBasedLocks.js +6 -6
  253. package/lib/cjs/internal/ServerBasedLocks.js.map +1 -1
  254. package/lib/cjs/internal/Symbols.d.ts +9 -0
  255. package/lib/cjs/internal/Symbols.d.ts.map +1 -1
  256. package/lib/cjs/internal/Symbols.js +10 -1
  257. package/lib/cjs/internal/Symbols.js.map +1 -1
  258. package/lib/cjs/internal/cross-package.js.map +1 -1
  259. package/lib/cjs/internal/workspace/SettingsImpl.js +6 -9
  260. package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -1
  261. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +8 -12
  262. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -1
  263. package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts +2 -16
  264. package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts.map +1 -1
  265. package/lib/cjs/internal/workspace/WorkspaceImpl.js +57 -121
  266. package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -1
  267. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js +1 -4
  268. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js.map +1 -1
  269. package/lib/cjs/rpc/multipart.d.ts.map +1 -1
  270. package/lib/cjs/rpc/multipart.js +2 -1
  271. package/lib/cjs/rpc/multipart.js.map +1 -1
  272. package/lib/cjs/rpc/tracing.js +2 -2
  273. package/lib/cjs/rpc/tracing.js.map +1 -1
  274. package/lib/cjs/rpc/web/logging.js.map +1 -1
  275. package/lib/cjs/rpc/web/request.d.ts.map +1 -1
  276. package/lib/cjs/rpc/web/request.js +2 -1
  277. package/lib/cjs/rpc/web/request.js.map +1 -1
  278. package/lib/cjs/rpc/web/response.js.map +1 -1
  279. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  280. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
  281. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +8 -4
  282. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  283. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +5 -3
  284. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  285. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  286. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +15 -25
  287. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  288. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  289. package/lib/cjs/workspace/Settings.js.map +1 -1
  290. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  291. package/lib/cjs/workspace/Workspace.d.ts +6 -13
  292. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  293. package/lib/cjs/workspace/Workspace.js.map +1 -1
  294. package/lib/cjs/workspace/WorkspaceEditor.d.ts +2 -7
  295. package/lib/cjs/workspace/WorkspaceEditor.d.ts.map +1 -1
  296. package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -1
  297. package/lib/esm/BackendHubAccess.d.ts +209 -0
  298. package/lib/esm/BackendHubAccess.d.ts.map +1 -0
  299. package/lib/esm/BackendHubAccess.js +41 -0
  300. package/lib/esm/BackendHubAccess.js.map +1 -0
  301. package/lib/esm/BackendLoggerCategory.d.ts +88 -0
  302. package/lib/esm/BackendLoggerCategory.d.ts.map +1 -0
  303. package/lib/esm/BackendLoggerCategory.js +93 -0
  304. package/lib/esm/BackendLoggerCategory.js.map +1 -0
  305. package/lib/esm/BisCoreSchema.d.ts +22 -0
  306. package/lib/esm/BisCoreSchema.d.ts.map +1 -0
  307. package/lib/esm/BisCoreSchema.js +61 -0
  308. package/lib/esm/BisCoreSchema.js.map +1 -0
  309. package/lib/esm/BlobContainerService.d.ts +159 -0
  310. package/lib/esm/BlobContainerService.d.ts.map +1 -0
  311. package/lib/esm/BlobContainerService.js +15 -0
  312. package/lib/esm/BlobContainerService.js.map +1 -0
  313. package/lib/esm/BriefcaseManager.d.ts +213 -0
  314. package/lib/esm/BriefcaseManager.d.ts.map +1 -0
  315. package/lib/esm/BriefcaseManager.js +520 -0
  316. package/lib/esm/BriefcaseManager.js.map +1 -0
  317. package/lib/esm/CatalogDb.d.ts +103 -0
  318. package/lib/esm/CatalogDb.d.ts.map +1 -0
  319. package/lib/esm/CatalogDb.js +267 -0
  320. package/lib/esm/CatalogDb.js.map +1 -0
  321. package/lib/esm/Category.d.ts +173 -0
  322. package/lib/esm/Category.d.ts.map +1 -0
  323. package/lib/esm/Category.js +297 -0
  324. package/lib/esm/Category.js.map +1 -0
  325. package/lib/esm/ChangeSummaryManager.d.ts +161 -0
  326. package/lib/esm/ChangeSummaryManager.d.ts.map +1 -0
  327. package/lib/esm/ChangeSummaryManager.js +421 -0
  328. package/lib/esm/ChangeSummaryManager.js.map +1 -0
  329. package/lib/esm/ChangedElementsDb.d.ts +101 -0
  330. package/lib/esm/ChangedElementsDb.d.ts.map +1 -0
  331. package/lib/esm/ChangedElementsDb.js +165 -0
  332. package/lib/esm/ChangedElementsDb.js.map +1 -0
  333. package/lib/esm/ChangesetECAdaptor.d.ts +203 -0
  334. package/lib/esm/ChangesetECAdaptor.d.ts.map +1 -0
  335. package/lib/esm/ChangesetECAdaptor.js +815 -0
  336. package/lib/esm/ChangesetECAdaptor.js.map +1 -0
  337. package/lib/esm/ChannelControl.d.ts +68 -0
  338. package/lib/esm/ChannelControl.d.ts.map +1 -0
  339. package/lib/esm/ChannelControl.js +15 -0
  340. package/lib/esm/ChannelControl.js.map +1 -0
  341. package/lib/esm/CheckpointManager.d.ts +118 -0
  342. package/lib/esm/CheckpointManager.d.ts.map +1 -0
  343. package/lib/esm/CheckpointManager.js +321 -0
  344. package/lib/esm/CheckpointManager.js.map +1 -0
  345. package/lib/esm/ClassRegistry.d.ts +134 -0
  346. package/lib/esm/ClassRegistry.d.ts.map +1 -0
  347. package/lib/esm/ClassRegistry.js +324 -0
  348. package/lib/esm/ClassRegistry.js.map +1 -0
  349. package/lib/esm/CloudSqlite.d.ts +766 -0
  350. package/lib/esm/CloudSqlite.d.ts.map +1 -0
  351. package/lib/esm/CloudSqlite.js +622 -0
  352. package/lib/esm/CloudSqlite.js.map +1 -0
  353. package/lib/esm/CodeService.d.ts +402 -0
  354. package/lib/esm/CodeService.d.ts.map +1 -0
  355. package/lib/esm/CodeService.js +65 -0
  356. package/lib/esm/CodeService.js.map +1 -0
  357. package/lib/esm/CodeSpecs.d.ts +59 -0
  358. package/lib/esm/CodeSpecs.d.ts.map +1 -0
  359. package/lib/esm/CodeSpecs.js +152 -0
  360. package/lib/esm/CodeSpecs.js.map +1 -0
  361. package/lib/esm/ConcurrentQuery.d.ts +14 -0
  362. package/lib/esm/ConcurrentQuery.d.ts.map +1 -0
  363. package/lib/esm/ConcurrentQuery.js +33 -0
  364. package/lib/esm/ConcurrentQuery.js.map +1 -0
  365. package/lib/esm/CustomViewState3dCreator.d.ts +22 -0
  366. package/lib/esm/CustomViewState3dCreator.d.ts.map +1 -0
  367. package/lib/esm/CustomViewState3dCreator.js +78 -0
  368. package/lib/esm/CustomViewState3dCreator.js.map +1 -0
  369. package/lib/esm/DevTools.d.ts +73 -0
  370. package/lib/esm/DevTools.d.ts.map +1 -0
  371. package/lib/esm/DevTools.js +153 -0
  372. package/lib/esm/DevTools.js.map +1 -0
  373. package/lib/esm/DisplayStyle.d.ts +104 -0
  374. package/lib/esm/DisplayStyle.d.ts.map +1 -0
  375. package/lib/esm/DisplayStyle.js +291 -0
  376. package/lib/esm/DisplayStyle.js.map +1 -0
  377. package/lib/esm/ECDb.d.ts +206 -0
  378. package/lib/esm/ECDb.d.ts.map +1 -0
  379. package/lib/esm/ECDb.js +410 -0
  380. package/lib/esm/ECDb.js.map +1 -0
  381. package/lib/esm/ECSchemaXmlContext.d.ts +46 -0
  382. package/lib/esm/ECSchemaXmlContext.d.ts.map +1 -0
  383. package/lib/esm/ECSchemaXmlContext.js +66 -0
  384. package/lib/esm/ECSchemaXmlContext.js.map +1 -0
  385. package/lib/esm/ECSqlStatement.d.ts +671 -0
  386. package/lib/esm/ECSqlStatement.d.ts.map +1 -0
  387. package/lib/esm/ECSqlStatement.js +1028 -0
  388. package/lib/esm/ECSqlStatement.js.map +1 -0
  389. package/lib/esm/Element.d.ts +1155 -0
  390. package/lib/esm/Element.d.ts.map +1 -0
  391. package/lib/esm/Element.js +1876 -0
  392. package/lib/esm/Element.js.map +1 -0
  393. package/lib/esm/ElementAspect.d.ts +164 -0
  394. package/lib/esm/ElementAspect.d.ts.map +1 -0
  395. package/lib/esm/ElementAspect.js +205 -0
  396. package/lib/esm/ElementAspect.js.map +1 -0
  397. package/lib/esm/ElementGraphics.d.ts +7 -0
  398. package/lib/esm/ElementGraphics.d.ts.map +1 -0
  399. package/lib/esm/ElementGraphics.js +36 -0
  400. package/lib/esm/ElementGraphics.js.map +1 -0
  401. package/lib/esm/ElementTreeWalker.d.ts +182 -0
  402. package/lib/esm/ElementTreeWalker.d.ts.map +1 -0
  403. package/lib/esm/ElementTreeWalker.js +425 -0
  404. package/lib/esm/ElementTreeWalker.js.map +1 -0
  405. package/lib/esm/Entity.d.ts +186 -0
  406. package/lib/esm/Entity.d.ts.map +1 -0
  407. package/lib/esm/Entity.js +244 -0
  408. package/lib/esm/Entity.js.map +1 -0
  409. package/lib/esm/EntityReferences.d.ts +50 -0
  410. package/lib/esm/EntityReferences.d.ts.map +1 -0
  411. package/lib/esm/EntityReferences.js +92 -0
  412. package/lib/esm/EntityReferences.js.map +1 -0
  413. package/lib/esm/ExportGraphics.d.ts +318 -0
  414. package/lib/esm/ExportGraphics.d.ts.map +1 -0
  415. package/lib/esm/ExportGraphics.js +209 -0
  416. package/lib/esm/ExportGraphics.js.map +1 -0
  417. package/lib/esm/ExternalSource.d.ts +89 -0
  418. package/lib/esm/ExternalSource.d.ts.map +1 -0
  419. package/lib/esm/ExternalSource.js +139 -0
  420. package/lib/esm/ExternalSource.js.map +1 -0
  421. package/lib/esm/FontFile.d.ts +68 -0
  422. package/lib/esm/FontFile.d.ts.map +1 -0
  423. package/lib/esm/FontFile.js +33 -0
  424. package/lib/esm/FontFile.js.map +1 -0
  425. package/lib/esm/GeoCoordConfig.d.ts +30 -0
  426. package/lib/esm/GeoCoordConfig.d.ts.map +1 -0
  427. package/lib/esm/GeoCoordConfig.js +78 -0
  428. package/lib/esm/GeoCoordConfig.js.map +1 -0
  429. package/lib/esm/GeographicCRSServices.d.ts +40 -0
  430. package/lib/esm/GeographicCRSServices.d.ts.map +1 -0
  431. package/lib/esm/GeographicCRSServices.js +17 -0
  432. package/lib/esm/GeographicCRSServices.js.map +1 -0
  433. package/lib/esm/GeometrySummary.d.ts +5 -0
  434. package/lib/esm/GeometrySummary.d.ts.map +1 -0
  435. package/lib/esm/GeometrySummary.js +381 -0
  436. package/lib/esm/GeometrySummary.js.map +1 -0
  437. package/lib/esm/IModelDb.d.ts +1390 -0
  438. package/lib/esm/IModelDb.d.ts.map +1 -0
  439. package/lib/esm/IModelDb.js +3327 -0
  440. package/lib/esm/IModelDb.js.map +1 -0
  441. package/lib/esm/IModelDbFonts.d.ts +54 -0
  442. package/lib/esm/IModelDbFonts.d.ts.map +1 -0
  443. package/lib/esm/IModelDbFonts.js +9 -0
  444. package/lib/esm/IModelDbFonts.js.map +1 -0
  445. package/lib/esm/IModelElementCloneContext.d.ts +92 -0
  446. package/lib/esm/IModelElementCloneContext.d.ts.map +1 -0
  447. package/lib/esm/IModelElementCloneContext.js +168 -0
  448. package/lib/esm/IModelElementCloneContext.js.map +1 -0
  449. package/lib/esm/IModelHost.d.ts +400 -0
  450. package/lib/esm/IModelHost.d.ts.map +1 -0
  451. package/lib/esm/IModelHost.js +508 -0
  452. package/lib/esm/IModelHost.js.map +1 -0
  453. package/lib/esm/IModelJsFs.d.ts +62 -0
  454. package/lib/esm/IModelJsFs.d.ts.map +1 -0
  455. package/lib/esm/IModelJsFs.js +151 -0
  456. package/lib/esm/IModelJsFs.js.map +1 -0
  457. package/lib/esm/ImageSourceConversion.d.ts +49 -0
  458. package/lib/esm/ImageSourceConversion.d.ts.map +1 -0
  459. package/lib/esm/ImageSourceConversion.js +33 -0
  460. package/lib/esm/ImageSourceConversion.js.map +1 -0
  461. package/lib/esm/IpcHost.d.ts +111 -0
  462. package/lib/esm/IpcHost.d.ts.map +1 -0
  463. package/lib/esm/IpcHost.js +292 -0
  464. package/lib/esm/IpcHost.js.map +1 -0
  465. package/lib/esm/LineStyle.d.ts +312 -0
  466. package/lib/esm/LineStyle.d.ts.map +1 -0
  467. package/lib/esm/LineStyle.js +293 -0
  468. package/lib/esm/LineStyle.js.map +1 -0
  469. package/lib/esm/LocalHub.d.ts +163 -0
  470. package/lib/esm/LocalHub.d.ts.map +1 -0
  471. package/lib/esm/LocalHub.js +583 -0
  472. package/lib/esm/LocalHub.js.map +1 -0
  473. package/lib/esm/LocalhostIpcHost.d.ts +22 -0
  474. package/lib/esm/LocalhostIpcHost.d.ts.map +1 -0
  475. package/lib/esm/LocalhostIpcHost.js +74 -0
  476. package/lib/esm/LocalhostIpcHost.js.map +1 -0
  477. package/lib/esm/LockControl.d.ts +73 -0
  478. package/lib/esm/LockControl.d.ts.map +1 -0
  479. package/lib/esm/LockControl.js +9 -0
  480. package/lib/esm/LockControl.js.map +1 -0
  481. package/lib/esm/Material.d.ts +150 -0
  482. package/lib/esm/Material.d.ts.map +1 -0
  483. package/lib/esm/Material.js +264 -0
  484. package/lib/esm/Material.js.map +1 -0
  485. package/lib/esm/Model.d.ts +411 -0
  486. package/lib/esm/Model.d.ts.map +1 -0
  487. package/lib/esm/Model.js +572 -0
  488. package/lib/esm/Model.js.map +1 -0
  489. package/lib/esm/NativeAppStorage.d.ts +52 -0
  490. package/lib/esm/NativeAppStorage.d.ts.map +1 -0
  491. package/lib/esm/NativeAppStorage.js +205 -0
  492. package/lib/esm/NativeAppStorage.js.map +1 -0
  493. package/lib/esm/NativeHost.d.ts +53 -0
  494. package/lib/esm/NativeHost.d.ts.map +1 -0
  495. package/lib/esm/NativeHost.js +161 -0
  496. package/lib/esm/NativeHost.js.map +1 -0
  497. package/lib/esm/NavigationRelationship.d.ts +185 -0
  498. package/lib/esm/NavigationRelationship.d.ts.map +1 -0
  499. package/lib/esm/NavigationRelationship.js +238 -0
  500. package/lib/esm/NavigationRelationship.js.map +1 -0
  501. package/lib/esm/PromiseMemoizer.d.ts +48 -0
  502. package/lib/esm/PromiseMemoizer.d.ts.map +1 -0
  503. package/lib/esm/PromiseMemoizer.js +101 -0
  504. package/lib/esm/PromiseMemoizer.js.map +1 -0
  505. package/lib/esm/PropertyStore.d.ts +134 -0
  506. package/lib/esm/PropertyStore.d.ts.map +1 -0
  507. package/lib/esm/PropertyStore.js +177 -0
  508. package/lib/esm/PropertyStore.js.map +1 -0
  509. package/lib/esm/Relationship.d.ts +399 -0
  510. package/lib/esm/Relationship.d.ts.map +1 -0
  511. package/lib/esm/Relationship.js +476 -0
  512. package/lib/esm/Relationship.js.map +1 -0
  513. package/lib/esm/RpcBackend.d.ts +6 -0
  514. package/lib/esm/RpcBackend.d.ts.map +1 -0
  515. package/lib/esm/RpcBackend.js +28 -0
  516. package/lib/esm/RpcBackend.js.map +1 -0
  517. package/lib/esm/SQLiteDb.d.ts +324 -0
  518. package/lib/esm/SQLiteDb.d.ts.map +1 -0
  519. package/lib/esm/SQLiteDb.js +380 -0
  520. package/lib/esm/SQLiteDb.js.map +1 -0
  521. package/lib/esm/Schema.d.ts +79 -0
  522. package/lib/esm/Schema.d.ts.map +1 -0
  523. package/lib/esm/Schema.js +113 -0
  524. package/lib/esm/Schema.js.map +1 -0
  525. package/lib/esm/SchemaSync.d.ts +47 -0
  526. package/lib/esm/SchemaSync.d.ts.map +1 -0
  527. package/lib/esm/SchemaSync.js +148 -0
  528. package/lib/esm/SchemaSync.js.map +1 -0
  529. package/lib/esm/SchemaUtils.d.ts +19 -0
  530. package/lib/esm/SchemaUtils.d.ts.map +1 -0
  531. package/lib/esm/SchemaUtils.js +37 -0
  532. package/lib/esm/SchemaUtils.js.map +1 -0
  533. package/lib/esm/SheetIndex.d.ts +148 -0
  534. package/lib/esm/SheetIndex.d.ts.map +1 -0
  535. package/lib/esm/SheetIndex.js +228 -0
  536. package/lib/esm/SheetIndex.js.map +1 -0
  537. package/lib/esm/SqliteChangesetReader.d.ts +278 -0
  538. package/lib/esm/SqliteChangesetReader.d.ts.map +1 -0
  539. package/lib/esm/SqliteChangesetReader.js +337 -0
  540. package/lib/esm/SqliteChangesetReader.js.map +1 -0
  541. package/lib/esm/SqliteStatement.d.ts +375 -0
  542. package/lib/esm/SqliteStatement.d.ts.map +1 -0
  543. package/lib/esm/SqliteStatement.js +615 -0
  544. package/lib/esm/SqliteStatement.js.map +1 -0
  545. package/lib/esm/TextAnnotationElement.d.ts +54 -0
  546. package/lib/esm/TextAnnotationElement.d.ts.map +1 -0
  547. package/lib/esm/TextAnnotationElement.js +89 -0
  548. package/lib/esm/TextAnnotationElement.js.map +1 -0
  549. package/lib/esm/TextAnnotationGeometry.d.ts +32 -0
  550. package/lib/esm/TextAnnotationGeometry.d.ts.map +1 -0
  551. package/lib/esm/TextAnnotationGeometry.js +181 -0
  552. package/lib/esm/TextAnnotationGeometry.js.map +1 -0
  553. package/lib/esm/TextAnnotationLayout.d.ts +177 -0
  554. package/lib/esm/TextAnnotationLayout.d.ts.map +1 -0
  555. package/lib/esm/TextAnnotationLayout.js +513 -0
  556. package/lib/esm/TextAnnotationLayout.js.map +1 -0
  557. package/lib/esm/Texture.d.ts +58 -0
  558. package/lib/esm/Texture.d.ts.map +1 -0
  559. package/lib/esm/Texture.js +81 -0
  560. package/lib/esm/Texture.js.map +1 -0
  561. package/lib/esm/TileStorage.d.ts +59 -0
  562. package/lib/esm/TileStorage.d.ts.map +1 -0
  563. package/lib/esm/TileStorage.js +158 -0
  564. package/lib/esm/TileStorage.js.map +1 -0
  565. package/lib/esm/TxnManager.d.ts +296 -0
  566. package/lib/esm/TxnManager.d.ts.map +1 -0
  567. package/lib/esm/TxnManager.js +620 -0
  568. package/lib/esm/TxnManager.js.map +1 -0
  569. package/lib/esm/ViewDefinition.d.ts +492 -0
  570. package/lib/esm/ViewDefinition.d.ts.map +1 -0
  571. package/lib/esm/ViewDefinition.js +846 -0
  572. package/lib/esm/ViewDefinition.js.map +1 -0
  573. package/lib/esm/ViewStateHydrator.d.ts +14 -0
  574. package/lib/esm/ViewStateHydrator.d.ts.map +1 -0
  575. package/lib/esm/ViewStateHydrator.js +89 -0
  576. package/lib/esm/ViewStateHydrator.js.map +1 -0
  577. package/lib/esm/ViewStore.d.ts +502 -0
  578. package/lib/esm/ViewStore.d.ts.map +1 -0
  579. package/lib/esm/ViewStore.js +1260 -0
  580. package/lib/esm/ViewStore.js.map +1 -0
  581. package/lib/esm/core-backend.d.ts +183 -0
  582. package/lib/esm/core-backend.d.ts.map +1 -0
  583. package/lib/esm/core-backend.js +187 -0
  584. package/lib/esm/core-backend.js.map +1 -0
  585. package/lib/esm/domains/FunctionalElements.d.ts +86 -0
  586. package/lib/esm/domains/FunctionalElements.d.ts.map +1 -0
  587. package/lib/esm/domains/FunctionalElements.js +117 -0
  588. package/lib/esm/domains/FunctionalElements.js.map +1 -0
  589. package/lib/esm/domains/FunctionalSchema.d.ts +14 -0
  590. package/lib/esm/domains/FunctionalSchema.d.ts.map +1 -0
  591. package/lib/esm/domains/FunctionalSchema.js +37 -0
  592. package/lib/esm/domains/FunctionalSchema.js.map +1 -0
  593. package/lib/esm/domains/GenericElements.d.ts +160 -0
  594. package/lib/esm/domains/GenericElements.d.ts.map +1 -0
  595. package/lib/esm/domains/GenericElements.js +225 -0
  596. package/lib/esm/domains/GenericElements.js.map +1 -0
  597. package/lib/esm/domains/GenericSchema.d.ts +11 -0
  598. package/lib/esm/domains/GenericSchema.d.ts.map +1 -0
  599. package/lib/esm/domains/GenericSchema.js +25 -0
  600. package/lib/esm/domains/GenericSchema.js.map +1 -0
  601. package/lib/esm/internal/ChangesetConflictArgs.d.ts +62 -0
  602. package/lib/esm/internal/ChangesetConflictArgs.d.ts.map +1 -0
  603. package/lib/esm/internal/ChangesetConflictArgs.js +104 -0
  604. package/lib/esm/internal/ChangesetConflictArgs.js.map +1 -0
  605. package/lib/esm/internal/ChannelAdmin.d.ts +34 -0
  606. package/lib/esm/internal/ChannelAdmin.d.ts.map +1 -0
  607. package/lib/esm/internal/ChannelAdmin.js +116 -0
  608. package/lib/esm/internal/ChannelAdmin.js.map +1 -0
  609. package/lib/esm/internal/ElementLRUCache.d.ts +28 -0
  610. package/lib/esm/internal/ElementLRUCache.d.ts.map +1 -0
  611. package/lib/esm/internal/ElementLRUCache.js +116 -0
  612. package/lib/esm/internal/ElementLRUCache.js.map +1 -0
  613. package/lib/esm/internal/FontFileImpl.d.ts +34 -0
  614. package/lib/esm/internal/FontFileImpl.d.ts.map +1 -0
  615. package/lib/esm/internal/FontFileImpl.js +135 -0
  616. package/lib/esm/internal/FontFileImpl.js.map +1 -0
  617. package/lib/esm/internal/HubMock.d.ts +94 -0
  618. package/lib/esm/internal/HubMock.d.ts.map +1 -0
  619. package/lib/esm/internal/HubMock.js +242 -0
  620. package/lib/esm/internal/HubMock.js.map +1 -0
  621. package/lib/esm/internal/IModelDbFontsImpl.d.ts +7 -0
  622. package/lib/esm/internal/IModelDbFontsImpl.d.ts.map +1 -0
  623. package/lib/esm/internal/IModelDbFontsImpl.js +183 -0
  624. package/lib/esm/internal/IModelDbFontsImpl.js.map +1 -0
  625. package/lib/esm/internal/NativePlatform.d.ts +15 -0
  626. package/lib/esm/internal/NativePlatform.d.ts.map +1 -0
  627. package/lib/esm/internal/NativePlatform.js +43 -0
  628. package/lib/esm/internal/NativePlatform.js.map +1 -0
  629. package/lib/esm/internal/NoLocks.d.ts +6 -0
  630. package/lib/esm/internal/NoLocks.d.ts.map +1 -0
  631. package/lib/esm/internal/NoLocks.js +24 -0
  632. package/lib/esm/internal/NoLocks.js.map +1 -0
  633. package/lib/esm/internal/ServerBasedLocks.d.ts +52 -0
  634. package/lib/esm/internal/ServerBasedLocks.d.ts.map +1 -0
  635. package/lib/esm/internal/ServerBasedLocks.js +175 -0
  636. package/lib/esm/internal/ServerBasedLocks.js.map +1 -0
  637. package/lib/esm/internal/Symbols.d.ts +20 -0
  638. package/lib/esm/internal/Symbols.d.ts.map +1 -0
  639. package/lib/esm/internal/Symbols.js +27 -0
  640. package/lib/esm/internal/Symbols.js.map +1 -0
  641. package/lib/esm/internal/cross-package.d.ts +4 -0
  642. package/lib/esm/internal/cross-package.d.ts.map +1 -0
  643. package/lib/esm/internal/cross-package.js +8 -0
  644. package/lib/esm/internal/cross-package.js.map +1 -0
  645. package/lib/esm/internal/workspace/SettingsImpl.d.ts +43 -0
  646. package/lib/esm/internal/workspace/SettingsImpl.d.ts.map +1 -0
  647. package/lib/esm/internal/workspace/SettingsImpl.js +154 -0
  648. package/lib/esm/internal/workspace/SettingsImpl.js.map +1 -0
  649. package/lib/esm/internal/workspace/SettingsSchemasImpl.d.ts +6 -0
  650. package/lib/esm/internal/workspace/SettingsSchemasImpl.d.ts.map +1 -0
  651. package/lib/esm/internal/workspace/SettingsSchemasImpl.js +268 -0
  652. package/lib/esm/internal/workspace/SettingsSchemasImpl.js.map +1 -0
  653. package/lib/esm/internal/workspace/WorkspaceImpl.d.ts +27 -0
  654. package/lib/esm/internal/workspace/WorkspaceImpl.d.ts.map +1 -0
  655. package/lib/esm/internal/workspace/WorkspaceImpl.js +627 -0
  656. package/lib/esm/internal/workspace/WorkspaceImpl.js.map +1 -0
  657. package/lib/esm/internal/workspace/WorkspaceSqliteDb.d.ts +10 -0
  658. package/lib/esm/internal/workspace/WorkspaceSqliteDb.d.ts.map +1 -0
  659. package/lib/esm/internal/workspace/WorkspaceSqliteDb.js +35 -0
  660. package/lib/esm/internal/workspace/WorkspaceSqliteDb.js.map +1 -0
  661. package/lib/esm/rpc/multipart.d.ts +12 -0
  662. package/lib/esm/rpc/multipart.d.ts.map +1 -0
  663. package/lib/esm/rpc/multipart.js +67 -0
  664. package/lib/esm/rpc/multipart.js.map +1 -0
  665. package/lib/esm/rpc/tracing.d.ts +29 -0
  666. package/lib/esm/rpc/tracing.d.ts.map +1 -0
  667. package/lib/esm/rpc/tracing.js +71 -0
  668. package/lib/esm/rpc/tracing.js.map +1 -0
  669. package/lib/esm/rpc/web/logging.d.ts +10 -0
  670. package/lib/esm/rpc/web/logging.d.ts.map +1 -0
  671. package/lib/esm/rpc/web/logging.js +41 -0
  672. package/lib/esm/rpc/web/logging.js.map +1 -0
  673. package/lib/esm/rpc/web/request.d.ts +7 -0
  674. package/lib/esm/rpc/web/request.d.ts.map +1 -0
  675. package/lib/esm/rpc/web/request.js +71 -0
  676. package/lib/esm/rpc/web/request.js.map +1 -0
  677. package/lib/esm/rpc/web/response.d.ts +7 -0
  678. package/lib/esm/rpc/web/response.d.ts.map +1 -0
  679. package/lib/esm/rpc/web/response.js +136 -0
  680. package/lib/esm/rpc/web/response.js.map +1 -0
  681. package/lib/esm/rpc-impl/DevToolsRpcImpl.d.ts +16 -0
  682. package/lib/esm/rpc-impl/DevToolsRpcImpl.d.ts.map +1 -0
  683. package/lib/esm/rpc-impl/DevToolsRpcImpl.js +29 -0
  684. package/lib/esm/rpc-impl/DevToolsRpcImpl.js.map +1 -0
  685. package/lib/esm/rpc-impl/IModelReadRpcImpl.d.ts +51 -0
  686. package/lib/esm/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -0
  687. package/lib/esm/rpc-impl/IModelReadRpcImpl.js +314 -0
  688. package/lib/esm/rpc-impl/IModelReadRpcImpl.js.map +1 -0
  689. package/lib/esm/rpc-impl/IModelTileRpcImpl.d.ts +21 -0
  690. package/lib/esm/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -0
  691. package/lib/esm/rpc-impl/IModelTileRpcImpl.js +193 -0
  692. package/lib/esm/rpc-impl/IModelTileRpcImpl.js.map +1 -0
  693. package/lib/esm/rpc-impl/RpcBriefcaseUtility.d.ts +45 -0
  694. package/lib/esm/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -0
  695. package/lib/esm/rpc-impl/RpcBriefcaseUtility.js +155 -0
  696. package/lib/esm/rpc-impl/RpcBriefcaseUtility.js.map +1 -0
  697. package/lib/esm/rpc-impl/SnapshotIModelRpcImpl.d.ts +18 -0
  698. package/lib/esm/rpc-impl/SnapshotIModelRpcImpl.d.ts.map +1 -0
  699. package/lib/esm/rpc-impl/SnapshotIModelRpcImpl.js +41 -0
  700. package/lib/esm/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -0
  701. package/lib/esm/test/AdvancedEqual.d.ts +38 -0
  702. package/lib/esm/test/AdvancedEqual.d.ts.map +1 -0
  703. package/lib/esm/test/AdvancedEqual.js +67 -0
  704. package/lib/esm/test/AdvancedEqual.js.map +1 -0
  705. package/lib/esm/test/AttachDb.test.d.ts +2 -0
  706. package/lib/esm/test/AttachDb.test.d.ts.map +1 -0
  707. package/lib/esm/test/AttachDb.test.js +157 -0
  708. package/lib/esm/test/AttachDb.test.js.map +1 -0
  709. package/lib/esm/test/ElementLRUCache.test.d.ts +2 -0
  710. package/lib/esm/test/ElementLRUCache.test.d.ts.map +1 -0
  711. package/lib/esm/test/ElementLRUCache.test.js +212 -0
  712. package/lib/esm/test/ElementLRUCache.test.js.map +1 -0
  713. package/lib/esm/test/GeometryTestUtil.d.ts +7 -0
  714. package/lib/esm/test/GeometryTestUtil.d.ts.map +1 -0
  715. package/lib/esm/test/GeometryTestUtil.js +25 -0
  716. package/lib/esm/test/GeometryTestUtil.js.map +1 -0
  717. package/lib/esm/test/IModelHost.test.d.ts +2 -0
  718. package/lib/esm/test/IModelHost.test.d.ts.map +1 -0
  719. package/lib/esm/test/IModelHost.test.js +187 -0
  720. package/lib/esm/test/IModelHost.test.js.map +1 -0
  721. package/lib/esm/test/IModelTestUtils.d.ts +177 -0
  722. package/lib/esm/test/IModelTestUtils.d.ts.map +1 -0
  723. package/lib/esm/test/IModelTestUtils.js +1146 -0
  724. package/lib/esm/test/IModelTestUtils.js.map +1 -0
  725. package/lib/esm/test/ImageSourceConversion.test.d.ts +2 -0
  726. package/lib/esm/test/ImageSourceConversion.test.d.ts.map +1 -0
  727. package/lib/esm/test/ImageSourceConversion.test.js +171 -0
  728. package/lib/esm/test/ImageSourceConversion.test.js.map +1 -0
  729. package/lib/esm/test/IpcHost.test.d.ts +2 -0
  730. package/lib/esm/test/IpcHost.test.d.ts.map +1 -0
  731. package/lib/esm/test/IpcHost.test.js +55 -0
  732. package/lib/esm/test/IpcHost.test.js.map +1 -0
  733. package/lib/esm/test/KnownTestLocations.d.ts +7 -0
  734. package/lib/esm/test/KnownTestLocations.d.ts.map +1 -0
  735. package/lib/esm/test/KnownTestLocations.js +27 -0
  736. package/lib/esm/test/KnownTestLocations.js.map +1 -0
  737. package/lib/esm/test/PrintElementTree.d.ts +7 -0
  738. package/lib/esm/test/PrintElementTree.d.ts.map +1 -0
  739. package/lib/esm/test/PrintElementTree.js +36 -0
  740. package/lib/esm/test/PrintElementTree.js.map +1 -0
  741. package/lib/esm/test/PropertyDb.test.d.ts +2 -0
  742. package/lib/esm/test/PropertyDb.test.d.ts.map +1 -0
  743. package/lib/esm/test/PropertyDb.test.js +71 -0
  744. package/lib/esm/test/PropertyDb.test.js.map +1 -0
  745. package/lib/esm/test/RevisionUtility.d.ts +33 -0
  746. package/lib/esm/test/RevisionUtility.d.ts.map +1 -0
  747. package/lib/esm/test/RevisionUtility.js +52 -0
  748. package/lib/esm/test/RevisionUtility.js.map +1 -0
  749. package/lib/esm/test/SchemaUtils.test.d.ts +2 -0
  750. package/lib/esm/test/SchemaUtils.test.d.ts.map +1 -0
  751. package/lib/esm/test/SchemaUtils.test.js +99 -0
  752. package/lib/esm/test/SchemaUtils.test.js.map +1 -0
  753. package/lib/esm/test/SequentialLogMatcher.d.ts +35 -0
  754. package/lib/esm/test/SequentialLogMatcher.d.ts.map +1 -0
  755. package/lib/esm/test/SequentialLogMatcher.js +130 -0
  756. package/lib/esm/test/SequentialLogMatcher.js.map +1 -0
  757. package/lib/esm/test/TestChangeSetUtility.d.ts +23 -0
  758. package/lib/esm/test/TestChangeSetUtility.d.ts.map +1 -0
  759. package/lib/esm/test/TestChangeSetUtility.js +65 -0
  760. package/lib/esm/test/TestChangeSetUtility.js.map +1 -0
  761. package/lib/esm/test/TestUtils.d.ts +38 -0
  762. package/lib/esm/test/TestUtils.d.ts.map +1 -0
  763. package/lib/esm/test/TestUtils.js +99 -0
  764. package/lib/esm/test/TestUtils.js.map +1 -0
  765. package/lib/esm/test/annotations/TextAnnotation.test.d.ts +2 -0
  766. package/lib/esm/test/annotations/TextAnnotation.test.d.ts.map +1 -0
  767. package/lib/esm/test/annotations/TextAnnotation.test.js +1135 -0
  768. package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -0
  769. package/lib/esm/test/categories/Category.test.d.ts +2 -0
  770. package/lib/esm/test/categories/Category.test.d.ts.map +1 -0
  771. package/lib/esm/test/categories/Category.test.js +51 -0
  772. package/lib/esm/test/categories/Category.test.js.map +1 -0
  773. package/lib/esm/test/codespec/CodeSpec.test.d.ts +2 -0
  774. package/lib/esm/test/codespec/CodeSpec.test.d.ts.map +1 -0
  775. package/lib/esm/test/codespec/CodeSpec.test.js +51 -0
  776. package/lib/esm/test/codespec/CodeSpec.test.js.map +1 -0
  777. package/lib/esm/test/ecdb/CTE.test.d.ts +2 -0
  778. package/lib/esm/test/ecdb/CTE.test.d.ts.map +1 -0
  779. package/lib/esm/test/ecdb/CTE.test.js +177 -0
  780. package/lib/esm/test/ecdb/CTE.test.js.map +1 -0
  781. package/lib/esm/test/ecdb/ConcurrentQueryLoad.test.d.ts +2 -0
  782. package/lib/esm/test/ecdb/ConcurrentQueryLoad.test.d.ts.map +1 -0
  783. package/lib/esm/test/ecdb/ConcurrentQueryLoad.test.js +167 -0
  784. package/lib/esm/test/ecdb/ConcurrentQueryLoad.test.js.map +1 -0
  785. package/lib/esm/test/ecdb/ECDb.test.d.ts +2 -0
  786. package/lib/esm/test/ecdb/ECDb.test.d.ts.map +1 -0
  787. package/lib/esm/test/ecdb/ECDb.test.js +653 -0
  788. package/lib/esm/test/ecdb/ECDb.test.js.map +1 -0
  789. package/lib/esm/test/ecdb/ECDbTestHelper.d.ts +5 -0
  790. package/lib/esm/test/ecdb/ECDbTestHelper.d.ts.map +1 -0
  791. package/lib/esm/test/ecdb/ECDbTestHelper.js +28 -0
  792. package/lib/esm/test/ecdb/ECDbTestHelper.js.map +1 -0
  793. package/lib/esm/test/ecdb/ECSchemaXmlContext.test.d.ts +2 -0
  794. package/lib/esm/test/ecdb/ECSchemaXmlContext.test.d.ts.map +1 -0
  795. package/lib/esm/test/ecdb/ECSchemaXmlContext.test.js +63 -0
  796. package/lib/esm/test/ecdb/ECSchemaXmlContext.test.js.map +1 -0
  797. package/lib/esm/test/ecdb/ECSqlAst.test.d.ts +5 -0
  798. package/lib/esm/test/ecdb/ECSqlAst.test.d.ts.map +1 -0
  799. package/lib/esm/test/ecdb/ECSqlAst.test.js +972 -0
  800. package/lib/esm/test/ecdb/ECSqlAst.test.js.map +1 -0
  801. package/lib/esm/test/ecdb/ECSqlQuery.test.d.ts +2 -0
  802. package/lib/esm/test/ecdb/ECSqlQuery.test.d.ts.map +1 -0
  803. package/lib/esm/test/ecdb/ECSqlQuery.test.js +753 -0
  804. package/lib/esm/test/ecdb/ECSqlQuery.test.js.map +1 -0
  805. package/lib/esm/test/ecdb/ECSqlReader.test.d.ts +2 -0
  806. package/lib/esm/test/ecdb/ECSqlReader.test.d.ts.map +1 -0
  807. package/lib/esm/test/ecdb/ECSqlReader.test.js +669 -0
  808. package/lib/esm/test/ecdb/ECSqlReader.test.js.map +1 -0
  809. package/lib/esm/test/ecdb/ECSqlStatement.test.d.ts +2 -0
  810. package/lib/esm/test/ecdb/ECSqlStatement.test.d.ts.map +1 -0
  811. package/lib/esm/test/ecdb/ECSqlStatement.test.js +3329 -0
  812. package/lib/esm/test/ecdb/ECSqlStatement.test.js.map +1 -0
  813. package/lib/esm/test/ecdb/SqliteStatement.test.d.ts +2 -0
  814. package/lib/esm/test/ecdb/SqliteStatement.test.d.ts.map +1 -0
  815. package/lib/esm/test/ecdb/SqliteStatement.test.js +510 -0
  816. package/lib/esm/test/ecdb/SqliteStatement.test.js.map +1 -0
  817. package/lib/esm/test/ecsql/dataset/ECSqlDatasets.d.ts +4 -0
  818. package/lib/esm/test/ecsql/dataset/ECSqlDatasets.d.ts.map +1 -0
  819. package/lib/esm/test/ecsql/dataset/ECSqlDatasets.js +127 -0
  820. package/lib/esm/test/ecsql/dataset/ECSqlDatasets.js.map +1 -0
  821. package/lib/esm/test/ecsql/src/ECSqlTestGenerator.d.ts +2 -0
  822. package/lib/esm/test/ecsql/src/ECSqlTestGenerator.d.ts.map +1 -0
  823. package/lib/esm/test/ecsql/src/ECSqlTestGenerator.js +197 -0
  824. package/lib/esm/test/ecsql/src/ECSqlTestGenerator.js.map +1 -0
  825. package/lib/esm/test/ecsql/src/ECSqlTestParser.d.ts +66 -0
  826. package/lib/esm/test/ecsql/src/ECSqlTestParser.d.ts.map +1 -0
  827. package/lib/esm/test/ecsql/src/ECSqlTestParser.js +420 -0
  828. package/lib/esm/test/ecsql/src/ECSqlTestParser.js.map +1 -0
  829. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.d.ts +2 -0
  830. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.d.ts.map +1 -0
  831. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.js +369 -0
  832. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.js.map +1 -0
  833. package/lib/esm/test/element/DeleteDefinitionElements.test.d.ts +2 -0
  834. package/lib/esm/test/element/DeleteDefinitionElements.test.d.ts.map +1 -0
  835. package/lib/esm/test/element/DeleteDefinitionElements.test.js +208 -0
  836. package/lib/esm/test/element/DeleteDefinitionElements.test.js.map +1 -0
  837. package/lib/esm/test/element/ElementAspect.test.d.ts +2 -0
  838. package/lib/esm/test/element/ElementAspect.test.d.ts.map +1 -0
  839. package/lib/esm/test/element/ElementAspect.test.js +363 -0
  840. package/lib/esm/test/element/ElementAspect.test.js.map +1 -0
  841. package/lib/esm/test/element/ElementDependencyGraph.test.d.ts +2 -0
  842. package/lib/esm/test/element/ElementDependencyGraph.test.d.ts.map +1 -0
  843. package/lib/esm/test/element/ElementDependencyGraph.test.js +383 -0
  844. package/lib/esm/test/element/ElementDependencyGraph.test.js.map +1 -0
  845. package/lib/esm/test/element/ElementRoundTrip.test.d.ts +2 -0
  846. package/lib/esm/test/element/ElementRoundTrip.test.d.ts.map +1 -0
  847. package/lib/esm/test/element/ElementRoundTrip.test.js +926 -0
  848. package/lib/esm/test/element/ElementRoundTrip.test.js.map +1 -0
  849. package/lib/esm/test/element/ExcludedElements.test.d.ts +2 -0
  850. package/lib/esm/test/element/ExcludedElements.test.d.ts.map +1 -0
  851. package/lib/esm/test/element/ExcludedElements.test.js +57 -0
  852. package/lib/esm/test/element/ExcludedElements.test.js.map +1 -0
  853. package/lib/esm/test/element/ExternalSource.test.d.ts +2 -0
  854. package/lib/esm/test/element/ExternalSource.test.d.ts.map +1 -0
  855. package/lib/esm/test/element/ExternalSource.test.js +107 -0
  856. package/lib/esm/test/element/ExternalSource.test.js.map +1 -0
  857. package/lib/esm/test/element/NullStructArray.test.d.ts +2 -0
  858. package/lib/esm/test/element/NullStructArray.test.d.ts.map +1 -0
  859. package/lib/esm/test/element/NullStructArray.test.js +77 -0
  860. package/lib/esm/test/element/NullStructArray.test.js.map +1 -0
  861. package/lib/esm/test/element/UrlLink.test.d.ts +2 -0
  862. package/lib/esm/test/element/UrlLink.test.d.ts.map +1 -0
  863. package/lib/esm/test/element/UrlLink.test.js +36 -0
  864. package/lib/esm/test/element/UrlLink.test.js.map +1 -0
  865. package/lib/esm/test/font/FontFile.test.d.ts +2 -0
  866. package/lib/esm/test/font/FontFile.test.d.ts.map +1 -0
  867. package/lib/esm/test/font/FontFile.test.js +139 -0
  868. package/lib/esm/test/font/FontFile.test.js.map +1 -0
  869. package/lib/esm/test/font/IModelDbFonts.test.d.ts +2 -0
  870. package/lib/esm/test/font/IModelDbFonts.test.d.ts.map +1 -0
  871. package/lib/esm/test/font/IModelDbFonts.test.js +266 -0
  872. package/lib/esm/test/font/IModelDbFonts.test.js.map +1 -0
  873. package/lib/esm/test/hubaccess/BriefcaseManager.test.d.ts +2 -0
  874. package/lib/esm/test/hubaccess/BriefcaseManager.test.d.ts.map +1 -0
  875. package/lib/esm/test/hubaccess/BriefcaseManager.test.js +176 -0
  876. package/lib/esm/test/hubaccess/BriefcaseManager.test.js.map +1 -0
  877. package/lib/esm/test/hubaccess/CheckpointManager.test.d.ts +2 -0
  878. package/lib/esm/test/hubaccess/CheckpointManager.test.d.ts.map +1 -0
  879. package/lib/esm/test/hubaccess/CheckpointManager.test.js +52 -0
  880. package/lib/esm/test/hubaccess/CheckpointManager.test.js.map +1 -0
  881. package/lib/esm/test/imageData.d.ts +9 -0
  882. package/lib/esm/test/imageData.d.ts.map +1 -0
  883. package/lib/esm/test/imageData.js +16 -0
  884. package/lib/esm/test/imageData.js.map +1 -0
  885. package/lib/esm/test/imodel/ElementTreeWalker.test.d.ts +2 -0
  886. package/lib/esm/test/imodel/ElementTreeWalker.test.d.ts.map +1 -0
  887. package/lib/esm/test/imodel/ElementTreeWalker.test.js +383 -0
  888. package/lib/esm/test/imodel/ElementTreeWalker.test.js.map +1 -0
  889. package/lib/esm/test/imodel/GetTextureImage.test.d.ts +2 -0
  890. package/lib/esm/test/imodel/GetTextureImage.test.d.ts.map +1 -0
  891. package/lib/esm/test/imodel/GetTextureImage.test.js +29 -0
  892. package/lib/esm/test/imodel/GetTextureImage.test.js.map +1 -0
  893. package/lib/esm/test/imodel/IModel.test.d.ts +2 -0
  894. package/lib/esm/test/imodel/IModel.test.d.ts.map +1 -0
  895. package/lib/esm/test/imodel/IModel.test.js +2626 -0
  896. package/lib/esm/test/imodel/IModel.test.js.map +1 -0
  897. package/lib/esm/test/imodel/ProjectExtents.test.d.ts +2 -0
  898. package/lib/esm/test/imodel/ProjectExtents.test.d.ts.map +1 -0
  899. package/lib/esm/test/imodel/ProjectExtents.test.js +66 -0
  900. package/lib/esm/test/imodel/ProjectExtents.test.js.map +1 -0
  901. package/lib/esm/test/imodel/SchemaXmlImport.test.d.ts +2 -0
  902. package/lib/esm/test/imodel/SchemaXmlImport.test.d.ts.map +1 -0
  903. package/lib/esm/test/imodel/SchemaXmlImport.test.js +74 -0
  904. package/lib/esm/test/imodel/SchemaXmlImport.test.js.map +1 -0
  905. package/lib/esm/test/index.d.ts +7 -0
  906. package/lib/esm/test/index.d.ts.map +1 -0
  907. package/lib/esm/test/index.js +11 -0
  908. package/lib/esm/test/index.js.map +1 -0
  909. package/lib/esm/test/misc/DevTools.test.d.ts +2 -0
  910. package/lib/esm/test/misc/DevTools.test.d.ts.map +1 -0
  911. package/lib/esm/test/misc/DevTools.test.js +72 -0
  912. package/lib/esm/test/misc/DevTools.test.js.map +1 -0
  913. package/lib/esm/test/misc/EntitySubClasses.test.d.ts +2 -0
  914. package/lib/esm/test/misc/EntitySubClasses.test.d.ts.map +1 -0
  915. package/lib/esm/test/misc/EntitySubClasses.test.js +106 -0
  916. package/lib/esm/test/misc/EntitySubClasses.test.js.map +1 -0
  917. package/lib/esm/test/misc/GeoServices.test.d.ts +2 -0
  918. package/lib/esm/test/misc/GeoServices.test.d.ts.map +1 -0
  919. package/lib/esm/test/misc/GeoServices.test.js +850 -0
  920. package/lib/esm/test/misc/GeoServices.test.js.map +1 -0
  921. package/lib/esm/test/misc/PromiseMemoizer.test.d.ts +2 -0
  922. package/lib/esm/test/misc/PromiseMemoizer.test.d.ts.map +1 -0
  923. package/lib/esm/test/misc/PromiseMemoizer.test.js +111 -0
  924. package/lib/esm/test/misc/PromiseMemoizer.test.js.map +1 -0
  925. package/lib/esm/test/native/DgnDbWorker.test.d.ts +2 -0
  926. package/lib/esm/test/native/DgnDbWorker.test.d.ts.map +1 -0
  927. package/lib/esm/test/native/DgnDbWorker.test.js +159 -0
  928. package/lib/esm/test/native/DgnDbWorker.test.js.map +1 -0
  929. package/lib/esm/test/rpc/response.test.d.ts +2 -0
  930. package/lib/esm/test/rpc/response.test.d.ts.map +1 -0
  931. package/lib/esm/test/rpc/response.test.js +112 -0
  932. package/lib/esm/test/rpc/response.test.js.map +1 -0
  933. package/lib/esm/test/schema/ClassRegistry.test.d.ts +2 -0
  934. package/lib/esm/test/schema/ClassRegistry.test.d.ts.map +1 -0
  935. package/lib/esm/test/schema/ClassRegistry.test.js +679 -0
  936. package/lib/esm/test/schema/ClassRegistry.test.js.map +1 -0
  937. package/lib/esm/test/schema/FunctionalDomain.test.d.ts +2 -0
  938. package/lib/esm/test/schema/FunctionalDomain.test.d.ts.map +1 -0
  939. package/lib/esm/test/schema/FunctionalDomain.test.js +490 -0
  940. package/lib/esm/test/schema/FunctionalDomain.test.js.map +1 -0
  941. package/lib/esm/test/schema/GenericDomain.test.d.ts +2 -0
  942. package/lib/esm/test/schema/GenericDomain.test.d.ts.map +1 -0
  943. package/lib/esm/test/schema/GenericDomain.test.js +133 -0
  944. package/lib/esm/test/schema/GenericDomain.test.js.map +1 -0
  945. package/lib/esm/test/schema/IModelSchemaContext.test.d.ts +2 -0
  946. package/lib/esm/test/schema/IModelSchemaContext.test.d.ts.map +1 -0
  947. package/lib/esm/test/schema/IModelSchemaContext.test.js +95 -0
  948. package/lib/esm/test/schema/IModelSchemaContext.test.js.map +1 -0
  949. package/lib/esm/test/sheetindex/SheetIndex.test.d.ts +4 -0
  950. package/lib/esm/test/sheetindex/SheetIndex.test.d.ts.map +1 -0
  951. package/lib/esm/test/sheetindex/SheetIndex.test.js +312 -0
  952. package/lib/esm/test/sheetindex/SheetIndex.test.js.map +1 -0
  953. package/lib/esm/test/standalone/ChangeMerge.test.d.ts +2 -0
  954. package/lib/esm/test/standalone/ChangeMerge.test.d.ts.map +1 -0
  955. package/lib/esm/test/standalone/ChangeMerge.test.js +409 -0
  956. package/lib/esm/test/standalone/ChangeMerge.test.js.map +1 -0
  957. package/lib/esm/test/standalone/ChangesetReader.test.d.ts +2 -0
  958. package/lib/esm/test/standalone/ChangesetReader.test.d.ts.map +1 -0
  959. package/lib/esm/test/standalone/ChangesetReader.test.js +891 -0
  960. package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -0
  961. package/lib/esm/test/standalone/CustomViewState3dCreator.test.d.ts +2 -0
  962. package/lib/esm/test/standalone/CustomViewState3dCreator.test.d.ts.map +1 -0
  963. package/lib/esm/test/standalone/CustomViewState3dCreator.test.js +49 -0
  964. package/lib/esm/test/standalone/CustomViewState3dCreator.test.js.map +1 -0
  965. package/lib/esm/test/standalone/DisplayStyle.test.d.ts +2 -0
  966. package/lib/esm/test/standalone/DisplayStyle.test.d.ts.map +1 -0
  967. package/lib/esm/test/standalone/DisplayStyle.test.js +136 -0
  968. package/lib/esm/test/standalone/DisplayStyle.test.js.map +1 -0
  969. package/lib/esm/test/standalone/Drawing.test.d.ts +2 -0
  970. package/lib/esm/test/standalone/Drawing.test.d.ts.map +1 -0
  971. package/lib/esm/test/standalone/Drawing.test.js +120 -0
  972. package/lib/esm/test/standalone/Drawing.test.js.map +1 -0
  973. package/lib/esm/test/standalone/ElementGraphics.test.d.ts +2 -0
  974. package/lib/esm/test/standalone/ElementGraphics.test.d.ts.map +1 -0
  975. package/lib/esm/test/standalone/ElementGraphics.test.js +127 -0
  976. package/lib/esm/test/standalone/ElementGraphics.test.js.map +1 -0
  977. package/lib/esm/test/standalone/ElementMesh.test.d.ts +2 -0
  978. package/lib/esm/test/standalone/ElementMesh.test.d.ts.map +1 -0
  979. package/lib/esm/test/standalone/ElementMesh.test.js +142 -0
  980. package/lib/esm/test/standalone/ElementMesh.test.js.map +1 -0
  981. package/lib/esm/test/standalone/ExportGraphics.test.d.ts +2 -0
  982. package/lib/esm/test/standalone/ExportGraphics.test.d.ts.map +1 -0
  983. package/lib/esm/test/standalone/ExportGraphics.test.js +1005 -0
  984. package/lib/esm/test/standalone/ExportGraphics.test.js.map +1 -0
  985. package/lib/esm/test/standalone/GeometryChangeEvents.test.d.ts +2 -0
  986. package/lib/esm/test/standalone/GeometryChangeEvents.test.d.ts.map +1 -0
  987. package/lib/esm/test/standalone/GeometryChangeEvents.test.js +139 -0
  988. package/lib/esm/test/standalone/GeometryChangeEvents.test.js.map +1 -0
  989. package/lib/esm/test/standalone/GeometryStream.test.d.ts +2 -0
  990. package/lib/esm/test/standalone/GeometryStream.test.d.ts.map +1 -0
  991. package/lib/esm/test/standalone/GeometryStream.test.js +2869 -0
  992. package/lib/esm/test/standalone/GeometryStream.test.js.map +1 -0
  993. package/lib/esm/test/standalone/HubMock.test.d.ts +2 -0
  994. package/lib/esm/test/standalone/HubMock.test.d.ts.map +1 -0
  995. package/lib/esm/test/standalone/HubMock.test.js +343 -0
  996. package/lib/esm/test/standalone/HubMock.test.js.map +1 -0
  997. package/lib/esm/test/standalone/IModelWrite.test.d.ts +7 -0
  998. package/lib/esm/test/standalone/IModelWrite.test.d.ts.map +1 -0
  999. package/lib/esm/test/standalone/IModelWrite.test.js +907 -0
  1000. package/lib/esm/test/standalone/IModelWrite.test.js.map +1 -0
  1001. package/lib/esm/test/standalone/InlineGeometryPartReferences.test.d.ts +2 -0
  1002. package/lib/esm/test/standalone/InlineGeometryPartReferences.test.d.ts.map +1 -0
  1003. package/lib/esm/test/standalone/InlineGeometryPartReferences.test.js +417 -0
  1004. package/lib/esm/test/standalone/InlineGeometryPartReferences.test.js.map +1 -0
  1005. package/lib/esm/test/standalone/MergeConflict.test.d.ts +7 -0
  1006. package/lib/esm/test/standalone/MergeConflict.test.d.ts.map +1 -0
  1007. package/lib/esm/test/standalone/MergeConflict.test.js +345 -0
  1008. package/lib/esm/test/standalone/MergeConflict.test.js.map +1 -0
  1009. package/lib/esm/test/standalone/NativeAppStorage.test.d.ts +2 -0
  1010. package/lib/esm/test/standalone/NativeAppStorage.test.d.ts.map +1 -0
  1011. package/lib/esm/test/standalone/NativeAppStorage.test.js +121 -0
  1012. package/lib/esm/test/standalone/NativeAppStorage.test.js.map +1 -0
  1013. package/lib/esm/test/standalone/RenderMaterialElement.test.d.ts +2 -0
  1014. package/lib/esm/test/standalone/RenderMaterialElement.test.d.ts.map +1 -0
  1015. package/lib/esm/test/standalone/RenderMaterialElement.test.js +399 -0
  1016. package/lib/esm/test/standalone/RenderMaterialElement.test.js.map +1 -0
  1017. package/lib/esm/test/standalone/RenderTimeline.test.d.ts +2 -0
  1018. package/lib/esm/test/standalone/RenderTimeline.test.d.ts.map +1 -0
  1019. package/lib/esm/test/standalone/RenderTimeline.test.js +71 -0
  1020. package/lib/esm/test/standalone/RenderTimeline.test.js.map +1 -0
  1021. package/lib/esm/test/standalone/SQLiteDb.test.d.ts +2 -0
  1022. package/lib/esm/test/standalone/SQLiteDb.test.d.ts.map +1 -0
  1023. package/lib/esm/test/standalone/SQLiteDb.test.js +63 -0
  1024. package/lib/esm/test/standalone/SQLiteDb.test.js.map +1 -0
  1025. package/lib/esm/test/standalone/SchemaUtils.test.d.ts +2 -0
  1026. package/lib/esm/test/standalone/SchemaUtils.test.d.ts.map +1 -0
  1027. package/lib/esm/test/standalone/SchemaUtils.test.js +25 -0
  1028. package/lib/esm/test/standalone/SchemaUtils.test.js.map +1 -0
  1029. package/lib/esm/test/standalone/SectionDrawing.test.d.ts +2 -0
  1030. package/lib/esm/test/standalone/SectionDrawing.test.d.ts.map +1 -0
  1031. package/lib/esm/test/standalone/SectionDrawing.test.js +83 -0
  1032. package/lib/esm/test/standalone/SectionDrawing.test.js.map +1 -0
  1033. package/lib/esm/test/standalone/ServerBasedLocks.test.d.ts +2 -0
  1034. package/lib/esm/test/standalone/ServerBasedLocks.test.d.ts.map +1 -0
  1035. package/lib/esm/test/standalone/ServerBasedLocks.test.js +279 -0
  1036. package/lib/esm/test/standalone/ServerBasedLocks.test.js.map +1 -0
  1037. package/lib/esm/test/standalone/Setting.test.d.ts +2 -0
  1038. package/lib/esm/test/standalone/Setting.test.d.ts.map +1 -0
  1039. package/lib/esm/test/standalone/Setting.test.js +76 -0
  1040. package/lib/esm/test/standalone/Setting.test.js.map +1 -0
  1041. package/lib/esm/test/standalone/Settings.test.d.ts +2 -0
  1042. package/lib/esm/test/standalone/Settings.test.d.ts.map +1 -0
  1043. package/lib/esm/test/standalone/Settings.test.js +349 -0
  1044. package/lib/esm/test/standalone/Settings.test.js.map +1 -0
  1045. package/lib/esm/test/standalone/SettingsSchemas.test.d.ts +2 -0
  1046. package/lib/esm/test/standalone/SettingsSchemas.test.d.ts.map +1 -0
  1047. package/lib/esm/test/standalone/SettingsSchemas.test.js +31 -0
  1048. package/lib/esm/test/standalone/SettingsSchemas.test.js.map +1 -0
  1049. package/lib/esm/test/standalone/SnapshotDb.test.d.ts +2 -0
  1050. package/lib/esm/test/standalone/SnapshotDb.test.d.ts.map +1 -0
  1051. package/lib/esm/test/standalone/SnapshotDb.test.js +156 -0
  1052. package/lib/esm/test/standalone/SnapshotDb.test.js.map +1 -0
  1053. package/lib/esm/test/standalone/Texture.test.d.ts +2 -0
  1054. package/lib/esm/test/standalone/Texture.test.d.ts.map +1 -0
  1055. package/lib/esm/test/standalone/Texture.test.js +90 -0
  1056. package/lib/esm/test/standalone/Texture.test.js.map +1 -0
  1057. package/lib/esm/test/standalone/TileCache.test.d.ts +9 -0
  1058. package/lib/esm/test/standalone/TileCache.test.d.ts.map +1 -0
  1059. package/lib/esm/test/standalone/TileCache.test.js +127 -0
  1060. package/lib/esm/test/standalone/TileCache.test.js.map +1 -0
  1061. package/lib/esm/test/standalone/TileTree.test.d.ts +2 -0
  1062. package/lib/esm/test/standalone/TileTree.test.d.ts.map +1 -0
  1063. package/lib/esm/test/standalone/TileTree.test.js +241 -0
  1064. package/lib/esm/test/standalone/TileTree.test.js.map +1 -0
  1065. package/lib/esm/test/standalone/TxnManager.test.d.ts +2 -0
  1066. package/lib/esm/test/standalone/TxnManager.test.d.ts.map +1 -0
  1067. package/lib/esm/test/standalone/TxnManager.test.js +878 -0
  1068. package/lib/esm/test/standalone/TxnManager.test.js.map +1 -0
  1069. package/lib/esm/test/standalone/ViewDefinition.test.d.ts +2 -0
  1070. package/lib/esm/test/standalone/ViewDefinition.test.d.ts.map +1 -0
  1071. package/lib/esm/test/standalone/ViewDefinition.test.js +279 -0
  1072. package/lib/esm/test/standalone/ViewDefinition.test.js.map +1 -0
  1073. package/lib/esm/test/standalone/ViewStoreDb.test.d.ts +2 -0
  1074. package/lib/esm/test/standalone/ViewStoreDb.test.d.ts.map +1 -0
  1075. package/lib/esm/test/standalone/ViewStoreDb.test.js +288 -0
  1076. package/lib/esm/test/standalone/ViewStoreDb.test.js.map +1 -0
  1077. package/lib/esm/test/standalone/Workspace.test.d.ts +2 -0
  1078. package/lib/esm/test/standalone/Workspace.test.d.ts.map +1 -0
  1079. package/lib/esm/test/standalone/Workspace.test.js +162 -0
  1080. package/lib/esm/test/standalone/Workspace.test.js.map +1 -0
  1081. package/lib/esm/workspace/Settings.d.ts +216 -0
  1082. package/lib/esm/workspace/Settings.d.ts.map +1 -0
  1083. package/lib/esm/workspace/Settings.js +83 -0
  1084. package/lib/esm/workspace/Settings.js.map +1 -0
  1085. package/lib/esm/workspace/SettingsSchemas.d.ts +135 -0
  1086. package/lib/esm/workspace/SettingsSchemas.d.ts.map +1 -0
  1087. package/lib/esm/workspace/SettingsSchemas.js +9 -0
  1088. package/lib/esm/workspace/SettingsSchemas.js.map +1 -0
  1089. package/lib/esm/workspace/Workspace.d.ts +500 -0
  1090. package/lib/esm/workspace/Workspace.d.ts.map +1 -0
  1091. package/lib/esm/workspace/Workspace.js +97 -0
  1092. package/lib/esm/workspace/Workspace.js.map +1 -0
  1093. package/lib/esm/workspace/WorkspaceEditor.d.ts +240 -0
  1094. package/lib/esm/workspace/WorkspaceEditor.d.ts.map +1 -0
  1095. package/lib/esm/workspace/WorkspaceEditor.js +31 -0
  1096. package/lib/esm/workspace/WorkspaceEditor.js.map +1 -0
  1097. package/package.json +37 -29
  1098. package/lib/cjs/HubMock.d.ts.map +0 -1
  1099. package/lib/cjs/HubMock.js.map +0 -1
  1100. package/lib/cjs/IModelCloneContext.d.ts +0 -9
  1101. package/lib/cjs/IModelCloneContext.d.ts.map +0 -1
  1102. package/lib/cjs/IModelCloneContext.js.map +0 -1
@@ -0,0 +1,3327 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module iModels
7
+ */
8
+ import * as fs from "fs";
9
+ import { join } from "path";
10
+ import * as touch from "touch";
11
+ import { assert, BeEvent, BentleyStatus, ChangeSetStatus, DbChangeStage, DbConflictCause, DbConflictResolution, DbResult, Guid, Id64, IModelStatus, JsonUtils, Logger, LogLevel, LRUMap, OpenMode } from "@itwin/core-bentley";
12
+ import { BriefcaseIdValue, Code, DomainOptions, ECJsNames, ECSqlReader, EntityMetaData, FontMap, IModel, IModelError, IModelNotFoundResponse, ProfileOptions, QueryRowFormat, SchemaState, ViewStoreRpc } from "@itwin/core-common";
13
+ import { Range2d, Range3d } from "@itwin/core-geometry";
14
+ import { BackendLoggerCategory } from "./BackendLoggerCategory";
15
+ import { BriefcaseManager } from "./BriefcaseManager";
16
+ import { ChannelControl } from "./ChannelControl";
17
+ import { createChannelControl } from "./internal/ChannelAdmin";
18
+ import { CheckpointManager, V2CheckpointManager } from "./CheckpointManager";
19
+ import { ClassRegistry, EntityJsClassMap, MetaDataRegistry } from "./ClassRegistry";
20
+ import { CloudSqlite } from "./CloudSqlite";
21
+ import { CodeService } from "./CodeService";
22
+ import { CodeSpecs } from "./CodeSpecs";
23
+ import { ConcurrentQuery } from "./ConcurrentQuery";
24
+ import { ECSqlStatement } from "./ECSqlStatement";
25
+ import { Element } from "./Element";
26
+ import { generateElementGraphics } from "./ElementGraphics";
27
+ import { Entity } from "./Entity";
28
+ import { GeoCoordConfig } from "./GeoCoordConfig";
29
+ import { IModelHost } from "./IModelHost";
30
+ import { IModelJsFs } from "./IModelJsFs";
31
+ import { IpcHost } from "./IpcHost";
32
+ import { Model } from "./Model";
33
+ import { Relationships } from "./Relationship";
34
+ import { SchemaSync } from "./SchemaSync";
35
+ import { createServerBasedLocks } from "./internal/ServerBasedLocks";
36
+ import { SqliteStatement, StatementCache } from "./SqliteStatement";
37
+ import { TxnManager } from "./TxnManager";
38
+ import { DrawingViewDefinition, SheetViewDefinition, ViewDefinition } from "./ViewDefinition";
39
+ import { ViewStore } from "./ViewStore";
40
+ import { SettingsPriority } from "./workspace/Settings";
41
+ import { Workspace, WorkspaceSettingNames } from "./workspace/Workspace";
42
+ import { constructWorkspace, throwWorkspaceDbLoadErrors } from "./internal/workspace/WorkspaceImpl";
43
+ import { SettingsImpl } from "./internal/workspace/SettingsImpl";
44
+ import { IModelNative } from "./internal/NativePlatform";
45
+ import { createNoOpLockControl } from "./internal/NoLocks";
46
+ import { createIModelDbFonts } from "./internal/IModelDbFontsImpl";
47
+ import { _cache, _close, _hubAccess, _nativeDb, _releaseAllLocks } from "./internal/Symbols";
48
+ import { SchemaContext, SchemaJsonLocater } from "@itwin/ecschema-metadata";
49
+ import { SchemaMap } from "./Schema";
50
+ import { ElementLRUCache } from "./internal/ElementLRUCache";
51
+ // spell:ignore fontid fontmap
52
+ const loggerCategory = BackendLoggerCategory.IModelDb;
53
+ /** @internal */
54
+ export var BriefcaseLocalValue;
55
+ (function (BriefcaseLocalValue) {
56
+ BriefcaseLocalValue["StandaloneEdit"] = "StandaloneEdit";
57
+ BriefcaseLocalValue["NoLocking"] = "NoLocking";
58
+ })(BriefcaseLocalValue || (BriefcaseLocalValue = {}));
59
+ // function to open an briefcaseDb, perform an operation, and then close it.
60
+ const withBriefcaseDb = async (briefcase, fn) => {
61
+ const db = await BriefcaseDb.open(briefcase);
62
+ try {
63
+ return await fn(db);
64
+ }
65
+ finally {
66
+ db.close();
67
+ }
68
+ };
69
+ /**
70
+ * Settings for an individual iModel. May only include settings priority for iModel, iTwin and organization.
71
+ * @note if there is more than one iModel for an iTwin or organization, they will *each* hold an independent copy of the settings for those priorities.
72
+ */
73
+ class IModelSettings extends SettingsImpl {
74
+ verifyPriority(priority) {
75
+ if (priority <= SettingsPriority.application)
76
+ throw new Error("Use IModelHost.appSettings to access settings of priority 'application' or lower");
77
+ }
78
+ *getSettingEntries(name) {
79
+ yield* super.getSettingEntries(name);
80
+ yield* IModelHost.appWorkspace.settings.getSettingEntries(name);
81
+ }
82
+ }
83
+ /** An iModel database file. The database file can either be a briefcase or a snapshot.
84
+ * @see [Accessing iModels]($docs/learning/backend/AccessingIModels.md)
85
+ * @see [About IModelDb]($docs/learning/backend/IModelDb.md)
86
+ * @public
87
+ */
88
+ export class IModelDb extends IModel {
89
+ _initialized = false;
90
+ /** Keep track of open imodels to support `tryFind` for RPC purposes */
91
+ static _openDbs = new Map();
92
+ static defaultLimit = 1000; // default limit for batching queries
93
+ static maxLimit = 10000; // maximum limit for batching queries
94
+ models = new IModelDb.Models(this);
95
+ elements = new IModelDb.Elements(this);
96
+ views = new IModelDb.Views(this);
97
+ tiles = new IModelDb.Tiles(this);
98
+ /** @beta */
99
+ channels = createChannelControl(this);
100
+ _relationships;
101
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
102
+ _statementCache = new StatementCache();
103
+ _sqliteStatementCache = new StatementCache();
104
+ _codeSpecs;
105
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
106
+ _classMetaDataRegistry;
107
+ _jsClassMap;
108
+ _schemaMap;
109
+ _schemaContext;
110
+ /** @deprecated in 5.0.0. Use [[fonts]]. */
111
+ _fontMap; // eslint-disable-line @typescript-eslint/no-deprecated
112
+ _fonts = createIModelDbFonts(this);
113
+ _workspace;
114
+ _snaps = new Map();
115
+ static _shutdownListener; // so we only register listener once
116
+ /** @internal */
117
+ _locks = createNoOpLockControl();
118
+ /** @internal */
119
+ _codeService;
120
+ /** @alpha */
121
+ get codeService() { return this._codeService; }
122
+ /** The [[LockControl]] that orchestrates [concurrent editing]($docs/learning/backend/ConcurrencyControl.md) of this iModel. */
123
+ get locks() { return this._locks; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
124
+ /** Provides methods for interacting with [font-related information]($docs/learning/backend/Fonts.md) stored in this iModel.
125
+ * @beta
126
+ */
127
+ get fonts() { return this._fonts; }
128
+ /**
129
+ * Get the [[Workspace]] for this iModel.
130
+ * @beta
131
+ */
132
+ get workspace() {
133
+ if (undefined === this._workspace)
134
+ this._workspace = constructWorkspace(new IModelSettings());
135
+ return this._workspace;
136
+ }
137
+ /**
138
+ * get the cloud container for this iModel, if it was opened from one
139
+ * @beta
140
+ */
141
+ get cloudContainer() {
142
+ return this[_nativeDb].cloudContainer;
143
+ }
144
+ /** Acquire the exclusive schema lock on this iModel.
145
+ * @note: To acquire the schema lock, all other briefcases must first release *all* their locks. No other briefcases
146
+ * will be able to acquire *any* locks while the schema lock is held.
147
+ */
148
+ async acquireSchemaLock() {
149
+ return this.locks.acquireLocks({ exclusive: IModel.repositoryModelId });
150
+ }
151
+ /** determine whether the schema lock is currently held for this iModel. */
152
+ get holdsSchemaLock() {
153
+ return this.locks.holdsExclusiveLock(IModel.repositoryModelId);
154
+ }
155
+ /** Event called after a changeset is applied to this IModelDb. */
156
+ onChangesetApplied = new BeEvent();
157
+ /** @internal */
158
+ notifyChangesetApplied() {
159
+ this.changeset = this[_nativeDb].getCurrentChangeset();
160
+ this.onChangesetApplied.raiseEvent();
161
+ }
162
+ /** @internal */
163
+ restartDefaultTxn() {
164
+ this[_nativeDb].restartDefaultTxn();
165
+ }
166
+ /** @deprecated in 5.0.0. Use [[fonts]]. */
167
+ get fontMap() {
168
+ return this._fontMap ?? (this._fontMap = new FontMap(this[_nativeDb].readFontMap())); // eslint-disable-line @typescript-eslint/no-deprecated
169
+ }
170
+ /** @internal */
171
+ clearFontMap() {
172
+ this._fontMap = undefined; // eslint-disable-line @typescript-eslint/no-deprecated
173
+ this[_nativeDb].invalidateFontMap();
174
+ }
175
+ /** Check if this iModel has been opened read-only or not. */
176
+ get isReadonly() { return this.openMode === OpenMode.Readonly; }
177
+ /** The Guid that identifies this iModel. */
178
+ get iModelId() {
179
+ assert(undefined !== super.iModelId);
180
+ return super.iModelId;
181
+ } // GuidString | undefined for the IModel superclass, but required for all IModelDb subclasses
182
+ /** @internal*/
183
+ [_nativeDb];
184
+ /** Get the full path fileName of this iModelDb
185
+ * @note this member is only valid while the iModel is opened.
186
+ */
187
+ get pathName() { return this[_nativeDb].getFilePath(); }
188
+ /** Get the full path to this iModel's "watch file".
189
+ * A read-only briefcase opened with `watchForChanges: true` creates this file next to the briefcase file on open, if it doesn't already exist.
190
+ * A writable briefcase "touches" this file if it exists whenever it commits changes to the briefcase.
191
+ * The read-only briefcase can use a file watcher to react when the writable briefcase makes changes to the briefcase.
192
+ * This is more reliable than watching the sqlite WAL file.
193
+ * @internal
194
+ */
195
+ get watchFilePathName() { return `${this.pathName}-watch`; }
196
+ /** @internal */
197
+ constructor(args) {
198
+ super({ ...args, iTwinId: args.nativeDb.getITwinId(), iModelId: args.nativeDb.getIModelId() });
199
+ this[_nativeDb] = args.nativeDb;
200
+ // it is illegal to create an IModelDb unless the nativeDb has been opened. Throw otherwise.
201
+ if (!this.isOpen)
202
+ throw new Error("cannot create an IModelDb unless it has already been opened");
203
+ // PR https://github.com/iTwin/imodel-native/pull/558 renamed closeIModel to closeFile because it changed its behavior.
204
+ // Ideally, nobody outside of core-backend would be calling it, but somebody important is.
205
+ // Make closeIModel available so their code doesn't break.
206
+ this[_nativeDb].closeIModel = () => {
207
+ if (!this.isReadonly)
208
+ this.saveChanges(); // preserve old behavior of closeIModel that was removed when renamed to closeFile
209
+ this[_nativeDb].closeFile();
210
+ };
211
+ this[_nativeDb].setIModelDb(this);
212
+ this.loadIModelSettings();
213
+ GeoCoordConfig.loadForImodel(this.workspace.settings); // load gcs data specified by iModel's settings dictionaries, must be done before calling initializeIModelDb
214
+ this.initializeIModelDb();
215
+ IModelDb._openDbs.set(this._fileKey, this);
216
+ if (undefined === IModelDb._shutdownListener) { // the first time we create an IModelDb, add a listener to close any orphan files at shutdown.
217
+ IModelDb._shutdownListener = IModelHost.onBeforeShutdown.addListener(() => {
218
+ IModelDb._openDbs.forEach((db) => {
219
+ try {
220
+ db.abandonChanges();
221
+ db.close();
222
+ }
223
+ catch { }
224
+ });
225
+ });
226
+ }
227
+ }
228
+ /**
229
+ * Attach an iModel file to this connection and load and register its schemas.
230
+ * @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'
231
+ * @param fileName IModel file name
232
+ * @param alias identifier for the attached file. This identifer is used to access schema from the attached file. e.g. if alias is 'abc' then schema can be accessed using 'abc.MySchema.MyClass'
233
+ *
234
+ * *Example:*
235
+ * ``` ts
236
+ * [[include:IModelDb_attachDb.code]]
237
+ * ```
238
+ */
239
+ attachDb(fileName, alias) {
240
+ if (alias.toLowerCase() === "main" || alias.toLowerCase() === "schema_sync_db" || alias.toLowerCase() === "ecchange" || alias.toLowerCase() === "temp") {
241
+ throw new IModelError(DbResult.BE_SQLITE_ERROR, "Reserved tablespace name cannot be used");
242
+ }
243
+ this[_nativeDb].attachDb(fileName, alias);
244
+ }
245
+ /**
246
+ * Detach the attached file from this connection. The attached file is closed and its schemas are unregistered.
247
+ * @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'
248
+ * @param alias identifer that was used in the call to [[attachDb]]
249
+ *
250
+ * *Example:*
251
+ * ``` ts
252
+ * [[include:IModelDb_attachDb.code]]
253
+ * ```
254
+ */
255
+ detachDb(alias) {
256
+ if (alias.toLowerCase() === "main" || alias.toLowerCase() === "schema_sync_db" || alias.toLowerCase() === "ecchange" || alias.toLowerCase() === "temp") {
257
+ throw new IModelError(DbResult.BE_SQLITE_ERROR, "Reserved tablespace name cannot be used");
258
+ }
259
+ this.clearCaches();
260
+ this[_nativeDb].detachDb(alias);
261
+ }
262
+ /** Close this IModel, if it is currently open, and save changes if it was opened in ReadWrite mode. */
263
+ close() {
264
+ if (!this.isOpen)
265
+ return; // don't continue if already closed
266
+ this.beforeClose();
267
+ IModelDb._openDbs.delete(this._fileKey);
268
+ this._workspace?.close();
269
+ this.locks[_close]();
270
+ this._locks = undefined;
271
+ this._codeService?.close();
272
+ this._codeService = undefined;
273
+ if (!this.isReadonly)
274
+ this.saveChanges();
275
+ this[_nativeDb].closeFile();
276
+ }
277
+ /** @internal */
278
+ async refreshContainerForRpc(_userAccessToken) { }
279
+ /** Event called when the iModel is about to be closed. */
280
+ onBeforeClose = new BeEvent();
281
+ /**
282
+ * Called by derived classes before closing the connection
283
+ * @internal
284
+ */
285
+ beforeClose() {
286
+ this.onBeforeClose.raiseEvent();
287
+ this.clearCaches();
288
+ }
289
+ /** @internal */
290
+ initializeIModelDb(when) {
291
+ const props = this[_nativeDb].getIModelProps(when);
292
+ super.initialize(props.rootSubject.name, props);
293
+ if (this._initialized)
294
+ return;
295
+ this._initialized = true;
296
+ const db = this.isBriefcaseDb() ? this : undefined;
297
+ if (!db || !IpcHost.isValid)
298
+ return;
299
+ db.onNameChanged.addListener(() => IpcHost.notifyTxns(db, "notifyIModelNameChanged", db.name));
300
+ db.onRootSubjectChanged.addListener(() => IpcHost.notifyTxns(db, "notifyRootSubjectChanged", db.rootSubject));
301
+ db.onProjectExtentsChanged.addListener(() => IpcHost.notifyTxns(db, "notifyProjectExtentsChanged", db.projectExtents.toJSON()));
302
+ db.onGlobalOriginChanged.addListener(() => IpcHost.notifyTxns(db, "notifyGlobalOriginChanged", db.globalOrigin.toJSON()));
303
+ db.onEcefLocationChanged.addListener(() => IpcHost.notifyTxns(db, "notifyEcefLocationChanged", db.ecefLocation?.toJSON()));
304
+ db.onGeographicCoordinateSystemChanged.addListener(() => IpcHost.notifyTxns(db, "notifyGeographicCoordinateSystemChanged", db.geographicCoordinateSystem?.toJSON()));
305
+ }
306
+ /** Returns true if this is a BriefcaseDb
307
+ * @see [[BriefcaseDb.open]]
308
+ */
309
+ get isBriefcase() { return false; }
310
+ /** Type guard for instanceof [[BriefcaseDb]] */
311
+ isBriefcaseDb() { return this.isBriefcase; }
312
+ /** Returns true if this is a SnapshotDb
313
+ * @see [[SnapshotDb.open]]
314
+ */
315
+ get isSnapshot() { return false; }
316
+ /** Type guard for instanceof [[SnapshotDb]] */
317
+ isSnapshotDb() { return this.isSnapshot; }
318
+ /** Returns true if this is a *standalone* iModel
319
+ * @see [[StandaloneDb.open]]
320
+ * @internal
321
+ */
322
+ get isStandalone() { return false; }
323
+ /** Type guard for instanceof [[StandaloneDb]]. */
324
+ isStandaloneDb() { return this.isStandalone; }
325
+ /** Return `true` if the underlying nativeDb is open and valid.
326
+ * @internal
327
+ */
328
+ get isOpen() { return this[_nativeDb].isOpen(); }
329
+ /** Get the briefcase Id of this iModel */
330
+ getBriefcaseId() { return this.isOpen ? this[_nativeDb].getBriefcaseId() : BriefcaseIdValue.Illegal; }
331
+ /**
332
+ * Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist
333
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
334
+ * in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be
335
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
336
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].
337
+ * @param sql The SQLite SQL statement to execute
338
+ * @param callback the callback to invoke on the prepared statement
339
+ * @param logErrors Determines if error will be logged if statement fail to prepare
340
+ * @returns the value returned by `callback`.
341
+ * @see [[withStatement]]
342
+ * @public
343
+ * @deprecated in 4.11. Use [[createQueryReader]] instead.
344
+ */
345
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
346
+ withPreparedStatement(ecsql, callback, logErrors = true) {
347
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
348
+ const stmt = this._statementCache.findAndRemove(ecsql) ?? this.prepareStatement(ecsql, logErrors);
349
+ const release = () => this._statementCache.addOrDispose(stmt);
350
+ try {
351
+ const val = callback(stmt);
352
+ if (val instanceof Promise) {
353
+ val.then(release, release);
354
+ }
355
+ else {
356
+ release();
357
+ }
358
+ return val;
359
+ }
360
+ catch (err) {
361
+ release();
362
+ throw err;
363
+ }
364
+ }
365
+ /**
366
+ * Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.
367
+ * Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.
368
+ * For statements that will be reused often, instead use [[withPreparedStatement]].
369
+ * @param sql The SQLite SQL statement to execute
370
+ * @param callback the callback to invoke on the prepared statement
371
+ * @param logErrors Determines if error will be logged if statement fail to prepare
372
+ * @returns the value returned by `callback`.
373
+ * @see [[withPreparedStatement]]
374
+ * @public
375
+ * @deprecated in 4.11. Use [[createQueryReader]] instead.
376
+ */
377
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
378
+ withStatement(ecsql, callback, logErrors = true) {
379
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
380
+ const stmt = this.prepareStatement(ecsql, logErrors);
381
+ const release = () => stmt[Symbol.dispose]();
382
+ try {
383
+ const val = callback(stmt);
384
+ if (val instanceof Promise) {
385
+ val.then(release, release);
386
+ }
387
+ else {
388
+ release();
389
+ }
390
+ return val;
391
+ }
392
+ catch (err) {
393
+ release();
394
+ throw err;
395
+ }
396
+ }
397
+ /** Allow to execute query and read results along with meta data. The result are streamed.
398
+ *
399
+ * See also:
400
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
401
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
402
+ * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)
403
+ *
404
+ * @param params The values to bind to the parameters (if the ECSQL has any).
405
+ * @param config Allow to specify certain flags which control how query is executed.
406
+ * @returns Returns an [ECSqlReader]($common) which helps iterate over the result set and also give access to metadata.
407
+ * @public
408
+ * */
409
+ createQueryReader(ecsql, params, config) {
410
+ if (!this[_nativeDb].isOpen())
411
+ throw new IModelError(DbResult.BE_SQLITE_ERROR, "db not open");
412
+ const executor = {
413
+ execute: async (request) => {
414
+ return ConcurrentQuery.executeQueryRequest(this[_nativeDb], request);
415
+ },
416
+ };
417
+ return new ECSqlReader(executor, ecsql, params, config);
418
+ }
419
+ /**
420
+ * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
421
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
422
+ * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
423
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
424
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
425
+ * @param sql The SQLite SQL statement to execute
426
+ * @param callback the callback to invoke on the prepared statement
427
+ * @param logErrors Determine if errors are logged or not
428
+ * @returns the value returned by `callback`.
429
+ * @see [[withPreparedStatement]]
430
+ * @public
431
+ */
432
+ withPreparedSqliteStatement(sql, callback, logErrors = true) {
433
+ const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql, logErrors);
434
+ const release = () => this._sqliteStatementCache.addOrDispose(stmt);
435
+ try {
436
+ const val = callback(stmt);
437
+ if (val instanceof Promise) {
438
+ val.then(release, release);
439
+ }
440
+ else {
441
+ release();
442
+ }
443
+ return val;
444
+ }
445
+ catch (err) {
446
+ release();
447
+ throw err;
448
+ }
449
+ }
450
+ /**
451
+ * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
452
+ * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
453
+ * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
454
+ * @param sql The SQLite SQL statement to execute
455
+ * @param callback the callback to invoke on the prepared statement
456
+ * @param logErrors Determine if errors are logged or not
457
+ * @returns the value returned by `callback`.
458
+ * @public
459
+ */
460
+ withSqliteStatement(sql, callback, logErrors = true) {
461
+ const stmt = this.prepareSqliteStatement(sql, logErrors);
462
+ const release = () => stmt[Symbol.dispose]();
463
+ try {
464
+ const val = callback(stmt);
465
+ if (val instanceof Promise) {
466
+ val.then(release, release);
467
+ }
468
+ else {
469
+ release();
470
+ }
471
+ return val;
472
+ }
473
+ catch (err) {
474
+ release();
475
+ throw err;
476
+ }
477
+ }
478
+ /** Prepare an SQL statement.
479
+ * @param sql The SQL statement to prepare
480
+ * @throws [[IModelError]] if there is a problem preparing the statement.
481
+ * @internal
482
+ */
483
+ prepareSqliteStatement(sql, logErrors = true) {
484
+ const stmt = new SqliteStatement(sql);
485
+ stmt.prepare(this[_nativeDb], logErrors);
486
+ return stmt;
487
+ }
488
+ /**
489
+ * queries the BisCore.SubCategory table for entries that are children of used spatial categories and 3D elements.
490
+ * @returns array of SubCategoryResultRow
491
+ * @internal
492
+ */
493
+ async queryAllUsedSpatialSubCategories() {
494
+ const result = [];
495
+ const parentCategoriesQuery = `SELECT DISTINCT Category.Id AS id FROM BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId FROM BisCore.SpatialCategory)`;
496
+ const parentCategories = [];
497
+ for await (const row of this.createQueryReader(parentCategoriesQuery)) {
498
+ parentCategories.push(row.id);
499
+ }
500
+ ;
501
+ const where = [...parentCategories].join(",");
502
+ const query = `SELECT ECInstanceId as id, Parent.Id as parentId, Properties as appearance FROM BisCore.SubCategory WHERE Parent.Id IN (${where})`;
503
+ try {
504
+ for await (const row of this.createQueryReader(query, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
505
+ result.push(row.toRow());
506
+ }
507
+ }
508
+ catch {
509
+ // We can ignore the error here, and just return whatever we were able to query.
510
+ }
511
+ return result;
512
+ }
513
+ /**
514
+ * queries the BisCore.SubCategory table for the entries that are children of the passed categoryIds.
515
+ * @param categoryIds categoryIds to query
516
+ * @returns array of SubCategoryResultRow
517
+ * @internal
518
+ */
519
+ async querySubCategories(categoryIds) {
520
+ const result = [];
521
+ const where = [...categoryIds].join(",");
522
+ const query = `SELECT ECInstanceId as id, Parent.Id as parentId, Properties as appearance FROM BisCore.SubCategory WHERE Parent.Id IN (${where})`;
523
+ try {
524
+ for await (const row of this.createQueryReader(query, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
525
+ result.push(row.toRow());
526
+ }
527
+ }
528
+ catch {
529
+ // We can ignore the error here, and just return whatever we were able to query.
530
+ }
531
+ return result;
532
+ }
533
+ /** Query for a set of entity ids, given an EntityQueryParams
534
+ * @param params The query parameters. The `limit` and `offset` members should be used to page results.
535
+ * @returns an Id64Set with results of query
536
+ * @throws [[IModelError]] if the generated statement is invalid or [IModelDb.maxLimit]($backend) exceeded when collecting ids.
537
+ *
538
+ * *Example:*
539
+ * ``` ts
540
+ * [[include:ECSQL-backend-queries.select-element-by-code-value-using-queryEntityIds]]
541
+ * ```
542
+ */
543
+ queryEntityIds(params) {
544
+ let sql = "SELECT ECInstanceId FROM ";
545
+ if (params.only)
546
+ sql += "ONLY ";
547
+ sql += params.from;
548
+ if (params.where)
549
+ sql += ` WHERE ${params.where}`;
550
+ if (params.orderBy)
551
+ sql += ` ORDER BY ${params.orderBy}`;
552
+ if (typeof params.limit === "number" && params.limit > 0)
553
+ sql += ` LIMIT ${params.limit}`;
554
+ if (typeof params.offset === "number" && params.offset > 0)
555
+ sql += ` OFFSET ${params.offset}`;
556
+ const ids = new Set();
557
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
558
+ this.withPreparedStatement(sql, (stmt) => {
559
+ if (params.bindings)
560
+ stmt.bindValues(params.bindings);
561
+ for (const row of stmt) {
562
+ if (row.id !== undefined) {
563
+ ids.add(row.id);
564
+ if (ids.size > IModelDb.maxLimit) {
565
+ throw new IModelError(IModelStatus.BadRequest, "Max LIMIT exceeded in SELECT statement");
566
+ }
567
+ }
568
+ }
569
+ });
570
+ return ids;
571
+ }
572
+ /** Clear all in-memory caches held in this IModelDb. */
573
+ clearCaches() {
574
+ this._statementCache.clear();
575
+ this._sqliteStatementCache.clear();
576
+ this._classMetaDataRegistry = undefined;
577
+ this._jsClassMap = undefined;
578
+ this._schemaMap = undefined;
579
+ this._schemaContext = undefined;
580
+ this.elements[_cache].clear();
581
+ this.models[_cache].clear();
582
+ }
583
+ /** Update the project extents for this iModel.
584
+ * <p><em>Example:</em>
585
+ * ``` ts
586
+ * [[include:IModelDb.updateProjectExtents]]
587
+ * ```
588
+ */
589
+ updateProjectExtents(newExtents) {
590
+ this.projectExtents = newExtents;
591
+ this.updateIModelProps();
592
+ }
593
+ /** Compute an appropriate project extents for this iModel based on the ranges of all spatial elements.
594
+ * Typically, the result is simply the union of the ranges of all spatial elements. However, the algorithm also detects "outlier elements",
595
+ * whose placements locate them so far from the rest of the spatial geometry that they are considered statistically insignificant. The
596
+ * range of an outlier element does not contribute to the computed extents.
597
+ * @param options Specifies the level of detail desired in the return value.
598
+ * @returns the computed extents.
599
+ * @note This method does not modify the IModel's stored project extents. @see [[updateProjectExtents]].
600
+ */
601
+ computeProjectExtents(options) {
602
+ const wantFullExtents = true === options?.reportExtentsWithOutliers;
603
+ const wantOutliers = true === options?.reportOutliers;
604
+ const result = this[_nativeDb].computeProjectExtents(wantFullExtents, wantOutliers);
605
+ return {
606
+ extents: Range3d.fromJSON(result.extents),
607
+ extentsWithOutliers: result.fullExtents ? Range3d.fromJSON(result.fullExtents) : undefined,
608
+ outliers: result.outliers,
609
+ };
610
+ }
611
+ /** Update the [EcefLocation]($docs/learning/glossary#eceflocation) of this iModel. */
612
+ updateEcefLocation(ecef) {
613
+ this.setEcefLocation(ecef);
614
+ this.updateIModelProps();
615
+ }
616
+ /** Update the IModelProps of this iModel in the database. */
617
+ updateIModelProps() {
618
+ this[_nativeDb].updateIModelProps(this.toJSON());
619
+ }
620
+ /** Commit unsaved changes in memory as a Txn to this iModelDb.
621
+ * @param description Optional description of the changes
622
+ * @throws [[IModelError]] if there is a problem saving changes or if there are pending, un-processed lock or code requests.
623
+ * @note This will not push changes to the iModelHub.
624
+ * @see [[IModelDb.pushChanges]] to push changes to the iModelHub.
625
+ */
626
+ saveChanges(description) {
627
+ if (this.openMode === OpenMode.Readonly)
628
+ throw new IModelError(IModelStatus.ReadOnly, "IModelDb was opened read-only");
629
+ const stat = this[_nativeDb].saveChanges(description);
630
+ if (DbResult.BE_SQLITE_OK !== stat)
631
+ throw new IModelError(stat, `Could not save changes (${description})`);
632
+ }
633
+ /** Abandon changes in memory that have not been saved as a Txn to this iModelDb.
634
+ * @note This will not delete Txns that have already been saved, even if they have not yet been pushed.
635
+ */
636
+ abandonChanges() {
637
+ this[_nativeDb].abandonChanges();
638
+ }
639
+ /**
640
+ * Save all changes and perform a [checkpoint](https://www.sqlite.org/c3ref/wal_checkpoint_v2.html) on this IModelDb.
641
+ * This ensures that all changes to the database since it was opened are saved to its file and the WAL file is truncated.
642
+ * @note Checkpoint automatically happens when IModelDbs are closed. However, the checkpoint
643
+ * operation itself can take some time. It may be useful to call this method prior to closing so that the checkpoint "penalty" is paid earlier.
644
+ * @note Another use for this function is to permit the file to be copied while it is open for write. iModel files should
645
+ * rarely be copied, and even less so while they're opened. But this scenario is sometimes encountered for tests.
646
+ */
647
+ performCheckpoint() {
648
+ if (!this.isReadonly) {
649
+ this.saveChanges();
650
+ this[_nativeDb].performCheckpoint();
651
+ }
652
+ }
653
+ /** @internal
654
+ * @deprecated in 4.8. Use `txns.reverseTxns`.
655
+ */
656
+ reverseTxns(numOperations) {
657
+ return this[_nativeDb].reverseTxns(numOperations);
658
+ }
659
+ /** @internal */
660
+ reinstateTxn() {
661
+ return this[_nativeDb].reinstateTxn();
662
+ }
663
+ /** @internal */
664
+ restartTxnSession() {
665
+ return this[_nativeDb].restartTxnSession();
666
+ }
667
+ /** Import an ECSchema. On success, the schema definition is stored in the iModel.
668
+ * This method is asynchronous (must be awaited) because, in the case where this IModelDb is a briefcase, this method first obtains the schema lock from the iModel server.
669
+ * You must import a schema into an iModel before you can insert instances of the classes in that schema. See [[Element]]
670
+ * @param schemaFileName array of Full paths to ECSchema.xml files to be imported.
671
+ * @param {SchemaImportOptions} options - options during schema import.
672
+ * @throws [[IModelError]] if the schema lock cannot be obtained or there is a problem importing the schema.
673
+ * @note Changes are saved if importSchemas is successful and abandoned if not successful.
674
+ * - You can use NativeLoggerCategory to turn on the native logs. You can also control [what exactly is logged by the loggers](https://www.itwinjs.org/learning/common/logging/#controlling-what-is-logged).
675
+ * - See [Schema Versioning]($docs/bis/guide/schema-evolution/schema-versioning-and-generations.md) for more information on acceptable changes to schemas.
676
+ * @see querySchemaVersion
677
+ */
678
+ async importSchemas(schemaFileNames, options) {
679
+ if (schemaFileNames.length === 0)
680
+ return;
681
+ const maybeCustomNativeContext = options?.ecSchemaXmlContext?.nativeContext;
682
+ if (this[_nativeDb].schemaSyncEnabled()) {
683
+ await SchemaSync.withLockedAccess(this, { openMode: OpenMode.Readonly, operationName: "schema sync" }, async (syncAccess) => {
684
+ const schemaSyncDbUri = syncAccess.getUri();
685
+ this.saveChanges();
686
+ try {
687
+ this[_nativeDb].importSchemas(schemaFileNames, { schemaLockHeld: false, ecSchemaXmlContext: maybeCustomNativeContext, schemaSyncDbUri });
688
+ }
689
+ catch (outerErr) {
690
+ if (DbResult.BE_SQLITE_ERROR_DataTransformRequired === outerErr.errorNumber) {
691
+ this.abandonChanges();
692
+ if (this[_nativeDb].getITwinId() !== Guid.empty)
693
+ await this.acquireSchemaLock();
694
+ try {
695
+ this[_nativeDb].importSchemas(schemaFileNames, { schemaLockHeld: true, ecSchemaXmlContext: maybeCustomNativeContext, schemaSyncDbUri });
696
+ }
697
+ catch (innerErr) {
698
+ throw new IModelError(innerErr.errorNumber, innerErr.message);
699
+ }
700
+ }
701
+ else {
702
+ throw new IModelError(outerErr.errorNumber, outerErr.message);
703
+ }
704
+ }
705
+ });
706
+ }
707
+ else {
708
+ const nativeImportOptions = {
709
+ schemaLockHeld: true,
710
+ ecSchemaXmlContext: maybeCustomNativeContext,
711
+ };
712
+ if (this[_nativeDb].getITwinId() !== Guid.empty) // if this iModel is associated with an iTwin, importing schema requires the schema lock
713
+ await this.acquireSchemaLock();
714
+ try {
715
+ this[_nativeDb].importSchemas(schemaFileNames, nativeImportOptions);
716
+ }
717
+ catch (err) {
718
+ throw new IModelError(err.errorNumber, err.message);
719
+ }
720
+ }
721
+ this.clearCaches();
722
+ }
723
+ /** Import ECSchema(s) serialized to XML. On success, the schema definition is stored in the iModel.
724
+ * This method is asynchronous (must be awaited) because, in the case where this IModelDb is a briefcase, this method first obtains the schema lock from the iModel server.
725
+ * You must import a schema into an iModel before you can insert instances of the classes in that schema. See [[Element]]
726
+ * @param serializedXmlSchemas The xml string(s) created from a serialized ECSchema.
727
+ * @throws [[IModelError]] if the schema lock cannot be obtained or there is a problem importing the schema.
728
+ * @note Changes are saved if importSchemaStrings is successful and abandoned if not successful.
729
+ * @see querySchemaVersion
730
+ * @alpha
731
+ */
732
+ async importSchemaStrings(serializedXmlSchemas) {
733
+ if (serializedXmlSchemas.length === 0)
734
+ return;
735
+ if (this[_nativeDb].schemaSyncEnabled()) {
736
+ await SchemaSync.withLockedAccess(this, { openMode: OpenMode.Readonly, operationName: "schemaSync" }, async (syncAccess) => {
737
+ const schemaSyncDbUri = syncAccess.getUri();
738
+ this.saveChanges();
739
+ try {
740
+ this[_nativeDb].importXmlSchemas(serializedXmlSchemas, { schemaLockHeld: false, schemaSyncDbUri });
741
+ }
742
+ catch (outerErr) {
743
+ if (DbResult.BE_SQLITE_ERROR_DataTransformRequired === outerErr.errorNumber) {
744
+ this.abandonChanges();
745
+ if (this[_nativeDb].getITwinId() !== Guid.empty)
746
+ await this.acquireSchemaLock();
747
+ try {
748
+ this[_nativeDb].importXmlSchemas(serializedXmlSchemas, { schemaLockHeld: true, schemaSyncDbUri });
749
+ }
750
+ catch (innerErr) {
751
+ throw new IModelError(innerErr.errorNumber, innerErr.message);
752
+ }
753
+ }
754
+ else {
755
+ throw new IModelError(outerErr.errorNumber, outerErr.message);
756
+ }
757
+ }
758
+ });
759
+ }
760
+ else {
761
+ if (this.iTwinId && this.iTwinId !== Guid.empty) // if this iModel is associated with an iTwin, importing schema requires the schema lock
762
+ await this.acquireSchemaLock();
763
+ try {
764
+ this[_nativeDb].importXmlSchemas(serializedXmlSchemas, { schemaLockHeld: true });
765
+ }
766
+ catch (err) {
767
+ throw new IModelError(err.errorNumber, err.message);
768
+ }
769
+ }
770
+ this.clearCaches();
771
+ }
772
+ /** Find an opened instance of any subclass of IModelDb, by filename
773
+ * @note this method returns an IModelDb if the filename is open for *any* subclass of IModelDb
774
+ */
775
+ static findByFilename(fileName) {
776
+ for (const entry of this._openDbs) {
777
+ // It shouldn't be possible for anything in _openDbs to not be open, but if so just skip them because `pathName` will throw an exception.
778
+ if (entry[1].isOpen && entry[1].pathName === fileName)
779
+ return entry[1];
780
+ }
781
+ return undefined;
782
+ }
783
+ /** Find an open IModelDb by its key.
784
+ * @note This method is mainly for use by RPC implementations.
785
+ * @throws [[IModelNotFoundResponse]] if an open IModelDb matching the key is not found.
786
+ * @see [IModel.key]($common)
787
+ */
788
+ static findByKey(key) {
789
+ const iModelDb = this.tryFindByKey(key);
790
+ if (undefined === iModelDb) {
791
+ // eslint-disable-next-line @typescript-eslint/only-throw-error
792
+ throw new IModelNotFoundResponse(); // a very specific status for the RpcManager
793
+ }
794
+ return iModelDb;
795
+ }
796
+ /** Attempt to find an open IModelDb by key.
797
+ * @returns The matching IModelDb or `undefined`.
798
+ */
799
+ static tryFindByKey(key) {
800
+ return this._openDbs.get(key);
801
+ }
802
+ /** @internal */
803
+ static openDgnDb(file, openMode, upgradeOptions, props) {
804
+ file.key = file.key ?? Guid.createValue();
805
+ if (this.tryFindByKey(file.key))
806
+ throw new IModelError(IModelStatus.AlreadyOpen, `key [${file.key}] for file [${file.path}] is already in use`);
807
+ const isUpgradeRequested = upgradeOptions?.domain === DomainOptions.Upgrade || upgradeOptions?.profile === ProfileOptions.Upgrade;
808
+ if (isUpgradeRequested && openMode !== OpenMode.ReadWrite)
809
+ throw new IModelError(IModelStatus.UpgradeFailed, "Cannot upgrade a Readonly Db");
810
+ try {
811
+ const nativeDb = new IModelNative.platform.DgnDb();
812
+ const container = props?.container;
813
+ if (container) {
814
+ // temp files for cloud-based Dbs should be in the profileDir in a subdirectory named for their container
815
+ const baseDir = join(IModelHost.profileDir, "CloudDbTemp", container.containerId);
816
+ IModelJsFs.recursiveMkDirSync(baseDir);
817
+ props = { ...props, tempFileBase: join(baseDir, file.path) };
818
+ }
819
+ nativeDb.openIModel(file.path, openMode, upgradeOptions, props, props?.container, props);
820
+ return nativeDb;
821
+ }
822
+ catch (err) {
823
+ throw new IModelError(err.errorNumber, `${err.message}, ${file.path}`);
824
+ }
825
+ }
826
+ /**
827
+ * Determines if the schemas in the Db must or can be upgraded by comparing them with those included in the
828
+ * current version of the software.
829
+ * @param filePath Full name of the briefcase including path
830
+ * @param forReadWrite Pass true if validating for read-write scenarios - note that the schema version requirements
831
+ * for opening the DgnDb read-write is more stringent than when opening the database read-only
832
+ * @throws [[IModelError]] If the Db was in an invalid state and that causes a problem with validating schemas
833
+ * @see [[BriefcaseDb.upgradeSchemas]] or [[StandaloneDb.upgradeSchemas]]
834
+ * @see ($docs/learning/backend/IModelDb.md#upgrading-schemas-in-an-imodel)
835
+ */
836
+ static validateSchemas(filePath, forReadWrite) {
837
+ const openMode = forReadWrite ? OpenMode.ReadWrite : OpenMode.Readonly;
838
+ const file = { path: filePath };
839
+ let result = DbResult.BE_SQLITE_OK;
840
+ try {
841
+ const upgradeOptions = {
842
+ domain: DomainOptions.CheckRecommendedUpgrades,
843
+ };
844
+ const nativeDb = this.openDgnDb(file, openMode, upgradeOptions);
845
+ nativeDb.closeFile();
846
+ }
847
+ catch (err) {
848
+ result = err.errorNumber;
849
+ }
850
+ let schemaState = SchemaState.UpToDate;
851
+ switch (result) {
852
+ case DbResult.BE_SQLITE_OK:
853
+ schemaState = SchemaState.UpToDate;
854
+ break;
855
+ case DbResult.BE_SQLITE_ERROR_ProfileTooOld:
856
+ case DbResult.BE_SQLITE_ERROR_ProfileTooOldForReadWrite:
857
+ case DbResult.BE_SQLITE_ERROR_SchemaTooOld:
858
+ schemaState = SchemaState.TooOld;
859
+ break;
860
+ case DbResult.BE_SQLITE_ERROR_ProfileTooNew:
861
+ case DbResult.BE_SQLITE_ERROR_ProfileTooNewForReadWrite:
862
+ case DbResult.BE_SQLITE_ERROR_SchemaTooNew:
863
+ schemaState = SchemaState.TooNew;
864
+ break;
865
+ case DbResult.BE_SQLITE_ERROR_SchemaUpgradeRecommended:
866
+ schemaState = SchemaState.UpgradeRecommended;
867
+ break;
868
+ case DbResult.BE_SQLITE_ERROR_SchemaUpgradeRequired:
869
+ schemaState = SchemaState.UpgradeRequired;
870
+ break;
871
+ case DbResult.BE_SQLITE_ERROR_InvalidProfileVersion:
872
+ throw new IModelError(DbResult.BE_SQLITE_ERROR_InvalidProfileVersion, "The profile of the Db is invalid. Cannot upgrade or open the Db.");
873
+ default:
874
+ throw new IModelError(DbResult.BE_SQLITE_ERROR, "Error validating schemas. Cannot upgrade or open the Db.");
875
+ }
876
+ return schemaState;
877
+ }
878
+ /** The registry of entity metadata for this iModel.
879
+ * @internal
880
+ * @deprecated in 5.0. Please use `schemaContext` from the `iModel` instead.
881
+ *
882
+ * @example
883
+ * ```typescript
884
+ * // Current usage:
885
+ * const classMetaData: EntityMetaData | undefined = iModel.classMetaDataRegistry.find("SchemaName:ClassName");
886
+ *
887
+ * // Replacement:
888
+ * const metaData: EntityClass | undefined = imodel.schemaContext.getSchemaItemSync("SchemaName.ClassName", EntityClass);
889
+ * ```
890
+ */
891
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
892
+ get classMetaDataRegistry() {
893
+ if (this._classMetaDataRegistry === undefined)
894
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
895
+ this._classMetaDataRegistry = new MetaDataRegistry();
896
+ return this._classMetaDataRegistry;
897
+ }
898
+ /**
899
+ * Allows registering js classes mapped to ECClasses
900
+ */
901
+ get jsClassMap() {
902
+ if (this._jsClassMap === undefined)
903
+ this._jsClassMap = new EntityJsClassMap();
904
+ return this._jsClassMap;
905
+ }
906
+ /**
907
+ * Allows locally registering a schema for this imodel, in constrast to [Schemas.registerSchema] which is a global operation
908
+ */
909
+ get schemaMap() {
910
+ if (this._schemaMap === undefined)
911
+ this._schemaMap = new SchemaMap();
912
+ return this._schemaMap;
913
+ }
914
+ /**
915
+ * Gets the context that allows accessing the metadata (ecschema-metadata package) of this iModel
916
+ * @public @preview
917
+ */
918
+ get schemaContext() {
919
+ if (this._schemaContext === undefined) {
920
+ const context = new SchemaContext();
921
+ // TODO: We probably need a more optimized locater for here
922
+ const locater = new SchemaJsonLocater((name) => this.getSchemaProps(name));
923
+ context.addLocater(locater);
924
+ this._schemaContext = context;
925
+ }
926
+ return this._schemaContext;
927
+ }
928
+ /** Get the linkTableRelationships for this IModel */
929
+ get relationships() {
930
+ return this._relationships || (this._relationships = new Relationships(this));
931
+ }
932
+ /** Get the CodeSpecs in this IModel. */
933
+ get codeSpecs() {
934
+ return (this._codeSpecs !== undefined) ? this._codeSpecs : (this._codeSpecs = new CodeSpecs(this));
935
+ }
936
+ /** Prepare an ECSQL statement.
937
+ * @param sql The ECSQL statement to prepare
938
+ * @param logErrors Determines if error will be logged if statement fail to prepare
939
+ * @throws [[IModelError]] if there is a problem preparing the statement.
940
+ * @deprecated in 4.11. Use [IModelDb.createQueryReader]($backend) or [ECDb.createQueryReader]($backend) to query.
941
+ */
942
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
943
+ prepareStatement(sql, logErrors = true) {
944
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
945
+ const stmt = new ECSqlStatement();
946
+ stmt.prepare(this[_nativeDb], sql, logErrors);
947
+ return stmt;
948
+ }
949
+ /** Prepare an ECSQL statement.
950
+ * @param sql The ECSQL statement to prepare
951
+ * @returns `undefined` if there is a problem preparing the statement.
952
+ * @deprecated in 4.11. Use [IModelDb.createQueryReader]($backend) or [ECDb.createQueryReader]($backend) to query.
953
+ */
954
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
955
+ tryPrepareStatement(sql) {
956
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
957
+ const statement = new ECSqlStatement();
958
+ const result = statement.tryPrepare(this[_nativeDb], sql);
959
+ return DbResult.BE_SQLITE_OK === result.status ? statement : undefined;
960
+ }
961
+ /** Construct an entity (Element or Model) from an iModel.
962
+ * @throws [[IModelError]] if the entity cannot be constructed.
963
+ */
964
+ constructEntity(props) {
965
+ const jsClass = this.getJsClass(props.classFullName);
966
+ return Entity.instantiate(jsClass, props, this);
967
+ }
968
+ /** Get the JavaScript class that handles a given entity class. */
969
+ getJsClass(classFullName) {
970
+ try {
971
+ return ClassRegistry.getClass(classFullName, this);
972
+ }
973
+ catch (err) {
974
+ if (!ClassRegistry.isNotFoundError(err)) {
975
+ throw err;
976
+ }
977
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
978
+ this.loadMetaData(classFullName);
979
+ return ClassRegistry.getClass(classFullName, this);
980
+ }
981
+ }
982
+ /** Constructs a ResolveInstanceKeyArgs from given parameters
983
+ * @throws [[IModelError]] if the combination of supplied parameters is invalid.
984
+ * @internal
985
+ */
986
+ getInstanceArgs(instanceId, baseClassName, federationGuid, code) {
987
+ if (instanceId && baseClassName) {
988
+ return { partialKey: { id: instanceId, baseClassName } };
989
+ }
990
+ else if (federationGuid) {
991
+ return { federationGuid };
992
+ }
993
+ else if (code) {
994
+ return { code };
995
+ }
996
+ else {
997
+ throw new IModelError(IModelStatus.InvalidId, "Either instanceId and baseClassName or federationGuid or code must be specified");
998
+ }
999
+ }
1000
+ /** Get metadata for a class. This method will load the metadata from the iModel into the cache as a side-effect, if necessary.
1001
+ * @throws [[IModelError]] if the metadata cannot be found nor loaded.
1002
+ * @deprecated in 5.0. Please use `getSchemaItem` from `SchemaContext` class instead.
1003
+ *
1004
+ * @example
1005
+ * * ```typescript
1006
+ * // Current usage:
1007
+ * const metaData: EntityMetaData = imodel.getMetaData("SchemaName:ClassName");
1008
+ *
1009
+ * // Replacement:
1010
+ * const metaData: EntityClass | undefined = imodel.schemaContext.getSchemaItemSync("SchemaName", "ClassName", EntityClass);
1011
+ * ```
1012
+ */
1013
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1014
+ getMetaData(classFullName) {
1015
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1016
+ let metadata = this.classMetaDataRegistry.find(classFullName);
1017
+ if (metadata === undefined) {
1018
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1019
+ this.loadMetaData(classFullName);
1020
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1021
+ metadata = this.classMetaDataRegistry.find(classFullName);
1022
+ if (metadata === undefined)
1023
+ throw ClassRegistry.makeMetaDataNotFoundError(classFullName); // do not log
1024
+ }
1025
+ return metadata;
1026
+ }
1027
+ /** Identical to [[getMetaData]], except it returns `undefined` instead of throwing an error if the metadata cannot be found nor loaded.
1028
+ * @deprecated in 5.0. Please use `getSchemaItem` from `SchemaContext` class instead.
1029
+ *
1030
+ * @example
1031
+ * * ```typescript
1032
+ * // Current usage:
1033
+ * const metaData: EntityMetaData | undefined = imodel.tryGetMetaData("SchemaName:ClassName");
1034
+ *
1035
+ * // Replacement:
1036
+ * const metaData: EntityClass | undefined = imodel.schemaContext.getSchemaItemSync("SchemaName.ClassName", EntityClass);
1037
+ * ```
1038
+ */
1039
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1040
+ tryGetMetaData(classFullName) {
1041
+ try {
1042
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1043
+ return this.getMetaData(classFullName);
1044
+ }
1045
+ catch {
1046
+ return undefined;
1047
+ }
1048
+ }
1049
+ /** Invoke a callback on each property of the specified class, optionally including superclass properties.
1050
+ * @param iModel The IModel that contains the schema
1051
+ * @param classFullName The full class name to load the metadata, if necessary
1052
+ * @param wantSuper If true, superclass properties will also be processed
1053
+ * @param func The callback to be invoked on each property
1054
+ * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.
1055
+ * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.
1056
+ * @deprecated in 5.0. Please use `forEachProperty` instead.
1057
+ *
1058
+ * @example
1059
+ * ```typescript
1060
+ * // Current usage:
1061
+ * IModelDb.forEachMetaData(imodel, "BisCore:Element", true, (name: string, propMetaData: PropertyMetaData) => {
1062
+ * console.log(`Property name: ${name}, Property type: ${propMetaData.primitiveType}`);
1063
+ * }, false);
1064
+ *
1065
+ * // Replacement:
1066
+ * await IModelDb.forEachProperty(imodel, "TestDomain.TestDomainClass", true, (propName: string, property: Property) => {
1067
+ * console.log(`Property name: ${propName}, Property type: ${property.propertyType}`);
1068
+ * }, false);
1069
+ * ```
1070
+ */
1071
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1072
+ static forEachMetaData(iModel, classFullName, wantSuper, func, includeCustom = true) {
1073
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1074
+ iModel.forEachMetaData(classFullName, wantSuper, func, includeCustom);
1075
+ }
1076
+ /** Invoke a callback on each property of the specified class, optionally including superclass properties.
1077
+ * @param classFullName The full class name to load the metadata, if necessary
1078
+ * @param wantSuper If true, superclass properties will also be processed
1079
+ * @param func The callback to be invoked on each property
1080
+ * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.
1081
+ * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.
1082
+ * @deprecated in 5.0. Use `forEachProperty` from `SchemaContext` class instead.
1083
+ *
1084
+ * @example
1085
+ * ```typescript
1086
+ * // Current usage:
1087
+ * iModel.forEachMetaData("BisCore:Element", true, (name: string, propMetaData: PropertyMetaData) => {
1088
+ * console.log(`Property name: ${name}, Property type: ${propMetaData.primitiveType}`);
1089
+ * });
1090
+ *
1091
+ * // Replacement:
1092
+ * imodel.schemaContext.forEachProperty("BisCore:Element", true, (propName: string, property: Property) => {
1093
+ * console.log(`Property name: ${propName}, Property type: ${property.propertyType}`);
1094
+ * });
1095
+ * ```
1096
+ */
1097
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1098
+ forEachMetaData(classFullName, wantSuper, func, includeCustom = true) {
1099
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1100
+ const meta = this.getMetaData(classFullName); // will load if necessary
1101
+ for (const propName in meta.properties) { // eslint-disable-line guard-for-in
1102
+ const propMeta = meta.properties[propName];
1103
+ if (includeCustom || !propMeta.isCustomHandled || propMeta.isCustomHandledOrphan)
1104
+ func(propName, propMeta);
1105
+ }
1106
+ if (wantSuper && meta.baseClasses && meta.baseClasses.length > 0)
1107
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1108
+ meta.baseClasses.forEach((baseClass) => this.forEachMetaData(baseClass, true, func, includeCustom));
1109
+ }
1110
+ /**
1111
+ * @internal
1112
+ * @deprecated in 5.0. Please use `schemaContext` from `iModel` instead to get metadata.
1113
+ */
1114
+ loadMetaData(classFullName) {
1115
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1116
+ if (this.classMetaDataRegistry.find(classFullName))
1117
+ return;
1118
+ const className = classFullName.split(":");
1119
+ if (className.length !== 2)
1120
+ throw new IModelError(IModelStatus.BadArg, `Invalid classFullName: ${classFullName}`);
1121
+ const val = this[_nativeDb].getECClassMetaData(className[0], className[1]);
1122
+ if (val.error)
1123
+ throw new IModelError(val.error.status, `Error getting class meta data for: ${classFullName}`);
1124
+ assert(undefined !== val.result);
1125
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1126
+ const metaData = new EntityMetaData(JSON.parse(val.result));
1127
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1128
+ this.classMetaDataRegistry.add(classFullName, metaData);
1129
+ // Recursive, to make sure that base classes are cached.
1130
+ if (metaData.baseClasses !== undefined && metaData.baseClasses.length > 0)
1131
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1132
+ metaData.baseClasses.forEach((baseClassName) => this.loadMetaData(baseClassName));
1133
+ }
1134
+ /** Returns the full schema for the input name.
1135
+ * @param name The name of the schema e.g. 'BisCore'
1136
+ * @returns The SchemaProps for the requested schema
1137
+ * @throws if the schema can not be found or loaded.
1138
+ */
1139
+ getSchemaProps(name) {
1140
+ return this[_nativeDb].getSchemaProps(name);
1141
+ }
1142
+ /** Query if this iModel contains the definition of the specified class.
1143
+ * @param classFullName The full name of the class, for example, SomeSchema:SomeClass
1144
+ * @returns true if the iModel contains the class definition or false if not.
1145
+ * @see querySchemaVersion
1146
+ * @see importSchema
1147
+ */
1148
+ containsClass(classFullName) {
1149
+ const classNameParts = classFullName.replace(".", ":").split(":");
1150
+ return classNameParts.length === 2 && this[_nativeDb].getECClassMetaData(classNameParts[0], classNameParts[1]).error === undefined;
1151
+ }
1152
+ /** Query for a schema of the specified name in this iModel.
1153
+ * @returns The schema version as a semver-compatible string or `undefined` if the schema has not been imported.
1154
+ */
1155
+ querySchemaVersion(schemaName) {
1156
+ const sql = `SELECT VersionMajor,VersionWrite,VersionMinor FROM ECDbMeta.ECSchemaDef WHERE Name=:schemaName LIMIT 1`;
1157
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1158
+ return this.withPreparedStatement(sql, (statement) => {
1159
+ statement.bindString("schemaName", schemaName);
1160
+ if (DbResult.BE_SQLITE_ROW === statement.step()) {
1161
+ const versionMajor = statement.getValue(0).getInteger(); // ECSchemaDef.VersionMajor --> semver.major
1162
+ const versionWrite = statement.getValue(1).getInteger(); // ECSchemaDef.VersionWrite --> semver.minor
1163
+ const versionMinor = statement.getValue(2).getInteger(); // ECSchemaDef.VersionMinor --> semver.patch
1164
+ return `${versionMajor}.${versionWrite}.${versionMinor}`;
1165
+ }
1166
+ return undefined;
1167
+ });
1168
+ }
1169
+ /** Retrieve a named texture image from this iModel, as a TextureData.
1170
+ * @param props the texture load properties which must include the name of the texture to load
1171
+ * @returns the TextureData or undefined if the texture image is not present.
1172
+ * @alpha
1173
+ */
1174
+ async queryTextureData(props) {
1175
+ return this[_nativeDb].queryTextureData(props);
1176
+ }
1177
+ /** Query a "file property" from this iModel, as a string.
1178
+ * @returns the property string or undefined if the property is not present.
1179
+ */
1180
+ queryFilePropertyString(prop) {
1181
+ return this[_nativeDb].queryFileProperty(prop, true);
1182
+ }
1183
+ /** Query a "file property" from this iModel, as a blob.
1184
+ * @returns the property blob or undefined if the property is not present.
1185
+ */
1186
+ queryFilePropertyBlob(prop) {
1187
+ return this[_nativeDb].queryFileProperty(prop, false);
1188
+ }
1189
+ /** Save a "file property" to this iModel
1190
+ * @param prop the FilePropertyProps that describes the new property
1191
+ * @param value either a string or a blob to save as the file property
1192
+ */
1193
+ saveFileProperty(prop, strValue, blobVal) {
1194
+ this[_nativeDb].saveFileProperty(prop, strValue, blobVal);
1195
+ }
1196
+ /** delete a "file property" from this iModel
1197
+ * @param prop the FilePropertyProps that describes the property
1198
+ */
1199
+ deleteFileProperty(prop) {
1200
+ this[_nativeDb].saveFileProperty(prop, undefined, undefined);
1201
+ }
1202
+ /** Query for the next available major id for a "file property" from this iModel.
1203
+ * @param prop the FilePropertyProps that describes the property
1204
+ * @returns the next available (that is, an unused) id for prop. If none are present, will return 0.
1205
+ */
1206
+ queryNextAvailableFileProperty(prop) { return this[_nativeDb].queryNextAvailableFileProperty(prop); }
1207
+ /** @internal */
1208
+ async requestSnap(sessionId, props) {
1209
+ let request = this._snaps.get(sessionId);
1210
+ if (undefined === request) {
1211
+ request = new IModelNative.platform.SnapRequest();
1212
+ this._snaps.set(sessionId, request);
1213
+ }
1214
+ else
1215
+ request.cancelSnap();
1216
+ try {
1217
+ return await request.doSnap(this[_nativeDb], JsonUtils.toObject(props));
1218
+ }
1219
+ finally {
1220
+ this._snaps.delete(sessionId);
1221
+ }
1222
+ }
1223
+ /** Cancel a previously requested snap.
1224
+ * @internal
1225
+ */
1226
+ cancelSnap(sessionId) {
1227
+ const request = this._snaps.get(sessionId);
1228
+ if (undefined !== request) {
1229
+ request.cancelSnap();
1230
+ this._snaps.delete(sessionId);
1231
+ }
1232
+ }
1233
+ /** Get the clip containment status for the supplied elements. */
1234
+ async getGeometryContainment(props) {
1235
+ return this[_nativeDb].getGeometryContainment(JsonUtils.toObject(props));
1236
+ }
1237
+ /** Get the mass properties for the supplied elements. */
1238
+ async getMassProperties(props) {
1239
+ return this[_nativeDb].getMassProperties(JsonUtils.toObject(props));
1240
+ }
1241
+ /** Get the IModel coordinate corresponding to each GeoCoordinate point in the input */
1242
+ async getIModelCoordinatesFromGeoCoordinates(props) {
1243
+ return this[_nativeDb].getIModelCoordinatesFromGeoCoordinates(props);
1244
+ }
1245
+ /** Get the GeoCoordinate (longitude, latitude, elevation) corresponding to each IModel Coordinate point in the input */
1246
+ async getGeoCoordinatesFromIModelCoordinates(props) {
1247
+ return this[_nativeDb].getGeoCoordinatesFromIModelCoordinates(props);
1248
+ }
1249
+ /** Export meshes suitable for graphics APIs from arbitrary geometry in elements in this IModelDb.
1250
+ * * Requests can be slow when processing many elements so it is expected that this function be used on a dedicated backend,
1251
+ * or that shared backends export a limited number of elements at a time.
1252
+ * * Vertices are exported in the IModelDb's world coordinate system, which is right-handed with Z pointing up.
1253
+ * * The results of changing [ExportGraphicsOptions]($core-backend) during the [ExportGraphicsOptions.onGraphics]($core-backend) callback are not defined.
1254
+ *
1255
+ * Example that prints the mesh for element 1 to stdout in [OBJ format](https://en.wikipedia.org/wiki/Wavefront_.obj_file)
1256
+ * ```ts
1257
+ * const onGraphics: ExportGraphicsFunction = (info: ExportGraphicsInfo) => {
1258
+ * const mesh: ExportGraphicsMesh = info.mesh;
1259
+ * for (let i = 0; i < mesh.points.length; i += 3) {
1260
+ * process.stdout.write(`v ${mesh.points[i]} ${mesh.points[i + 1]} ${mesh.points[i + 2]}\n`);
1261
+ * process.stdout.write(`vn ${mesh.normals[i]} ${mesh.normals[i + 1]} ${mesh.normals[i + 2]}\n`);
1262
+ * }
1263
+ *
1264
+ * for (let i = 0; i < mesh.params.length; i += 2) {
1265
+ * process.stdout.write(`vt ${mesh.params[i]} ${mesh.params[i + 1]}\n`);
1266
+ * }
1267
+ *
1268
+ * for (let i = 0; i < mesh.indices.length; i += 3) {
1269
+ * const p1 = mesh.indices[i];
1270
+ * const p2 = mesh.indices[i + 1];
1271
+ * const p3 = mesh.indices[i + 2];
1272
+ * process.stdout.write(`f ${p1}/${p1}/${p1} ${p2}/${p2}/${p2} ${p3}/${p3}/${p3}\n`);
1273
+ * }
1274
+ * };
1275
+ *
1276
+ * iModel.exportGraphics(({ onGraphics, elementIdArray: ["0x1"] }));
1277
+ * ```
1278
+ * @returns 0 if successful, status otherwise
1279
+ * @public
1280
+ */
1281
+ exportGraphics(exportProps) {
1282
+ return this[_nativeDb].exportGraphics(exportProps);
1283
+ }
1284
+ /**
1285
+ * Exports meshes suitable for graphics APIs from a specified [GeometryPart]($core-backend)
1286
+ * in this IModelDb.
1287
+ * The expected use case is to call [IModelDb.exportGraphics]($core-backend) and supply the
1288
+ * optional partInstanceArray argument, then call this function for each unique GeometryPart from
1289
+ * that list.
1290
+ * * The results of changing [ExportPartGraphicsOptions]($core-backend) during the
1291
+ * [ExportPartGraphicsOptions.onPartGraphics]($core-backend) callback are not defined.
1292
+ * * See export-gltf under test-apps in the iTwin.js monorepo for a working reference.
1293
+ * @returns 0 is successful, status otherwise
1294
+ * @public
1295
+ */
1296
+ exportPartGraphics(exportProps) {
1297
+ return this[_nativeDb].exportPartGraphics(exportProps);
1298
+ }
1299
+ /** Request geometry stream information from an element in binary format instead of json.
1300
+ * @returns IModelStatus.Success if successful
1301
+ * @beta
1302
+ */
1303
+ elementGeometryRequest(requestProps) {
1304
+ return this[_nativeDb].processGeometryStream(requestProps);
1305
+ }
1306
+ /** Request the creation of a backend geometry cache for the specified geometric element.
1307
+ * @returns ElementGeometryCacheResponseProps
1308
+ * @beta
1309
+ */
1310
+ async updateElementGeometryCache(requestProps) {
1311
+ return this[_nativeDb].updateElementGeometryCache(requestProps);
1312
+ }
1313
+ /** Request operation using the backend geometry cache populated by first calling elementGeometryRequest.
1314
+ * @returns SUCCESS if requested operation could be applied.
1315
+ * @beta
1316
+ */
1317
+ elementGeometryCacheOperation(requestProps) {
1318
+ return this[_nativeDb].elementGeometryCacheOperation(requestProps);
1319
+ }
1320
+ /** Create brep geometry for inclusion in an element's geometry stream.
1321
+ * @returns IModelStatus.Success if successful
1322
+ * @throws [[IModelError]] to report issues with input geometry or parameters
1323
+ * @alpha
1324
+ */
1325
+ createBRepGeometry(createProps) {
1326
+ return this[_nativeDb].createBRepGeometry(createProps);
1327
+ }
1328
+ /** Generate graphics for an element or geometry stream.
1329
+ * @see [readElementGraphics]($frontend) to convert the result to a [RenderGraphic]($frontend) for display.
1330
+ */
1331
+ async generateElementGraphics(request) {
1332
+ return generateElementGraphics(request, this);
1333
+ }
1334
+ static _settingPropNamespace = "settings";
1335
+ /** Save a `SettingDictionary` in this iModel that will be loaded into [[workspace.settings]] every time this iModel is opened in future sessions.
1336
+ * @param name The name for the SettingDictionary. If a dictionary by that name already exists in the iModel, its value is replaced.
1337
+ * @param dict The SettingDictionary object to stringify and save.
1338
+ * @note All saved `SettingDictionary`s are loaded into [[workspace.settings]] every time an iModel is opened.
1339
+ * @beta
1340
+ */
1341
+ saveSettingDictionary(name, dict) {
1342
+ this.withSqliteStatement("REPLACE INTO be_Prop(id,SubId,TxnMode,Namespace,Name,strData) VALUES(0,0,0,?,?,?)", (stmt) => {
1343
+ stmt.bindString(1, IModelDb._settingPropNamespace);
1344
+ stmt.bindString(2, name);
1345
+ stmt.bindString(3, JSON.stringify(dict));
1346
+ stmt.stepForWrite();
1347
+ });
1348
+ this.saveChanges("add settings");
1349
+ }
1350
+ /** Delete a SettingDictionary, previously added with [[saveSettingDictionary]], from this iModel.
1351
+ * @param name The name of the dictionary to delete.
1352
+ * @beta
1353
+ */
1354
+ deleteSettingDictionary(name) {
1355
+ this.withSqliteStatement("DELETE FROM be_Prop WHERE Namespace=? AND Name=?", (stmt) => {
1356
+ stmt.bindString(1, IModelDb._settingPropNamespace);
1357
+ stmt.bindString(2, name);
1358
+ stmt.stepForWrite();
1359
+ });
1360
+ this.saveChanges("delete settings");
1361
+ }
1362
+ /** Load all setting dictionaries in this iModel into `this.workspace.settings` */
1363
+ loadIModelSettings() {
1364
+ if (!this[_nativeDb].isOpen())
1365
+ return;
1366
+ this.withSqliteStatement("SELECT Name,StrData FROM be_Prop WHERE Namespace=?", (stmt) => {
1367
+ stmt.bindString(1, IModelDb._settingPropNamespace);
1368
+ while (stmt.nextRow()) {
1369
+ try {
1370
+ const settings = JSON.parse(stmt.getValueString(1));
1371
+ this.workspace.settings.addDictionary({ name: stmt.getValueString(0), priority: SettingsPriority.iModel }, settings);
1372
+ }
1373
+ catch (e) {
1374
+ Workspace.exceptionDiagnosticFn(e);
1375
+ }
1376
+ }
1377
+ });
1378
+ }
1379
+ /** @internal */
1380
+ async loadWorkspaceSettings() {
1381
+ try {
1382
+ const problems = [];
1383
+ const settingProps = [];
1384
+ // Note: we can't use `getArray` here because we only look at dictionaries in the iModel's workspace, not appWorkspace.
1385
+ // Also, we must concatenate all entries in all of the dictionaries stored in the iModel into a single array *before*
1386
+ // calling `loadSettingsDictionary` since that function will add new dictionaries to the workspace.
1387
+ for (const dict of this.workspace.settings.dictionaries) {
1388
+ try {
1389
+ const props = dict.getSetting(WorkspaceSettingNames.settingsWorkspaces);
1390
+ if (props)
1391
+ settingProps.push(...IModelHost.settingsSchemas.validateSetting(props, WorkspaceSettingNames.settingsWorkspaces));
1392
+ }
1393
+ catch (e) {
1394
+ problems.push(e); // something wrong with the setting stored in the iModel
1395
+ }
1396
+ }
1397
+ if (settingProps.length > 0)
1398
+ await this.workspace.loadSettingsDictionary(settingProps, problems);
1399
+ if (problems.length > 0)
1400
+ throwWorkspaceDbLoadErrors(`attempting to load workspace settings for iModel '${this.name}':`, problems);
1401
+ }
1402
+ catch (e) {
1403
+ // we don't want to throw exceptions when attempting to load Dictionaries. Call the diagnostics function instead.
1404
+ Workspace.exceptionDiagnosticFn(e);
1405
+ }
1406
+ }
1407
+ /**
1408
+ * Controls how [Code]($common)s are copied from this iModel into another iModel, to work around problems with iModels
1409
+ * created by older connectors. The [imodel-transformer](https://github.com/iTwin/imodel-transformer) sets this appropriately
1410
+ * on your behalf - you should never need to set or interrogate this property yourself.
1411
+ * @public
1412
+ */
1413
+ get codeValueBehavior() {
1414
+ return this[_nativeDb].getCodeValueBehavior();
1415
+ }
1416
+ set codeValueBehavior(newBehavior) {
1417
+ this[_nativeDb].setCodeValueBehavior(newBehavior);
1418
+ }
1419
+ /** @internal */
1420
+ computeRangesForText(args) {
1421
+ const props = this[_nativeDb].computeRangesForText(args.chars, args.fontId, args.bold, args.italic, args.widthFactor, args.lineHeight);
1422
+ return {
1423
+ layout: Range2d.fromJSON(props.layout),
1424
+ justification: Range2d.fromJSON(props.justification),
1425
+ };
1426
+ }
1427
+ /** Writes the contents of a single ECSchema to a file on the local file system.
1428
+ * @beta
1429
+ */
1430
+ exportSchema(args) {
1431
+ processSchemaWriteStatus(this[_nativeDb].exportSchema(args.schemaName, args.outputDirectory, args.outputFileName));
1432
+ }
1433
+ /** Writes the contents of all ECSchemas in this iModel to files in a directory on the local file system.
1434
+ * @beta
1435
+ */
1436
+ exportSchemas(outputDirectory) {
1437
+ processSchemaWriteStatus(this[_nativeDb].exportSchemas(outputDirectory));
1438
+ }
1439
+ /** Attempt to simplify the geometry stream of a single [[GeometricElement]] or [[GeometryPart]] as specified by `args`.
1440
+ * @beta
1441
+ */
1442
+ simplifyElementGeometry(args) {
1443
+ return this[_nativeDb].simplifyElementGeometry(args);
1444
+ }
1445
+ /** Attempts to optimize all of the geometry in this iModel by identifying [[GeometryPart]]s that are referenced by exactly one
1446
+ * element's geometry stream. Each such reference is replaced by inserting the part's geometry directly into the element's geometry stream.
1447
+ * Then, the no-longer-used geometry part is deleted.
1448
+ * This can improve performance when a connector inadvertently creates large numbers of parts that are each only used once.
1449
+ * @beta
1450
+ */
1451
+ inlineGeometryParts() {
1452
+ return this[_nativeDb].inlineGeometryPartReferences();
1453
+ }
1454
+ /** Returns a string representation of the error that most recently arose during an operation on the underlying SQLite database.
1455
+ * If no errors have occurred, an empty string is returned.
1456
+ * Otherwise, a string of the format `message (code)` is returned, where `message` is a human-readable diagnostic string and `code` is an integer status code.
1457
+ * See [SQLite error codes and messages](https://www.sqlite.org/c3ref/errcode.html)
1458
+ * @note Do not rely upon this value or its specific contents in error handling logic. It is only intended for use in debugging.
1459
+ */
1460
+ getLastError() {
1461
+ return this[_nativeDb].getLastError();
1462
+ }
1463
+ }
1464
+ function processSchemaWriteStatus(status) {
1465
+ switch (status) {
1466
+ case 0 /* SchemaWriteStatus.Success */: return;
1467
+ case 1 /* SchemaWriteStatus.FailedToSaveXml */: throw new Error("Failed to save schema XML");
1468
+ case 2 /* SchemaWriteStatus.FailedToCreateXml */: throw new Error("Failed to create schema XML");
1469
+ case 3 /* SchemaWriteStatus.FailedToCreateJson */: throw new Error("Failed to create schema JSON");
1470
+ case 4 /* SchemaWriteStatus.FailedToWriteFile */: throw new Error("Failed to write schema file");
1471
+ default: throw new Error("Unknown error while exporting schema");
1472
+ }
1473
+ }
1474
+ /** @public */
1475
+ (function (IModelDb) {
1476
+ /** The collection of models in an [[IModelDb]].
1477
+ * @public
1478
+ */
1479
+ class Models {
1480
+ _iModel;
1481
+ /** @internal */
1482
+ [_cache] = new LRUMap(500);
1483
+ /** @internal */
1484
+ constructor(_iModel) {
1485
+ this._iModel = _iModel;
1486
+ }
1487
+ /** Get the ModelProps with the specified identifier.
1488
+ * @param modelId The Model identifier.
1489
+ * @throws [[IModelError]] if the model is not found or cannot be loaded.
1490
+ * @see tryGetModelProps
1491
+ */
1492
+ getModelProps(id) {
1493
+ const model = this.tryGetModelProps(id);
1494
+ if (undefined === model)
1495
+ throw new IModelError(IModelStatus.NotFound, `Model=${id}`);
1496
+ return model;
1497
+ }
1498
+ /** Get the ModelProps with the specified identifier.
1499
+ * @param modelId The Model identifier.
1500
+ * @returns The ModelProps or `undefined` if the model is not found.
1501
+ * @throws [[IModelError]] if the model cannot be loaded.
1502
+ * @note Useful for cases when a model may or may not exist and throwing an `Error` would be overkill.
1503
+ * @see getModelProps
1504
+ */
1505
+ tryGetModelProps(id) {
1506
+ try {
1507
+ if (IModelHost.configuration?.disableThinnedNativeInstanceWorkflow) {
1508
+ return this._iModel[_nativeDb].getModel({ id });
1509
+ }
1510
+ const cachedMdl = this[_cache].get(id);
1511
+ if (cachedMdl) {
1512
+ return cachedMdl;
1513
+ }
1514
+ const options = { useJsNames: true };
1515
+ const instanceKey = this.resolveModelKey({ id });
1516
+ const rawInstance = this._iModel[_nativeDb].readInstance(instanceKey, options);
1517
+ const classDef = this._iModel.getJsClass(rawInstance.classFullName);
1518
+ const modelProps = classDef.deserialize({ row: rawInstance, iModel: this._iModel });
1519
+ this[_cache].set(id, modelProps);
1520
+ return modelProps;
1521
+ }
1522
+ catch {
1523
+ return undefined;
1524
+ }
1525
+ }
1526
+ /** Query for the last modified time for a [[Model]].
1527
+ * @param modelId The Id of the model.
1528
+ * @throws IModelError if `modelId` does not identify a model in the iModel.
1529
+ */
1530
+ queryLastModifiedTime(modelId) {
1531
+ const sql = `SELECT LastMod FROM ${Model.classFullName} WHERE ECInstanceId=:modelId`;
1532
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1533
+ return this._iModel.withPreparedStatement(sql, (statement) => {
1534
+ statement.bindId("modelId", modelId);
1535
+ if (DbResult.BE_SQLITE_ROW === statement.step()) {
1536
+ return statement.getValue(0).getDateTime();
1537
+ }
1538
+ throw new IModelError(IModelStatus.InvalidId, `Can't get lastMod time for Model ${modelId}`);
1539
+ });
1540
+ }
1541
+ /** Get the Model with the specified identifier.
1542
+ * @param modelId The Model identifier.
1543
+ * @param modelClass Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (`T`) parameter.
1544
+ * @throws [[IModelError]] if the model is not found, cannot be loaded, or fails validation when `modelClass` is specified.
1545
+ * @see tryGetModel
1546
+ */
1547
+ getModel(modelId, modelClass) {
1548
+ const model = this.tryGetModel(modelId, modelClass);
1549
+ if (undefined === model) {
1550
+ throw new IModelError(IModelStatus.NotFound, `Model=${modelId}`);
1551
+ }
1552
+ return model;
1553
+ }
1554
+ /** Get the Model with the specified identifier.
1555
+ * @param modelId The Model identifier.
1556
+ * @param modelClass Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (`T`) parameter.
1557
+ * @returns The Model or `undefined` if the model is not found or fails validation when `modelClass` is specified.
1558
+ * @throws [[IModelError]] if the model cannot be loaded.
1559
+ * @note Useful for cases when a model may or may not exist and throwing an `Error` would be overkill.
1560
+ * @see getModel
1561
+ */
1562
+ tryGetModel(modelId, modelClass) {
1563
+ const modelProps = this.tryGetModelProps(modelId);
1564
+ if (undefined === modelProps)
1565
+ return undefined; // no Model with that modelId found
1566
+ const model = this._iModel.constructEntity(modelProps);
1567
+ if (undefined === modelClass)
1568
+ return model; // modelClass was not specified, cannot call instanceof to validate
1569
+ return model instanceof modelClass ? model : undefined;
1570
+ }
1571
+ resolveModelKey(modelIdArg) {
1572
+ const baseClassName = "BisCore:Model";
1573
+ let args;
1574
+ if (modelIdArg.id) {
1575
+ args = { partialKey: { id: modelIdArg.id, baseClassName } };
1576
+ }
1577
+ else if (modelIdArg.code) {
1578
+ const modelId = this._iModel.elements.getElementProps({ code: modelIdArg.code }).id;
1579
+ if (!modelId)
1580
+ throw new IModelError(IModelStatus.NotFound, `Model not found with code: [spec:${modelIdArg.code.spec}, scope:${modelIdArg.code.scope}, value:${modelIdArg.code.value}])`);
1581
+ args = { partialKey: { id: modelId, baseClassName } };
1582
+ }
1583
+ else {
1584
+ throw new IModelError(IModelStatus.InvalidId, `Invalid model identifier: ${JSON.stringify(modelIdArg)}`);
1585
+ }
1586
+ return this._iModel[_nativeDb].resolveInstanceKey(args);
1587
+ }
1588
+ /** Get the sub-model of the specified Element.
1589
+ * See [[IModelDb.Elements.queryElementIdByCode]] for more on how to find an element by Code.
1590
+ * @param modeledElementId Identifies the modeled element.
1591
+ * @param modelClass Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (`T`) parameter.
1592
+ * @throws [[IModelError]] if the sub-model is not found, cannot be loaded, or fails validation when `modelClass` is specified.
1593
+ * @see tryGetSubModel
1594
+ */
1595
+ getSubModel(modeledElementId, modelClass) {
1596
+ const modeledElementProps = this._iModel.elements.getElementProps(modeledElementId);
1597
+ if (undefined === modeledElementProps.id || modeledElementProps.id === IModel.rootSubjectId)
1598
+ throw new IModelError(IModelStatus.NotFound, "Root subject does not have a sub-model");
1599
+ return this.getModel(modeledElementProps.id, modelClass);
1600
+ }
1601
+ /** Get the sub-model of the specified Element.
1602
+ * See [[IModelDb.Elements.queryElementIdByCode]] for more on how to find an element by Code.
1603
+ * @param modeledElementId Identifies the modeled element.
1604
+ * @param modelClass Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (`T`) parameter.
1605
+ * @returns The sub-model or `undefined` if the specified element does not have a sub-model or fails validation when `modelClass` is specified.
1606
+ * @see getSubModel
1607
+ */
1608
+ tryGetSubModel(modeledElementId, modelClass) {
1609
+ const modeledElementProps = this._iModel.elements.tryGetElementProps(modeledElementId);
1610
+ if (undefined === modeledElementProps?.id || (IModel.rootSubjectId === modeledElementProps.id))
1611
+ return undefined;
1612
+ return this.tryGetModel(modeledElementProps.id, modelClass);
1613
+ }
1614
+ /** Create a new model in memory.
1615
+ * See the example in [[InformationPartitionElement]].
1616
+ * @param modelProps The properties to use when creating the model.
1617
+ * @throws [[IModelError]] if there is a problem creating the model.
1618
+ */
1619
+ createModel(modelProps) { return this._iModel.constructEntity(modelProps); }
1620
+ /** Insert a new model.
1621
+ * @param props The data for the new model.
1622
+ * @returns The newly inserted model's Id.
1623
+ * @throws [[IModelError]] if unable to insert the model.
1624
+ */
1625
+ insertModel(props) {
1626
+ try {
1627
+ return props.id = this._iModel[_nativeDb].insertModel(props);
1628
+ }
1629
+ catch (err) {
1630
+ throw new IModelError(err.errorNumber, `Error inserting model [${err.message}], class=${props.classFullName}`);
1631
+ }
1632
+ }
1633
+ /** Update an existing model.
1634
+ * @param props the properties of the model to change
1635
+ * @throws [[IModelError]] if unable to update the model.
1636
+ */
1637
+ updateModel(props) {
1638
+ try {
1639
+ if (props.id)
1640
+ this[_cache].delete(props.id);
1641
+ this._iModel[_nativeDb].updateModel(props);
1642
+ }
1643
+ catch (err) {
1644
+ throw new IModelError(err.errorNumber, `error updating model [${err.message}] id=${props.id}`);
1645
+ }
1646
+ }
1647
+ /** Mark the geometry of [[GeometricModel]] as having changed, by recording an indirect change to its GeometryGuid property.
1648
+ * Typically the GeometryGuid changes automatically when [[GeometricElement]]s within the model are modified, but
1649
+ * explicitly updating it is occasionally useful after modifying definition elements like line styles or materials that indirectly affect the appearance of
1650
+ * [[GeometricElement]]s that reference those definition elements in their geometry streams.
1651
+ * Cached [Tile]($frontend)s are only invalidated after the geometry guid of the model changes.
1652
+ * @note This will throw IModelError with [IModelStatus.VersionTooOld]($core-bentley) if a version of the BisCore schema older than 1.0.11 is present in the iModel.
1653
+ * @throws IModelError if unable to update the geometry guid.
1654
+ * @see [[TxnManager.onModelGeometryChanged]] for the event emitted in response to such a change.
1655
+ */
1656
+ updateGeometryGuid(modelId) {
1657
+ this._iModel.models[_cache].delete(modelId);
1658
+ const error = this._iModel[_nativeDb].updateModelGeometryGuid(modelId);
1659
+ if (error !== IModelStatus.Success)
1660
+ throw new IModelError(error, `updating geometry guid for model ${modelId}`);
1661
+ }
1662
+ /** Delete one or more existing models.
1663
+ * @param ids The Ids of the models to be deleted
1664
+ * @throws [[IModelError]]
1665
+ */
1666
+ deleteModel(ids) {
1667
+ Id64.toIdSet(ids).forEach((id) => {
1668
+ try {
1669
+ this[_cache].delete(id);
1670
+ this._iModel[_nativeDb].deleteModel(id);
1671
+ }
1672
+ catch (err) {
1673
+ throw new IModelError(err.errorNumber, `error deleting model [${err.message}] id ${id}`);
1674
+ }
1675
+ });
1676
+ }
1677
+ /** For each specified [[GeometricModel]], attempts to obtain the union of the volumes of all geometric elements within that model.
1678
+ * @param ids The Id or Ids of the [[GeometricModel]]s for which to obtain the extents.
1679
+ * @returns An array of results, one per supplied Id, in the order in which the Ids were supplied. If the extents could not be obtained, the
1680
+ * corresponding results entry's `extents` will be a "null" range (@see [Range3d.isNull]($geometry)) and its `status` will indicate
1681
+ * why the extents could not be obtained (e.g., because the Id did not identify a [[GeometricModel]]).
1682
+ * @see [[queryRange]] to obtain the union of all of the models' extents.
1683
+ */
1684
+ async queryExtents(ids) {
1685
+ ids = typeof ids === "string" ? [ids] : ids;
1686
+ if (ids.length === 0)
1687
+ return [];
1688
+ return this._iModel[_nativeDb].queryModelExtentsAsync(ids);
1689
+ }
1690
+ /** Computes the union of the volumes of all geometric elements within one or more [[GeometricModel]]s, specified by model Id.
1691
+ * @see [[queryExtents]] to obtain discrete volumes for each model.
1692
+ */
1693
+ async queryRange(ids) {
1694
+ const results = await this.queryExtents(ids);
1695
+ const range = new Range3d();
1696
+ for (const result of results)
1697
+ range.union(Range3d.fromJSON(result.extents), range);
1698
+ return range;
1699
+ }
1700
+ }
1701
+ IModelDb.Models = Models;
1702
+ /** The collection of elements in an [[IModelDb]].
1703
+ * @public
1704
+ */
1705
+ class Elements {
1706
+ _iModel;
1707
+ /** @internal */
1708
+ [_cache] = new ElementLRUCache();
1709
+ /** @internal */
1710
+ constructor(_iModel) {
1711
+ this._iModel = _iModel;
1712
+ }
1713
+ getFederationGuidFromId(id) {
1714
+ return this._iModel.withPreparedSqliteStatement(`SELECT FederationGuid FROM bis_Element WHERE Id=?`, (stmt) => {
1715
+ stmt.bindId(1, id);
1716
+ return stmt.nextRow() ? stmt.getValueGuid(0) : undefined;
1717
+ });
1718
+ }
1719
+ getIdFromFederationGuid(guid) {
1720
+ return guid ? this._iModel.withPreparedSqliteStatement(`SELECT Id FROM bis_Element WHERE FederationGuid=?`, (stmt) => {
1721
+ stmt.bindGuid(1, guid);
1722
+ return !stmt.nextRow() ? undefined : stmt.getValueId(0);
1723
+ }) : undefined;
1724
+ }
1725
+ /** Get properties of an Element by Id, FederationGuid, or Code
1726
+ * @throws [[IModelError]] if the element is not found or cannot be loaded.
1727
+ * @see tryGetElementProps
1728
+ */
1729
+ getElementProps(props) {
1730
+ const elProp = this.tryGetElementProps(props);
1731
+ if (undefined === elProp)
1732
+ throw new IModelError(IModelStatus.NotFound, `element not found`);
1733
+ return elProp;
1734
+ }
1735
+ resolveElementKey(props) {
1736
+ const baseClassName = "BisCore:Element";
1737
+ let args;
1738
+ if (typeof props === "string") {
1739
+ args = Id64.isId64(props) ? { partialKey: { id: props, baseClassName } } : { federationGuid: props };
1740
+ }
1741
+ else if (props instanceof Code) {
1742
+ args = { code: props };
1743
+ }
1744
+ else {
1745
+ if (props.id) {
1746
+ args = { partialKey: { id: props.id, baseClassName } };
1747
+ }
1748
+ else if (props.federationGuid) {
1749
+ args = { federationGuid: props.federationGuid };
1750
+ }
1751
+ else if (props.code) {
1752
+ args = { code: props.code };
1753
+ }
1754
+ else {
1755
+ throw new IModelError(IModelStatus.InvalidId, "Element Id or FederationGuid or Code is required");
1756
+ }
1757
+ }
1758
+ return this._iModel[_nativeDb].resolveInstanceKey(args);
1759
+ }
1760
+ /** Get properties of an Element by Id, FederationGuid, or Code
1761
+ * @returns The properties of the element or `undefined` if the element is not found.
1762
+ * @throws [[IModelError]] if the element exists, but cannot be loaded.
1763
+ * @note Useful for cases when an element may or may not exist and throwing an `Error` would be overkill.
1764
+ * @see getElementProps
1765
+ */
1766
+ tryGetElementProps(props) {
1767
+ if (typeof props === "string") {
1768
+ props = Id64.isId64(props) ? { id: props } : { federationGuid: props };
1769
+ }
1770
+ else if (props instanceof Code) {
1771
+ props = { code: props };
1772
+ }
1773
+ try {
1774
+ if (IModelHost.configuration?.disableThinnedNativeInstanceWorkflow) {
1775
+ return this._iModel[_nativeDb].getElement(props);
1776
+ }
1777
+ const cachedElm = this[_cache].get(props);
1778
+ if (cachedElm) {
1779
+ return cachedElm.elProps;
1780
+ }
1781
+ const options = { ...props, useJsNames: true };
1782
+ const instanceKey = this.resolveElementKey(props);
1783
+ const rawInstance = this._iModel[_nativeDb].readInstance(instanceKey, options);
1784
+ const classDef = this._iModel.getJsClass(rawInstance.classFullName);
1785
+ const elementProps = classDef.deserialize({ row: rawInstance, iModel: this._iModel, options: { element: props } });
1786
+ this[_cache].set({ elProps: elementProps, loadOptions: props });
1787
+ return elementProps;
1788
+ }
1789
+ catch {
1790
+ return undefined;
1791
+ }
1792
+ }
1793
+ /** Get an element by Id, FederationGuid, or Code
1794
+ * @param elementId either the element's Id, Code, or FederationGuid, or an ElementLoadProps
1795
+ * @param elementClass Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (`T`) parameter.
1796
+ * @throws [[IModelError]] if the element is not found, cannot be loaded, or fails validation when `elementClass` is specified.
1797
+ * @see tryGetElement
1798
+ */
1799
+ getElement(elementId, elementClass) {
1800
+ const element = this.tryGetElement(elementId, elementClass);
1801
+ if (undefined === element) {
1802
+ if (typeof elementId === "string" || elementId instanceof Code)
1803
+ throw new IModelError(IModelStatus.NotFound, `Element=${elementId}`);
1804
+ else
1805
+ throw new IModelError(IModelStatus.NotFound, `Element={id: ${elementId.id} federationGuid: ${elementId.federationGuid}, code: ${elementId.code}}`);
1806
+ }
1807
+ return element;
1808
+ }
1809
+ /** Get an element by Id, FederationGuid, or Code
1810
+ * @param elementId either the element's Id, Code, or FederationGuid, or an ElementLoadProps
1811
+ * @param elementClass Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (`T`) parameter.
1812
+ * @returns The element or `undefined` if the element is not found or fails validation when `elementClass` is specified.
1813
+ * @throws [[IModelError]] if the element exists, but cannot be loaded.
1814
+ * @note Useful for cases when an element may or may not exist and throwing an `Error` would be overkill.
1815
+ * @see getElement
1816
+ */
1817
+ tryGetElement(elementId, elementClass) {
1818
+ if (typeof elementId === "string")
1819
+ elementId = Id64.isId64(elementId) ? { id: elementId } : { federationGuid: elementId };
1820
+ else if (elementId instanceof Code)
1821
+ elementId = { code: elementId };
1822
+ else
1823
+ elementId.onlyBaseProperties = false; // we must load all properties to construct the element.
1824
+ const elementProps = this.tryGetElementProps(elementId);
1825
+ if (undefined === elementProps)
1826
+ return undefined; // no Element with that elementId found
1827
+ const element = this._iModel.constructEntity(elementProps);
1828
+ if (undefined === elementClass)
1829
+ return element; // elementClass was not specified, cannot call instanceof to validate
1830
+ return element instanceof elementClass ? element : undefined;
1831
+ }
1832
+ /** Query for the Id of the element that has a specified code.
1833
+ * This method is for the case where you know the element's Code.
1834
+ * If you only know the code *value*, then in the simplest case, you can query on that
1835
+ * and filter the results.
1836
+ * In the simple case, call [[IModelDb.queryEntityIds]], specifying the code value in the where clause of the query params.
1837
+ * Or, you can execute an ECSQL select statement. See
1838
+ * [frequently used ECSQL queries]($docs/learning/backend/ECSQL-queries.md) for an example.
1839
+ * @param code The code to look for
1840
+ * @returns The element that uses the code or undefined if the code is not used.
1841
+ * @throws IModelError if the code is invalid
1842
+ */
1843
+ queryElementIdByCode(code) {
1844
+ if (Id64.isInvalid(code.spec))
1845
+ throw new IModelError(IModelStatus.InvalidCodeSpec, "Invalid CodeSpec");
1846
+ if (code.value === undefined)
1847
+ throw new IModelError(IModelStatus.InvalidCode, "Invalid Code");
1848
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1849
+ return this._iModel.withPreparedStatement("SELECT ECInstanceId FROM BisCore:Element WHERE CodeSpec.Id=? AND CodeScope.Id=? AND CodeValue=?", (stmt) => {
1850
+ stmt.bindId(1, code.spec);
1851
+ stmt.bindId(2, Id64.fromString(code.scope));
1852
+ stmt.bindString(3, code.value);
1853
+ if (DbResult.BE_SQLITE_ROW !== stmt.step())
1854
+ return undefined;
1855
+ return stmt.getValue(0).getId();
1856
+ });
1857
+ }
1858
+ /** Query for an [[Element]]'s last modified time.
1859
+ * @param elementId The Id of the element.
1860
+ * @throws IModelError if `elementId` does not identify an element in the iModel.
1861
+ */
1862
+ queryLastModifiedTime(elementId) {
1863
+ const sql = "SELECT LastMod FROM BisCore:Element WHERE ECInstanceId=:elementId";
1864
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1865
+ return this._iModel.withPreparedStatement(sql, (statement) => {
1866
+ statement.bindId("elementId", elementId);
1867
+ if (DbResult.BE_SQLITE_ROW === statement.step())
1868
+ return statement.getValue(0).getDateTime();
1869
+ throw new IModelError(IModelStatus.InvalidId, `Can't get lastMod time for Element ${elementId}`);
1870
+ });
1871
+ }
1872
+ /** Create a new instance of an element.
1873
+ * @param elProps The properties of the new element.
1874
+ * @throws [[IModelError]] if there is a problem creating the element.
1875
+ */
1876
+ createElement(elProps) { return this._iModel.constructEntity(elProps); }
1877
+ /** Insert a new element into the iModel.
1878
+ * @param elProps The properties of the new element.
1879
+ * @returns The newly inserted element's Id.
1880
+ * @throws [[IModelError]] if unable to insert the element.
1881
+ * @note For convenience, the value of `elProps.id` is updated to reflect the resultant element's id.
1882
+ * However when `elProps.federationGuid` is not present or undefined, a new Guid will be generated and stored on the resultant element. But
1883
+ * the value of `elProps.federationGuid` is *not* updated. Generally, it is best to re-read the element after inserting (e.g. via [[getElementProps]])
1884
+ * if you intend to continue working with it. That will ensure its values reflect the persistent state.
1885
+ */
1886
+ insertElement(elProps, options) {
1887
+ try {
1888
+ this[_cache].delete({
1889
+ id: elProps.id,
1890
+ federationGuid: elProps.federationGuid,
1891
+ code: elProps.code,
1892
+ });
1893
+ return elProps.id = this._iModel[_nativeDb].insertElement(elProps, options);
1894
+ }
1895
+ catch (err) {
1896
+ err.message = `Error inserting element [${err.message}]`;
1897
+ err.metadata = { elProps };
1898
+ throw err;
1899
+ }
1900
+ }
1901
+ /**
1902
+ * Update some properties of an existing element.
1903
+ * All parts of `elProps` are optional *other than* `id`. If id is missing, an exception is thrown.
1904
+ *
1905
+ * To support clearing a property value, every property name that is present in the `elProps` object will be updated even if the value is `undefined`.
1906
+ * To keep an individual element property unchanged, it should either be excluded from the `elProps` parameter or set to its current value.
1907
+ * @param elProps the properties of the element to update.
1908
+ * @note The values of `classFullName` and `model` *may not be changed* by this method. Further, it will permute the `elProps` object by adding or
1909
+ * overwriting their values to the correct values.
1910
+ * @throws [[IModelError]] if unable to update the element.
1911
+ */
1912
+ updateElement(elProps) {
1913
+ try {
1914
+ this[_cache].delete({
1915
+ id: elProps.id,
1916
+ federationGuid: elProps.federationGuid,
1917
+ code: elProps.code,
1918
+ });
1919
+ this._iModel[_nativeDb].updateElement(elProps);
1920
+ }
1921
+ catch (err) {
1922
+ err.message = `Error updating element [${err.message}], id: ${elProps.id}`;
1923
+ err.metadata = { elProps };
1924
+ throw err;
1925
+ }
1926
+ }
1927
+ /** Delete one or more elements from this iModel.
1928
+ * @param ids The set of Ids of the element(s) to be deleted
1929
+ * @throws [[IModelError]]
1930
+ * @see deleteDefinitionElements
1931
+ */
1932
+ deleteElement(ids) {
1933
+ const iModel = this._iModel;
1934
+ Id64.toIdSet(ids).forEach((id) => {
1935
+ try {
1936
+ this[_cache].delete({ id });
1937
+ iModel[_nativeDb].deleteElement(id);
1938
+ }
1939
+ catch (err) {
1940
+ err.message = `Error deleting element [${err.message}], id: ${id}`;
1941
+ err.metadata = { elementId: id };
1942
+ throw err;
1943
+ }
1944
+ });
1945
+ }
1946
+ /** DefinitionElements can only be deleted if it can be determined that they are not referenced by other Elements.
1947
+ * This *usage query* can be expensive since it may involve scanning the GeometryStreams of all GeometricElements.
1948
+ * Since [[deleteElement]] does not perform these additional checks, it fails in order to prevent potentially referenced DefinitionElements from being deleted.
1949
+ * This method performs those expensive checks and then calls *delete* if not referenced.
1950
+ * @param ids The Ids of the DefinitionElements to attempt to delete. To prevent multiple passes over the same GeometricElements, it is best to pass in the entire array of
1951
+ * DefinitionElements rather than calling this method separately for each one. Ids that are not valid DefinitionElements will be ignored.
1952
+ * @returns An IdSet of the DefinitionElements that are used and were therefore not deleted.
1953
+ * @see deleteElement
1954
+ * @beta
1955
+ */
1956
+ deleteDefinitionElements(definitionElementIds) {
1957
+ const usageInfo = this._iModel[_nativeDb].queryDefinitionElementUsage(definitionElementIds);
1958
+ if (!usageInfo) {
1959
+ throw new IModelError(IModelStatus.BadRequest, "Error querying for DefinitionElement usage");
1960
+ }
1961
+ const usedIdSet = usageInfo.usedIds ? Id64.toIdSet(usageInfo.usedIds) : new Set();
1962
+ const deleteIfUnused = (ids, used) => {
1963
+ if (ids) {
1964
+ ids.forEach((id) => {
1965
+ if (!used.has(id))
1966
+ this._iModel.elements.deleteElement(id);
1967
+ });
1968
+ }
1969
+ };
1970
+ try {
1971
+ this._iModel[_nativeDb].beginPurgeOperation();
1972
+ deleteIfUnused(usageInfo.spatialCategoryIds, usedIdSet);
1973
+ deleteIfUnused(usageInfo.drawingCategoryIds, usedIdSet);
1974
+ deleteIfUnused(usageInfo.viewDefinitionIds, usedIdSet);
1975
+ deleteIfUnused(usageInfo.geometryPartIds, usedIdSet);
1976
+ deleteIfUnused(usageInfo.lineStyleIds, usedIdSet);
1977
+ deleteIfUnused(usageInfo.renderMaterialIds, usedIdSet);
1978
+ deleteIfUnused(usageInfo.subCategoryIds, usedIdSet);
1979
+ deleteIfUnused(usageInfo.textureIds, usedIdSet);
1980
+ deleteIfUnused(usageInfo.displayStyleIds, usedIdSet);
1981
+ deleteIfUnused(usageInfo.categorySelectorIds, usedIdSet);
1982
+ deleteIfUnused(usageInfo.modelSelectorIds, usedIdSet);
1983
+ if (usageInfo.otherDefinitionElementIds) {
1984
+ this._iModel.elements.deleteElement(usageInfo.otherDefinitionElementIds);
1985
+ }
1986
+ }
1987
+ finally {
1988
+ this._iModel[_nativeDb].endPurgeOperation();
1989
+ }
1990
+ if (usageInfo.viewDefinitionIds) {
1991
+ // take another pass in case a deleted ViewDefinition was the only usage of these view-related DefinitionElements
1992
+ let viewRelatedIds = [];
1993
+ if (usageInfo.displayStyleIds)
1994
+ viewRelatedIds = viewRelatedIds.concat(usageInfo.displayStyleIds.filter((id) => usedIdSet.has(id)));
1995
+ if (usageInfo.categorySelectorIds)
1996
+ viewRelatedIds = viewRelatedIds.concat(usageInfo.categorySelectorIds.filter((id) => usedIdSet.has(id)));
1997
+ if (usageInfo.modelSelectorIds)
1998
+ viewRelatedIds = viewRelatedIds.concat(usageInfo.modelSelectorIds.filter((id) => usedIdSet.has(id)));
1999
+ if (viewRelatedIds.length > 0) {
2000
+ const viewRelatedUsageInfo = this._iModel[_nativeDb].queryDefinitionElementUsage(viewRelatedIds);
2001
+ if (viewRelatedUsageInfo) {
2002
+ const usedViewRelatedIdSet = viewRelatedUsageInfo.usedIds ? Id64.toIdSet(viewRelatedUsageInfo.usedIds) : new Set();
2003
+ try {
2004
+ this._iModel[_nativeDb].beginPurgeOperation();
2005
+ deleteIfUnused(viewRelatedUsageInfo.displayStyleIds, usedViewRelatedIdSet);
2006
+ deleteIfUnused(viewRelatedUsageInfo.categorySelectorIds, usedViewRelatedIdSet);
2007
+ deleteIfUnused(viewRelatedUsageInfo.modelSelectorIds, usedViewRelatedIdSet);
2008
+ }
2009
+ finally {
2010
+ this._iModel[_nativeDb].endPurgeOperation();
2011
+ }
2012
+ viewRelatedIds.forEach((id) => {
2013
+ if (!usedViewRelatedIdSet.has(id))
2014
+ usedIdSet.delete(id);
2015
+ });
2016
+ }
2017
+ }
2018
+ }
2019
+ return usedIdSet;
2020
+ }
2021
+ /** Query for the child elements of the specified element.
2022
+ * @returns Returns an array of child element identifiers.
2023
+ * @throws [[IModelError]]
2024
+ */
2025
+ queryChildren(elementId) {
2026
+ const sql = "SELECT ECInstanceId FROM BisCore:Element WHERE Parent.Id=:elementId";
2027
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2028
+ return this._iModel.withPreparedStatement(sql, (statement) => {
2029
+ statement.bindId("elementId", elementId);
2030
+ const childIds = [];
2031
+ while (DbResult.BE_SQLITE_ROW === statement.step()) {
2032
+ childIds.push(statement.getValue(0).getId());
2033
+ }
2034
+ return childIds;
2035
+ });
2036
+ }
2037
+ /** Query for the parent of the specified element.
2038
+ * @param elementId The element to check for a parent
2039
+ * @returns The identifier of the element's parent or undefined if the element has no parent
2040
+ * @throws [[IModelError]] if the element does not exist
2041
+ */
2042
+ queryParent(elementId) {
2043
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2044
+ return this._iModel.withPreparedStatement(`select parent.id from ${Element.classFullName} where ecinstanceid=?`, (stmt) => {
2045
+ stmt.bindId(1, elementId);
2046
+ if (stmt.step() !== DbResult.BE_SQLITE_ROW)
2047
+ throw new IModelError(IModelStatus.NotFound, `Element=${elementId}`);
2048
+ const value = stmt.getValue(0);
2049
+ return value.isNull ? undefined : value.getId();
2050
+ });
2051
+ }
2052
+ /** Returns true if the specified Element has a sub-model.
2053
+ * @see [[IModelDb.Models.getSubModel]]
2054
+ */
2055
+ hasSubModel(elementId) {
2056
+ if (IModel.rootSubjectId === elementId)
2057
+ return false; // Special case since the RepositoryModel does not sub-model the root Subject
2058
+ // A sub-model will have the same Id value as the element it is describing
2059
+ const sql = "SELECT ECInstanceId FROM BisCore:Model WHERE ECInstanceId=:elementId";
2060
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2061
+ return this._iModel.withPreparedStatement(sql, (statement) => {
2062
+ statement.bindId("elementId", elementId);
2063
+ return DbResult.BE_SQLITE_ROW === statement.step();
2064
+ });
2065
+ }
2066
+ /** Get the root subject element. */
2067
+ getRootSubject() { return this.getElement(IModel.rootSubjectId); }
2068
+ /** Query for aspects of a particular class (polymorphically) associated with this element.
2069
+ * @throws [[IModelError]]
2070
+ * @note Most cases should use the [[getAspects]] wrapper rather than calling this method directly.
2071
+ * @internal
2072
+ */
2073
+ _queryAspects(elementId, fromClassFullName, excludedClassFullNames) {
2074
+ const sql = `SELECT ECInstanceId,ECClassId FROM ${fromClassFullName} WHERE Element.Id=:elementId ORDER BY ECClassId,ECInstanceId`; // ORDER BY to maximize statement reuse
2075
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2076
+ return this._iModel.withPreparedStatement(sql, (statement) => {
2077
+ statement.bindId("elementId", elementId);
2078
+ const aspects = [];
2079
+ while (DbResult.BE_SQLITE_ROW === statement.step()) {
2080
+ const aspectInstanceId = statement.getValue(0).getId();
2081
+ const aspectClassFullName = statement.getValue(1).getClassNameForClassId().replace(".", ":");
2082
+ if ((undefined === excludedClassFullNames) || (!excludedClassFullNames.has(aspectClassFullName))) {
2083
+ aspects.push(this._queryAspect(aspectInstanceId, aspectClassFullName));
2084
+ }
2085
+ }
2086
+ return aspects;
2087
+ });
2088
+ }
2089
+ /** Query for aspect by ECInstanceId
2090
+ * @throws [[IModelError]]
2091
+ */
2092
+ _queryAspect(aspectInstanceId, aspectClassName) {
2093
+ const sql = `SELECT * FROM ${aspectClassName} WHERE ECInstanceId=:aspectInstanceId`;
2094
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2095
+ const aspect = this._iModel.withPreparedStatement(sql, (statement) => {
2096
+ statement.bindId("aspectInstanceId", aspectInstanceId);
2097
+ if (DbResult.BE_SQLITE_ROW === statement.step()) {
2098
+ const aspectProps = statement.getRow(); // start with everything that SELECT * returned
2099
+ aspectProps.classFullName = aspectProps.className.replace(".", ":"); // add in property required by EntityProps
2100
+ aspectProps.className = undefined; // clear property from SELECT * that we don't want in the final instance
2101
+ return aspectProps;
2102
+ }
2103
+ return undefined;
2104
+ });
2105
+ if (undefined === aspect) {
2106
+ throw new IModelError(IModelStatus.NotFound, `ElementAspect not found ${aspectInstanceId}, ${aspectClassName}`);
2107
+ }
2108
+ return this._iModel.constructEntity(aspect);
2109
+ }
2110
+ /** Get a single ElementAspect by its instance Id.
2111
+ * @throws [[IModelError]]
2112
+ */
2113
+ getAspect(aspectInstanceId) {
2114
+ const sql = "SELECT ECClassId FROM BisCore:ElementAspect WHERE ECInstanceId=:aspectInstanceId";
2115
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2116
+ const aspectClassFullName = this._iModel.withPreparedStatement(sql, (statement) => {
2117
+ statement.bindId("aspectInstanceId", aspectInstanceId);
2118
+ return (DbResult.BE_SQLITE_ROW === statement.step()) ? statement.getValue(0).getClassNameForClassId().replace(".", ":") : undefined;
2119
+ });
2120
+ if (undefined === aspectClassFullName) {
2121
+ throw new IModelError(IModelStatus.NotFound, `ElementAspect not found ${aspectInstanceId}`);
2122
+ }
2123
+ return this._queryAspect(aspectInstanceId, aspectClassFullName);
2124
+ }
2125
+ static classMap = new Map();
2126
+ runInstanceQuery(sql, elementId, excludedClassFullNames) {
2127
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2128
+ return this._iModel.withPreparedStatement(sql, (statement) => {
2129
+ statement.bindId("elementId", elementId);
2130
+ const aspects = [];
2131
+ while (DbResult.BE_SQLITE_ROW === statement.step()) {
2132
+ const row = {};
2133
+ const parsedRow = JSON.parse(statement.getValue(0).getString());
2134
+ // eslint-disable-next-line guard-for-in
2135
+ for (const key in parsedRow) {
2136
+ const jsName = ECJsNames.toJsName(key[0].toUpperCase() + key.substring(1));
2137
+ Object.defineProperty(row, jsName, { enumerable: true, configurable: true, writable: true, value: parsedRow[key] });
2138
+ }
2139
+ const aspectProps = row;
2140
+ aspectProps.classFullName = aspectProps.className.replace(".", ":"); // add in property required by EntityProps
2141
+ aspectProps.className = undefined; // clear property from SELECT $ that we don't want in the final instance
2142
+ if ((undefined === excludedClassFullNames) || !excludedClassFullNames.has(aspectProps.classFullName))
2143
+ aspects.push(this._iModel.constructEntity(aspectProps));
2144
+ }
2145
+ return aspects;
2146
+ });
2147
+ }
2148
+ /** Get the ElementAspect instances that are owned by the specified element.
2149
+ * @param elementId Get ElementAspects associated with this Element
2150
+ * @param aspectClassFullName Optionally filter ElementAspects polymorphically by this class name
2151
+ * @param excludedClassFullNames Optional filter to exclude aspects from classes in the given set.
2152
+ * @throws [[IModelError]]
2153
+ */
2154
+ getAspects(elementId, aspectClassFullName, excludedClassFullNames) {
2155
+ if (aspectClassFullName === undefined) {
2156
+ const allAspects = this.runInstanceQuery(`SELECT $ FROM (
2157
+ SELECT ECInstanceId, ECClassId FROM Bis.ElementMultiAspect WHERE Element.Id = :elementId
2158
+ UNION ALL
2159
+ SELECT ECInstanceId, ECClassId FROM Bis.ElementUniqueAspect WHERE Element.Id = :elementId) OPTIONS USE_JS_PROP_NAMES DO_NOT_TRUNCATE_BLOB`, elementId, excludedClassFullNames);
2160
+ if (allAspects.length === 0)
2161
+ Logger.logInfo(BackendLoggerCategory.ECDb, `No aspects found for class ${aspectClassFullName} and element ${elementId}`);
2162
+ return allAspects;
2163
+ }
2164
+ // Check if class is abstract
2165
+ const fullClassName = aspectClassFullName.replace(".", ":").split(":");
2166
+ const val = this._iModel[_nativeDb].getECClassMetaData(fullClassName[0], fullClassName[1]);
2167
+ if (val.result !== undefined) {
2168
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2169
+ const metaData = new EntityMetaData(JSON.parse(val.result));
2170
+ if (metaData.modifier !== "Abstract") // Class is not abstract, use normal query to retrieve aspects
2171
+ return this._queryAspects(elementId, aspectClassFullName, excludedClassFullNames);
2172
+ }
2173
+ // If class specified is abstract, get the list of all classes derived from it
2174
+ let classIdList = IModelDb.Elements.classMap.get(aspectClassFullName);
2175
+ if (classIdList === undefined) {
2176
+ const classIds = [];
2177
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2178
+ this._iModel.withPreparedStatement(`select SourceECInstanceId from meta.ClassHasAllBaseClasses where TargetECInstanceId = (select ECInstanceId from meta.ECClassDef where Name='${fullClassName[1]}'
2179
+ and Schema.Id = (select ECInstanceId from meta.ECSchemaDef where Name='${fullClassName[0]}')) and SourceECInstanceId != TargetECInstanceId`,
2180
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2181
+ (statement) => {
2182
+ while (statement.step() === DbResult.BE_SQLITE_ROW)
2183
+ classIds.push(statement.getValue(0).getId());
2184
+ });
2185
+ if (classIds.length > 0) {
2186
+ classIdList = classIds.join(",");
2187
+ IModelDb.Elements.classMap.set(aspectClassFullName, classIdList);
2188
+ }
2189
+ }
2190
+ if (classIdList === undefined) {
2191
+ Logger.logError(BackendLoggerCategory.ECDb, `No aspects found for the class ${aspectClassFullName}`);
2192
+ return [];
2193
+ }
2194
+ // Execute an instance query to retrieve all aspects from all the derived classes
2195
+ const aspects = this.runInstanceQuery(`SELECT $ FROM (
2196
+ SELECT ECInstanceId, ECClassId FROM Bis.ElementMultiAspect WHERE Element.Id = :elementId AND ECClassId IN (${classIdList})
2197
+ UNION ALL
2198
+ SELECT ECInstanceId, ECClassId FROM Bis.ElementUniqueAspect WHERE Element.Id = :elementId AND ECClassId IN (${classIdList})
2199
+ ) OPTIONS USE_JS_PROP_NAMES DO_NOT_TRUNCATE_BLOB`, elementId, excludedClassFullNames);
2200
+ if (aspects.length === 0)
2201
+ Logger.logInfo(BackendLoggerCategory.ECDb, `No aspects found for class ${aspectClassFullName} and element ${elementId}`);
2202
+ return aspects;
2203
+ }
2204
+ /** Insert a new ElementAspect into the iModel.
2205
+ * @param aspectProps The properties of the new ElementAspect.
2206
+ * @throws [[IModelError]] if unable to insert the ElementAspect.
2207
+ * @returns the id of the newly inserted aspect.
2208
+ * @note Aspect Ids may collide with element Ids, so don't put both in a container like Set or Map
2209
+ * use [EntityReference]($common) for that instead.
2210
+ */
2211
+ insertAspect(aspectProps) {
2212
+ try {
2213
+ return this._iModel[_nativeDb].insertElementAspect(aspectProps);
2214
+ }
2215
+ catch (err) {
2216
+ throw new IModelError(err.errorNumber, `Error inserting ElementAspect [${err.message}], class: ${aspectProps.classFullName}`);
2217
+ }
2218
+ }
2219
+ /** Update an exist ElementAspect within the iModel.
2220
+ * @param aspectProps The properties to use to update the ElementAspect.
2221
+ * @throws [[IModelError]] if unable to update the ElementAspect.
2222
+ */
2223
+ updateAspect(aspectProps) {
2224
+ try {
2225
+ this._iModel[_nativeDb].updateElementAspect(aspectProps);
2226
+ }
2227
+ catch (err) {
2228
+ throw new IModelError(err.errorNumber, `Error updating ElementAspect [${err.message}], id: ${aspectProps.id}`);
2229
+ }
2230
+ }
2231
+ /** Delete one or more ElementAspects from this iModel.
2232
+ * @param aspectInstanceIds The set of instance Ids of the ElementAspect(s) to be deleted
2233
+ * @throws [[IModelError]] if unable to delete the ElementAspect.
2234
+ */
2235
+ deleteAspect(aspectInstanceIds) {
2236
+ const iModel = this._iModel;
2237
+ Id64.toIdSet(aspectInstanceIds).forEach((aspectInstanceId) => {
2238
+ try {
2239
+ iModel[_nativeDb].deleteElementAspect(aspectInstanceId);
2240
+ }
2241
+ catch (err) {
2242
+ throw new IModelError(err.errorNumber, `Error deleting ElementAspect [${err.message}], id: ${aspectInstanceId}`);
2243
+ }
2244
+ });
2245
+ }
2246
+ }
2247
+ IModelDb.Elements = Elements;
2248
+ /** The collection of views in an [[IModelDb]].
2249
+ * @public
2250
+ */
2251
+ class Views {
2252
+ _iModel;
2253
+ /** @internal */
2254
+ constructor(_iModel) {
2255
+ this._iModel = _iModel;
2256
+ }
2257
+ static viewStoreProperty = { namespace: "itwinjs", name: "DefaultViewStore" };
2258
+ _viewStore;
2259
+ get hasViewStore() { return undefined !== this._viewStore; }
2260
+ /** @beta */
2261
+ get viewStore() {
2262
+ if (undefined === this._viewStore)
2263
+ throw new IModelError(IModelStatus.BadRequest, "No ViewStore available");
2264
+ return this._viewStore;
2265
+ }
2266
+ set viewStore(viewStore) {
2267
+ this._viewStore = viewStore;
2268
+ }
2269
+ /** @beta */
2270
+ async accessViewStore(args) {
2271
+ let props = args.props;
2272
+ if (undefined === props) {
2273
+ const propsString = this._iModel.queryFilePropertyString(Views.viewStoreProperty);
2274
+ if (!propsString)
2275
+ throw new Error("iModel does not have a default ViewStore");
2276
+ props = JSON.parse(propsString);
2277
+ }
2278
+ const accessToken = await CloudSqlite.requestToken({
2279
+ ...props,
2280
+ accessLevel: args.accessLevel,
2281
+ });
2282
+ if (!this._viewStore)
2283
+ this._viewStore = new ViewStore.CloudAccess({ ...props, accessToken, iModel: this._iModel });
2284
+ this._viewStore.container.accessToken = accessToken;
2285
+ return this._viewStore;
2286
+ }
2287
+ /** @beta */
2288
+ saveDefaultViewStore(arg) {
2289
+ const props = { baseUri: arg.baseUri, containerId: arg.containerId, storageType: arg.storageType }; // sanitize to only known properties
2290
+ this._iModel.saveFileProperty(Views.viewStoreProperty, JSON.stringify(props));
2291
+ this._iModel.saveChanges("update default ViewStore");
2292
+ }
2293
+ /** Query for the array of ViewDefinitionProps of the specified class and matching the specified IsPrivate setting.
2294
+ * @param className Query for view definitions of this class.
2295
+ * @param wantPrivate If true, include private view definitions.
2296
+ */
2297
+ queryViewDefinitionProps(className = "BisCore.ViewDefinition", limit = IModelDb.defaultLimit, offset = 0, wantPrivate = false) {
2298
+ const where = (wantPrivate === false) ? "IsPrivate=FALSE" : "";
2299
+ const ids = this._iModel.queryEntityIds({ from: className, limit, offset, where });
2300
+ const props = [];
2301
+ const imodel = this._iModel;
2302
+ ids.forEach((id) => {
2303
+ try {
2304
+ props.push(imodel.elements.getElementProps(id));
2305
+ }
2306
+ catch { }
2307
+ });
2308
+ return props;
2309
+ }
2310
+ /** Default parameters for iterating/querying ViewDefinitions. Includes all subclasses of ViewDefinition, excluding only those marked 'private'. */
2311
+ static defaultQueryParams = { from: "BisCore.ViewDefinition", where: "IsPrivate=FALSE" };
2312
+ /** Iterate all ViewDefinitions matching the supplied query.
2313
+ * @param params Specifies the query by which views are selected.
2314
+ * @param callback Function invoked for each ViewDefinition matching the query. Return false to terminate iteration, true to continue.
2315
+ * @returns true if all views were iterated, false if iteration was terminated early due to callback returning false.
2316
+ */
2317
+ iterateViews(params, callback) {
2318
+ const ids = this._iModel.queryEntityIds(params);
2319
+ let finished = true;
2320
+ for (const id of ids) {
2321
+ try {
2322
+ const view = this._iModel.elements.getElement(id);
2323
+ if (undefined !== view && view instanceof ViewDefinition) {
2324
+ finished = callback(view);
2325
+ if (!finished)
2326
+ break;
2327
+ }
2328
+ }
2329
+ catch { }
2330
+ }
2331
+ return finished;
2332
+ }
2333
+ loadViewData(viewId, options) {
2334
+ const iModel = this._iModel;
2335
+ const elements = iModel.elements;
2336
+ const loader = (() => {
2337
+ if (ViewStoreRpc.isViewStoreId(viewId)) {
2338
+ const reader = this.viewStore.reader;
2339
+ return {
2340
+ loadView: () => reader.getViewDefinitionSync({ viewId }),
2341
+ loadCategorySelector: (id) => reader.getCategorySelectorSync({ id, bindings: options?.queryBindings?.categorySelector }),
2342
+ loadDisplayStyle: (id) => reader.getDisplayStyleSync({ id, opts: options?.displayStyle }),
2343
+ loadModelSelector: (id) => reader.getModelSelectorSync({ id, bindings: options?.queryBindings?.modelSelector }),
2344
+ };
2345
+ }
2346
+ return {
2347
+ loadView: () => elements.getElementProps(viewId),
2348
+ loadCategorySelector: (id) => elements.getElementProps(id),
2349
+ loadDisplayStyle: (id) => elements.getElementProps({ id, displayStyle: options?.displayStyle }),
2350
+ loadModelSelector: (id) => elements.getElementProps(id),
2351
+ };
2352
+ })();
2353
+ const props = {};
2354
+ props.viewDefinitionProps = loader.loadView();
2355
+ props.categorySelectorProps = loader.loadCategorySelector(props.viewDefinitionProps.categorySelectorId);
2356
+ props.displayStyleProps = loader.loadDisplayStyle(props.viewDefinitionProps.displayStyleId);
2357
+ const modelSelectorId = props.viewDefinitionProps.modelSelectorId;
2358
+ if (modelSelectorId !== undefined)
2359
+ props.modelSelectorProps = loader.loadModelSelector(modelSelectorId);
2360
+ const viewClass = iModel.getJsClass(props.viewDefinitionProps.classFullName);
2361
+ const baseModelId = props.viewDefinitionProps.baseModelId;
2362
+ if (viewClass.is(SheetViewDefinition)) {
2363
+ props.sheetProps = elements.getElementProps(baseModelId);
2364
+ props.sheetAttachments = Array.from(iModel.queryEntityIds({
2365
+ from: "BisCore.ViewAttachment",
2366
+ where: `Model.Id=${baseModelId}`,
2367
+ }));
2368
+ }
2369
+ else if (viewClass.is(DrawingViewDefinition)) {
2370
+ // Include information about the associated [[SectionDrawing]], if any.
2371
+ // NB: The SectionDrawing ECClass may not exist in the iModel's version of the BisCore ECSchema.
2372
+ const sectionDrawing = iModel.elements.tryGetElement(baseModelId);
2373
+ if (sectionDrawing && sectionDrawing.spatialView && Id64.isValidId64(sectionDrawing.spatialView.id)) {
2374
+ props.sectionDrawing = {
2375
+ spatialView: sectionDrawing.spatialView.id,
2376
+ displaySpatialView: true === sectionDrawing.jsonProperties.displaySpatialView,
2377
+ drawingToSpatialTransform: sectionDrawing.jsonProperties.drawingToSpatialTransform,
2378
+ };
2379
+ }
2380
+ }
2381
+ return props;
2382
+ }
2383
+ /** Obtain a [ViewStateProps]($common) for a [[ViewDefinition]] specified by ViewIdString. */
2384
+ async getViewStateProps(viewDefinitionId, options) {
2385
+ const viewStateData = this.loadViewData(viewDefinitionId, options);
2386
+ const baseModelId = viewStateData.viewDefinitionProps.baseModelId;
2387
+ if (baseModelId) {
2388
+ const drawingExtents = await this._iModel.models.queryRange(baseModelId);
2389
+ if (!drawingExtents.isNull)
2390
+ viewStateData.modelExtents = drawingExtents.toJSON();
2391
+ }
2392
+ return viewStateData;
2393
+ }
2394
+ getViewThumbnailArg(viewDefinitionId) {
2395
+ if (!Id64.isValid(viewDefinitionId))
2396
+ throw new Error("illegal thumbnail id");
2397
+ return { namespace: "dgn_View", name: "Thumbnail", id: viewDefinitionId };
2398
+ }
2399
+ /** Get the thumbnail for a view.
2400
+ * @param viewDefinitionId The Id of the view for thumbnail
2401
+ * @returns the ThumbnailProps, or undefined if no thumbnail exists.
2402
+ */
2403
+ getThumbnail(viewDefinitionId) {
2404
+ const viewArg = this.getViewThumbnailArg(viewDefinitionId);
2405
+ const sizeProps = this._iModel[_nativeDb].queryFileProperty(viewArg, true);
2406
+ if (undefined === sizeProps)
2407
+ return undefined;
2408
+ const out = JSON.parse(sizeProps);
2409
+ out.image = this._iModel[_nativeDb].queryFileProperty(viewArg, false);
2410
+ return out;
2411
+ }
2412
+ /** Save a thumbnail for a view.
2413
+ * @param viewDefinitionId The Id of the view for thumbnail
2414
+ * @param thumbnail The thumbnail data.
2415
+ * @returns 0 if successful
2416
+ */
2417
+ saveThumbnail(viewDefinitionId, thumbnail) {
2418
+ const viewArg = this.getViewThumbnailArg(viewDefinitionId);
2419
+ const props = { format: thumbnail.format, height: thumbnail.height, width: thumbnail.width };
2420
+ this._iModel[_nativeDb].saveFileProperty(viewArg, JSON.stringify(props), thumbnail.image);
2421
+ return 0;
2422
+ }
2423
+ /** Set the default view property the iModel.
2424
+ * @param viewId The Id of the ViewDefinition to use as the default
2425
+ * @deprecated in 4.2.x. Avoid setting this property - it is not practical for one single view to serve the needs of the many applications
2426
+ * that might wish to view the contents of the iModel.
2427
+ */
2428
+ setDefaultViewId(viewId) {
2429
+ const spec = { namespace: "dgn_View", name: "DefaultView" };
2430
+ const blob32 = new Uint32Array(2);
2431
+ blob32[0] = Id64.getLowerUint32(viewId);
2432
+ blob32[1] = Id64.getUpperUint32(viewId);
2433
+ const blob8 = new Uint8Array(blob32.buffer);
2434
+ this._iModel.saveFileProperty(spec, undefined, blob8);
2435
+ }
2436
+ }
2437
+ IModelDb.Views = Views;
2438
+ /** Represents the current state of a pollable tile content request.
2439
+ * Note: lack of a "completed" state because polling a completed request returns the content as a Uint8Array.
2440
+ * @internal
2441
+ */
2442
+ let TileContentState;
2443
+ (function (TileContentState) {
2444
+ TileContentState[TileContentState["New"] = 0] = "New";
2445
+ TileContentState[TileContentState["Pending"] = 1] = "Pending";
2446
+ TileContentState[TileContentState["Loading"] = 2] = "Loading";
2447
+ })(TileContentState = IModelDb.TileContentState || (IModelDb.TileContentState = {}));
2448
+ /** @internal */
2449
+ class Tiles {
2450
+ _iModel;
2451
+ /** @internal */
2452
+ constructor(_iModel) {
2453
+ this._iModel = _iModel;
2454
+ }
2455
+ /** @internal */
2456
+ async requestTileTreeProps(id) {
2457
+ return new Promise((resolve, reject) => {
2458
+ this._iModel[_nativeDb].getTileTree(id, (ret) => {
2459
+ if (undefined !== ret.error)
2460
+ reject(new IModelError(ret.error.status, `TreeId=${id}`));
2461
+ else
2462
+ resolve(ret.result);
2463
+ });
2464
+ });
2465
+ }
2466
+ pollTileContent(resolve, reject, treeId, tileId) {
2467
+ let ret;
2468
+ try {
2469
+ ret = this._iModel[_nativeDb].pollTileContent(treeId, tileId);
2470
+ }
2471
+ catch (err) {
2472
+ // Typically "imodel not open".
2473
+ reject(err);
2474
+ return;
2475
+ }
2476
+ if (ret.error) {
2477
+ reject(new IModelError(ret.error.status, `TreeId=${treeId} TileId=${tileId}`));
2478
+ }
2479
+ else if (ret.result && typeof ret.result !== "number") { // if type is not a number, it's the TileContent interface
2480
+ const res = ret.result;
2481
+ const iModelId = this._iModel.iModelId;
2482
+ const tileSizeThreshold = IModelHost.logTileSizeThreshold;
2483
+ const tileSize = res.content.length;
2484
+ if (tileSize > tileSizeThreshold) {
2485
+ Logger.logWarning(loggerCategory, "Tile size (in bytes) larger than specified threshold", () => ({ tileSize, tileSizeThreshold, treeId, tileId, iModelId }));
2486
+ }
2487
+ const loadTimeThreshold = IModelHost.logTileLoadTimeThreshold;
2488
+ const loadTime = res.elapsedSeconds;
2489
+ if (loadTime > loadTimeThreshold) {
2490
+ Logger.logWarning(loggerCategory, "Tile load time (in seconds) greater than specified threshold", () => ({ loadTime, loadTimeThreshold, treeId, tileId, iModelId }));
2491
+ }
2492
+ resolve(res);
2493
+ }
2494
+ else { // if the type is a number, it's the TileContentState enum
2495
+ // ###TODO: Decide appropriate timeout interval. May want to switch on state (new vs loading vs pending)
2496
+ setTimeout(() => this.pollTileContent(resolve, reject, treeId, tileId), 10);
2497
+ }
2498
+ }
2499
+ /** @internal */
2500
+ async requestTileContent(treeId, tileId) {
2501
+ return new Promise((resolve, reject) => {
2502
+ this.pollTileContent(resolve, reject, treeId, tileId);
2503
+ });
2504
+ }
2505
+ /** @internal */
2506
+ async getTileContent(treeId, tileId) {
2507
+ const ret = await new Promise((resolve) => {
2508
+ this._iModel[_nativeDb].getTileContent(treeId, tileId, resolve);
2509
+ });
2510
+ if (undefined !== ret.error) {
2511
+ throw new IModelError(ret.error.status, `TreeId=${treeId} TileId=${tileId}`);
2512
+ }
2513
+ assert(undefined !== ret.result);
2514
+ return ret.result;
2515
+ }
2516
+ }
2517
+ IModelDb.Tiles = Tiles;
2518
+ })(IModelDb || (IModelDb = {}));
2519
+ /**
2520
+ * A local copy of an iModel from iModelHub that can pull and potentially push changesets.
2521
+ * BriefcaseDb raises a set of events to allow apps and subsystems to track its object life cycle, including [[onOpen]] and [[onOpened]].
2522
+ * @public
2523
+ */
2524
+ export class BriefcaseDb extends IModelDb {
2525
+ /** Manages local changes to this briefcase. */
2526
+ txns = new TxnManager(this);
2527
+ /** override superclass method */
2528
+ get isBriefcase() { return true; }
2529
+ /* the BriefcaseId of the briefcase opened with this BriefcaseDb */
2530
+ briefcaseId;
2531
+ _skipSyncSchemasOnPullAndPush;
2532
+ /** @internal */
2533
+ get skipSyncSchemasOnPullAndPush() { return this._skipSyncSchemasOnPullAndPush ?? false; }
2534
+ /**
2535
+ * Event raised just before a BriefcaseDb is opened. Supplies the arguments that will be used to open the BriefcaseDb.
2536
+ * Throw an exception to stop the open.
2537
+ *
2538
+ * **Example:**
2539
+ * ``` ts
2540
+ * [[include:BriefcaseDb.onOpen]]
2541
+ * ```
2542
+ */
2543
+ static onOpen = new BeEvent();
2544
+ /**
2545
+ * Event raised just after a BriefcaseDb is opened. Supplies the newly opened BriefcaseDb and the arguments that were used to open it.
2546
+ *
2547
+ * **Example:**
2548
+ * ``` ts
2549
+ * [[include:BriefcaseDb.onOpened]]
2550
+ * ```
2551
+ */
2552
+ static onOpened = new BeEvent();
2553
+ /** Event raised after a BriefcaseDb has been closed. */
2554
+ onClosed = new BeEvent();
2555
+ /** @alpha */
2556
+ static onCodeServiceCreated = new BeEvent();
2557
+ static findByKey(key) {
2558
+ return super.findByKey(key);
2559
+ }
2560
+ static tryFindByKey(key) {
2561
+ const db = super.tryFindByKey(key);
2562
+ return db?.isBriefcaseDb() ? db : undefined;
2563
+ }
2564
+ /**
2565
+ * The Guid that identifies the *context* that owns this iModel.
2566
+ * GuidString | undefined for the superclass, but required for BriefcaseDb
2567
+ * */
2568
+ get iTwinId() { return super.iTwinId; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
2569
+ /**
2570
+ * Determine whether this BriefcaseDb should use a lock server.
2571
+ * All must be true:
2572
+ * - file is open for write
2573
+ * - has an assigned briefcaseId
2574
+ * - the "no locking" flag is not present. This is a property of an iModel, established when the iModel is created in IModelHub.
2575
+ */
2576
+ get useLockServer() {
2577
+ return !this[_nativeDb].isReadonly() && (this.briefcaseId !== BriefcaseIdValue.Unassigned) && (undefined === this[_nativeDb].queryLocalValue(BriefcaseLocalValue.NoLocking));
2578
+ }
2579
+ // if the iModel uses a lock server, create a ServerBasedLocks LockControl for this BriefcaseDb.
2580
+ makeLockControl() {
2581
+ if (this.useLockServer)
2582
+ this._locks = createServerBasedLocks(this);
2583
+ }
2584
+ constructor(args) {
2585
+ super({ ...args, changeset: args.nativeDb.getCurrentChangeset() });
2586
+ this._openMode = args.openMode;
2587
+ this.briefcaseId = args.briefcaseId;
2588
+ this.makeLockControl();
2589
+ }
2590
+ /** Upgrades the profile or domain schemas. File must be closed before this call and is always left closed. */
2591
+ static async doUpgrade(briefcase, upgradeOptions, description) {
2592
+ let wasChanges = false;
2593
+ const executeUpgrade = () => {
2594
+ const nativeDb = this.openDgnDb({ path: briefcase.fileName }, OpenMode.ReadWrite, upgradeOptions); // performs the upgrade
2595
+ wasChanges = nativeDb.hasPendingTxns();
2596
+ nativeDb.closeFile();
2597
+ };
2598
+ const isSchemaSyncEnabled = await withBriefcaseDb(briefcase, async (db) => {
2599
+ await SchemaSync.pull(db);
2600
+ return db[_nativeDb].schemaSyncEnabled();
2601
+ });
2602
+ if (isSchemaSyncEnabled) {
2603
+ await SchemaSync.withLockedAccess(briefcase, { openMode: OpenMode.Readonly, operationName: "schema sync" }, async (syncAccess) => {
2604
+ const schemaSyncDbUri = syncAccess.getUri();
2605
+ executeUpgrade();
2606
+ await withBriefcaseDb(briefcase, async (db) => {
2607
+ db[_nativeDb].schemaSyncPush(schemaSyncDbUri);
2608
+ db.saveChanges();
2609
+ });
2610
+ syncAccess.synchronizeWithCloud();
2611
+ });
2612
+ }
2613
+ else {
2614
+ executeUpgrade();
2615
+ }
2616
+ if (wasChanges)
2617
+ await withBriefcaseDb(briefcase, async (db) => db.pushChanges({ ...briefcase, description, retainLocks: true }));
2618
+ }
2619
+ /** Upgrades the schemas in the iModel based on the current version of the software. Follows a sequence of operations -
2620
+ * * Acquires a schema lock to prevent other users from making any other changes while upgrade is happening
2621
+ * * Updates the local briefcase with the schema changes.
2622
+ * * Pushes the resulting changeset(s) to iModelHub.
2623
+ * Note that the upgrade requires that the local briefcase be closed, and may result in one or two change sets depending on whether both
2624
+ * profile and domain schemas need to get upgraded.
2625
+ * @see ($docs/learning/backend/IModelDb.md#upgrading-schemas-in-an-imodel)
2626
+ */
2627
+ static async upgradeSchemas(briefcase) {
2628
+ // upgrading schemas involves closing and reopening the file repeatedly. That's because the process of upgrading
2629
+ // happens on a file open. We have to open-and-close the file at *each* of these steps:
2630
+ // - acquire schema lock
2631
+ // - upgrade profile
2632
+ // - push changes
2633
+ // - upgrade domain
2634
+ // - push changes
2635
+ // - release schema lock
2636
+ // good thing computers are fast. Fortunately upgrading should be rare (and the push time will dominate anyway.) Don't try to optimize any of this away.
2637
+ try {
2638
+ await this.doUpgrade(briefcase, { profile: ProfileOptions.Upgrade }, "Upgraded profile");
2639
+ }
2640
+ catch (error) {
2641
+ if (error.errorNumber === DbResult.BE_SQLITE_ERROR_DataTransformRequired) {
2642
+ Logger.logInfo(loggerCategory, `Profile upgrade contains data transform. Retrying upgrade with a schema lock.`);
2643
+ try {
2644
+ await withBriefcaseDb(briefcase, async (db) => db.acquireSchemaLock()); // may not really acquire lock if iModel uses "noLocks" mode.
2645
+ await this.doUpgrade(briefcase, { profile: ProfileOptions.Upgrade, schemaLockHeld: true }, "Upgraded profile");
2646
+ await this.doUpgrade(briefcase, { domain: DomainOptions.Upgrade, schemaLockHeld: true }, "Upgraded domain schemas");
2647
+ }
2648
+ finally {
2649
+ await withBriefcaseDb(briefcase, async (db) => db.locks[_releaseAllLocks]());
2650
+ }
2651
+ return;
2652
+ }
2653
+ throw error;
2654
+ }
2655
+ try {
2656
+ await this.doUpgrade(briefcase, { domain: DomainOptions.Upgrade }, "Upgraded domain schemas");
2657
+ }
2658
+ catch (error) {
2659
+ if (error.errorNumber === DbResult.BE_SQLITE_ERROR_DataTransformRequired) {
2660
+ Logger.logInfo(loggerCategory, `Domain schema upgrade contains data transform. Retrying upgrade with a schema lock.`);
2661
+ try {
2662
+ await withBriefcaseDb(briefcase, async (db) => db.acquireSchemaLock()); // may not really acquire lock if iModel uses "noLocks" mode.
2663
+ await this.doUpgrade(briefcase, { domain: DomainOptions.Upgrade, schemaLockHeld: true }, "Upgraded domain schemas");
2664
+ }
2665
+ finally {
2666
+ await withBriefcaseDb(briefcase, async (db) => db.locks[_releaseAllLocks]());
2667
+ }
2668
+ return;
2669
+ }
2670
+ throw error;
2671
+ }
2672
+ }
2673
+ /** Open a briefcase file and return a new BriefcaseDb to interact with it.
2674
+ * @param args parameters that specify the file name, and options for opening the briefcase file
2675
+ */
2676
+ static async open(args) {
2677
+ this.onOpen.raiseEvent(args);
2678
+ const file = { path: args.fileName, key: args.key };
2679
+ const openMode = (args.readonly || args.watchForChanges) ? OpenMode.Readonly : OpenMode.ReadWrite;
2680
+ const nativeDb = this.openDgnDb(file, openMode, undefined, args);
2681
+ const briefcaseDb = new this({ nativeDb, key: file.key ?? Guid.createValue(), openMode, briefcaseId: nativeDb.getBriefcaseId() });
2682
+ // If they asked to watch for changes, set an fs.watch on the "-watch" file (only it is modified while we hold this connection.)
2683
+ // Whenever there are changes, restart our defaultTxn. That loads the changes from the other connection and sends
2684
+ // notifications as if they happened on this connection. Note: the watcher is called only when the backend event loop cycles.
2685
+ if (args.watchForChanges && undefined === args.container) {
2686
+ // Must touch the file synchronously - cannot watch a file until it exists.
2687
+ touch.sync(briefcaseDb.watchFilePathName);
2688
+ // Restart default txn to trigger events when watch file is changed by some other process.
2689
+ const watcher = fs.watch(briefcaseDb.watchFilePathName, { persistent: false }, () => {
2690
+ nativeDb.clearECDbCache();
2691
+ nativeDb.restartDefaultTxn();
2692
+ briefcaseDb.changeset = briefcaseDb[_nativeDb].getCurrentChangeset();
2693
+ });
2694
+ // Stop the watcher when we close this connection.
2695
+ briefcaseDb.onBeforeClose.addOnce(() => {
2696
+ watcher.close();
2697
+ });
2698
+ }
2699
+ // load all of the settings from workspaces
2700
+ await briefcaseDb.loadWorkspaceSettings();
2701
+ if (openMode === OpenMode.ReadWrite && CodeService.createForIModel) {
2702
+ try {
2703
+ briefcaseDb._codeService = await CodeService.createForIModel(briefcaseDb);
2704
+ this.onCodeServiceCreated.raiseEvent(briefcaseDb);
2705
+ }
2706
+ catch (e) {
2707
+ if (e.errorId !== "NoCodeIndex") { // no code index means iModel isn't enforcing codes.
2708
+ Logger.logWarning(loggerCategory, `The CodeService is not available for this briefcase: errorId: ${e.errorId}, errorMessage; ${e.message}. Proceeding with BriefcaseDb.open(), but all operations involving codes will fail.`);
2709
+ briefcaseDb._codeService = {
2710
+ verifyCode: (props) => {
2711
+ if (!Code.isEmpty(props.props.code)) {
2712
+ e.message = `The CodeService is not available for this briefcase: errorId: ${e.errorId}, errorMessage; ${e.message}.`;
2713
+ throw e;
2714
+ }
2715
+ },
2716
+ appParams: {
2717
+ author: { name: "unknown" },
2718
+ origin: { name: "unknown" },
2719
+ },
2720
+ close: () => { },
2721
+ initialize: async () => { },
2722
+ };
2723
+ }
2724
+ }
2725
+ }
2726
+ this.onOpened.raiseEvent(briefcaseDb, args);
2727
+ return briefcaseDb;
2728
+ }
2729
+ /** This is called by native code when applying a changeset */
2730
+ onChangesetConflict(args) {
2731
+ // returning undefined will result in native handler to resolve conflict
2732
+ const category = "DgnCore";
2733
+ const interpretConflictCause = (cause) => {
2734
+ switch (cause) {
2735
+ case DbConflictCause.Data:
2736
+ return "data";
2737
+ case DbConflictCause.NotFound:
2738
+ return "not found";
2739
+ case DbConflictCause.Conflict:
2740
+ return "conflict";
2741
+ case DbConflictCause.Constraint:
2742
+ return "constraint";
2743
+ case DbConflictCause.ForeignKey:
2744
+ return "foreign key";
2745
+ }
2746
+ };
2747
+ if (args.cause === DbConflictCause.Data && !args.indirect) {
2748
+ /*
2749
+ * From SQLite Docs CHANGESET_DATA as the second argument
2750
+ * when processing a DELETE or UPDATE change if a row with the required
2751
+ * PRIMARY KEY fields is present in the database, but one or more other
2752
+ * (non primary-key) fields modified by the update do not contain the
2753
+ * expected "before" values.
2754
+ *
2755
+ * The conflicting row, in this case, is the database row with the matching
2756
+ * primary key.
2757
+ *
2758
+ * Another reason this will be invoked is when SQLITE_CHANGESETAPPLY_FKNOACTION
2759
+ * is passed ApplyChangeset(). The flag will disable CASCADE action and treat
2760
+ * them as CASCADE NONE resulting in conflict handler been called.
2761
+ */
2762
+ if (!this.txns.hasPendingTxns) {
2763
+ // This changeset is bad. However, it is already in the timeline. We must allow services such as
2764
+ // checkpoint-creation, change history, and other apps to apply any changeset that is in the timeline.
2765
+ Logger.logWarning(category, "UPDATE/DELETE before value do not match with one in db or CASCADE action was triggered.");
2766
+ args.dump();
2767
+ }
2768
+ else {
2769
+ if (args.tableName === "be_Prop") {
2770
+ if (args.getValueText(0, DbChangeStage.Old) === "ec_Db" && args.getValueText(1, DbChangeStage.Old) === "localDbInfo") {
2771
+ return DbConflictResolution.Replace;
2772
+ }
2773
+ }
2774
+ if (args.tableName.startsWith("ec_")) {
2775
+ return DbConflictResolution.Skip;
2776
+ }
2777
+ const msg = "UPDATE/DELETE before value do not match with one in db or CASCADE action was triggered.";
2778
+ args.setLastError(msg);
2779
+ Logger.logError(category, msg);
2780
+ args.dump();
2781
+ return DbConflictResolution.Abort;
2782
+ }
2783
+ }
2784
+ // Handle some special cases
2785
+ if (args.cause === DbConflictCause.Conflict) {
2786
+ // From the SQLite docs: "CHANGESET_CONFLICT is passed as the second argument to the conflict handler while processing an INSERT change if the operation would result in duplicate primary key values."
2787
+ // This is always a fatal error - it can happen only if the app started with a briefcase that is behind the tip and then uses the same primary key values (e.g., ElementIds)
2788
+ // that have already been used by some other app using the SAME briefcase ID that recently pushed changes. That can happen only if the app makes changes without first pulling and acquiring locks.
2789
+ if (!this.txns.hasPendingTxns) {
2790
+ // This changeset is bad. However, it is already in the timeline. We must allow services such as
2791
+ // checkpoint-creation, change history, and other apps to apply any changeset that is in the timeline.
2792
+ Logger.logWarning(category, "PRIMARY KEY INSERT CONFLICT - resolved by replacing the existing row with the incoming row");
2793
+ args.dump();
2794
+ }
2795
+ else {
2796
+ if (args.tableName.startsWith("ec_")) {
2797
+ return DbConflictResolution.Skip;
2798
+ }
2799
+ const msg = "PRIMARY KEY INSERT CONFLICT - rejecting this changeset";
2800
+ args.setLastError(msg);
2801
+ Logger.logError(category, msg);
2802
+ args.dump();
2803
+ return DbConflictResolution.Abort;
2804
+ }
2805
+ }
2806
+ if (args.cause === DbConflictCause.ForeignKey) {
2807
+ // Note: No current or conflicting row information is provided if it's a FKey conflict
2808
+ // Since we abort on FKey conflicts, always try and provide details about the error
2809
+ const nConflicts = args.getForeignKeyConflicts();
2810
+ // Note: There is no performance implication of follow code as it happen toward end of
2811
+ // apply_changeset only once so we be querying value for 'DebugAllowFkViolations' only once.
2812
+ if (this[_nativeDb].queryLocalValue("DebugAllowFkViolations")) {
2813
+ Logger.logError(category, `Detected ${nConflicts} foreign key conflicts in changeset. Continuing merge as 'DebugAllowFkViolations' flag is set. Run 'PRAGMA foreign_key_check' to get list of violations.`);
2814
+ return DbConflictResolution.Skip;
2815
+ }
2816
+ else {
2817
+ const msg = `Detected ${nConflicts} foreign key conflicts in ChangeSet. Aborting merge.`;
2818
+ args.setLastError(msg);
2819
+ return DbConflictResolution.Abort;
2820
+ }
2821
+ }
2822
+ if (args.cause === DbConflictCause.NotFound) {
2823
+ /*
2824
+ * Note: If DbConflictCause = NotFound, the primary key was not found, and returning DbConflictResolution::Replace is
2825
+ * not an option at all - this will cause a BE_SQLITE_MISUSE error.
2826
+ */
2827
+ return DbConflictResolution.Skip;
2828
+ }
2829
+ if (args.cause === DbConflictCause.Constraint) {
2830
+ if (Logger.isEnabled(category, LogLevel.Info)) {
2831
+ Logger.logInfo(category, "------------------------------------------------------------------");
2832
+ Logger.logInfo(category, `Conflict detected - Cause: ${interpretConflictCause(args.cause)}`);
2833
+ args.dump();
2834
+ }
2835
+ Logger.logWarning(category, "Constraint conflict handled by rejecting incoming change. Constraint conflicts are NOT expected. These happen most often when two clients both insert elements with the same code. That indicates a bug in the client or the code server.");
2836
+ return DbConflictResolution.Skip;
2837
+ }
2838
+ /*
2839
+ * If we don't have a control, we always accept the incoming revision in cases of conflicts:
2840
+ *
2841
+ * + In a briefcase with no local changes, the state of a row in the Db (i.e., the final state of a previous revision)
2842
+ * may not exactly match the initial state of the incoming revision. This will cause a conflict.
2843
+ * - The final state of the incoming (later) revision will always be setup exactly right to accommodate
2844
+ * cases where dependency handlers won't be available (for instance on the server), and we have to rely on
2845
+ * the revision to correctly set the final state of the row in the Db. Therefore it's best to resolve the
2846
+ * conflict in favor of the incoming change.
2847
+ * + In a briefcase with local changes, the state of relevant dependent properties (due to propagated indirect changes)
2848
+ * may not correspond with the initial state of these properties in an incoming revision. This will cause a conflict.
2849
+ * - Resolving the conflict in favor of the incoming revision may cause some dependent properties to be set
2850
+ * incorrectly, but the dependency handlers will run anyway and set this right. The new changes will be part of
2851
+ * a subsequent revision generated from that briefcase.
2852
+ *
2853
+ * + Note that conflicts can NEVER happen between direct changes made locally and direct changes in the incoming revision.
2854
+ * - Only one user can make a direct change at one time, and the next user has to pull those changes before getting a
2855
+ * lock to the same element
2856
+ *
2857
+ * + Also see comments in TxnManager::MergeDataChanges()
2858
+ */
2859
+ if (Logger.isEnabled(category, LogLevel.Info)) {
2860
+ Logger.logInfo(category, `Conflict detected - Cause: ${interpretConflictCause(args.cause)}`);
2861
+ args.dump();
2862
+ Logger.logInfo(category, "Conflicting resolved by replacing the existing entry with the change");
2863
+ }
2864
+ return DbConflictResolution.Replace;
2865
+ }
2866
+ /** If the briefcase is read-only, reopen the native briefcase for writing.
2867
+ * Execute the supplied function.
2868
+ * If the briefcase was read-only, reopen the native briefcase as read-only.
2869
+ * @note this._openMode is not changed from its initial value.
2870
+ * @internal Exported strictly for tests
2871
+ */
2872
+ async executeWritable(func) {
2873
+ const fileName = this.pathName;
2874
+ const isReadonly = this.isReadonly;
2875
+ let locks;
2876
+ try {
2877
+ if (isReadonly) {
2878
+ this.closeAndReopen(OpenMode.ReadWrite, fileName);
2879
+ locks = this.locks;
2880
+ this.makeLockControl(); // create a ServerBasedLocks, if necessary
2881
+ }
2882
+ await func();
2883
+ }
2884
+ finally {
2885
+ if (isReadonly) {
2886
+ if (locks !== this._locks) { // did we have to create a ServerBasedLocks?
2887
+ this.locks[_close](); // yes, close it and reset back to previous
2888
+ this._locks = locks;
2889
+ }
2890
+ this.closeAndReopen(OpenMode.Readonly, fileName);
2891
+ }
2892
+ }
2893
+ }
2894
+ closeAndReopen(openMode, fileName) {
2895
+ // Unclosed statements will produce BUSY error when attempting to close.
2896
+ this.clearCaches();
2897
+ // The following resets the native db's pointer to this JavaScript object.
2898
+ this[_nativeDb].closeFile();
2899
+ this[_nativeDb].openIModel(fileName, openMode);
2900
+ // Restore the native db's pointer to this JavaScript object.
2901
+ this[_nativeDb].setIModelDb(this);
2902
+ // refresh cached properties that could have been changed by another process writing to the same briefcase
2903
+ this.changeset = this[_nativeDb].getCurrentChangeset();
2904
+ // assert what should never change
2905
+ if (this.iModelId !== this[_nativeDb].getIModelId() || this.iTwinId !== this[_nativeDb].getITwinId())
2906
+ throw new Error("closeAndReopen detected change in iModelId and/or iTwinId");
2907
+ }
2908
+ /** Pull and apply changesets from iModelHub */
2909
+ async pullChanges(arg) {
2910
+ await this.executeWritable(async () => {
2911
+ await BriefcaseManager.pullAndApplyChangesets(this, arg ?? {});
2912
+ if (!this.skipSyncSchemasOnPullAndPush)
2913
+ await SchemaSync.pull(this);
2914
+ this.initializeIModelDb("pullMerge");
2915
+ });
2916
+ IpcHost.notifyTxns(this, "notifyPulledChanges", this.changeset);
2917
+ this.txns.touchWatchFile();
2918
+ }
2919
+ /** Revert timeline changes and then push resulting changeset */
2920
+ async revertAndPushChanges(arg) {
2921
+ const nativeDb = this[_nativeDb];
2922
+ if (arg.toIndex === undefined) {
2923
+ throw new IModelError(ChangeSetStatus.ApplyError, "Cannot revert without a toIndex");
2924
+ }
2925
+ if (nativeDb.hasUnsavedChanges()) {
2926
+ throw new IModelError(ChangeSetStatus.HasUncommittedChanges, "Cannot revert with unsaved changes");
2927
+ }
2928
+ if (nativeDb.hasPendingTxns()) {
2929
+ throw new IModelError(ChangeSetStatus.HasLocalChanges, "Cannot revert with pending txns");
2930
+ }
2931
+ const skipSchemaSyncPull = async (func) => {
2932
+ if (nativeDb.schemaSyncEnabled()) {
2933
+ this._skipSyncSchemasOnPullAndPush = true;
2934
+ try {
2935
+ return await func();
2936
+ }
2937
+ finally {
2938
+ this._skipSyncSchemasOnPullAndPush = undefined;
2939
+ }
2940
+ }
2941
+ else {
2942
+ return func();
2943
+ }
2944
+ };
2945
+ this.clearCaches();
2946
+ await skipSchemaSyncPull(async () => this.pullChanges({ ...arg, toIndex: undefined }));
2947
+ await this.acquireSchemaLock();
2948
+ if (nativeDb.schemaSyncEnabled()) {
2949
+ arg.skipSchemaChanges = true;
2950
+ }
2951
+ try {
2952
+ await BriefcaseManager.revertTimelineChanges(this, arg);
2953
+ this.saveChanges("Revert changes");
2954
+ if (!arg.description) {
2955
+ arg.description = `Reverted changes from ${this.changeset.index} to ${arg.toIndex}${arg.skipSchemaChanges ? " (schema changes skipped)" : ""}`;
2956
+ }
2957
+ const pushArgs = {
2958
+ description: arg.description,
2959
+ accessToken: arg.accessToken,
2960
+ mergeRetryCount: arg.mergeRetryCount,
2961
+ mergeRetryDelay: arg.mergeRetryDelay,
2962
+ pushRetryCount: arg.pushRetryCount,
2963
+ pushRetryDelay: arg.pushRetryDelay,
2964
+ retainLocks: arg.retainLocks,
2965
+ };
2966
+ await skipSchemaSyncPull(async () => this.pushChanges(pushArgs));
2967
+ this.clearCaches();
2968
+ }
2969
+ catch (err) {
2970
+ if (!arg.retainLocks) {
2971
+ await this.locks.releaseAllLocks();
2972
+ throw err;
2973
+ }
2974
+ }
2975
+ finally {
2976
+ this.abandonChanges();
2977
+ }
2978
+ }
2979
+ /** Push changes to iModelHub. */
2980
+ async pushChanges(arg) {
2981
+ if (this.briefcaseId === BriefcaseIdValue.Unassigned)
2982
+ return;
2983
+ if (this[_nativeDb].hasUnsavedChanges()) {
2984
+ throw new IModelError(ChangeSetStatus.HasUncommittedChanges, "Cannot push with unsaved changes");
2985
+ }
2986
+ else if (!this[_nativeDb].hasPendingTxns()) {
2987
+ // Nothing to push.
2988
+ if (!arg.retainLocks) {
2989
+ await this.locks.releaseAllLocks();
2990
+ }
2991
+ return;
2992
+ }
2993
+ // pushing changes requires a writeable briefcase
2994
+ await this.executeWritable(async () => {
2995
+ await BriefcaseManager.pullMergePush(this, arg);
2996
+ this.initializeIModelDb("pullMerge");
2997
+ });
2998
+ const changeset = this.changeset;
2999
+ IpcHost.notifyTxns(this, "notifyPushedChanges", changeset);
3000
+ this.txns.touchWatchFile();
3001
+ }
3002
+ close() {
3003
+ if (this.isBriefcase && this.isOpen && !this.isReadonly && this.txns.changeMergeManager.inProgress()) {
3004
+ this.abandonChanges();
3005
+ }
3006
+ super.close();
3007
+ this.onClosed.raiseEvent();
3008
+ }
3009
+ }
3010
+ /** Used to reattach Daemon from a user's accessToken for V2 checkpoints.
3011
+ * @note Reattach only happens if the previous access token either has expired or is about to expire within an application-supplied safety duration.
3012
+ */
3013
+ class RefreshV2CheckpointSas {
3014
+ /** the time at which the current token should be refreshed (its expiry minus safetySeconds) */
3015
+ _timestamp = 0;
3016
+ /** while a refresh is happening, all callers get this promise. */
3017
+ _promise;
3018
+ /** Time, in seconds, before the current token expires to obtain a new token. Default is 1 hour. */
3019
+ _safetySeconds;
3020
+ constructor(sasToken, safetySeconds) {
3021
+ this._safetySeconds = safetySeconds ?? 60 * 60; // default to 1 hour
3022
+ this.setTimestamp(sasToken);
3023
+ }
3024
+ async performRefresh(accessToken, iModel) {
3025
+ this._timestamp = 0; // everyone needs to wait until token is valid
3026
+ // we're going to request that the checkpoint manager use this user's accessToken to obtain a new access token for this checkpoint's storage account.
3027
+ Logger.logInfo(BackendLoggerCategory.Authorization, "attempting to refresh sasToken for checkpoint");
3028
+ try {
3029
+ // this exchanges the supplied user accessToken for an expiring blob-store token to read the checkpoint.
3030
+ const container = iModel.cloudContainer;
3031
+ if (!container)
3032
+ throw new Error("checkpoint is not from a cloud container");
3033
+ assert(undefined !== iModel.iTwinId);
3034
+ const props = await IModelHost[_hubAccess].queryV2Checkpoint({ accessToken, iTwinId: iModel.iTwinId, iModelId: iModel.iModelId, changeset: iModel.changeset });
3035
+ if (!props)
3036
+ throw new Error("can't reset checkpoint sas token");
3037
+ container.accessToken = props.sasToken;
3038
+ this.setTimestamp(props.sasToken);
3039
+ Logger.logInfo(BackendLoggerCategory.Authorization, "refreshed checkpoint sasToken successfully");
3040
+ }
3041
+ finally {
3042
+ this._promise = undefined;
3043
+ }
3044
+ }
3045
+ setTimestamp(sasToken) {
3046
+ const exp = new URLSearchParams(sasToken).get("se");
3047
+ const sasTokenExpiry = exp ? Date.parse(exp) : 0;
3048
+ this._timestamp = sasTokenExpiry - (this._safetySeconds * 1000);
3049
+ if (this._timestamp < Date.now())
3050
+ Logger.logError(BackendLoggerCategory.Authorization, "attached with timestamp that expires before safety interval");
3051
+ }
3052
+ async refreshSas(accessToken, iModel) {
3053
+ if (this._timestamp > Date.now())
3054
+ return; // current token is fine
3055
+ if (undefined === this._promise) // has reattach already begun?
3056
+ this._promise = this.performRefresh(accessToken, iModel); // no, start it
3057
+ return this._promise;
3058
+ }
3059
+ }
3060
+ /** A *snapshot* iModel database file that is used for archival and data transfer purposes.
3061
+ * @see [Snapshot iModels]($docs/learning/backend/AccessingIModels.md#snapshot-imodels)
3062
+ * @see [About IModelDb]($docs/learning/backend/IModelDb.md)
3063
+ * @public
3064
+ */
3065
+ export class SnapshotDb extends IModelDb {
3066
+ get isSnapshot() { return true; }
3067
+ _refreshSas;
3068
+ /** Timer used to restart the default txn on the SnapshotDb after some inactivity. This is only used for checkpoints.
3069
+ * Restarting the default txn lets CloudSqlite know that any blocks that may have been read may now be ejected.
3070
+ * Without restarting the default txn, CloudSQLite can get into a state where it can not evict any blocks to make space for more blocks.
3071
+ */
3072
+ _restartDefaultTxnTimer;
3073
+ _createClassViewsOnClose;
3074
+ static onOpen = new BeEvent();
3075
+ static onOpened = new BeEvent();
3076
+ constructor(nativeDb, key) {
3077
+ super({ nativeDb, key, changeset: nativeDb.getCurrentChangeset() });
3078
+ this._openMode = nativeDb.isReadonly() ? OpenMode.Readonly : OpenMode.ReadWrite;
3079
+ }
3080
+ static findByKey(key) {
3081
+ return super.findByKey(key);
3082
+ }
3083
+ static tryFindByKey(key) {
3084
+ const db = super.tryFindByKey(key);
3085
+ return db?.isSnapshotDb() ? db : undefined;
3086
+ }
3087
+ /** Create an *empty* local [Snapshot]($docs/learning/backend/AccessingIModels.md#snapshot-imodels) iModel file.
3088
+ * Snapshots are not synchronized with iModelHub, so do not have a change timeline.
3089
+ * @note: A *snapshot* cannot be modified after [[close]] is called.
3090
+ * @param filePath The file that will contain the new iModel *snapshot*
3091
+ * @param options The parameters that define the new iModel *snapshot*
3092
+ * @returns A writeable SnapshotDb
3093
+ * @see [Snapshot iModels]($docs/learning/backend/AccessingIModels.md#snapshot-imodels)
3094
+ */
3095
+ static createEmpty(filePath, options) {
3096
+ const nativeDb = new IModelNative.platform.DgnDb();
3097
+ nativeDb.createIModel(filePath, options);
3098
+ nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);
3099
+ const snapshotDb = new SnapshotDb(nativeDb, Guid.createValue());
3100
+ snapshotDb.channels.addAllowedChannel(ChannelControl.sharedChannelName);
3101
+ if (options.createClassViews)
3102
+ snapshotDb._createClassViewsOnClose = true; // save flag that will be checked when close() is called
3103
+ return snapshotDb;
3104
+ }
3105
+ /** Create a local [Snapshot]($docs/learning/backend/AccessingIModels.md#snapshot-imodels) iModel file, using this iModel as a *seed* or starting point.
3106
+ * Snapshots are not synchronized with iModelHub, so do not have a change timeline.
3107
+ * @note: A *snapshot* cannot be modified after [[close]] is called.
3108
+ * @param iModelDb The snapshot will be initialized from the current contents of this iModelDb
3109
+ * @param snapshotFile The file that will contain the new iModel *snapshot*
3110
+ * @param options Optional properties that determine how the snapshot iModel is created.
3111
+ * @returns A writeable SnapshotDb
3112
+ * @see [Snapshot iModels]($docs/learning/backend/AccessingIModels.md#snapshot-imodels)
3113
+ */
3114
+ static createFrom(iModelDb, snapshotFile, options) {
3115
+ iModelDb.performCheckpoint();
3116
+ IModelJsFs.copySync(iModelDb.pathName, snapshotFile);
3117
+ const nativeDb = new IModelNative.platform.DgnDb();
3118
+ nativeDb.openIModel(snapshotFile, OpenMode.ReadWrite, undefined);
3119
+ nativeDb.vacuum();
3120
+ // Replace iModelId if seedFile is a snapshot, preserve iModelId if seedFile is an iModelHub-managed briefcase
3121
+ if (!BriefcaseManager.isValidBriefcaseId(nativeDb.getBriefcaseId()))
3122
+ nativeDb.setIModelId(Guid.createValue());
3123
+ nativeDb.deleteLocalValue(BriefcaseLocalValue.StandaloneEdit);
3124
+ nativeDb.saveChanges();
3125
+ nativeDb.deleteAllTxns();
3126
+ nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);
3127
+ const snapshotDb = new SnapshotDb(nativeDb, Guid.createValue());
3128
+ if (options?.createClassViews)
3129
+ snapshotDb._createClassViewsOnClose = true; // save flag that will be checked when close() is called
3130
+ return snapshotDb;
3131
+ }
3132
+ /** open this SnapshotDb read/write, strictly to apply incoming changesets. Used for creating new checkpoints.
3133
+ * @internal
3134
+ */
3135
+ static openForApplyChangesets(path, props) {
3136
+ const file = { path, key: props?.key };
3137
+ const nativeDb = this.openDgnDb(file, OpenMode.ReadWrite, undefined, props);
3138
+ assert(undefined !== file.key);
3139
+ return new SnapshotDb(nativeDb, file.key);
3140
+ }
3141
+ /** Open a read-only iModel *snapshot*.
3142
+ * @param path the full path of the snapshot iModel file to open.
3143
+ * @param props options for opening snapshot
3144
+ * @see [[close]]
3145
+ * @throws [[IModelError]] If the file is not found or is not a valid *snapshot*.
3146
+ */
3147
+ static openFile(path, opts) {
3148
+ this.onOpen.raiseEvent(path, opts);
3149
+ const file = { path, key: opts?.key };
3150
+ const wasKeyUndefined = opts?.key === undefined;
3151
+ const nativeDb = this.openDgnDb(file, OpenMode.Readonly, undefined, opts);
3152
+ if (wasKeyUndefined) {
3153
+ file.key = `${nativeDb.getIModelId()}:${nativeDb.getCurrentChangeset().id}`;
3154
+ }
3155
+ assert(undefined !== file.key);
3156
+ const db = new this(nativeDb, file.key);
3157
+ this.onOpened.raiseEvent(db);
3158
+ return db;
3159
+ }
3160
+ static async attachAndOpenCheckpoint(checkpoint) {
3161
+ const { dbName, container } = await V2CheckpointManager.attach(checkpoint);
3162
+ const key = CheckpointManager.getKey(checkpoint);
3163
+ const db = SnapshotDb.openFile(dbName, { key, container });
3164
+ await db.loadWorkspaceSettings();
3165
+ return db;
3166
+ }
3167
+ /** @internal */
3168
+ static async openCheckpointFromRpc(checkpoint) {
3169
+ const snapshot = await this.attachAndOpenCheckpoint(checkpoint);
3170
+ snapshot._iTwinId = checkpoint.iTwinId;
3171
+ try {
3172
+ CheckpointManager.validateCheckpointGuids(checkpoint, snapshot);
3173
+ }
3174
+ catch (err) {
3175
+ snapshot.close();
3176
+ throw err;
3177
+ }
3178
+ // unref timer, so it doesn't prevent a process from shutting down.
3179
+ snapshot._restartDefaultTxnTimer = setTimeout(() => {
3180
+ snapshot.restartDefaultTxn();
3181
+ }, (10 * 60) * 1000).unref(); // 10 minutes
3182
+ const cloudContainer = snapshot.cloudContainer;
3183
+ if (cloudContainer !== undefined) {
3184
+ snapshot._refreshSas = new RefreshV2CheckpointSas(cloudContainer.accessToken, checkpoint.reattachSafetySeconds);
3185
+ }
3186
+ return snapshot;
3187
+ }
3188
+ /**
3189
+ * Open a Checkpoint directly from its cloud container.
3190
+ * @beta
3191
+ */
3192
+ static async openCheckpoint(args) {
3193
+ return this.attachAndOpenCheckpoint(await CheckpointManager.toCheckpointProps(args));
3194
+ }
3195
+ /** Used to refresh the container sasToken using the current user's accessToken.
3196
+ * Also restarts the timer which causes the default txn to be restarted on db if the timer activates.
3197
+ * @internal
3198
+ */
3199
+ async refreshContainerForRpc(userAccessToken) {
3200
+ this._restartDefaultTxnTimer?.refresh();
3201
+ return this._refreshSas?.refreshSas(userAccessToken, this);
3202
+ }
3203
+ /** @internal */
3204
+ beforeClose() {
3205
+ super.beforeClose();
3206
+ if (this._restartDefaultTxnTimer)
3207
+ clearTimeout(this._restartDefaultTxnTimer);
3208
+ if (this._createClassViewsOnClose) { // check for flag set during create
3209
+ if (BentleyStatus.SUCCESS !== this[_nativeDb].createClassViewsInDb()) {
3210
+ throw new IModelError(IModelStatus.SQLiteError, "Error creating class views");
3211
+ }
3212
+ else {
3213
+ this.saveChanges();
3214
+ }
3215
+ }
3216
+ }
3217
+ }
3218
+ /**
3219
+ * Standalone iModels are read/write files that are not associated with an iTwin or managed by iModelHub.
3220
+ * They are relevant only for testing, or for small-scale single-user scenarios.
3221
+ * Standalone iModels are designed such that the API for Standalone iModels and Briefcase
3222
+ * iModels (those synchronized with iModelHub) are as similar and consistent as possible.
3223
+ * This leads to a straightforward process where the a user starts with StandaloneDb and can
3224
+ * optionally choose to upgrade to an iTwin.
3225
+ *
3226
+ * Some additional details. Standalone iModels:
3227
+ * - always have [Guid.empty]($bentley) for their iTwinId (they are "unassociated" files)
3228
+ * - always have BriefcaseId === [BriefcaseIdValue.Unassigned]($common)
3229
+ * - are connected to the frontend via [BriefcaseConnection.openStandalone]($frontend)
3230
+ * - may be opened without supplying any user credentials
3231
+ * - may be opened read/write
3232
+ * - cannot apply a changeset to nor generate a changesets (since there is no timeline from which to get/push changesets)
3233
+ * @public
3234
+ */
3235
+ export class StandaloneDb extends BriefcaseDb {
3236
+ get isStandalone() { return true; }
3237
+ get useLockServer() { return false; } // standalone iModels have no lock server
3238
+ static findByKey(key) {
3239
+ return super.findByKey(key);
3240
+ }
3241
+ static tryFindByKey(key) {
3242
+ const db = super.tryFindByKey(key);
3243
+ return db?.isStandaloneDb() ? db : undefined;
3244
+ }
3245
+ /** Create an *empty* standalone iModel.
3246
+ * @param filePath The file path for the iModel
3247
+ * @param args The parameters that define the new iModel
3248
+ */
3249
+ static createEmpty(filePath, args) {
3250
+ const nativeDb = new IModelNative.platform.DgnDb();
3251
+ nativeDb.createIModel(filePath, args);
3252
+ nativeDb.saveLocalValue(BriefcaseLocalValue.StandaloneEdit, args.allowEdit);
3253
+ nativeDb.setITwinId(Guid.empty);
3254
+ nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);
3255
+ nativeDb.saveChanges();
3256
+ const db = new this({ nativeDb, key: Guid.createValue(), briefcaseId: BriefcaseIdValue.Unassigned, openMode: OpenMode.ReadWrite });
3257
+ db.channels.addAllowedChannel(ChannelControl.sharedChannelName);
3258
+ return db;
3259
+ }
3260
+ /**
3261
+ * Upgrades the schemas in the standalone iModel file.
3262
+ * Note that the upgrade requires that the file be closed, and will leave it back in the closed state.
3263
+ * @param filePath Full path name of the standalone iModel file.
3264
+ * @see ($docs/learning/backend/IModelDb.md#upgrading-schemas-in-an-imodel)
3265
+ * @see [[StandaloneDb.validateSchemas]]
3266
+ */
3267
+ static upgradeStandaloneSchemas(filePath) {
3268
+ let nativeDb = this.openDgnDb({ path: filePath }, OpenMode.ReadWrite, { profile: ProfileOptions.Upgrade, schemaLockHeld: true });
3269
+ nativeDb.saveChanges();
3270
+ nativeDb.closeFile();
3271
+ nativeDb = this.openDgnDb({ path: filePath }, OpenMode.ReadWrite, { domain: DomainOptions.Upgrade, schemaLockHeld: true });
3272
+ nativeDb.saveChanges();
3273
+ nativeDb.closeFile();
3274
+ }
3275
+ /** Creates or updates views in the iModel to permit visualizing the EC content as ECClasses and ECProperties rather than raw database tables and columns.
3276
+ * 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.
3277
+ * @throws IModelError if view creation failed.
3278
+ * @note The views are strictly intended for developers and debugging purposes only - they should not be used in application code.
3279
+ * @beta
3280
+ */
3281
+ createClassViews() {
3282
+ const result = this[_nativeDb].createClassViewsInDb();
3283
+ if (BentleyStatus.SUCCESS !== result)
3284
+ throw new IModelError(result, "Error creating class views");
3285
+ else
3286
+ this.saveChanges();
3287
+ }
3288
+ /** Open a standalone iModel file.
3289
+ * @param filePath The path of the standalone iModel file.
3290
+ * @param openMode Optional open mode for the standalone iModel. The default is read/write.
3291
+ * @throws [[IModelError]] if the file is not a standalone iModel.
3292
+ * @see [BriefcaseConnection.openStandalone]($frontend) to open a StandaloneDb from the frontend
3293
+ */
3294
+ static openFile(filePath, openMode = OpenMode.ReadWrite, options) {
3295
+ const file = { path: filePath, key: options?.key };
3296
+ const nativeDb = this.openDgnDb(file, openMode, undefined, options);
3297
+ try {
3298
+ const iTwinId = nativeDb.getITwinId();
3299
+ if (iTwinId !== Guid.empty) // a "standalone" iModel means it is not associated with an iTwin
3300
+ throw new IModelError(IModelStatus.WrongIModel, `${filePath} is not a Standalone iModel. iTwinId=${iTwinId}`);
3301
+ assert(undefined !== file.key);
3302
+ const db = new this({ nativeDb, key: file.key, openMode, briefcaseId: BriefcaseIdValue.Unassigned });
3303
+ return db;
3304
+ }
3305
+ catch (error) {
3306
+ nativeDb.closeFile();
3307
+ throw error;
3308
+ }
3309
+ }
3310
+ /** Convert an iModel stored on the local file system into a StandaloneDb, chiefly for testing purposes.
3311
+ * The file must not be open in any application.
3312
+ * @param iModelFileName the path to the iModel on the local file system.
3313
+ * @beta
3314
+ */
3315
+ static convertToStandalone(iModelFileName) {
3316
+ const nativeDb = new IModelNative.platform.DgnDb();
3317
+ nativeDb.openIModel(iModelFileName, OpenMode.ReadWrite);
3318
+ nativeDb.setITwinId(Guid.empty); // empty iTwinId means "standalone"
3319
+ nativeDb.saveChanges(); // save change to iTwinId
3320
+ nativeDb.deleteAllTxns(); // necessary before resetting briefcaseId
3321
+ nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned); // standalone iModels should always have BriefcaseId unassigned
3322
+ nativeDb.saveLocalValue("StandaloneEdit", JSON.stringify({ txns: true }));
3323
+ nativeDb.saveChanges(); // save change to briefcaseId
3324
+ nativeDb.closeFile();
3325
+ }
3326
+ }
3327
+ //# sourceMappingURL=IModelDb.js.map