@itwin/core-backend 4.8.0-dev.4 → 4.8.0-dev.41

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 (230) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +18 -16
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +16 -15
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  7. package/lib/cjs/BriefcaseManager.js +19 -11
  8. package/lib/cjs/BriefcaseManager.js.map +1 -1
  9. package/lib/cjs/Category.d.ts +0 -6
  10. package/lib/cjs/Category.d.ts.map +1 -1
  11. package/lib/cjs/Category.js +0 -6
  12. package/lib/cjs/Category.js.map +1 -1
  13. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
  14. package/lib/cjs/ChangeSummaryManager.js +11 -9
  15. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  16. package/lib/cjs/ChangedElementsDb.d.ts +1 -0
  17. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  18. package/lib/cjs/ChangedElementsDb.js +6 -4
  19. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  20. package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
  21. package/lib/cjs/ChangesetECAdaptor.js +26 -21
  22. package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
  23. package/lib/cjs/ChannelControl.d.ts +4 -26
  24. package/lib/cjs/ChannelControl.d.ts.map +1 -1
  25. package/lib/cjs/ChannelControl.js +2 -101
  26. package/lib/cjs/ChannelControl.js.map +1 -1
  27. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  28. package/lib/cjs/CheckpointManager.js +5 -3
  29. package/lib/cjs/CheckpointManager.js.map +1 -1
  30. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  31. package/lib/cjs/ClassRegistry.js +3 -2
  32. package/lib/cjs/ClassRegistry.js.map +1 -1
  33. package/lib/cjs/CloudSqlite.d.ts +28 -11
  34. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  35. package/lib/cjs/CloudSqlite.js +42 -1
  36. package/lib/cjs/CloudSqlite.js.map +1 -1
  37. package/lib/cjs/DevTools.d.ts.map +1 -1
  38. package/lib/cjs/DevTools.js +2 -1
  39. package/lib/cjs/DevTools.js.map +1 -1
  40. package/lib/cjs/DisplayStyle.d.ts +0 -3
  41. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  42. package/lib/cjs/DisplayStyle.js +0 -3
  43. package/lib/cjs/DisplayStyle.js.map +1 -1
  44. package/lib/cjs/ECDb.d.ts +6 -1
  45. package/lib/cjs/ECDb.d.ts.map +1 -1
  46. package/lib/cjs/ECDb.js +19 -14
  47. package/lib/cjs/ECDb.js.map +1 -1
  48. package/lib/cjs/ECSchemaXmlContext.js +2 -2
  49. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  50. package/lib/cjs/ECSqlStatement.d.ts +6 -3
  51. package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
  52. package/lib/cjs/ECSqlStatement.js +3 -3
  53. package/lib/cjs/ECSqlStatement.js.map +1 -1
  54. package/lib/cjs/Element.d.ts +3 -60
  55. package/lib/cjs/Element.d.ts.map +1 -1
  56. package/lib/cjs/Element.js +8 -64
  57. package/lib/cjs/Element.js.map +1 -1
  58. package/lib/cjs/ElementAspect.d.ts +0 -5
  59. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  60. package/lib/cjs/ElementAspect.js +4 -8
  61. package/lib/cjs/ElementAspect.js.map +1 -1
  62. package/lib/cjs/ElementGraphics.d.ts.map +1 -1
  63. package/lib/cjs/ElementGraphics.js +2 -1
  64. package/lib/cjs/ElementGraphics.js.map +1 -1
  65. package/lib/cjs/ElementTreeWalker.d.ts +19 -0
  66. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  67. package/lib/cjs/ElementTreeWalker.js +23 -9
  68. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  69. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  70. package/lib/cjs/GeoCoordConfig.js +2 -1
  71. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  72. package/lib/cjs/GeographicCRSServices.js +2 -2
  73. package/lib/cjs/GeographicCRSServices.js.map +1 -1
  74. package/lib/cjs/GeometrySummary.d.ts.map +1 -1
  75. package/lib/cjs/GeometrySummary.js +2 -1
  76. package/lib/cjs/GeometrySummary.js.map +1 -1
  77. package/lib/cjs/IModelDb.d.ts +25 -95
  78. package/lib/cjs/IModelDb.d.ts.map +1 -1
  79. package/lib/cjs/IModelDb.js +192 -142
  80. package/lib/cjs/IModelDb.js.map +1 -1
  81. package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -1
  82. package/lib/cjs/IModelElementCloneContext.js +5 -4
  83. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  84. package/lib/cjs/IModelHost.d.ts +5 -3
  85. package/lib/cjs/IModelHost.d.ts.map +1 -1
  86. package/lib/cjs/IModelHost.js +16 -18
  87. package/lib/cjs/IModelHost.js.map +1 -1
  88. package/lib/cjs/IpcHost.d.ts.map +1 -1
  89. package/lib/cjs/IpcHost.js +15 -13
  90. package/lib/cjs/IpcHost.js.map +1 -1
  91. package/lib/cjs/LocalHub.d.ts +2 -2
  92. package/lib/cjs/LocalHub.d.ts.map +1 -1
  93. package/lib/cjs/LocalHub.js +17 -17
  94. package/lib/cjs/LocalHub.js.map +1 -1
  95. package/lib/cjs/LockControl.d.ts +73 -0
  96. package/lib/cjs/LockControl.d.ts.map +1 -0
  97. package/lib/cjs/LockControl.js +11 -0
  98. package/lib/cjs/LockControl.js.map +1 -0
  99. package/lib/cjs/Material.d.ts +2 -5
  100. package/lib/cjs/Material.d.ts.map +1 -1
  101. package/lib/cjs/Material.js +6 -4
  102. package/lib/cjs/Material.js.map +1 -1
  103. package/lib/cjs/Model.d.ts +0 -22
  104. package/lib/cjs/Model.d.ts.map +1 -1
  105. package/lib/cjs/Model.js +5 -26
  106. package/lib/cjs/Model.js.map +1 -1
  107. package/lib/cjs/Relationship.d.ts +0 -12
  108. package/lib/cjs/Relationship.d.ts.map +1 -1
  109. package/lib/cjs/Relationship.js +5 -16
  110. package/lib/cjs/Relationship.js.map +1 -1
  111. package/lib/cjs/SQLiteDb.d.ts +6 -1
  112. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  113. package/lib/cjs/SQLiteDb.js +23 -16
  114. package/lib/cjs/SQLiteDb.js.map +1 -1
  115. package/lib/cjs/SchemaSync.d.ts +3 -0
  116. package/lib/cjs/SchemaSync.d.ts.map +1 -1
  117. package/lib/cjs/SchemaSync.js +24 -11
  118. package/lib/cjs/SchemaSync.js.map +1 -1
  119. package/lib/cjs/SchemaUtils.js +3 -3
  120. package/lib/cjs/SchemaUtils.js.map +1 -1
  121. package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
  122. package/lib/cjs/SqliteChangesetReader.js +2 -2
  123. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  124. package/lib/cjs/SqliteStatement.js +2 -2
  125. package/lib/cjs/SqliteStatement.js.map +1 -1
  126. package/lib/cjs/TextAnnotationGeometry.d.ts +1 -1
  127. package/lib/cjs/TextAnnotationGeometry.d.ts.map +1 -1
  128. package/lib/cjs/TextAnnotationGeometry.js +9 -5
  129. package/lib/cjs/TextAnnotationGeometry.js.map +1 -1
  130. package/lib/cjs/TextAnnotationLayout.d.ts.map +1 -1
  131. package/lib/cjs/TextAnnotationLayout.js +18 -5
  132. package/lib/cjs/TextAnnotationLayout.js.map +1 -1
  133. package/lib/cjs/TxnManager.d.ts +2 -1
  134. package/lib/cjs/TxnManager.d.ts.map +1 -1
  135. package/lib/cjs/TxnManager.js +4 -2
  136. package/lib/cjs/TxnManager.js.map +1 -1
  137. package/lib/cjs/ViewDefinition.d.ts +1 -18
  138. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  139. package/lib/cjs/ViewDefinition.js +1 -18
  140. package/lib/cjs/ViewDefinition.js.map +1 -1
  141. package/lib/cjs/ViewStore.d.ts.map +1 -1
  142. package/lib/cjs/ViewStore.js +6 -5
  143. package/lib/cjs/ViewStore.js.map +1 -1
  144. package/lib/cjs/core-backend.d.ts +2 -1
  145. package/lib/cjs/core-backend.d.ts.map +1 -1
  146. package/lib/cjs/core-backend.js +3 -5
  147. package/lib/cjs/core-backend.js.map +1 -1
  148. package/lib/cjs/domains/FunctionalElements.d.ts +0 -10
  149. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
  150. package/lib/cjs/domains/FunctionalElements.js +0 -10
  151. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  152. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
  153. package/lib/cjs/domains/FunctionalSchema.js +2 -1
  154. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  155. package/lib/cjs/domains/GenericElements.d.ts +0 -18
  156. package/lib/cjs/domains/GenericElements.d.ts.map +1 -1
  157. package/lib/cjs/domains/GenericElements.js +0 -18
  158. package/lib/cjs/domains/GenericElements.js.map +1 -1
  159. package/lib/cjs/internal/ChangesetConflictArgs.d.ts +24 -0
  160. package/lib/cjs/internal/ChangesetConflictArgs.d.ts.map +1 -0
  161. package/lib/cjs/internal/ChangesetConflictArgs.js +7 -0
  162. package/lib/cjs/internal/ChangesetConflictArgs.js.map +1 -0
  163. package/lib/cjs/internal/ChannelAdmin.d.ts +34 -0
  164. package/lib/cjs/internal/ChannelAdmin.d.ts.map +1 -0
  165. package/lib/cjs/internal/ChannelAdmin.js +117 -0
  166. package/lib/cjs/internal/ChannelAdmin.js.map +1 -0
  167. package/lib/cjs/internal/NativePlatform.d.ts +15 -0
  168. package/lib/cjs/internal/NativePlatform.d.ts.map +1 -0
  169. package/lib/cjs/internal/NativePlatform.js +49 -0
  170. package/lib/cjs/internal/NativePlatform.js.map +1 -0
  171. package/lib/cjs/internal/NoLocks.d.ts +6 -0
  172. package/lib/cjs/internal/NoLocks.d.ts.map +1 -0
  173. package/lib/cjs/internal/NoLocks.js +31 -0
  174. package/lib/cjs/internal/NoLocks.js.map +1 -0
  175. package/lib/cjs/{ServerBasedLocks.d.ts → internal/ServerBasedLocks.d.ts} +10 -16
  176. package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -0
  177. package/lib/cjs/{ServerBasedLocks.js → internal/ServerBasedLocks.js} +29 -18
  178. package/lib/cjs/internal/ServerBasedLocks.js.map +1 -0
  179. package/lib/cjs/internal/Symbols.d.ts +11 -0
  180. package/lib/cjs/internal/Symbols.d.ts.map +1 -0
  181. package/lib/cjs/internal/Symbols.js +21 -0
  182. package/lib/cjs/internal/Symbols.js.map +1 -0
  183. package/lib/cjs/internal/cross-package.d.ts +4 -0
  184. package/lib/cjs/internal/cross-package.d.ts.map +1 -0
  185. package/lib/cjs/internal/cross-package.js +16 -0
  186. package/lib/cjs/internal/cross-package.js.map +1 -0
  187. package/lib/cjs/internal/workspace/SettingsImpl.d.ts +2 -2
  188. package/lib/cjs/internal/workspace/SettingsImpl.d.ts.map +1 -1
  189. package/lib/cjs/internal/workspace/SettingsImpl.js +3 -3
  190. package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -1
  191. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +2 -2
  192. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -1
  193. package/lib/cjs/internal/workspace/WorkspaceImpl.js +14 -14
  194. package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -1
  195. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts.map +1 -1
  196. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js +2 -1
  197. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js.map +1 -1
  198. package/lib/cjs/rpc/tracing.d.ts.map +1 -1
  199. package/lib/cjs/rpc/tracing.js +5 -2
  200. package/lib/cjs/rpc/tracing.js.map +1 -1
  201. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +1 -0
  202. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
  203. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +9 -4
  204. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  205. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  206. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +5 -3
  207. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  208. package/lib/cjs/workspace/Settings.d.ts +3 -3
  209. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  210. package/lib/cjs/workspace/Settings.js +1 -1
  211. package/lib/cjs/workspace/Settings.js.map +1 -1
  212. package/lib/cjs/workspace/SettingsSchemas.d.ts +2 -2
  213. package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -1
  214. package/lib/cjs/workspace/SettingsSchemas.js +1 -1
  215. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  216. package/lib/cjs/workspace/Workspace.d.ts +4 -4
  217. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  218. package/lib/cjs/workspace/Workspace.js +1 -1
  219. package/lib/cjs/workspace/Workspace.js.map +1 -1
  220. package/lib/cjs/workspace/WorkspaceEditor.d.ts +2 -2
  221. package/lib/cjs/workspace/WorkspaceEditor.d.ts.map +1 -1
  222. package/lib/cjs/workspace/WorkspaceEditor.js +1 -1
  223. package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -1
  224. package/package.json +15 -14
  225. package/lib/cjs/ServerBasedLocks.d.ts.map +0 -1
  226. package/lib/cjs/ServerBasedLocks.js.map +0 -1
  227. package/lib/cjs/internal/ImplementationProhibited.d.ts +0 -44
  228. package/lib/cjs/internal/ImplementationProhibited.d.ts.map +0 -1
  229. package/lib/cjs/internal/ImplementationProhibited.js +0 -51
  230. package/lib/cjs/internal/ImplementationProhibited.js.map +0 -1
