@itwin/core-backend 4.0.0-dev.10 → 4.0.0-dev.101

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 (295) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +226 -224
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +41 -41
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.d.ts +90 -91
  7. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.js +98 -99
  9. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  10. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  11. package/lib/cjs/BisCoreSchema.js +60 -60
  12. package/lib/cjs/BisCoreSchema.js.map +1 -1
  13. package/lib/cjs/BlobContainerService.d.ts +120 -0
  14. package/lib/cjs/BlobContainerService.d.ts.map +1 -0
  15. package/lib/cjs/BlobContainerService.js +18 -0
  16. package/lib/cjs/BlobContainerService.js.map +1 -0
  17. package/lib/cjs/BriefcaseManager.d.ts +184 -170
  18. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  19. package/lib/cjs/BriefcaseManager.js +421 -414
  20. package/lib/cjs/BriefcaseManager.js.map +1 -1
  21. package/lib/cjs/Category.d.ts +153 -153
  22. package/lib/cjs/Category.js +243 -243
  23. package/lib/cjs/Category.js.map +1 -1
  24. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  25. package/lib/cjs/ChangeSummaryManager.js +446 -447
  26. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  27. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  28. package/lib/cjs/ChangedElementsDb.js +165 -165
  29. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  30. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  31. package/lib/cjs/ChangedElementsManager.js +88 -88
  32. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  33. package/lib/cjs/ChannelControl.d.ts +70 -0
  34. package/lib/cjs/ChannelControl.d.ts.map +1 -0
  35. package/lib/cjs/ChannelControl.js +89 -0
  36. package/lib/cjs/ChannelControl.js.map +1 -0
  37. package/lib/cjs/CheckpointManager.d.ts +121 -121
  38. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  39. package/lib/cjs/CheckpointManager.js +351 -349
  40. package/lib/cjs/CheckpointManager.js.map +1 -1
  41. package/lib/cjs/ClassRegistry.d.ts +79 -79
  42. package/lib/cjs/ClassRegistry.js +254 -250
  43. package/lib/cjs/ClassRegistry.js.map +1 -1
  44. package/lib/cjs/CloudSqlite.d.ts +572 -350
  45. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  46. package/lib/cjs/CloudSqlite.js +374 -153
  47. package/lib/cjs/CloudSqlite.js.map +1 -1
  48. package/lib/cjs/CodeService.d.ts +399 -396
  49. package/lib/cjs/CodeService.d.ts.map +1 -1
  50. package/lib/cjs/CodeService.js +63 -63
  51. package/lib/cjs/CodeService.js.map +1 -1
  52. package/lib/cjs/CodeSpecs.d.ts +58 -55
  53. package/lib/cjs/CodeSpecs.d.ts.map +1 -1
  54. package/lib/cjs/CodeSpecs.js +154 -124
  55. package/lib/cjs/CodeSpecs.js.map +1 -1
  56. package/lib/cjs/ConcurrentQuery.d.ts +13 -13
  57. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
  58. package/lib/cjs/ConcurrentQuery.js +36 -36
  59. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  60. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  61. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  62. package/lib/cjs/CustomViewState3dCreator.js +80 -81
  63. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  64. package/lib/cjs/DevTools.d.ts +74 -71
  65. package/lib/cjs/DevTools.d.ts.map +1 -1
  66. package/lib/cjs/DevTools.js +156 -154
  67. package/lib/cjs/DevTools.js.map +1 -1
  68. package/lib/cjs/DisplayStyle.d.ts +104 -106
  69. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  70. package/lib/cjs/DisplayStyle.js +251 -256
  71. package/lib/cjs/DisplayStyle.js.map +1 -1
  72. package/lib/cjs/ECDb.d.ts +194 -191
  73. package/lib/cjs/ECDb.d.ts.map +1 -1
  74. package/lib/cjs/ECDb.js +351 -350
  75. package/lib/cjs/ECDb.js.map +1 -1
  76. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  77. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  78. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  79. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  80. package/lib/cjs/ECSqlStatement.d.ts +473 -473
  81. package/lib/cjs/ECSqlStatement.js +791 -791
  82. package/lib/cjs/ECSqlStatement.js.map +1 -1
  83. package/lib/cjs/Element.d.ts +1105 -1109
  84. package/lib/cjs/Element.d.ts.map +1 -1
  85. package/lib/cjs/Element.js +1416 -1427
  86. package/lib/cjs/Element.js.map +1 -1
  87. package/lib/cjs/ElementAspect.d.ts +175 -179
  88. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  89. package/lib/cjs/ElementAspect.js +202 -211
  90. package/lib/cjs/ElementAspect.js.map +1 -1
  91. package/lib/cjs/ElementGraphics.d.ts +9 -9
  92. package/lib/cjs/ElementGraphics.js +41 -41
  93. package/lib/cjs/ElementGraphics.js.map +1 -1
  94. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  95. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  96. package/lib/cjs/ElementTreeWalker.js +409 -409
  97. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  98. package/lib/cjs/Entity.d.ts +102 -106
  99. package/lib/cjs/Entity.d.ts.map +1 -1
  100. package/lib/cjs/Entity.js +118 -134
  101. package/lib/cjs/Entity.js.map +1 -1
  102. package/lib/cjs/EntityReferences.d.ts +49 -49
  103. package/lib/cjs/EntityReferences.d.ts.map +1 -1
  104. package/lib/cjs/EntityReferences.js +95 -95
  105. package/lib/cjs/EntityReferences.js.map +1 -1
  106. package/lib/cjs/ExportGraphics.d.ts +317 -317
  107. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  108. package/lib/cjs/ExportGraphics.js +208 -208
  109. package/lib/cjs/ExportGraphics.js.map +1 -1
  110. package/lib/cjs/ExternalSource.d.ts +95 -96
  111. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  112. package/lib/cjs/ExternalSource.js +130 -131
  113. package/lib/cjs/ExternalSource.js.map +1 -1
  114. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  115. package/lib/cjs/GeoCoordConfig.js +85 -85
  116. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  117. package/lib/cjs/GeometrySummary.d.ts +4 -4
  118. package/lib/cjs/GeometrySummary.js +380 -380
  119. package/lib/cjs/GeometrySummary.js.map +1 -1
  120. package/lib/cjs/HubMock.d.ts +94 -94
  121. package/lib/cjs/HubMock.js +220 -222
  122. package/lib/cjs/HubMock.js.map +1 -1
  123. package/lib/cjs/IModelCloneContext.d.ts +8 -8
  124. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  125. package/lib/cjs/IModelCloneContext.js +15 -15
  126. package/lib/cjs/IModelCloneContext.js.map +1 -1
  127. package/lib/cjs/IModelDb.d.ts +1222 -1196
  128. package/lib/cjs/IModelDb.d.ts.map +1 -1
  129. package/lib/cjs/IModelDb.js +2389 -2392
  130. package/lib/cjs/IModelDb.js.map +1 -1
  131. package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
  132. package/lib/cjs/IModelElementCloneContext.js +159 -159
  133. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  134. package/lib/cjs/IModelHost.d.ts +370 -369
  135. package/lib/cjs/IModelHost.d.ts.map +1 -1
  136. package/lib/cjs/IModelHost.js +476 -496
  137. package/lib/cjs/IModelHost.js.map +1 -1
  138. package/lib/cjs/IModelJsFs.d.ts +62 -62
  139. package/lib/cjs/IModelJsFs.js +139 -140
  140. package/lib/cjs/IModelJsFs.js.map +1 -1
  141. package/lib/cjs/IpcHost.d.ts +104 -104
  142. package/lib/cjs/IpcHost.js +276 -278
  143. package/lib/cjs/IpcHost.js.map +1 -1
  144. package/lib/cjs/LineStyle.d.ts +311 -311
  145. package/lib/cjs/LineStyle.js +295 -295
  146. package/lib/cjs/LineStyle.js.map +1 -1
  147. package/lib/cjs/LocalHub.d.ts +162 -162
  148. package/lib/cjs/LocalHub.d.ts.map +1 -1
  149. package/lib/cjs/LocalHub.js +580 -585
  150. package/lib/cjs/LocalHub.js.map +1 -1
  151. package/lib/cjs/LocalhostIpcHost.d.ts +21 -20
  152. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
  153. package/lib/cjs/LocalhostIpcHost.js +79 -81
  154. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  155. package/lib/cjs/Material.d.ts +131 -131
  156. package/lib/cjs/Material.d.ts.map +1 -1
  157. package/lib/cjs/Material.js +185 -181
  158. package/lib/cjs/Material.js.map +1 -1
  159. package/lib/cjs/Model.d.ts +391 -392
  160. package/lib/cjs/Model.d.ts.map +1 -1
  161. package/lib/cjs/Model.js +487 -485
  162. package/lib/cjs/Model.js.map +1 -1
  163. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  164. package/lib/cjs/NativeAppStorage.js +202 -202
  165. package/lib/cjs/NativeAppStorage.js.map +1 -1
  166. package/lib/cjs/NativeHost.d.ts +52 -52
  167. package/lib/cjs/NativeHost.d.ts.map +1 -1
  168. package/lib/cjs/NativeHost.js +158 -163
  169. package/lib/cjs/NativeHost.js.map +1 -1
  170. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  171. package/lib/cjs/NavigationRelationship.js +225 -225
  172. package/lib/cjs/NavigationRelationship.js.map +1 -1
  173. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  174. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  175. package/lib/cjs/PromiseMemoizer.js +101 -101
  176. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  177. package/lib/cjs/PropertyStore.d.ts +123 -132
  178. package/lib/cjs/PropertyStore.d.ts.map +1 -1
  179. package/lib/cjs/PropertyStore.js +179 -11
  180. package/lib/cjs/PropertyStore.js.map +1 -1
  181. package/lib/cjs/Relationship.d.ts +413 -416
  182. package/lib/cjs/Relationship.d.ts.map +1 -1
  183. package/lib/cjs/Relationship.js +491 -494
  184. package/lib/cjs/Relationship.js.map +1 -1
  185. package/lib/cjs/RpcBackend.d.ts +5 -5
  186. package/lib/cjs/RpcBackend.js +32 -32
  187. package/lib/cjs/RpcBackend.js.map +1 -1
  188. package/lib/cjs/SQLiteDb.d.ts +317 -219
  189. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  190. package/lib/cjs/SQLiteDb.js +318 -214
  191. package/lib/cjs/SQLiteDb.js.map +1 -1
  192. package/lib/cjs/Schema.d.ts +55 -55
  193. package/lib/cjs/Schema.js +83 -83
  194. package/lib/cjs/Schema.js.map +1 -1
  195. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  196. package/lib/cjs/ServerBasedLocks.js +168 -168
  197. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  198. package/lib/cjs/SqliteStatement.d.ts +360 -360
  199. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  200. package/lib/cjs/SqliteStatement.js +586 -586
  201. package/lib/cjs/SqliteStatement.js.map +1 -1
  202. package/lib/cjs/Texture.d.ts +58 -58
  203. package/lib/cjs/Texture.js +82 -82
  204. package/lib/cjs/Texture.js.map +1 -1
  205. package/lib/cjs/TileStorage.d.ts +44 -18
  206. package/lib/cjs/TileStorage.d.ts.map +1 -1
  207. package/lib/cjs/TileStorage.js +109 -90
  208. package/lib/cjs/TileStorage.js.map +1 -1
  209. package/lib/cjs/TxnManager.d.ts +202 -202
  210. package/lib/cjs/TxnManager.d.ts.map +1 -1
  211. package/lib/cjs/TxnManager.js +356 -356
  212. package/lib/cjs/TxnManager.js.map +1 -1
  213. package/lib/cjs/ViewDefinition.d.ts +429 -439
  214. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  215. package/lib/cjs/ViewDefinition.js +640 -646
  216. package/lib/cjs/ViewDefinition.js.map +1 -1
  217. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  218. package/lib/cjs/ViewStateHydrator.js +103 -103
  219. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  220. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  221. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  222. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  223. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  224. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  225. package/lib/cjs/core-backend.d.ts +181 -184
  226. package/lib/cjs/core-backend.d.ts.map +1 -1
  227. package/lib/cjs/core-backend.js +205 -204
  228. package/lib/cjs/core-backend.js.map +1 -1
  229. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  230. package/lib/cjs/domains/FunctionalElements.js +145 -145
  231. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  232. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  233. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
  234. package/lib/cjs/domains/FunctionalSchema.js +39 -40
  235. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  236. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  237. package/lib/cjs/domains/GenericElements.js +263 -263
  238. package/lib/cjs/domains/GenericElements.js.map +1 -1
  239. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  240. package/lib/cjs/domains/GenericSchema.js +28 -28
  241. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  242. package/lib/cjs/rpc/multipart.d.ts +11 -11
  243. package/lib/cjs/rpc/multipart.js +71 -71
  244. package/lib/cjs/rpc/multipart.js.map +1 -1
  245. package/lib/cjs/rpc/tracing.d.ts +28 -28
  246. package/lib/cjs/rpc/tracing.js +73 -74
  247. package/lib/cjs/rpc/tracing.js.map +1 -1
  248. package/lib/cjs/rpc/web/logging.d.ts +9 -9
  249. package/lib/cjs/rpc/web/logging.js +43 -43
  250. package/lib/cjs/rpc/web/logging.js.map +1 -1
  251. package/lib/cjs/rpc/web/request.d.ts +6 -6
  252. package/lib/cjs/rpc/web/request.js +73 -74
  253. package/lib/cjs/rpc/web/request.js.map +1 -1
  254. package/lib/cjs/rpc/web/response.d.ts +6 -6
  255. package/lib/cjs/rpc/web/response.js +105 -106
  256. package/lib/cjs/rpc/web/response.js.map +1 -1
  257. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  258. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  259. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  260. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
  261. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -294
  262. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  263. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +20 -22
  264. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  265. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -205
  266. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  267. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  268. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +166 -168
  269. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  270. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  271. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -43
  272. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  273. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  274. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  275. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  276. package/lib/cjs/workspace/Settings.d.ts +186 -186
  277. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  278. package/lib/cjs/workspace/Settings.js +155 -155
  279. package/lib/cjs/workspace/Settings.js.map +1 -1
  280. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  281. package/lib/cjs/workspace/SettingsSchemas.js +190 -191
  282. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  283. package/lib/cjs/workspace/Workspace.d.ts +411 -414
  284. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  285. package/lib/cjs/workspace/Workspace.js +521 -543
  286. package/lib/cjs/workspace/Workspace.js.map +1 -1
  287. package/package.json +25 -28
  288. package/lib/cjs/AliCloudStorageService.d.ts +0 -24
  289. package/lib/cjs/AliCloudStorageService.d.ts.map +0 -1
  290. package/lib/cjs/AliCloudStorageService.js +0 -72
  291. package/lib/cjs/AliCloudStorageService.js.map +0 -1
  292. package/lib/cjs/CloudStorageBackend.d.ts +0 -59
  293. package/lib/cjs/CloudStorageBackend.d.ts.map +0 -1
  294. package/lib/cjs/CloudStorageBackend.js +0 -174
  295. package/lib/cjs/CloudStorageBackend.js.map +0 -1
