@itwin/core-backend 5.0.0-dev.9 → 5.0.0-dev.92

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