@@ -6,6 +6,7 @@
6
6
  /** @packageDocumentation
7
7
  * @module SQLiteDb
8
8
  */
9
+ var _a;
9
10
  Object.defineProperty(exports, "__esModule", { value: true });
10
11
  exports.VersionedSqliteDb = exports.SQLiteDb = void 0;
11
12
  const fs = require("fs");
@@ -13,9 +14,10 @@ const path_1 = require("path");
13
14
  const semver = require("semver");
14
15
  const core_bentley_1 = require("@itwin/core-bentley");
15
16
  const CloudSqlite_1 = require("./CloudSqlite");
16
- const IModelHost_1 = require("./IModelHost");
17
+ const NativePlatform_1 = require("./internal/NativePlatform");
17
18
  const IModelJsFs_1 = require("./IModelJsFs");
18
19
  const SqliteStatement_1 = require("./SqliteStatement");
20
+ const Symbols_1 = require("./internal/Symbols");
19
21
  // cspell:ignore savepoint julianday rowid
20
22
  /* eslint-disable @typescript-eslint/unified-signatures */
21
23
  /**
@@ -25,12 +27,16 @@ const SqliteStatement_1 = require("./SqliteStatement");
25
27
  class SQLiteDb {
26
28
  constructor() {
27
29
  /** @internal */
28
- this.nativeDb = new IModelHost_1.IModelHost.platform.SQLiteDb();
30
+ this[_a] = new NativePlatform_1.IModelNative.platform.SQLiteDb();
29
31
  this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
30
32
  }
33
+ /** @internal
34
+ * @deprecated in 4.8. This internal API will be removed in 5.0. Use SQLiteDb's public API instead.
35
+ */
36
+ get nativeDb() { return this[Symbols_1._nativeDb]; }
31
37
  /** @internal */
32
38
  static createBlobIO() {
33
- return new IModelHost_1.IModelHost.platform.BlobIO();
39
+ return new NativePlatform_1.IModelNative.platform.BlobIO();
34
40
  }
35
41
  /** alias for closeDb.
36
42
  * @deprecated in 4.0, use [[closeDb]]
@@ -39,10 +45,10 @@ class SQLiteDb {
39
45
  this.closeDb();
40
46
  }
41
47
  createDb(dbName, container, params) {
42
- this.nativeDb.createDb(dbName, container, params);
48
+ this[Symbols_1._nativeDb].createDb(dbName, container, params);
43
49
  }
44
50
  openDb(dbName, openMode, container) {
45
- this.nativeDb.openDb(dbName, openMode, container);
51
+ this[Symbols_1._nativeDb].openDb(dbName, openMode, container);
46
52
  }
47
53
  /** Close SQLiteDb.
48
54
  * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
@@ -51,12 +57,12 @@ class SQLiteDb {
51
57
  if (saveChanges && this.isOpen)
52
58
  this.saveChanges();
53
59
  this._sqliteStatementCache.clear();
54
- this.nativeDb.closeDb();
60
+ this[Symbols_1._nativeDb].closeDb();
55
61
  }
56
62
  /** Returns true if this SQLiteDb is open */
57
- get isOpen() { return this.nativeDb.isOpen(); }
63
+ get isOpen() { return this[Symbols_1._nativeDb].isOpen(); }
58
64
  /** Returns true if this SQLiteDb is open readonly */
59
- get isReadonly() { return this.nativeDb.isReadonly(); }
65
+ get isReadonly() { return this[Symbols_1._nativeDb].isReadonly(); }
60
66
  /** Create a new table in this database. */
61
67
  createTable(args) {
62
68
  const timestampCol = args.addTimestamp ? ",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))" : "";
@@ -122,15 +128,15 @@ class SQLiteDb {
122
128
  * @see https://www.sqlite.org/lang_vacuum.html
123
129
  */
124
130
  vacuum(args) {
125
- this.nativeDb.vacuum(args);
131
+ this[Symbols_1._nativeDb].vacuum(args);
126
132
  }
127
133
  /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */
128
134
  saveChanges() {
129
- this.nativeDb.saveChanges();
135
+ this[Symbols_1._nativeDb].saveChanges();
130
136
  }
131
137
  /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */
132
138
  abandonChanges() {
133
- this.nativeDb.abandonChanges();
139
+ this[Symbols_1._nativeDb].abandonChanges();
134
140
  }
135
141
  /**
136
142
  * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
@@ -201,7 +207,7 @@ class SQLiteDb {
201
207
  */
202
208
  prepareSqliteStatement(sql, logErrors = true) {
203
209
  const stmt = new SqliteStatement_1.SqliteStatement(sql);
204
- stmt.prepare(this.nativeDb, logErrors);
210
+ stmt.prepare(this[Symbols_1._nativeDb], logErrors);
205
211
  return stmt;
206
212
  }
207
213
  /** execute an SQL statement */
@@ -216,6 +222,7 @@ class SQLiteDb {
216
222
  }
217
223
  }
218
224
  exports.SQLiteDb = SQLiteDb;
225
+ _a = Symbols_1._nativeDb;
219
226
  /**
220
227
  * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.
221
228
  * This class provides version checking when the database is opened, to guarantee that a valid version of software is
@@ -236,16 +243,16 @@ class VersionedSqliteDb extends SQLiteDb {
236
243
  */
237
244
  setRequiredVersions(versions) {
238
245
  // 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 }));
246
+ this[Symbols_1._nativeDb].saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));
240
247
  }
241
248
  /** Get the required version ranges necessary to open this VersionedSqliteDb. */