@@ -1,215 +1,319 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module SQLiteDb
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SQLiteDb = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const CloudSqlite_1 = require("./CloudSqlite");
13
- const IModelHost_1 = require("./IModelHost");
14
- const SqliteStatement_1 = require("./SqliteStatement");
15
- // cspell:ignore savepoint
16
- /* eslint-disable @typescript-eslint/unified-signatures */
17
- /** A SQLiteDb file
18
- * @public
19
- */
20
- class SQLiteDb {
21
- constructor() {
22
- /** @internal */
23
- this.nativeDb = new IModelHost_1.IModelHost.platform.SQLiteDb();
24
- this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
25
- }
26
- /** @internal */
27
- static createBlobIO() {
28
- return new IModelHost_1.IModelHost.platform.BlobIO();
29
- }
30
- /** alias for closeDb. */
31
- dispose() {
32
- this.closeDb();
33
- }
34
- /** @internal */
35
- createDb(dbName, container, params) {
36
- this.nativeDb.createDb(dbName, container, params);
37
- }
38
- /** @internal */
39
- openDb(dbName, openMode, container) {
40
- this.nativeDb.openDb(dbName, openMode, container);
41
- }
42
- /** Close SQLiteDb.
43
- * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
44
- */
45
- closeDb(saveChanges) {
46
- if (saveChanges && this.isOpen)
47
- this.saveChanges();
48
- this._sqliteStatementCache.clear();
49
- this.nativeDb.closeDb();
50
- }
51
- /** Returns true if this SQLiteDb is open */
52
- get isOpen() { return this.nativeDb.isOpen(); }
53
- /** Returns true if this SQLiteDb is open readonly */
54
- get isReadonly() { return this.nativeDb.isReadonly(); }
55
- /**
56
- * Open a database, perform an operation, then close the database.
57
- *
58
- * Details:
59
- * - if database is open, throw an error
60
- * - open a database
61
- * - call a function with the database opened. If it is async, await its return.
62
- * - if function throws, abandon all changes, close database, and rethrow
63
- * - save all changes
64
- * - close the database
65
- * @return value from operation
66
- */
67
- withOpenDb(args, operation) {
68
- var _a;
69
- if (this.isOpen)
70
- throw new Error("database is already open");
71
- const save = () => this.closeDb(true), abandon = () => this.closeDb(false);
72
- this.openDb(args.dbName, (_a = args.openMode) !== null && _a !== void 0 ? _a : core_bentley_1.OpenMode.Readonly, args.container);
73
- try {
74
- const result = operation();
75
- result instanceof Promise ? result.then(save, abandon) : save();
76
- return result;
77
- }
78
- catch (e) {
79
- abandon();
80
- throw e;
81
- }
82
- }
83
- /**
84
- * Perform an operation on a database in a CloudContainer with the write lock held.
85
- *
86
- * Details:
87
- * - acquire the write lock on a CloudContainer
88
- * - call `withOpenDb` with openMode `ReadWrite`
89
- * - upload changes
90
- * - release the write lock
91
- * @param args arguments to lock the container and open the database
92
- * @param operation an operation performed on the database with the write lock held.
93
- * @return value from operation
94
- * @internal
95
- */
96
- async withLockedContainer(args, operation) {
97
- return CloudSqlite_1.CloudSqlite.withWriteLock(args.user, args.container, () => this.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation), args.busyHandler);
98
- }
99
- /** vacuum this database
100
- * @see https://www.sqlite.org/lang_vacuum.html
101
- */
102
- vacuum(args) {
103
- this.nativeDb.vacuum(args);
104
- }
105
- /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */
106
- saveChanges() {
107
- this.nativeDb.saveChanges();
108
- }
109
- /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */
110
- abandonChanges() {
111
- this.nativeDb.abandonChanges();
112
- }
113
- /**
114
- * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
115
- * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
116
- * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
117
- * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
118
- * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
119
- * @param sql The SQLite SQL statement to execute
120
- * @param callback the callback to invoke on the prepared statement
121
- * @returns the value returned by `callback`.
122
- */
123
- withPreparedSqliteStatement(sql, callback) {
124
- var _a;
125
- const stmt = (_a = this._sqliteStatementCache.findAndRemove(sql)) !== null && _a !== void 0 ? _a : this.prepareSqliteStatement(sql);
126
- const release = () => this._sqliteStatementCache.addOrDispose(stmt);
127
- try {
128
- const val = callback(stmt);
129
- val instanceof Promise ? val.then(release, release) : release();
130
- return val;
131
- }
132
- catch (err) {
133
- release();
134
- throw err;
135
- }
136
- }
137
- /**
138
- * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
139
- * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
140
- * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
141
- * @param sql The SQLite SQL statement to execute
142
- * @param callback the callback to invoke on the prepared statement
143
- * @returns the value returned by `callback`.
144
- */
145
- withSqliteStatement(sql, callback) {
146
- const stmt = this.prepareSqliteStatement(sql);
147
- const release = () => stmt.dispose();
148
- try {
149
- const val = callback(stmt);
150
- val instanceof Promise ? val.then(release, release) : release();
151
- return val;
152
- }
153
- catch (err) {
154
- release();
155
- throw err;
156
- }
157
- }
158
- /**
159
- * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the
160
- * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back
161
- * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.
162
- */
163
- withSavePoint(savePointName, operation) {
164
- if (this.isReadonly)
165
- throw new Error("database is readonly");
166
- this.executeSQL(`SAVEPOINT ${savePointName}`);
167
- try {
168
- operation();
169
- this.executeSQL(`RELEASE ${savePointName}`);
170
- }
171
- catch (e) {
172
- this.executeSQL(`ROLLBACK TO ${savePointName}`);
173
- throw e;
174
- }
175
- }
176
- /** Prepare an SQL statement.
177
- * @param sql The SQLite SQL statement to prepare
178
- * @param logErrors Determine if errors are logged or not
179
- * @internal
180
- */
181
- prepareSqliteStatement(sql, logErrors = true) {
182
- const stmt = new SqliteStatement_1.SqliteStatement(sql);
183
- stmt.prepare(this.nativeDb, logErrors);
184
- return stmt;
185
- }
186
- /** execute an SQL statement */
187
- executeSQL(sql) {
188
- const stmt = this.prepareSqliteStatement(sql);
189
- try {
190
- return stmt.step();
191
- }
192
- finally {
193
- stmt.dispose();
194
- }
195
- }
196
- }
197
- exports.SQLiteDb = SQLiteDb;
198
- /** @public */
199
- (function (SQLiteDb) {
200
- /** Default transaction mode for SQLiteDbs.
201
- * @see https://www.sqlite.org/lang_transaction.html
202
- */
203
- let DefaultTxnMode;
204
- (function (DefaultTxnMode) {
205
- /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */
206
- DefaultTxnMode[DefaultTxnMode["None"] = 0] = "None";
207
- /** A deferred transaction is started when the file is first opened. This is the default. */
208
- DefaultTxnMode[DefaultTxnMode["Deferred"] = 1] = "Deferred";
209
- /** An immediate transaction is started when the file is first opened. */
210
- DefaultTxnMode[DefaultTxnMode["Immediate"] = 2] = "Immediate";
211
- /** An exclusive transaction is started when the file is first opened. */
212
- DefaultTxnMode[DefaultTxnMode["Exclusive"] = 3] = "Exclusive";
213
- })(DefaultTxnMode = SQLiteDb.DefaultTxnMode || (SQLiteDb.DefaultTxnMode = {}));
214
- })(SQLiteDb = exports.SQLiteDb || (exports.SQLiteDb = {}));
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module SQLiteDb
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.VersionedSqliteDb = exports.SQLiteDb = void 0;
11
+ const fs = require("fs");
12
+ const path_1 = require("path");
13
+ const semver = require("semver");
14
+ const core_bentley_1 = require("@itwin/core-bentley");
15
+ const CloudSqlite_1 = require("./CloudSqlite");
16
+ const IModelHost_1 = require("./IModelHost");
17
+ const IModelJsFs_1 = require("./IModelJsFs");
18
+ const SqliteStatement_1 = require("./SqliteStatement");
19
+ // cspell:ignore savepoint julianday rowid
20
+ /* eslint-disable @typescript-eslint/unified-signatures */
21
+ /**
22
+ * A "generic" SQLiteDb. This class may be used to access local files or databases in a cloud container.
23
+ * @public
24
+ */
25
+ class SQLiteDb {
26
+ constructor() {
27
+ /** @internal */
28
+ this.nativeDb = new IModelHost_1.IModelHost.platform.SQLiteDb();
29
+ this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
30
+ }
31
+ /** @internal */
32
+ static createBlobIO() {
33
+ return new IModelHost_1.IModelHost.platform.BlobIO();
34
+ }
35
+ /** alias for closeDb.
36
+ * @deprecated in 4.0, use [[closeDb]]
37
+ */
38
+ dispose() {
39
+ this.closeDb();
40
+ }
41
+ createDb(dbName, container, params) {
42
+ this.nativeDb.createDb(dbName, container, params);
43
+ }
44
+ openDb(dbName, openMode, container) {
45
+ this.nativeDb.openDb(dbName, openMode, container);
46
+ }
47
+ /** Close SQLiteDb.
48
+ * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
49
+ */
50
+ closeDb(saveChanges) {
51
+ if (saveChanges && this.isOpen)
52
+ this.saveChanges();
53
+ this._sqliteStatementCache.clear();
54
+ this.nativeDb.closeDb();
55
+ }
56
+ /** Returns true if this SQLiteDb is open */
57
+ get isOpen() { return this.nativeDb.isOpen(); }
58
+ /** Returns true if this SQLiteDb is open readonly */
59
+ get isReadonly() { return this.nativeDb.isReadonly(); }
60
+ /** Create a new table in this database. */
61
+ createTable(args) {
62
+ const timestampCol = args.addTimestamp ? ",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))" : "";
63
+ const constraints = args.constraints ? `,${args.constraints}` : "";
64
+ this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);
65
+ if (args.addTimestamp)
66
+ this.executeSQL(`CREATE TRIGGER ${args.tableName}_timestamp AFTER UPDATE ON ${args.tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${args.tableName} SET lastMod=julianday('now') WHERE rowid=new.rowid; END`);
67
+ }
68
+ /**
69
+ * Get the last modified date for a row in a table of this database.
70
+ * @note the table must have been created with `addTimestamp: true`
71
+ */
72
+ readLastModTime(tableName, rowId) {
73
+ return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {
74
+ stmt.bindInteger(1, rowId);
75
+ return stmt.getValueDate(0);
76
+ });
77
+ }
78
+ /**
79
+ * Open a database, perform an operation, then close the database.
80
+ *
81
+ * Details:
82
+ * - if database is open, throw an error
83
+ * - open a database
84
+ * - call a function with the database opened. If it is async, await its return.
85
+ * - if function throws, abandon all changes, close database, and rethrow
86
+ * - save all changes
87
+ * - close the database
88
+ * @return value from operation
89
+ */
90
+ withOpenDb(args, operation) {
91
+ if (this.isOpen)
92
+ throw new Error("database is already open");
93
+ const save = () => this.closeDb(true), abandon = () => this.closeDb(false);
94
+ this.openDb(args.dbName, args.openMode ?? core_bentley_1.OpenMode.Readonly, args.container);
95
+ try {
96
+ const result = operation();
97
+ result instanceof Promise ? result.then(save, abandon) : save();
98
+ return result;
99
+ }
100
+ catch (e) {
101
+ abandon();
102
+ throw e;
103
+ }
104
+ }
105
+ /**
106
+ * Perform an operation on a database in a CloudContainer with the write lock held.
107
+ *
108
+ * Details:
109
+ * - acquire the write lock on a CloudContainer
110
+ * - call `withOpenDb` with openMode `ReadWrite`
111
+ * - upload changes
112
+ * - release the write lock
113
+ * @param args arguments to lock the container and open the database
114
+ * @param operation an operation performed on the database with the write lock held.
115
+ * @return value from operation
116
+ * @internal
117
+ */
118
+ async withLockedContainer(args, operation) {
119
+ return CloudSqlite_1.CloudSqlite.withWriteLock(args.moniker, args.container, async () => this.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation), args.busyHandler);
120
+ }
121
+ /** vacuum this database
122
+ * @see https://www.sqlite.org/lang_vacuum.html
123
+ */
124
+ vacuum(args) {
125
+ this.nativeDb.vacuum(args);
126
+ }
127
+ /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */
128
+ saveChanges() {
129
+ this.nativeDb.saveChanges();
130
+ }
131
+ /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */
132
+ abandonChanges() {
133
+ this.nativeDb.abandonChanges();
134
+ }
135
+ /**
136
+ * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
137
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
138
+ * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
139
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
140
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
141
+ * @param sql The SQLite SQL statement to execute
142
+ * @param callback the callback to invoke on the prepared statement
143
+ * @returns the value returned by `callback`.
144
+ */
145
+ withPreparedSqliteStatement(sql, callback) {
146
+ const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);
147
+ const release = () => this._sqliteStatementCache.addOrDispose(stmt);
148
+ try {
149
+ const val = callback(stmt);
150
+ val instanceof Promise ? val.then(release, release) : release();
151
+ return val;
152
+ }
153
+ catch (err) {
154
+ release();
155
+ throw err;
156
+ }
157
+ }
158
+ /**
159
+ * Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.
160
+ * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
161
+ * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
162
+ * @param sql The SQLite SQL statement to execute
163
+ * @param callback the callback to invoke on the prepared statement
164
+ * @returns the value returned by `callback`.
165
+ */
166
+ withSqliteStatement(sql, callback) {
167
+ const stmt = this.prepareSqliteStatement(sql);
168
+ const release = () => stmt.dispose();
169
+ try {
170
+ const val = callback(stmt);
171
+ val instanceof Promise ? val.then(release, release) : release();
172
+ return val;
173
+ }
174
+ catch (err) {
175
+ release();
176
+ throw err;
177
+ }
178
+ }
179
+ /**
180
+ * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the
181
+ * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back
182
+ * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.
183
+ */
184
+ withSavePoint(savePointName, operation) {
185
+ if (this.isReadonly)
186
+ throw new Error("database is readonly");
187
+ this.executeSQL(`SAVEPOINT ${savePointName}`);
188
+ try {
189
+ operation();
190
+ this.executeSQL(`RELEASE ${savePointName}`);
191
+ }
192
+ catch (e) {
193
+ this.executeSQL(`ROLLBACK TO ${savePointName}`);
194
+ throw e;
195
+ }
196
+ }
197
+ /** Prepare an SQL statement.
198
+ * @param sql The SQLite SQL statement to prepare
199
+ * @param logErrors Determine if errors are logged or not
200
+ * @internal
201
+ */
202
+ prepareSqliteStatement(sql, logErrors = true) {
203
+ const stmt = new SqliteStatement_1.SqliteStatement(sql);
204
+ stmt.prepare(this.nativeDb, logErrors);
205
+ return stmt;
206
+ }
207
+ /** execute an SQL statement */
208
+ executeSQL(sql) {
209
+ const stmt = this.prepareSqliteStatement(sql);
210
+ try {
211
+ return stmt.step();
212
+ }
213
+ finally {
214
+ stmt.dispose();
215
+ }
216
+ }
217
+ }
218
+ exports.SQLiteDb = SQLiteDb;
219
+ /**
220
+ * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.
221
+ * This class provides version checking when the database is opened, to guarantee that a valid version of software is
222
+ * always used for access.
223
+ *
224
+ * Notes:
225
+ * - This class may be used either to access a local file, or one stored in a cloud container.
226
+ * - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its
227
+ * tables.
228
+ * @beta
229
+ */
230
+ class VersionedSqliteDb extends SQLiteDb {
231
+ /**
232
+ * Change the "versions required to open this database" property stored in this database. After this call,
233
+ * versions of software that don't meet the supplied ranges will fail.
234
+ * @param versions the new versions required for reading and writing this database.
235
+ * @note the database must be opened for write access.
236
+ */
237
+ setRequiredVersions(versions) {
238
+ // NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.
239
+ this.nativeDb.saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));
240
+ }
241
+ /** Get the required version ranges necessary to open this VersionedSqliteDb. */
242
+ getRequiredVersions() {
243
+ const checkIsString = (value) => {
244
+ if (typeof value !== "string")
245
+ throw new Error(`CloudDb ${this.nativeDb.getFilePath()} has invalid "versions" property`);
246
+ return value;
247
+ };
248
+ const versionJson = checkIsString(this.nativeDb.queryFileProperty(VersionedSqliteDb._versionProps, true));
249
+ const versionRanges = JSON.parse(versionJson);
250
+ checkIsString(versionRanges.readVersion);
251
+ checkIsString(versionRanges.writeVersion);
252
+ return versionRanges;
253
+ }
254
+ /**
255
+ * Create a new database file for the subclass of VersionedSqliteDb.
256
+ * @param fileName the name of a local
257
+ * @note The required versions are saved as [[myVersion]] or newer for both read and write.
258
+ */
259
+ static createNewDb(fileName) {
260
+ const db = new this(); // "as any" necessary because VersionedSqliteDb is abstract
261
+ IModelJsFs_1.IModelJsFs.recursiveMkDirSync((0, path_1.dirname)(fileName));
262
+ if (fs.existsSync(fileName))
263
+ fs.unlinkSync(fileName);
264
+ db.createDb(fileName);
265
+ db.createDDL();
266
+ const minVer = `^${db.myVersion}`;
267
+ db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });
268
+ db.closeDb(true);
269
+ }
270
+ /**
271
+ * Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.
272
+ * Throws otherwise.
273
+ */
274
+ verifyVersions() {
275
+ const versions = this.getRequiredVersions();
276
+ const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.
277
+ const range = isReadonly ? versions.readVersion : versions.writeVersion;
278
+ if (semver.satisfies(this.myVersion, range))
279
+ return;
280
+ this.closeDb();
281
+ const tooNew = semver.gtr(this.myVersion, range);
282
+ throw new Error(`${this.nativeDb.getFilePath()} requires ${tooNew ? "older" : "newer"} version of ${this.constructor.name} for ${isReadonly ? "read" : "write"}`);
283
+ }
284
+ /**
285
+ * Open this database and verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.
286
+ * Throws otherwise.
287
+ * @see [[SqliteDb.openDb]] for argument types
288
+ */
289
+ openDb(dbName, openMode, container) {
290
+ super.openDb(dbName, openMode, container);
291
+ this.verifyVersions();
292
+ }
293
+ async upgradeSchema(arg) {
294
+ // can't use "this" because it checks for version, which we don't want here
295
+ return (arg.lockContainer) ?
296
+ super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :
297
+ super.withOpenDb({ ...arg, openMode: core_bentley_1.OpenMode.ReadWrite }, arg.upgradeFn);
298
+ }
299
+ }
300
+ VersionedSqliteDb._versionProps = { namespace: "SQLiteDb", name: "versions" };
301
+ exports.VersionedSqliteDb = VersionedSqliteDb;
302
+ /** @public */
303
+ (function (SQLiteDb) {
304
+ /** Default transaction mode for SQLiteDbs.
305
+ * @see https://www.sqlite.org/lang_transaction.html
306
+ */
307
+ let DefaultTxnMode;
308
+ (function (DefaultTxnMode) {
309
+ /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */
310
+ DefaultTxnMode[DefaultTxnMode["None"] = 0] = "None";
311
+ /** A deferred transaction is started when the file is first opened. This is the default. */
312
+ DefaultTxnMode[DefaultTxnMode["Deferred"] = 1] = "Deferred";
313
+ /** An immediate transaction is started when the file is first opened. */
314
+ DefaultTxnMode[DefaultTxnMode["Immediate"] = 2] = "Immediate";
315
+ /** An exclusive transaction is started when the file is first opened. */
316
+ DefaultTxnMode[DefaultTxnMode["Exclusive"] = 3] = "Exclusive";
317
+ })(DefaultTxnMode = SQLiteDb.DefaultTxnMode || (SQLiteDb.DefaultTxnMode = {}));
318
+ })(SQLiteDb = exports.SQLiteDb || (exports.SQLiteDb = {}));
215
319
  //# sourceMappingURL=SQLiteDb.js.map