@itwin/core-backend 5.0.0-dev.10 → 5.0.0-dev.102

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