242
249
  getRequiredVersions() {
243
250
  const checkIsString = (value) => {
244
251
  if (typeof value !== "string")
245
- throw new Error(`CloudDb ${this.nativeDb.getFilePath()} has invalid "versions" property`);
252
+ throw new Error(`CloudDb ${this[Symbols_1._nativeDb].getFilePath()} has invalid "versions" property`);
246
253
  return value;
247
254
  };
248
- const versionJson = checkIsString(this.nativeDb.queryFileProperty(VersionedSqliteDb._versionProps, true));
255
+ const versionJson = checkIsString(this[Symbols_1._nativeDb].queryFileProperty(VersionedSqliteDb._versionProps, true));
249
256
  const versionRanges = JSON.parse(versionJson);
250
257
  checkIsString(versionRanges.readVersion);
251
258
  checkIsString(versionRanges.writeVersion);
@@ -278,7 +285,7 @@ class VersionedSqliteDb extends SQLiteDb {
278
285
  return;
279
286
  this.closeDb();
280
287
  const tooNew = semver.gtr(this.myVersion, range);
281
- throw new Error(`${this.nativeDb.getFilePath()} requires ${tooNew ? "older" : "newer"} version of ${this.constructor.name} for ${isReadonly ? "read" : "write"}`);
288
+ throw new Error(`${this[Symbols_1._nativeDb].getFilePath()} requires ${tooNew ? "older" : "newer"} version of ${this.constructor.name} for ${isReadonly ? "read" : "write"}`);
282
289
  }
283
290
  /**
284
291
  * 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.
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yBAAyB;AACzB,+BAA+B;AAC/B,iCAAiC;AAEjC,sDAAyD;AAEzD,+CAA4C;AAC5C,6CAA0C;AAC1C,6CAA0C;AAC1C,uDAAoE;AAEpE,0CAA0C;AAE1C,0DAA0D;AAE1D;;;GAGG;AACH,MAAa,QAAQ;IAArB;QACE,gBAAgB;QACA,aAAQ,GAAG,IAAI,uBAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtD,0BAAqB,GAAG,IAAI,gCAAc,EAAmB,CAAC;IAmOxE,CAAC;IAjOC,gBAAgB;IACT,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,uBAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAQM,QAAQ,CAAC,MAAc,EAAE,SAAsC,EAAE,MAA8B;QACpG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAWM,MAAM,CAAC,MAAc,EAAE,QAAwC,EAAE,SAAsC;QAC5G,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,WAAqB;QAClC,IAAI,WAAW,IAAI,IAAI,CA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U,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,uBAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9E,CAAC;;AA7FH,8CA8FC;AA7FkB,+BAAa,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAW,CAAC;AA+FxF,cAAc;AACd,WAAiB,QAAQ;IAqEvB;;OAEG;IACH,IAAY,cASX;IATD,WAAY,cAAc;QACxB,4GAA4G;QAC5G,mDAAQ,CAAA;QACR,4FAA4F;QAC5F,2DAAY,CAAA;QACZ,yEAAyE;QACzE,6DAAa,CAAA;QACb,yEAAyE;QACzE,6DAAa,CAAA;IACf,CAAC,EATW,cAAc,GAAd,uBAAc,KAAd,uBAAc,QASzB;AAgDH,CAAC,EAjIgB,QAAQ,wBAAR,QAAQ,QAiIxB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport { dirname } from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\n// cspell:ignore savepoint julianday rowid\r\n\r\n/* eslint-disable @typescript-eslint/unified-signatures */\r\n\r\n/**\r\n * A \"generic\" SQLiteDb. This class may be used to access local files or databases in a cloud container.\r\n * @public\r\n */\r\nexport class SQLiteDb {\r\n /** @internal */\r\n public readonly nativeDb = new IModelHost.platform.SQLiteDb();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public static createBlobIO(): SQLiteDb.BlobIO {\r\n return new IModelHost.platform.BlobIO();\r\n }\r\n\r\n /** alias for closeDb.\r\n * @deprecated in 4.0, use [[closeDb]]\r\n */\r\n public dispose(): void {\r\n this.closeDb();\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param dbName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(dbName: string): void;\r\n /** @beta */\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void {\r\n this.nativeDb.createDb(dbName, container, params);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param dbName The path to the SQLiteDb file to open\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\r\n /**\r\n * @param container optional CloudContainer holding database\r\n * @beta\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void {\r\n this.nativeDb.openDb(dbName, openMode, container);\r\n }\r\n\r\n /** Close SQLiteDb.\r\n * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.\r\n */\r\n public closeDb(saveChanges?: boolean): void {\r\n if (saveChanges && this.isOpen)\r\n this.saveChanges();\r\n this._sqliteStatementCache.clear();\r\n this.nativeDb.closeDb();\r\n }\r\n\r\n /** Returns true if this SQLiteDb is open */\r\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\r\n\r\n /** Returns true if this SQLiteDb is open readonly */\r\n public get isReadonly(): boolean { return this.nativeDb.isReadonly(); }\r\n\r\n /** Create a new table in this database. */\r\n protected createTable(args: {\r\n /** The name of the table to create. */\r\n tableName: string;\r\n /** all of the columns in the table. */\r\n columns: string;\r\n /** any unique or foreign key constraints */\r\n constraints?: string;\r\n /** if true, add a \"lastMod\" timestamp column and triggers to automatically update it. */\r\n addTimestamp?: boolean;\r\n }) {\r\n const timestampCol = args.addTimestamp ? \",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))\" : \"\";\r\n const constraints = args.constraints ? `,${args.constraints}` : \"\";\r\n this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);\r\n if (args.addTimestamp)\r\n 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`);\r\n }\r\n\r\n /**\r\n * Get the last modified date for a row in a table of this database.\r\n * @note the table must have been created with `addTimestamp: true`\r\n */\r\n public readLastModTime(tableName: string, rowId: number): Date {\r\n return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {\r\n stmt.bindInteger(1, rowId);\r\n return stmt.getValueDate(0);\r\n });\r\n }\r\n\r\n /**\r\n * Open a database, perform an operation, then close the database.\r\n *\r\n * Details:\r\n * - if database is open, throw an error\r\n * - open a database\r\n * - call a function with the database opened. If it is async, await its return.\r\n * - if function throws, abandon all changes, close database, and rethrow\r\n * - save all changes\r\n * - close the database\r\n * @return value from operation\r\n */\r\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\r\n if (this.isOpen)\r\n throw new Error(\"database is already open\");\r\n\r\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\r\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n try {\r\n const result = operation();\r\n result instanceof Promise ? result.then(save, abandon) : save();\r\n return result;\r\n } catch (e) {\r\n abandon();\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on a database in a CloudContainer with the write lock held.\r\n *\r\n * Details:\r\n * - acquire the write lock on a CloudContainer\r\n * - call `withOpenDb` with openMode `ReadWrite`\r\n * - upload changes\r\n * - release the write lock\r\n * @param args arguments to lock the container and open the database\r\n * @param operation an operation performed on the database with the write lock held.\r\n * @return value from operation\r\n * @internal\r\n */\r\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => Promise<T>) {\r\n return CloudSqlite.withWriteLock(args, async () => this.withOpenDb({ ...args, openMode: args.openMode ?? OpenMode.ReadWrite }, operation));\r\n }\r\n\r\n /** vacuum this database\r\n * @see https://www.sqlite.org/lang_vacuum.html\r\n */\r\n public vacuum(args?: SQLiteDb.VacuumDbArgs) {\r\n this.nativeDb.vacuum(args);\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */\r\n public saveChanges(): void {\r\n this.nativeDb.saveChanges();\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */\r\n public abandonChanges(): void {\r\n this.nativeDb.abandonChanges();\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n const release = () => stmt.dispose();\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\r\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\r\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\r\n */\r\n public withSavePoint(savePointName: string, operation: () => void) {\r\n if (this.isReadonly)\r\n throw new Error(\"database is readonly\");\r\n\r\n this.executeSQL(`SAVEPOINT ${savePointName}`);\r\n try {\r\n operation();\r\n this.executeSQL(`RELEASE ${savePointName}`);\r\n } catch (e) {\r\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\r\n throw e;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this.nativeDb, logErrors);\r\n return stmt;\r\n }\r\n\r\n /** execute an SQL statement */\r\n public executeSQL(sql: string): DbResult {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n try {\r\n return stmt.step();\r\n } finally {\r\n stmt.dispose();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.\r\n * This class provides version checking when the database is opened, to guarantee that a valid version of software is\r\n * always used for access.\r\n *\r\n * Notes:\r\n * - This class may be used either to access a local file, or one stored in a cloud container.\r\n * - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its\r\n * tables.\r\n * @beta\r\n */\r\nexport abstract class VersionedSqliteDb extends SQLiteDb {\r\n protected static _versionProps = { namespace: \"SQLiteDb\", name: \"versions\" } as const;\r\n\r\n /** The current semver \"persistence version\" of this class.\r\n * @note This value should only be changed when logic in its code is modified in a way that affects the operation of extant copies.\r\n * If this value is outside of the range of accepted versions of a to-be-opened VersionedSqliteDb, the operation will fail. In this manner, if\r\n * changes are made to the format of a VersionedSqliteDb, or if bug fixes are necessary, the `requiredVersions` property in a VersionedSqliteDb may be updated\r\n * and immediately old versions of the package will refuse to open the VersionedSqliteDb, with a message to the user that they need to upgrade their\r\n * software. Likewise, if a new version of the package is asked to open an older VersionedSqliteDb that has not been upgraded to the lowest version\r\n * supported by it, the user will be informed that they need to upgrade their software.\r\n * @note this identifier is independent of versions in `package.json` files.\r\n */\r\n public abstract myVersion: string;\r\n\r\n /**\r\n * Change the \"versions required to open this database\" property stored in this database. After this call,\r\n * versions of software that don't meet the supplied ranges will fail.\r\n * @param versions the new versions required for reading and writing this database.\r\n * @note the database must be opened for write access.\r\n */\r\n public setRequiredVersions(versions: SQLiteDb.RequiredVersionRanges) {\r\n // NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.\r\n this.nativeDb.saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));\r\n }\r\n\r\n /** Get the required version ranges necessary to open this VersionedSqliteDb. */\r\n public getRequiredVersions() {\r\n const checkIsString = (value: any) => {\r\n if (typeof value !== \"string\")\r\n throw new Error(`CloudDb ${this.nativeDb.getFilePath()} has invalid \"versions\" property`);\r\n return value;\r\n };\r\n const versionJson = checkIsString(this.nativeDb.queryFileProperty(VersionedSqliteDb._versionProps, true));\r\n const versionRanges = JSON.parse(versionJson) as SQLiteDb.RequiredVersionRanges;\r\n checkIsString(versionRanges.readVersion);\r\n checkIsString(versionRanges.writeVersion);\r\n return versionRanges;\r\n }\r\n\r\n /**\r\n * Implement this method to create all tables for this subclass of `VersionedSqliteDb` when a new database file is created. Called from [[createNewDb]].\r\n */\r\n protected abstract createDDL(args: any): void;\r\n\r\n /**\r\n * Create a new database file for the subclass of VersionedSqliteDb.\r\n * @note The required versions are saved as [[myVersion]] or newer for both read and write.\r\n */\r\n public static createNewDb(fileName: LocalFileName, setupArgs?: any) {\r\n const db = new (this as any)() as VersionedSqliteDb; // \"as any\" necessary because VersionedSqliteDb is abstract\r\n IModelJsFs.recursiveMkDirSync(dirname(fileName));\r\n if (fs.existsSync(fileName))\r\n fs.unlinkSync(fileName);\r\n\r\n db.createDb(fileName);\r\n db.createDDL(setupArgs);\r\n const minVer = `^${db.myVersion}`;\r\n db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });\r\n db.closeDb(true);\r\n }\r\n\r\n /**\r\n * Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n */\r\n protected verifyVersions() {\r\n const versions = this.getRequiredVersions();\r\n const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.\r\n const range = isReadonly ? versions.readVersion : versions.writeVersion;\r\n if (semver.satisfies(this.myVersion, range))\r\n return;\r\n\r\n this.closeDb();\r\n const tooNew = semver.gtr(this.myVersion, range);\r\n throw new Error(`${this.nativeDb.getFilePath()} requires ${tooNew ? \"older\" : \"newer\"} version of ${this.constructor.name} for ${isReadonly ? \"read\" : \"write\"}`);\r\n\r\n }\r\n\r\n /**\r\n * 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.\r\n * Throws otherwise.\r\n * @see [[SqliteDb.openDb]] for argument types\r\n */\r\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\r\n super.openDb(dbName, openMode, container);\r\n this.verifyVersions();\r\n }\r\n\r\n public async upgradeSchema(arg: { dbName: string, lockContainer?: { container: CloudSqlite.CloudContainer, user: string }, upgradeFn: () => void }) {\r\n // can't use \"this\" because it checks for version, which we don't want here\r\n return (arg.lockContainer) ?\r\n super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :\r\n super.withOpenDb({ ...arg, openMode: OpenMode.ReadWrite }, arg.upgradeFn);\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SQLiteDb {\r\n /** A semver version range.\r\n * @see https://docs.npmjs.com/cli/v6/using-npm/semver\r\n */\r\n export type VersionRange = string;\r\n\r\n /**\r\n * A pair of semver [[SQLiteDb.VersionRange]]s, one for read and one for write, required to access a [[VersionedSqliteDb]].\r\n * If the version of the software attempting to read or write the database does not satisfy the range, access is denied.\r\n */\r\n export interface RequiredVersionRanges {\r\n /** a range of acceptable persistence versions for reading from a VersionedSqliteDb. */\r\n readonly readVersion: VersionRange;\r\n /** a range of acceptable persistence versions for writing to a VersionedSqliteDb. */\r\n readonly writeVersion: VersionRange;\r\n }\r\n\r\n /** interface for reading and writing to a blob in a SQLiteDb\r\n * @internal\r\n */\r\n export interface BlobIO {\r\n /** Close this BlobIO if it is opened.\r\n * @note this BlobIO *may* be reused after this call by calling `open` again.\r\n */\r\n close(): void;\r\n /** get the total number of bytes in the blob */\r\n getNumBytes(): number;\r\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\r\n isValid(): boolean;\r\n /** Open this BlobIO against a table/row/column in a Db */\r\n open(\r\n /** The database for the blob */\r\n db: IModelJsNative.AnyDb,\r\n args: {\r\n /** the name of the table for the blob*/\r\n tableName: string;\r\n /** the name of the column for the blob */\r\n columnName: string;\r\n /** The rowId of the blob */\r\n row: number;\r\n /** If true, open this BlobIO for write access */\r\n writeable?: boolean;\r\n }): void;\r\n /** Read from a blob\r\n * @returns the contents of the requested byte range\r\n */\r\n read(args: {\r\n /** The number of bytes to read */\r\n numBytes: number;\r\n /** starting offset within the blob to read */\r\n offset: number;\r\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\r\n blob?: ArrayBuffer;\r\n }): Uint8Array;\r\n /** Reposition this BlobIO to a new rowId\r\n * @note this BlobIO must be valid when this methods is called.\r\n */\r\n changeRow(row: number): void;\r\n /** Write to a blob */\r\n write(args: {\r\n /** The number of bytes to write */\r\n numBytes: number;\r\n /** starting offset within the blob to write */\r\n offset: number;\r\n /** the value to write */\r\n blob: ArrayBuffer;\r\n }): void;\r\n }\r\n\r\n /** Default transaction mode for SQLiteDbs.\r\n * @see https://www.sqlite.org/lang_transaction.html\r\n */\r\n export enum DefaultTxnMode {\r\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\r\n None = 0,\r\n /** A deferred transaction is started when the file is first opened. This is the default. */\r\n Deferred = 1,\r\n /** An immediate transaction is started when the file is first opened. */\r\n Immediate = 2,\r\n /** An exclusive transaction is started when the file is first opened. */\r\n Exclusive = 3\r\n }\r\n\r\n /** parameters common to opening or creating a new SQLiteDb */\r\n export interface OpenOrCreateParams {\r\n /** If true, do not require that the `be_Prop` table exist */\r\n rawSQLite?: boolean;\r\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\r\n immutable?: boolean;\r\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\r\n skipFileCheck?: boolean;\r\n /** the default transaction mode\r\n * @see [[SQLiteDb.DefaultTxnMode]]\r\n */\r\n defaultTxn?: 0 | 1 | 2 | 3;\r\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\r\n queryParam?: string;\r\n }\r\n\r\n /** Parameters for opening an existing SQLiteDb */\r\n export interface OpenParams extends OpenOrCreateParams {\r\n /** use OpenMode.ReadWrite to open the file with write access */\r\n openMode: OpenMode;\r\n }\r\n\r\n /** Size of a SQLiteDb page in bytes */\r\n export interface PageSize {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export type CreateParams = OpenOrCreateParams & PageSize;\r\n\r\n /** Arguments for `SqliteDb.withOpenDb` */\r\n export interface WithOpenDbArgs {\r\n /** The name of the database to open */\r\n dbName: string;\r\n /** either an object with the open parameters or just OpenMode value. */\r\n openMode?: OpenMode | SQLiteDb.OpenParams;\r\n /** @internal */\r\n container?: CloudSqlite.CloudContainer;\r\n }\r\n\r\n /** Arguments for `SQLiteDb.vacuum` */\r\n export interface VacuumDbArgs extends PageSize {\r\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\r\n into?: LocalFileName;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,yBAAyB;AACzB,+BAA+B;AAC/B,iCAAiC;AAEjC,sDAAyD;AAEzD,+CAA4C;AAC5C,8DAAyD;AACzD,6CAA0C;AAC1C,uDAAoE;AACpE,gDAA+C;AAE/C,0CAA0C;AAE1C,0DAA0D;AAE1D;;;GAGG;AACH,MAAa,QAAQ;IAArB;QAME,gBAAgB;QACA,QAAW,GAAG,IAAI,6BAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC3D,0BAAqB,GAAG,IAAI,gCAAc,EAAmB,CAAC;IAmOxE,CAAC;IA1OC;;OAEG;IACH,IAAW,QAAQ,KAA8B,OAAO,IAAI,CAAC,mBAAS,CAAC,CAAC,CAAC,CAAC;IAM1E,gBAAgB;IACT,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,6BAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAQM,QAAQ,CAAC,MAAc,EAAE,SAAsC,EAAE,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KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,GAAuH;QAChJ,2EAA2E;QAC3E,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;YAC1B,KAAK,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,aAAa,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;YACpG,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,uBAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9E,CAAC;;AA7FH,8CA8FC;AA7FkB,+BAAa,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAW,CAAC;AA+FxF,cAAc;AACd,WAAiB,QAAQ;IAqEvB;;OAEG;IACH,IAAY,cASX;IATD,WAAY,cAAc;QACxB,4GAA4G;QAC5G,mDAAQ,CAAA;QACR,4FAA4F;QAC5F,2DAAY,CAAA;QACZ,yEAAyE;QACzE,6DAAa,CAAA;QACb,yEAAyE;QACzE,6DAAa,CAAA;IACf,CAAC,EATW,cAAc,GAAd,uBAAc,KAAd,uBAAc,QASzB;AAgDH,CAAC,EAjIgB,QAAQ,wBAAR,QAAQ,QAiIxB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport { dirname } from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\n\r\n// cspell:ignore savepoint julianday rowid\r\n\r\n/* eslint-disable @typescript-eslint/unified-signatures */\r\n\r\n/**\r\n * A \"generic\" SQLiteDb. This class may be used to access local files or databases in a cloud container.\r\n * @public\r\n */\r\nexport class SQLiteDb {\r\n /** @internal\r\n * @deprecated in 4.8. This internal API will be removed in 5.0. Use SQLiteDb's public API instead.\r\n */\r\n public get nativeDb(): IModelJsNative.SQLiteDb { return this[_nativeDb]; }\r\n\r\n /** @internal */\r\n public readonly [_nativeDb] = new IModelNative.platform.SQLiteDb();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public static createBlobIO(): SQLiteDb.BlobIO {\r\n return new IModelNative.platform.BlobIO();\r\n }\r\n\r\n /** alias for closeDb.\r\n * @deprecated in 4.0, use [[closeDb]]\r\n */\r\n public dispose(): void {\r\n this.closeDb();\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param dbName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(dbName: string): void;\r\n /** @beta */\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void {\r\n this[_nativeDb].createDb(dbName, container, params);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param dbName The path to the SQLiteDb file to open\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\r\n /**\r\n * @param container optional CloudContainer holding database\r\n * @beta\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void {\r\n this[_nativeDb].openDb(dbName, openMode, container);\r\n }\r\n\r\n /** Close SQLiteDb.\r\n * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.\r\n */\r\n public closeDb(saveChanges?: boolean): void {\r\n if (saveChanges && this.isOpen)\r\n this.saveChanges();\r\n this._sqliteStatementCache.clear();\r\n this[_nativeDb].closeDb();\r\n }\r\n\r\n /** Returns true if this SQLiteDb is open */\r\n public get isOpen(): boolean { return this[_nativeDb].isOpen(); }\r\n\r\n /** Returns true if this SQLiteDb is open readonly */\r\n public get isReadonly(): boolean { return this[_nativeDb].isReadonly(); }\r\n\r\n /** Create a new table in this database. */\r\n protected createTable(args: {\r\n /** The name of the table to create. */\r\n tableName: string;\r\n /** all of the columns in the table. */\r\n columns: string;\r\n /** any unique or foreign key constraints */\r\n constraints?: string;\r\n /** if true, add a \"lastMod\" timestamp column and triggers to automatically update it. */\r\n addTimestamp?: boolean;\r\n }) {\r\n const timestampCol = args.addTimestamp ? \",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))\" : \"\";\r\n const constraints = args.constraints ? `,${args.constraints}` : \"\";\r\n this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);\r\n if (args.addTimestamp)\r\n 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`);\r\n }\r\n\r\n /**\r\n * Get the last modified date for a row in a table of this database.\r\n * @note the table must have been created with `addTimestamp: true`\r\n */\r\n public readLastModTime(tableName: string, rowId: number): Date {\r\n return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {\r\n stmt.bindInteger(1, rowId);\r\n return stmt.getValueDate(0);\r\n });\r\n }\r\n\r\n /**\r\n * Open a database, perform an operation, then close the database.\r\n *\r\n * Details:\r\n * - if database is open, throw an error\r\n * - open a database\r\n * - call a function with the database opened. If it is async, await its return.\r\n * - if function throws, abandon all changes, close database, and rethrow\r\n * - save all changes\r\n * - close the database\r\n * @return value from operation\r\n */\r\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\r\n if (this.isOpen)\r\n throw new Error(\"database is already open\");\r\n\r\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\r\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n try {\r\n const result = operation();\r\n result instanceof Promise ? result.then(save, abandon) : save();\r\n return result;\r\n } catch (e) {\r\n abandon();\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on a database in a CloudContainer with the write lock held.\r\n *\r\n * Details:\r\n * - acquire the write lock on a CloudContainer\r\n * - call `withOpenDb` with openMode `ReadWrite`\r\n * - upload changes\r\n * - release the write lock\r\n * @param args arguments to lock the container and open the database\r\n * @param operation an operation performed on the database with the write lock held.\r\n * @return value from operation\r\n * @internal\r\n */\r\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => Promise<T>) {\r\n return CloudSqlite.withWriteLock(args, async () => this.withOpenDb({ ...args, openMode: args.openMode ?? OpenMode.ReadWrite }, operation));\r\n }\r\n\r\n /** vacuum this database\r\n * @see https://www.sqlite.org/lang_vacuum.html\r\n */\r\n public vacuum(args?: SQLiteDb.VacuumDbArgs) {\r\n this[_nativeDb].vacuum(args);\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */\r\n public saveChanges(): void {\r\n this[_nativeDb].saveChanges();\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */\r\n public abandonChanges(): void {\r\n this[_nativeDb].abandonChanges();\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n const release = () => stmt.dispose();\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\r\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\r\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\r\n */\r\n public withSavePoint(savePointName: string, operation: () => void) {\r\n if (this.isReadonly)\r\n throw new Error(\"database is readonly\");\r\n\r\n this.executeSQL(`SAVEPOINT ${savePointName}`);\r\n try {\r\n operation();\r\n this.executeSQL(`RELEASE ${savePointName}`);\r\n } catch (e) {\r\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\r\n throw e;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this[_nativeDb], logErrors);\r\n return stmt;\r\n }\r\n\r\n /** execute an SQL statement */\r\n public executeSQL(sql: string): DbResult {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n try {\r\n return stmt.step();\r\n } finally {\r\n stmt.dispose();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.\r\n * This class provides version checking when the database is opened, to guarantee that a valid version of software is\r\n * always used for access.\r\n *\r\n * Notes:\r\n * - This class may be used either to access a local file, or one stored in a cloud container.\r\n * - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its\r\n * tables.\r\n * @beta\r\n */\r\nexport abstract class VersionedSqliteDb extends SQLiteDb {\r\n protected static _versionProps = { namespace: \"SQLiteDb\", name: \"versions\" } as const;\r\n\r\n /** The current semver \"persistence version\" of this class.\r\n * @note This value should only be changed when logic in its code is modified in a way that affects the operation of extant copies.\r\n * If this value is outside of the range of accepted versions of a to-be-opened VersionedSqliteDb, the operation will fail. In this manner, if\r\n * changes are made to the format of a VersionedSqliteDb, or if bug fixes are necessary, the `requiredVersions` property in a VersionedSqliteDb may be updated\r\n * and immediately old versions of the package will refuse to open the VersionedSqliteDb, with a message to the user that they need to upgrade their\r\n * software. Likewise, if a new version of the package is asked to open an older VersionedSqliteDb that has not been upgraded to the lowest version\r\n * supported by it, the user will be informed that they need to upgrade their software.\r\n * @note this identifier is independent of versions in `package.json` files.\r\n */\r\n public abstract myVersion: string;\r\n\r\n /**\r\n * Change the \"versions required to open this database\" property stored in this database. After this call,\r\n * versions of software that don't meet the supplied ranges will fail.\r\n * @param versions the new versions required for reading and writing this database.\r\n * @note the database must be opened for write access.\r\n */\r\n public setRequiredVersions(versions: SQLiteDb.RequiredVersionRanges) {\r\n // NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.\r\n this[_nativeDb].saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));\r\n }\r\n\r\n /** Get the required version ranges necessary to open this VersionedSqliteDb. */\r\n public getRequiredVersions() {\r\n const checkIsString = (value: any) => {\r\n if (typeof value !== \"string\")\r\n throw new Error(`CloudDb ${this[_nativeDb].getFilePath()} has invalid \"versions\" property`);\r\n return value;\r\n };\r\n const versionJson = checkIsString(this[_nativeDb].queryFileProperty(VersionedSqliteDb._versionProps, true));\r\n const versionRanges = JSON.parse(versionJson) as SQLiteDb.RequiredVersionRanges;\r\n checkIsString(versionRanges.readVersion);\r\n checkIsString(versionRanges.writeVersion);\r\n return versionRanges;\r\n }\r\n\r\n /**\r\n * Implement this method to create all tables for this subclass of `VersionedSqliteDb` when a new database file is created. Called from [[createNewDb]].\r\n */\r\n protected abstract createDDL(args: any): void;\r\n\r\n /**\r\n * Create a new database file for the subclass of VersionedSqliteDb.\r\n * @note The required versions are saved as [[myVersion]] or newer for both read and write.\r\n */\r\n public static createNewDb(fileName: LocalFileName, setupArgs?: any) {\r\n const db = new (this as any)() as VersionedSqliteDb; // \"as any\" necessary because VersionedSqliteDb is abstract\r\n IModelJsFs.recursiveMkDirSync(dirname(fileName));\r\n if (fs.existsSync(fileName))\r\n fs.unlinkSync(fileName);\r\n\r\n db.createDb(fileName);\r\n db.createDDL(setupArgs);\r\n const minVer = `^${db.myVersion}`;\r\n db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });\r\n db.closeDb(true);\r\n }\r\n\r\n /**\r\n * Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n */\r\n protected verifyVersions() {\r\n const versions = this.getRequiredVersions();\r\n const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.\r\n const range = isReadonly ? versions.readVersion : versions.writeVersion;\r\n if (semver.satisfies(this.myVersion, range))\r\n return;\r\n\r\n this.closeDb();\r\n const tooNew = semver.gtr(this.myVersion, range);\r\n throw new Error(`${this[_nativeDb].getFilePath()} requires ${tooNew ? \"older\" : \"newer\"} version of ${this.constructor.name} for ${isReadonly ? \"read\" : \"write\"}`);\r\n\r\n }\r\n\r\n /**\r\n * 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.\r\n * Throws otherwise.\r\n * @see [[SqliteDb.openDb]] for argument types\r\n */\r\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\r\n super.openDb(dbName, openMode, container);\r\n this.verifyVersions();\r\n }\r\n\r\n public async upgradeSchema(arg: { dbName: string, lockContainer?: { container: CloudSqlite.CloudContainer, user: string }, upgradeFn: () => void }) {\r\n // can't use \"this\" because it checks for version, which we don't want here\r\n return (arg.lockContainer) ?\r\n super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :\r\n super.withOpenDb({ ...arg, openMode: OpenMode.ReadWrite }, arg.upgradeFn);\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SQLiteDb {\r\n /** A semver version range.\r\n * @see https://docs.npmjs.com/cli/v6/using-npm/semver\r\n */\r\n export type VersionRange = string;\r\n\r\n /**\r\n * A pair of semver [[SQLiteDb.VersionRange]]s, one for read and one for write, required to access a [[VersionedSqliteDb]].\r\n * If the version of the software attempting to read or write the database does not satisfy the range, access is denied.\r\n */\r\n export interface RequiredVersionRanges {\r\n /** a range of acceptable persistence versions for reading from a VersionedSqliteDb. */\r\n readonly readVersion: VersionRange;\r\n /** a range of acceptable persistence versions for writing to a VersionedSqliteDb. */\r\n readonly writeVersion: VersionRange;\r\n }\r\n\r\n /** interface for reading and writing to a blob in a SQLiteDb\r\n * @internal\r\n */\r\n export interface BlobIO {\r\n /** Close this BlobIO if it is opened.\r\n * @note this BlobIO *may* be reused after this call by calling `open` again.\r\n */\r\n close(): void;\r\n /** get the total number of bytes in the blob */\r\n getNumBytes(): number;\r\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\r\n isValid(): boolean;\r\n /** Open this BlobIO against a table/row/column in a Db */\r\n open(\r\n /** The database for the blob */\r\n db: IModelJsNative.AnyDb,\r\n args: {\r\n /** the name of the table for the blob*/\r\n tableName: string;\r\n /** the name of the column for the blob */\r\n columnName: string;\r\n /** The rowId of the blob */\r\n row: number;\r\n /** If true, open this BlobIO for write access */\r\n writeable?: boolean;\r\n }): void;\r\n /** Read from a blob\r\n * @returns the contents of the requested byte range\r\n */\r\n read(args: {\r\n /** The number of bytes to read */\r\n numBytes: number;\r\n /** starting offset within the blob to read */\r\n offset: number;\r\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\r\n blob?: ArrayBuffer;\r\n }): Uint8Array;\r\n /** Reposition this BlobIO to a new rowId\r\n * @note this BlobIO must be valid when this methods is called.\r\n */\r\n changeRow(row: number): void;\r\n /** Write to a blob */\r\n write(args: {\r\n /** The number of bytes to write */\r\n numBytes: number;\r\n /** starting offset within the blob to write */\r\n offset: number;\r\n /** the value to write */\r\n blob: ArrayBuffer;\r\n }): void;\r\n }\r\n\r\n /** Default transaction mode for SQLiteDbs.\r\n * @see https://www.sqlite.org/lang_transaction.html\r\n */\r\n export enum DefaultTxnMode {\r\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\r\n None = 0,\r\n /** A deferred transaction is started when the file is first opened. This is the default. */\r\n Deferred = 1,\r\n /** An immediate transaction is started when the file is first opened. */\r\n Immediate = 2,\r\n /** An exclusive transaction is started when the file is first opened. */\r\n Exclusive = 3\r\n }\r\n\r\n /** parameters common to opening or creating a new SQLiteDb */\r\n export interface OpenOrCreateParams {\r\n /** If true, do not require that the `be_Prop` table exist */\r\n rawSQLite?: boolean;\r\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\r\n immutable?: boolean;\r\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\r\n skipFileCheck?: boolean;\r\n /** the default transaction mode\r\n * @see [[SQLiteDb.DefaultTxnMode]]\r\n */\r\n defaultTxn?: 0 | 1 | 2 | 3;\r\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\r\n queryParam?: string;\r\n }\r\n\r\n /** Parameters for opening an existing SQLiteDb */\r\n export interface OpenParams extends OpenOrCreateParams {\r\n /** use OpenMode.ReadWrite to open the file with write access */\r\n openMode: OpenMode;\r\n }\r\n\r\n /** Size of a SQLiteDb page in bytes */\r\n export interface PageSize {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export type CreateParams = OpenOrCreateParams & PageSize;\r\n\r\n /** Arguments for `SqliteDb.withOpenDb` */\r\n export interface WithOpenDbArgs {\r\n /** The name of the database to open */\r\n dbName: string;\r\n /** either an object with the open parameters or just OpenMode value. */\r\n openMode?: OpenMode | SQLiteDb.OpenParams;\r\n /** @internal */\r\n container?: CloudSqlite.CloudContainer;\r\n }\r\n\r\n /** Arguments for `SQLiteDb.vacuum` */\r\n export interface VacuumDbArgs extends PageSize {\r\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\r\n into?: LocalFileName;\r\n }\r\n}\r\n"]}
@@ -21,6 +21,9 @@ export declare namespace SchemaSync {
21
21
  openMode?: OpenMode;
22
22
  user?: string;
23
23
  }, operation: (access: CloudAccess) => Promise<void>) => Promise<void>;
24
+ const withReadonlyAccess: (iModel: IModelDb | {
25
+ readonly fileName: LocalFileName;
26
+ }, operation: (access: CloudAccess) => Promise<void>) => Promise<void>;
24
27
  /** Synchronize local briefcase schemas with cloud container */
25
28
  const pull: (iModel: IModelDb) => Promise<void>;
26
29
  const initializeForIModel: (arg: {
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaSync.d.ts","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAe,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAY,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAe,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAIhE,gBAAgB;AAChB,yBAAiB,UAAU,CAAC;IAE1B,kFAAkF;IAClF,MAAa,YAAa,SAAQ,iBAAiB;QACjD,SAAyB,SAAS,WAAW;kBAC1B,SAAS;KAC7B;IAMM,MAAM,YAAY,WAAY,QAAQ,cAAc,MAAM,SAKhE,CAAC;IA8BK,MAAM,gBAAgB,WAAkB,QAAQ,GAAG;QAAE,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAA;KAAE,QAAQ;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,sBAAsB,WAAW,KAAK,QAAQ,IAAI,CAAC,KAAG,QAAQ,IAAI,CAOpO,CAAC;IAEF,+DAA+D;IACxD,MAAM,IAAI,WAAkB,QAAQ,kBAU1C,CAAC;IAEK,MAAM,mBAAmB,QAAe;QAAE,MAAM,EAAE,QAAQ,CAAC;QAAC,cAAc,EAAE,YAAY,cAAc,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,kBA6B3I,CAAC;IAEF,0EAA0E;IAC1E,MAAa,WAAY,SAAQ,WAAW,CAAC,QAAQ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AM,EAAE,QAAQ,CAAC;QAAC,cAAc,EAAE,YAAY,cAAc,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,kBA6B3I,CAAC;IAEF,0EAA0E;IAC1E,MAAa,WAAY,SAAQ,WAAW,CAAC,QAAQ,CAAC,YAAY,CAAC;oBAC9C,KAAK,EAAE,WAAW,CAAC,oBAAoB;QAInD,MAAM;QAGb;;;;SAIC;eACmB,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,cAAc;KAGnE;CACF"}
@@ -13,10 +13,12 @@ const SQLiteDb_1 = require("./SQLiteDb");
13
13
  const IModelDb_1 = require("./IModelDb");
14
14
  const core_bentley_1 = require("@itwin/core-bentley");
15
15
  const core_common_1 = require("@itwin/core-common");
16
- const IModelHost_1 = require("./IModelHost");
16
+ const NativePlatform_1 = require("./internal/NativePlatform");
17
+ const Symbols_1 = require("./internal/Symbols");
17
18
  /** @internal */
18
19
  var SchemaSync;
19
20
  (function (SchemaSync) {
21
+ const lockParams = { retryDelayMs: 1000, nRetries: 30 };
20
22
  /** A CloudSqlite database for synchronizing schema changes across briefcases. */
21
23
  class SchemaSyncDb extends SQLiteDb_1.VersionedSqliteDb {
22
24
  constructor() {
@@ -32,18 +34,18 @@ var SchemaSync;
32
34
  // for tests only
33
35
  SchemaSync.setTestCache = (iModel, cacheName) => {
34
36
  if (cacheName)
35
- iModel.nativeDb.saveLocalValue(testSyncCachePropKey, cacheName);
37
+ iModel[Symbols_1._nativeDb].saveLocalValue(testSyncCachePropKey, cacheName);
36
38
  else
37
- iModel.nativeDb.deleteLocalValue(testSyncCachePropKey);
39
+ iModel[Symbols_1._nativeDb].deleteLocalValue(testSyncCachePropKey);
38
40
  };
39
41
  const getCloudAccess = async (arg) => {
40
42
  let nativeDb;
41
43
  const argIsIModelDb = arg instanceof IModelDb_1.IModelDb;
42
44
  if (argIsIModelDb) {
43
- nativeDb = arg.nativeDb;
45
+ nativeDb = arg[Symbols_1._nativeDb];
44
46
  }
45
47
  else {
46
- nativeDb = new IModelHost_1.IModelHost.platform.DgnDb();
48
+ nativeDb = new NativePlatform_1.IModelNative.platform.DgnDb();
47
49
  nativeDb.openIModel(arg.fileName, core_bentley_1.OpenMode.Readonly);
48
50
  }
49
51
  const propsString = nativeDb.queryFileProperty(syncProperty, true);
@@ -53,6 +55,7 @@ var SchemaSync;
53
55
  const props = JSON.parse(propsString);
54
56
  const accessToken = await CloudSqlite_1.CloudSqlite.requestToken(props);
55
57
  const access = new CloudAccess({ ...props, accessToken });
58
+ Object.assign(access.lockParams, lockParams);
56
59
  const testSyncCache = nativeDb.queryLocalValue(testSyncCachePropKey);
57
60
  if (testSyncCache)
58
61
  access.setCache(CloudSqlite_1.CloudSqlite.CloudCaches.getCache({ cacheName: testSyncCache }));
@@ -73,14 +76,24 @@ var SchemaSync;
73
76
  access.close();
74
77
  }
75
78
  };
79
+ SchemaSync.withReadonlyAccess = async (iModel, operation) => {
80
+ const access = await getCloudAccess(iModel);
81
+ access.synchronizeWithCloud();
82
+ access.openForRead();
83
+ try {
84
+ await operation(access);
85
+ }
86
+ finally {
87
+ access.close();
88
+ }
89
+ };
76
90
  /** Synchronize local briefcase schemas with cloud container */
77
91
  SchemaSync.pull = async (iModel) => {
78
- if (iModel.nativeDb.schemaSyncEnabled() && !iModel.isReadonly) {
79
- await SchemaSync.withLockedAccess(iModel, { openMode: core_bentley_1.OpenMode.Readonly, operationName: "schema sync" }, async (syncAccess) => {
92
+ if (iModel[Symbols_1._nativeDb].schemaSyncEnabled() && !iModel.isReadonly) {
93
+ await SchemaSync.withReadonlyAccess(iModel, async (syncAccess) => {
80
94
  const schemaSyncDbUri = syncAccess.getUri();
81
- syncAccess.synchronizeWithCloud();
82
95
  iModel.clearCaches();
83
- iModel.nativeDb.schemaSyncPull(schemaSyncDbUri);
96
+ iModel[Symbols_1._nativeDb].schemaSyncPull(schemaSyncDbUri);
84
97
  iModel.saveChanges("schema synchronized with cloud container");
85
98
  });
86
99
  }
@@ -99,7 +112,7 @@ var SchemaSync;
99
112
  try {
100
113
  iModel.saveFileProperty(syncProperty, JSON.stringify(props));
101
114
  await SchemaSync.withLockedAccess(arg.iModel, { operationName: "initialize schemaSync", openMode: core_bentley_1.OpenMode.Readonly }, async (syncAccess) => {
102
- iModel.nativeDb.schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);
115
+ iModel[Symbols_1._nativeDb].schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);
103
116
  iModel.saveChanges(`Enable SchemaSync (container id: ${props.containerId})`);
104
117
  });
105
118
  }
@@ -122,7 +135,7 @@ var SchemaSync;
122
135
  super({ dbType: SchemaSyncDb, props, dbName: defaultDbName });
123
136
  }
124
137
  getUri() {
125
- return `${this.getCloudDb().nativeDb.getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;
138
+ return `${this.getCloudDb()[Symbols_1._nativeDb].getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;
126
139
  }
127
140
  /**
128
141
  * Initialize a cloud container for use as a SchemaSync. The container must first be created via its storage supplier api (e.g. Azure, or AWS).
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaSync.js","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,+CAA4C;AAC5C,yCAA+C;AAC/C,yCAAmD;AACnD,sDAAyD;AACzD,oDAAgE;AAEhE,6CAA0C;AAE1C,gBAAgB;AAChB,IAAiB,UAAU,CAsH1B;AAtHD,WAAiB,UAAU;IAEzB,kFAAkF;IAClF,MAAa,YAAa,SAAQ,4BAAiB;QAAnD;;YAC2B,cAAS,GAAG,OAAO,CAAC;QAE/C,CAAC;QADoB,SAAS,KAAK,CAAC;KACnC;IAHY,uBAAY,eAGxB,CAAA;IAED,MAAM,YAAY,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,Y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AC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,cAAc,EAAE,CAAC;QAC1B,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,GAAG,CAAC,iBAAiB;gBACvB,MAAM,SAAS,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,uDAAuD,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;;gBAEzH,MAAM,SAAS,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,mDAAmD,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACzH,CAAC;IACH,CAAC,CAAC;IAEF,0EAA0E;IAC1E,MAAa,WAAY,SAAQ,yBAAW,CAAC,QAAsB;QACjE,YAAmB,KAAuC;YACxD,KAAK,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QAChE,CAAC;QAEM,MAAM;YACX,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,aAAa,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxI,CAAC;QACD;;;;SAIC;QACM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,KAAiC;YAChE,OAAO,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACrF,CAAC;KACF;IAhBY,sBAAW,cAgBvB,CAAA;AACH,CAAC,EAtHgB,UAAU,0BAAV,UAAU,QAsH1B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { VersionedSqliteDb } from \"./SQLiteDb\";\r\nimport { BriefcaseDb, IModelDb } from \"./IModelDb\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n/** @internal */\r\nexport namespace SchemaSync {\r\n\r\n /** A CloudSqlite database for synchronizing schema changes across briefcases. */\r\n export class SchemaSyncDb extends VersionedSqliteDb {\r\n public override readonly myVersion = \"4.0.0\";\r\n protected override createDDL() { }\r\n }\r\n\r\n const syncProperty = { namespace: \"itwinjs\", name: \"SchemaSync\" };\r\n const defaultDbName = \"SchemaSyncDb\" as const;\r\n const testSyncCachePropKey = \"test.schema_sync.cache_name\" as const;\r\n // for tests only\r\n export const setTestCache = (iModel: IModelDb, cacheName?: string) => {\r\n if (cacheName)\r\n iModel.nativeDb.saveLocalValue(testSyncCachePropKey, cacheName);\r\n else\r\n iModel.nativeDb.deleteLocalValue(testSyncCachePropKey);\r\n };\r\n\r\n const getCloudAccess = async (arg: IModelDb | { readonly fileName: LocalFileName }) => {\r\n let nativeDb: IModelJsNative.DgnDb | undefined;\r\n const argIsIModelDb = arg instanceof IModelDb;\r\n if (argIsIModelDb) {\r\n nativeDb = arg.nativeDb;\r\n } else {\r\n nativeDb = new IModelHost.platform.DgnDb();\r\n nativeDb.openIModel(arg.fileName, OpenMode.Readonly);\r\n }\r\n\r\n const propsString = nativeDb.queryFileProperty(syncProperty, true) as string | undefined;\r\n if (!propsString)\r\n throw new Error(\"iModel does not have a SchemaSyncDb\");\r\n try {\r\n const props = JSON.parse(propsString) as CloudSqlite.ContainerProps;\r\n const accessToken = await CloudSqlite.requestToken(props);\r\n const access = new CloudAccess({ ...props, accessToken });\r\n const testSyncCache = nativeDb.queryLocalValue(testSyncCachePropKey);\r\n if (testSyncCache)\r\n access.setCache(CloudSqlite.CloudCaches.getCache({ cacheName: testSyncCache }));\r\n return access;\r\n } finally {\r\n if (!argIsIModelDb) {\r\n nativeDb.closeFile();\r\n }\r\n }\r\n };\r\n\r\n export const withLockedAccess = async (iModel: IModelDb | { readonly fileName: LocalFileName }, args: { operationName: string, openMode?: OpenMode, user?: string }, operation: (access: CloudAccess) => Promise<void>): Promise<void> => {\r\n const access = await getCloudAccess(iModel);\r\n try {\r\n await access.withLockedDb(args, async () => operation(access));\r\n } finally {\r\n access.close();\r\n }\r\n };\r\n\r\n /** Synchronize local briefcase schemas with cloud container */\r\n export const pull = async (iModel: IModelDb) => {\r\n if (iModel.nativeDb.schemaSyncEnabled() && !iModel.isReadonly) {\r\n await SchemaSync.withLockedAccess(iModel, { openMode: OpenMode.Readonly, operationName: \"schema sync\" }, async (syncAccess) => {\r\n const schemaSyncDbUri = syncAccess.getUri();\r\n syncAccess.synchronizeWithCloud();\r\n iModel.clearCaches();\r\n iModel.nativeDb.schemaSyncPull(schemaSyncDbUri);\r\n iModel.saveChanges(\"schema synchronized with cloud container\");\r\n });\r\n }\r\n };\r\n\r\n export const initializeForIModel = async (arg: { iModel: IModelDb, containerProps: CloudSqlite.ContainerProps, overrideContainer?: boolean }) => {\r\n const props = { baseUri: arg.containerProps.baseUri, containerId: arg.containerProps.containerId, storageType: arg.containerProps.storageType }; // sanitize to only known properties\r\n const iModel = arg.iModel;\r\n const briefcase = iModel instanceof BriefcaseDb ? iModel : undefined;\r\n await iModel.acquireSchemaLock();\r\n if (briefcase) {\r\n if (briefcase.txns.hasLocalChanges) {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Enabling SchemaSync for iModel failed. There are unsaved or un-pushed local changes.\");\r\n }\r\n await briefcase.pullChanges();\r\n }\r\n try {\r\n iModel.saveFileProperty(syncProperty, JSON.stringify(props));\r\n await withLockedAccess(arg.iModel, { operationName: \"initialize schemaSync\", openMode: OpenMode.Readonly }, async (syncAccess) => {\r\n iModel.nativeDb.schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);\r\n iModel.saveChanges(`Enable SchemaSync (container id: ${props.containerId})`);\r\n });\r\n } catch (err) {\r\n throw err;\r\n } finally {\r\n iModel.abandonChanges();\r\n }\r\n\r\n if (briefcase) {\r\n if (arg.overrideContainer)\r\n await briefcase.pushChanges({ description: `Overriding SchemaSync for iModel with container-id: ${props.containerId}` });\r\n else\r\n await briefcase.pushChanges({ description: `Enable SchemaSync for iModel with container-id: ${props.containerId}` });\r\n }\r\n };\r\n\r\n /** Provides access to a cloud-based `SchemaSyncDb` to hold ECSchemas. */\r\n export class CloudAccess extends CloudSqlite.DbAccess<SchemaSyncDb> {\r\n public constructor(props: CloudSqlite.ContainerAccessProps) {\r\n super({ dbType: SchemaSyncDb, props, dbName: defaultDbName });\r\n }\r\n\r\n public getUri() {\r\n return `${this.getCloudDb().nativeDb.getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;\r\n }\r\n /**\r\n * Initialize a cloud container for use as a SchemaSync. The container must first be created via its storage supplier api (e.g. Azure, or AWS).\r\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty ChannelDb into the container.\r\n * @note this deletes any existing content in the container.\r\n */\r\n public static async initializeDb(props: CloudSqlite.ContainerProps) {\r\n return super._initializeDb({ props, dbType: SchemaSyncDb, dbName: defaultDbName });\r\n }\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"SchemaSync.js","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,+CAA4C;AAC5C,yCAA+C;AAC/C,yCAAmD;AACnD,sDAAyD;AACzD,oDAAgE;AAEhE,8DAAyD;AACzD,gDAA+C;AAE/C,gBAAgB;AAChB,IAAiB,UAAU,CAkI1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,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QAChE,CAAC;QAEM,MAAM;YACX,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,mBAAS,CAAC,CAAC,WAAW,EAAE,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,aAAa,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1I,CAAC;QACD;;;;SAIC;QACM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,KAAiC;YAChE,OAAO,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACrF,CAAC;KACF;IAhBY,sBAAW,cAgBvB,CAAA;AACH,CAAC,EAlIgB,UAAU,0BAAV,UAAU,QAkI1B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { VersionedSqliteDb } from \"./SQLiteDb\";\r\nimport { BriefcaseDb, IModelDb } from \"./IModelDb\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\n\r\n/** @internal */\r\nexport namespace SchemaSync {\r\n const lockParams: CloudSqlite.ObtainLockParams = { retryDelayMs: 1000, nRetries: 30 };\r\n\r\n /** A CloudSqlite database for synchronizing schema changes across briefcases. */\r\n export class SchemaSyncDb extends VersionedSqliteDb {\r\n public override readonly myVersion = \"4.0.0\";\r\n protected override createDDL() { }\r\n }\r\n\r\n const syncProperty = { namespace: \"itwinjs\", name: \"SchemaSync\" };\r\n const defaultDbName = \"SchemaSyncDb\" as const;\r\n const testSyncCachePropKey = \"test.schema_sync.cache_name\" as const;\r\n // for tests only\r\n export const setTestCache = (iModel: IModelDb, cacheName?: string) => {\r\n if (cacheName)\r\n iModel[_nativeDb].saveLocalValue(testSyncCachePropKey, cacheName);\r\n else\r\n iModel[_nativeDb].deleteLocalValue(testSyncCachePropKey);\r\n };\r\n\r\n const getCloudAccess = async (arg: IModelDb | { readonly fileName: LocalFileName }) => {\r\n let nativeDb: IModelJsNative.DgnDb | undefined;\r\n const argIsIModelDb = arg instanceof IModelDb;\r\n if (argIsIModelDb) {\r\n nativeDb = arg[_nativeDb];\r\n } else {\r\n nativeDb = new IModelNative.platform.DgnDb();\r\n nativeDb.openIModel(arg.fileName, OpenMode.Readonly);\r\n }\r\n\r\n const propsString = nativeDb.queryFileProperty(syncProperty, true) as string | undefined;\r\n if (!propsString)\r\n throw new Error(\"iModel does not have a SchemaSyncDb\");\r\n try {\r\n const props = JSON.parse(propsString) as CloudSqlite.ContainerProps;\r\n const accessToken = await CloudSqlite.requestToken(props);\r\n const access = new CloudAccess({ ...props, accessToken });\r\n Object.assign(access.lockParams, lockParams);\r\n const testSyncCache = nativeDb.queryLocalValue(testSyncCachePropKey);\r\n if (testSyncCache)\r\n access.setCache(CloudSqlite.CloudCaches.getCache({ cacheName: testSyncCache }));\r\n return access;\r\n } finally {\r\n if (!argIsIModelDb) {\r\n nativeDb.closeFile();\r\n }\r\n }\r\n };\r\n\r\n export const withLockedAccess = async (iModel: IModelDb | { readonly fileName: LocalFileName }, args: { operationName: string, openMode?: OpenMode, user?: string }, operation: (access: CloudAccess) => Promise<void>): Promise<void> => {\r\n const access = await getCloudAccess(iModel);\r\n try {\r\n await access.withLockedDb(args, async () => operation(access));\r\n } finally {\r\n access.close();\r\n }\r\n };\r\n\r\n export const withReadonlyAccess = async (iModel: IModelDb | { readonly fileName: LocalFileName }, operation: (access: CloudAccess) => Promise<void>): Promise<void> => {\r\n const access = await getCloudAccess(iModel);\r\n access.synchronizeWithCloud();\r\n access.openForRead();\r\n try {\r\n await operation(access);\r\n } finally {\r\n access.close();\r\n }\r\n };\r\n\r\n /** Synchronize local briefcase schemas with cloud container */\r\n export const pull = async (iModel: IModelDb) => {\r\n if (iModel[_nativeDb].schemaSyncEnabled() && !iModel.isReadonly) {\r\n await SchemaSync.withReadonlyAccess(iModel, async (syncAccess) => {\r\n const schemaSyncDbUri = syncAccess.getUri();\r\n iModel.clearCaches();\r\n iModel[_nativeDb].schemaSyncPull(schemaSyncDbUri);\r\n iModel.saveChanges(\"schema synchronized with cloud container\");\r\n });\r\n }\r\n };\r\n\r\n export const initializeForIModel = async (arg: { iModel: IModelDb, containerProps: CloudSqlite.ContainerProps, overrideContainer?: boolean }) => {\r\n const props = { baseUri: arg.containerProps.baseUri, containerId: arg.containerProps.containerId, storageType: arg.containerProps.storageType }; // sanitize to only known properties\r\n const iModel = arg.iModel;\r\n const briefcase = iModel instanceof BriefcaseDb ? iModel : undefined;\r\n await iModel.acquireSchemaLock();\r\n if (briefcase) {\r\n if (briefcase.txns.hasLocalChanges) {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Enabling SchemaSync for iModel failed. There are unsaved or un-pushed local changes.\");\r\n }\r\n await briefcase.pullChanges();\r\n }\r\n try {\r\n iModel.saveFileProperty(syncProperty, JSON.stringify(props));\r\n await withLockedAccess(arg.iModel, { operationName: \"initialize schemaSync\", openMode: OpenMode.Readonly }, async (syncAccess) => {\r\n iModel[_nativeDb].schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);\r\n iModel.saveChanges(`Enable SchemaSync (container id: ${props.containerId})`);\r\n });\r\n } catch (err) {\r\n throw err;\r\n } finally {\r\n iModel.abandonChanges();\r\n }\r\n\r\n if (briefcase) {\r\n if (arg.overrideContainer)\r\n await briefcase.pushChanges({ description: `Overriding SchemaSync for iModel with container-id: ${props.containerId}` });\r\n else\r\n await briefcase.pushChanges({ description: `Enable SchemaSync for iModel with container-id: ${props.containerId}` });\r\n }\r\n };\r\n\r\n /** Provides access to a cloud-based `SchemaSyncDb` to hold ECSchemas. */\r\n export class CloudAccess extends CloudSqlite.DbAccess<SchemaSyncDb> {\r\n public constructor(props: CloudSqlite.ContainerAccessProps) {\r\n super({ dbType: SchemaSyncDb, props, dbName: defaultDbName });\r\n }\r\n\r\n public getUri() {\r\n return `${this.getCloudDb()[_nativeDb].getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;\r\n }\r\n /**\r\n * Initialize a cloud container for use as a SchemaSync. The container must first be created via its storage supplier api (e.g. Azure, or AWS).\r\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty ChannelDb into the container.\r\n * @note this deletes any existing content in the container.\r\n */\r\n public static async initializeDb(props: CloudSqlite.ContainerProps) {\r\n return super._initializeDb({ props, dbType: SchemaSyncDb, dbName: defaultDbName });\r\n }\r\n }\r\n}\r\n\r\n"]}
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.upgradeCustomAttributesToEC3 = exports.convertEC2SchemasToEC3Schemas = void 0;
11
11
  const core_bentley_1 = require("@itwin/core-bentley");
12
12
  const core_common_1 = require("@itwin/core-common");
13
- const IModelHost_1 = require("./IModelHost");
13
+ const NativePlatform_1 = require("./internal/NativePlatform");
14
14
  /** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.
15
15
  * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.
16
16
  * @returns EC3.2 Xml ECSchema(s).
@@ -19,7 +19,7 @@ const IModelHost_1 = require("./IModelHost");
19
19
  */
20
20
  function convertEC2SchemasToEC3Schemas(ec2XmlSchemas, schemaContext) {
21
21
  const maybeNativeContext = schemaContext?.nativeContext;
22
- const ec3XmlSchemas = IModelHost_1.IModelHost.platform.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);
22
+ const ec3XmlSchemas = NativePlatform_1.IModelNative.platform.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);
23
23
  if (ec2XmlSchemas.length === 0)
24
24
  throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Error converting EC2 Xml schemas");
25
25
  return ec3XmlSchemas;
@@ -33,7 +33,7 @@ exports.convertEC2SchemasToEC3Schemas = convertEC2SchemasToEC3Schemas;
33
33
  */
34
34
  function upgradeCustomAttributesToEC3(xmlSchemas, schemaContext) {
35
35
  const maybeNativeContext = schemaContext?.nativeContext;
36
- const schemasWithConvertedCA = IModelHost_1.IModelHost.platform.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);
36
+ const schemasWithConvertedCA = NativePlatform_1.IModelNative.platform.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);
37
37
  if (schemasWithConvertedCA.length === 0)
38
38
  throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Error converting custom attributes of Xml schemas");
39
39
  return schemasWithConvertedCA;
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaUtils.js","sourceRoot":"","sources":["../../src/SchemaUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAAiD;AAEjD,6CAA0C;AAE1C;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,aAAuB,EAAE,aAAkC;IACvG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,aAAa,GAAa,uBAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,oBAAoB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;IAC1H,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kCAAkC,CAAC,CAAC;IAEjF,OAAO,aAAa,CAAC;AACvB,CAAC;AAPD,sEAOC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAAC,UAAoB,EAAE,aAAkC;IACnG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,sBAAsB,GAAa,uBAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;IACnI,IAAI,sBAAsB,CAAC,MAAM,KAAK,CAAC;QACrC,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,mDAAmD,CAAC,CAAC;IAElG,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAPD,oEAOC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { ECSchemaXmlContext } from \"./ECSchemaXmlContext\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n/** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.\r\n * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.\r\n * @returns EC3.2 Xml ECSchema(s).\r\n * @throws [[IModelError]] if there is a problem converting the EC2 schemas.\r\n * @beta\r\n */\r\nexport function convertEC2SchemasToEC3Schemas(ec2XmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const ec3XmlSchemas: string[] = IModelHost.platform.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);\r\n if (ec2XmlSchemas.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting EC2 Xml schemas\");\r\n\r\n return ec3XmlSchemas;\r\n}\r\n\r\n/** Converts schema metadata to EC3 concepts by traversing custom attributes of the supplied schema and calling converters based on schemaName:customAttributeName\r\n * @param xmlSchemas The ECSchema Xml string(s).\r\n * @returns EC3.2 Xml ECSchema(s) with converted custom attributes.\r\n * @throws [[IModelError]] if there is a problem converting the custom attributes of a schema.\r\n * @beta\r\n */\r\nexport function upgradeCustomAttributesToEC3(xmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const schemasWithConvertedCA: string[] = IModelHost.platform.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);\r\n if (schemasWithConvertedCA.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting custom attributes of Xml schemas\");\r\n\r\n return schemasWithConvertedCA;\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaUtils.js","sourceRoot":"","sources":["../../src/SchemaUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAAiD;AAEjD,8DAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,aAAuB,EAAE,aAAkC;IACvG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,aAAa,GAAa,6BAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,oBAAoB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;IAC5H,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kCAAkC,CAAC,CAAC;IAEjF,OAAO,aAAa,CAAC;AACvB,CAAC;AAPD,sEAOC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAAC,UAAoB,EAAE,aAAkC;IACnG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,sBAAsB,GAAa,6BAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;IACrI,IAAI,sBAAsB,CAAC,MAAM,KAAK,CAAC;QACrC,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,mDAAmD,CAAC,CAAC;IAElG,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAPD,oEAOC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { ECSchemaXmlContext } from \"./ECSchemaXmlContext\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\n\r\n/** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.\r\n * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.\r\n * @returns EC3.2 Xml ECSchema(s).\r\n * @throws [[IModelError]] if there is a problem converting the EC2 schemas.\r\n * @beta\r\n */\r\nexport function convertEC2SchemasToEC3Schemas(ec2XmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const ec3XmlSchemas: string[] = IModelNative.platform.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);\r\n if (ec2XmlSchemas.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting EC2 Xml schemas\");\r\n\r\n return ec3XmlSchemas;\r\n}\r\n\r\n/** Converts schema metadata to EC3 concepts by traversing custom attributes of the supplied schema and calling converters based on schemaName:customAttributeName\r\n * @param xmlSchemas The ECSchema Xml string(s).\r\n * @returns EC3.2 Xml ECSchema(s) with converted custom attributes.\r\n * @throws [[IModelError]] if there is a problem converting the custom attributes of a schema.\r\n * @beta\r\n */\r\nexport function upgradeCustomAttributesToEC3(xmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const schemasWithConvertedCA: string[] = IModelNative.platform.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);\r\n if (schemasWithConvertedCA.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting custom attributes of Xml schemas\");\r\n\r\n return schemasWithConvertedCA;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteChangesetReader.d.ts","sourceRoot":"","sources":["../../src/SqliteChangesetReader.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAqC,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC;;EAEE;AACF,KAAK,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAEnE;;EAEE;AACF,KAAK,gBAAgB,GAAG,WAAW,EAAE,CAAC;AACtC;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,IAAI,CAAC;IACxB,sBAAsB;IACtB,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,2BAA2B;IAC3B,kBAAkB,CAAC,EAAE,IAAI,CAAC;IAC1B,4BAA4B;IAC5B,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,2CAA2C;IAC3C,4BAA4B,CAAC,EAAE,IAAI,CAAC;CACrC;AAED;;EAEE;AACF,MAAM,MA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,IAAI,GAAG,SAAS;IAIrG;;;;;;OAMG;IACI,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;IAIlG;;;;;;OAMG;IACI,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,GAAG,SAAS;IAI3F;;;;;;OAMG;IACI,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,WAAW,GAAG,SAAS;IAIhG;;;;;;OAMG;IACI,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,WAAW;IAGhF;;;;;OAKG;IACI,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,SAAS;IAGlF;;;;;;OAMG;IACI,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,GAAE,gBAAqB,GAAG,YAAY,GAAG,SAAS;IAyC5G;;;;;;OAMG;IACI,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAkBlD;;OAEG;IACH,IAAW,WAAW,WAAgC;IACtD;;;OAGG;IACI,KAAK;IAIZ;;;OAGG;IACI,OAAO,IAAI,IAAI;CAGvB"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqliteChangesetReader = void 0;
4
4
  const core_bentley_1 = require("@itwin/core-bentley");
5
- const IModelHost_1 = require("./IModelHost");
5
+ const NativePlatform_1 = require("./internal/NativePlatform");
6
6
  /**
7
7
  * Read raw sqlite changeset from disk and enumerate changes.
8
8
  * It also optionally let you format change with schema from
@@ -14,7 +14,7 @@ class SqliteChangesetReader {
14
14
  /** db from where sql schema will be read */
15
15
  db) {
16
16
  this.db = db;
17
- this._nativeReader = new IModelHost_1.IModelHost.platform.ChangesetReader();
17
+ this._nativeReader = new NativePlatform_1.IModelNative.platform.ChangesetReader();
18
18
  this._schemaCache = new Map();
19
19
  this._disableSchemaCheck = false;
20
20
  this._changeIndex = 0;