@itwin/core-backend 5.2.0-dev.7 → 5.3.0-dev.1

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 (192) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +2 -0
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js.map +1 -1
  5. package/lib/cjs/BackendLoggerCategory.d.ts +6 -0
  6. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  7. package/lib/cjs/BackendLoggerCategory.js +6 -0
  8. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  9. package/lib/cjs/BriefcaseManager.d.ts +57 -3
  10. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  11. package/lib/cjs/BriefcaseManager.js +151 -42
  12. package/lib/cjs/BriefcaseManager.js.map +1 -1
  13. package/lib/cjs/CloudSqlite.d.ts +4 -0
  14. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  15. package/lib/cjs/CloudSqlite.js.map +1 -1
  16. package/lib/cjs/ECDb.d.ts +8 -0
  17. package/lib/cjs/ECDb.d.ts.map +1 -1
  18. package/lib/cjs/ECDb.js +22 -0
  19. package/lib/cjs/ECDb.js.map +1 -1
  20. package/lib/cjs/IModelDb.d.ts +54 -3
  21. package/lib/cjs/IModelDb.d.ts.map +1 -1
  22. package/lib/cjs/IModelDb.js +87 -9
  23. package/lib/cjs/IModelDb.js.map +1 -1
  24. package/lib/cjs/IModelHost.d.ts +11 -1
  25. package/lib/cjs/IModelHost.d.ts.map +1 -1
  26. package/lib/cjs/IModelHost.js +5 -0
  27. package/lib/cjs/IModelHost.js.map +1 -1
  28. package/lib/cjs/IModelIncrementalSchemaLocater.d.ts +1 -5
  29. package/lib/cjs/IModelIncrementalSchemaLocater.d.ts.map +1 -1
  30. package/lib/cjs/IModelIncrementalSchemaLocater.js +0 -6
  31. package/lib/cjs/IModelIncrementalSchemaLocater.js.map +1 -1
  32. package/lib/cjs/SqliteChangesetReader.d.ts +8 -0
  33. package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
  34. package/lib/cjs/SqliteChangesetReader.js +11 -0
  35. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  36. package/lib/cjs/StashManager.d.ts +175 -0
  37. package/lib/cjs/StashManager.d.ts.map +1 -0
  38. package/lib/cjs/StashManager.js +306 -0
  39. package/lib/cjs/StashManager.js.map +1 -0
  40. package/lib/cjs/TxnManager.d.ts +226 -15
  41. package/lib/cjs/TxnManager.d.ts.map +1 -1
  42. package/lib/cjs/TxnManager.js +249 -23
  43. package/lib/cjs/TxnManager.js.map +1 -1
  44. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts +10 -1
  45. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  46. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js +15 -6
  47. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  48. package/lib/cjs/annotations/LeaderGeometry.d.ts +3 -2
  49. package/lib/cjs/annotations/LeaderGeometry.d.ts.map +1 -1
  50. package/lib/cjs/annotations/LeaderGeometry.js +5 -4
  51. package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
  52. package/lib/cjs/annotations/TextAnnotationElement.d.ts +52 -24
  53. package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
  54. package/lib/cjs/annotations/TextAnnotationElement.js +49 -59
  55. package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
  56. package/lib/cjs/annotations/TextAnnotationGeometry.d.ts +2 -0
  57. package/lib/cjs/annotations/TextAnnotationGeometry.d.ts.map +1 -1
  58. package/lib/cjs/annotations/TextAnnotationGeometry.js +26 -19
  59. package/lib/cjs/annotations/TextAnnotationGeometry.js.map +1 -1
  60. package/lib/cjs/annotations/TextBlockGeometry.d.ts.map +1 -1
  61. package/lib/cjs/annotations/TextBlockGeometry.js +8 -0
  62. package/lib/cjs/annotations/TextBlockGeometry.js.map +1 -1
  63. package/lib/cjs/annotations/TextBlockLayout.d.ts +49 -36
  64. package/lib/cjs/annotations/TextBlockLayout.d.ts.map +1 -1
  65. package/lib/cjs/annotations/TextBlockLayout.js +204 -135
  66. package/lib/cjs/annotations/TextBlockLayout.js.map +1 -1
  67. package/lib/cjs/internal/ChannelAdmin.js +1 -1
  68. package/lib/cjs/internal/ChannelAdmin.js.map +1 -1
  69. package/lib/cjs/internal/Symbols.d.ts +1 -0
  70. package/lib/cjs/internal/Symbols.d.ts.map +1 -1
  71. package/lib/cjs/internal/Symbols.js +2 -1
  72. package/lib/cjs/internal/Symbols.js.map +1 -1
  73. package/lib/cjs/internal/annotations/fields.d.ts +2 -12
  74. package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
  75. package/lib/cjs/internal/annotations/fields.js +49 -45
  76. package/lib/cjs/internal/annotations/fields.js.map +1 -1
  77. package/lib/cjs/workspace/Workspace.d.ts +1 -1
  78. package/lib/cjs/workspace/Workspace.js.map +1 -1
  79. package/lib/esm/BackendHubAccess.d.ts +2 -0
  80. package/lib/esm/BackendHubAccess.d.ts.map +1 -1
  81. package/lib/esm/BackendHubAccess.js.map +1 -1
  82. package/lib/esm/BackendLoggerCategory.d.ts +6 -0
  83. package/lib/esm/BackendLoggerCategory.d.ts.map +1 -1
  84. package/lib/esm/BackendLoggerCategory.js +6 -0
  85. package/lib/esm/BackendLoggerCategory.js.map +1 -1
  86. package/lib/esm/BriefcaseManager.d.ts +57 -3
  87. package/lib/esm/BriefcaseManager.d.ts.map +1 -1
  88. package/lib/esm/BriefcaseManager.js +152 -43
  89. package/lib/esm/BriefcaseManager.js.map +1 -1
  90. package/lib/esm/CloudSqlite.d.ts +4 -0
  91. package/lib/esm/CloudSqlite.d.ts.map +1 -1
  92. package/lib/esm/CloudSqlite.js.map +1 -1
  93. package/lib/esm/ECDb.d.ts +8 -0
  94. package/lib/esm/ECDb.d.ts.map +1 -1
  95. package/lib/esm/ECDb.js +22 -0
  96. package/lib/esm/ECDb.js.map +1 -1
  97. package/lib/esm/IModelDb.d.ts +54 -3
  98. package/lib/esm/IModelDb.d.ts.map +1 -1
  99. package/lib/esm/IModelDb.js +88 -10
  100. package/lib/esm/IModelDb.js.map +1 -1
  101. package/lib/esm/IModelHost.d.ts +11 -1
  102. package/lib/esm/IModelHost.d.ts.map +1 -1
  103. package/lib/esm/IModelHost.js +5 -0
  104. package/lib/esm/IModelHost.js.map +1 -1
  105. package/lib/esm/IModelIncrementalSchemaLocater.d.ts +1 -5
  106. package/lib/esm/IModelIncrementalSchemaLocater.d.ts.map +1 -1
  107. package/lib/esm/IModelIncrementalSchemaLocater.js +0 -6
  108. package/lib/esm/IModelIncrementalSchemaLocater.js.map +1 -1
  109. package/lib/esm/SqliteChangesetReader.d.ts +8 -0
  110. package/lib/esm/SqliteChangesetReader.d.ts.map +1 -1
  111. package/lib/esm/SqliteChangesetReader.js +11 -0
  112. package/lib/esm/SqliteChangesetReader.js.map +1 -1
  113. package/lib/esm/StashManager.d.ts +175 -0
  114. package/lib/esm/StashManager.d.ts.map +1 -0
  115. package/lib/esm/StashManager.js +301 -0
  116. package/lib/esm/StashManager.js.map +1 -0
  117. package/lib/esm/TxnManager.d.ts +226 -15
  118. package/lib/esm/TxnManager.d.ts.map +1 -1
  119. package/lib/esm/TxnManager.js +247 -21
  120. package/lib/esm/TxnManager.js.map +1 -1
  121. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts +10 -1
  122. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  123. package/lib/esm/annotations/ElementDrivesTextAnnotation.js +13 -5
  124. package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  125. package/lib/esm/annotations/LeaderGeometry.d.ts +3 -2
  126. package/lib/esm/annotations/LeaderGeometry.d.ts.map +1 -1
  127. package/lib/esm/annotations/LeaderGeometry.js +5 -4
  128. package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
  129. package/lib/esm/annotations/TextAnnotationElement.d.ts +52 -24
  130. package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
  131. package/lib/esm/annotations/TextAnnotationElement.js +51 -61
  132. package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
  133. package/lib/esm/annotations/TextAnnotationGeometry.d.ts +2 -0
  134. package/lib/esm/annotations/TextAnnotationGeometry.d.ts.map +1 -1
  135. package/lib/esm/annotations/TextAnnotationGeometry.js +26 -19
  136. package/lib/esm/annotations/TextAnnotationGeometry.js.map +1 -1
  137. package/lib/esm/annotations/TextBlockGeometry.d.ts.map +1 -1
  138. package/lib/esm/annotations/TextBlockGeometry.js +8 -0
  139. package/lib/esm/annotations/TextBlockGeometry.js.map +1 -1
  140. package/lib/esm/annotations/TextBlockLayout.d.ts +49 -36
  141. package/lib/esm/annotations/TextBlockLayout.d.ts.map +1 -1
  142. package/lib/esm/annotations/TextBlockLayout.js +205 -136
  143. package/lib/esm/annotations/TextBlockLayout.js.map +1 -1
  144. package/lib/esm/internal/ChannelAdmin.js +1 -1
  145. package/lib/esm/internal/ChannelAdmin.js.map +1 -1
  146. package/lib/esm/internal/Symbols.d.ts +1 -0
  147. package/lib/esm/internal/Symbols.d.ts.map +1 -1
  148. package/lib/esm/internal/Symbols.js +1 -0
  149. package/lib/esm/internal/Symbols.js.map +1 -1
  150. package/lib/esm/internal/annotations/fields.d.ts +2 -12
  151. package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
  152. package/lib/esm/internal/annotations/fields.js +51 -47
  153. package/lib/esm/internal/annotations/fields.js.map +1 -1
  154. package/lib/esm/test/AnnotationTestUtils.d.ts +5 -1
  155. package/lib/esm/test/AnnotationTestUtils.d.ts.map +1 -1
  156. package/lib/esm/test/AnnotationTestUtils.js +6 -1
  157. package/lib/esm/test/AnnotationTestUtils.js.map +1 -1
  158. package/lib/esm/test/annotations/Fields.test.js +163 -46
  159. package/lib/esm/test/annotations/Fields.test.js.map +1 -1
  160. package/lib/esm/test/annotations/LeaderGeometry.test.js +12 -10
  161. package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
  162. package/lib/esm/test/annotations/TextAnnotation.test.js +299 -43
  163. package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
  164. package/lib/esm/test/annotations/TextBlock.test.js +453 -86
  165. package/lib/esm/test/annotations/TextBlock.test.js.map +1 -1
  166. package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.d.ts +46 -0
  167. package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.d.ts.map +1 -1
  168. package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.js +20 -2
  169. package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.js.map +1 -1
  170. package/lib/esm/test/ecdb/ECDb.test.js +71 -1
  171. package/lib/esm/test/ecdb/ECDb.test.js.map +1 -1
  172. package/lib/esm/test/hubaccess/Rebase.test.d.ts +2 -0
  173. package/lib/esm/test/hubaccess/Rebase.test.d.ts.map +1 -0
  174. package/lib/esm/test/hubaccess/Rebase.test.js +640 -0
  175. package/lib/esm/test/hubaccess/Rebase.test.js.map +1 -0
  176. package/lib/esm/test/incrementalSchemaLocater/ECSqlQueries.test.js +20 -20
  177. package/lib/esm/test/incrementalSchemaLocater/ECSqlQueries.test.js.map +1 -1
  178. package/lib/esm/test/incrementalSchemaLocater/IncrementalLoading.test.js +3 -3
  179. package/lib/esm/test/incrementalSchemaLocater/IncrementalLoading.test.js.map +1 -1
  180. package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.d.ts +16 -1
  181. package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.d.ts.map +1 -1
  182. package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.js +47 -0
  183. package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.js.map +1 -1
  184. package/lib/esm/test/standalone/ChangeMerge.test.js +15 -19
  185. package/lib/esm/test/standalone/ChangeMerge.test.js.map +1 -1
  186. package/lib/esm/test/standalone/ChangesetReader.test.js +131 -1
  187. package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
  188. package/lib/esm/test/standalone/MergeConflict.test.js +3 -3
  189. package/lib/esm/test/standalone/MergeConflict.test.js.map +1 -1
  190. package/lib/esm/workspace/Workspace.d.ts +1 -1
  191. package/lib/esm/workspace/Workspace.js.map +1 -1
  192. package/package.json +13 -13
@@ -7,7 +7,7 @@
7
7
  * @module iModels
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.TxnManager = exports.ChangeMergeManager = void 0;
10
+ exports.TxnManager = exports.RebaseManager = void 0;
11
11
  exports.setMaxEntitiesPerEvent = setMaxEntitiesPerEvent;
12
12
  const touch = require("touch");
13
13
  const core_bentley_1 = require("@itwin/core-bentley");
@@ -16,6 +16,7 @@ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
16
16
  const IpcHost_1 = require("./IpcHost");
17
17
  const Symbols_1 = require("./internal/Symbols");
18
18
  const ChangesetConflictArgs_1 = require("./internal/ChangesetConflictArgs");
19
+ const BriefcaseManager_1 = require("./BriefcaseManager");
19
20
  /** Strictly for tests. @internal */
20
21
  function setMaxEntitiesPerEvent(max) {
21
22
  const prevMax = ChangedEntitiesProc.maxPerEvent;
@@ -197,21 +198,162 @@ class ChangedEntitiesProc {
197
198
  }
198
199
  }
199
200
  /**
200
- * @internal
201
- * Manages conflict resolution during a merge operation.
202
- */
203
- class ChangeMergeManager {
201
+ * Manages the process of merging and rebasing local changes (transactions) in a [[BriefcaseDb]] or [[StandaloneDb]].
202
+ *
203
+ * The `RebaseManager` coordinates the rebase of local transactions when pulling and merging changes from other sources,
204
+ * such as remote repositories or other users. It provides mechanisms to handle transaction conflicts, register custom conflict
205
+ * handlers, and manage the rebase workflow. This includes resuming rebases, invoking user-defined handlers for conflict resolution,
206
+ * and tracking the current merge/rebase state.
207
+ *
208
+ * Key responsibilities:
209
+ * - Orchestrates the rebase of local transactions after a pull/merge operation.
210
+ * - Allows registration and removal of custom conflict handlers to resolve changeset conflicts during rebase.
211
+ * - Provides methods to check the current merge/rebase state.
212
+ * - Raises events before and after each transaction is rebased.
213
+ * - Ensures changes are saved or aborted appropriately based on the outcome of the rebase process.
214
+ *
215
+ * @alpha
216
+ */
217
+ class RebaseManager {
204
218
  _iModel;
205
219
  _conflictHandlers;
220
+ _customHandler;
206
221
  constructor(_iModel) {
207
222
  this._iModel = _iModel;
208
223
  }
209
- resume() {
210
- this._iModel[Symbols_1._nativeDb].pullMergeResume();
224
+ /**
225
+ * Resumes the rebase process for the current iModel, applying any pending local changes
226
+ * on top of the latest pulled changes from the remote source.
227
+ *
228
+ * This method performs the following steps:
229
+ * 1. Begins the rebase process using the native database.
230
+ * 2. Iterates through each transaction that needs to be rebased:
231
+ * - Retrieves transaction properties.
232
+ * - Raises events before and after rebasing each transaction.
233
+ * - Optionally reinstates local changes based on the rebase handler.
234
+ * - Optionally recomputes transaction data using the rebase handler.
235
+ * - Updates the transaction in the native database.
236
+ * 3. Ends the rebase process and saves changes if the database is not read-only.
237
+ * 4. Drops any restore point associated with the pull-merge operation.
238
+ *
239
+ * If an error occurs during the process, the rebase is aborted and the error is rethrown.
240
+ *
241
+ * @throws {Error} If a transaction cannot be found or if any step in the rebase process fails.
242
+ */
243
+ async resume() {
244
+ const nativeDb = this._iModel[Symbols_1._nativeDb];
245
+ const txns = this._iModel.txns;
246
+ try {
247
+ nativeDb.pullMergeRebaseBegin();
248
+ let txnId = nativeDb.pullMergeRebaseNext();
249
+ while (txnId) {
250
+ const txnProps = txns.getTxnProps(txnId);
251
+ if (!txnProps) {
252
+ throw new Error(`Transaction ${txnId} not found`);
253
+ }
254
+ txns.onRebaseTxnBegin.raiseEvent(txnProps);
255
+ core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.BackendLoggerCategory.IModelDb, `Rebasing local changes for transaction ${txnId}`);
256
+ const shouldReinstate = this._customHandler?.shouldReinstate(txnProps) ?? true;
257
+ if (shouldReinstate) {
258
+ nativeDb.pullMergeRebaseReinstateTxn();
259
+ core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.BackendLoggerCategory.IModelDb, `Reinstated local changes for transaction ${txnId}`);
260
+ }
261
+ if (this._customHandler) {
262
+ await this._customHandler.recompute(txnProps);
263
+ }
264
+ nativeDb.pullMergeRebaseUpdateTxn();
265
+ txns.onRebaseTxnEnd.raiseEvent(txnProps);
266
+ txnId = nativeDb.pullMergeRebaseNext();
267
+ }
268
+ nativeDb.pullMergeRebaseEnd();
269
+ if (!nativeDb.isReadonly) {
270
+ nativeDb.saveChanges("Merge.");
271
+ }
272
+ if (BriefcaseManager_1.BriefcaseManager.containsRestorePoint(this._iModel, BriefcaseManager_1.BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME)) {
273
+ BriefcaseManager_1.BriefcaseManager.dropRestorePoint(this._iModel, BriefcaseManager_1.BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME);
274
+ }
275
+ }
276
+ catch (err) {
277
+ nativeDb.pullMergeRebaseAbortTxn();
278
+ throw err;
279
+ }
280
+ }
281
+ /**
282
+ * Determines whether the current transaction can be aborted.
283
+ *
284
+ * This method checks if a transaction is currently in progress and if a specific restore point,
285
+ * identified by `BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME`, exists in the briefcase manager.
286
+ *
287
+ * @returns {boolean} Returns `true` if a transaction is in progress and the required restore point exists; otherwise, returns `false`.
288
+ */
289
+ canAbort() {
290
+ return this.inProgress() && BriefcaseManager_1.BriefcaseManager.containsRestorePoint(this._iModel, BriefcaseManager_1.BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME);
291
+ }
292
+ /**
293
+ * Aborts the current transaction by restoring the iModel to a predefined restore point.
294
+ *
295
+ * If a restore point is available (as determined by `canAbort()`), this method restores the iModel
296
+ * to the state saved at the restore point named by `BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME`.
297
+ * If no restore point is available, an error is thrown.
298
+ *
299
+ * @returns A promise that resolves when the restore operation is complete.
300
+ * @throws {Error} If there is no restore point to abort to.
301
+ */
302
+ async abort() {
303
+ if (this.canAbort()) {
304
+ return BriefcaseManager_1.BriefcaseManager.restorePoint(this._iModel, BriefcaseManager_1.BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME);
305
+ }
306
+ else {
307
+ throw new Error("No restore point to abort to");
308
+ }
309
+ }
310
+ /**
311
+ * Sets the handler to be invoked for rebase operations.
312
+ *
313
+ * @param handler - The {@link RebaseHandler} to handle rebase events.
314
+ */
315
+ setCustomHandler(handler) {
316
+ if (this._customHandler) {
317
+ core_bentley_1.Logger.logWarning(BackendLoggerCategory_1.BackendLoggerCategory.IModelDb, "Rebase handler already set");
318
+ }
319
+ this._customHandler = handler;
211
320
  }
321
+ /**
322
+ * Determines whether a transaction is currently in progress.
323
+ *
324
+ * @returns {boolean} Returns `true` if there is an active transaction stage, otherwise `false`.
325
+ */
212
326
  inProgress() {
213
- return this._iModel[Symbols_1._nativeDb].pullMergeInProgress();
327
+ return this._iModel[Symbols_1._nativeDb].pullMergeGetStage() !== "None";
214
328
  }
329
+ /**
330
+ * Indicates whether the current transaction manager is in the "Rebasing" stage.
331
+ *
332
+ * This property checks the internal native database's merge stage to determine if a rebase operation is in progress.
333
+ *
334
+ * @returns `true` if the transaction manager is currently rebasing; otherwise, `false`.
335
+ */
336
+ get isRebasing() {
337
+ return this._iModel[Symbols_1._nativeDb].pullMergeGetStage() === "Rebasing";
338
+ }
339
+ /**
340
+ * Indicates whether the current iModel is in the process of merging changes from a pull operation.
341
+ *
342
+ * @returns `true` if the iModel is currently merging changes; otherwise, `false`.
343
+ */
344
+ get isMerging() {
345
+ return this._iModel[Symbols_1._nativeDb].pullMergeGetStage() === "Merging";
346
+ }
347
+ /**
348
+ * Attempts to resolve a changeset conflict by invoking registered conflict handlers in sequence.
349
+ *
350
+ * Iterates through the linked list of conflict handlers, passing the provided conflict arguments to each handler.
351
+ * If a handler returns a defined resolution, logs the resolution and returns it immediately.
352
+ * If no handler resolves the conflict, returns `undefined`.
353
+ *
354
+ * @param args - The arguments describing the changeset conflict to resolve.
355
+ * @returns The conflict resolution provided by a handler, or `undefined` if no handler resolves the conflict.
356
+ */
215
357
  onConflict(args) {
216
358
  let curr = this._conflictHandlers;
217
359
  while (curr) {
@@ -224,6 +366,18 @@ class ChangeMergeManager {
224
366
  }
225
367
  return undefined;
226
368
  }
369
+ /**
370
+ * Registers a new conflict handler for rebase changeset conflicts.
371
+ *
372
+ * @param args - An object containing:
373
+ * - `id`: A unique identifier for the conflict handler.
374
+ * - `handler`: A function that handles rebase changeset conflicts and returns a `DbConflictResolution` or `undefined`.
375
+ * @throws IModelError if a conflict handler with the same `id` already exists.
376
+ *
377
+ * @remarks
378
+ * Conflict handlers are used during changeset rebase operations to resolve conflicts.
379
+ * Each handler must have a unique `id`. Attempting to register a handler with a duplicate `id` will result in an error.
380
+ */
227
381
  addConflictHandler(args) {
228
382
  const idExists = (id) => {
229
383
  let curr = this._conflictHandlers;
@@ -238,6 +392,14 @@ class ChangeMergeManager {
238
392
  throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `Conflict handler with id ${args.id} already exists`);
239
393
  this._conflictHandlers = { ...args, next: this._conflictHandlers };
240
394
  }
395
+ /**
396
+ * Removes a conflict handler from the internal linked list by its identifier.
397
+ *
398
+ * @param id - The unique identifier of the conflict handler to remove.
399
+ *
400
+ * If the handler with the specified `id` exists in the list, it will be removed.
401
+ * If no handler with the given `id` is found, the method does nothing.
402
+ */
241
403
  removeConflictHandler(id) {
242
404
  if (!this._conflictHandlers)
243
405
  return;
@@ -257,7 +419,7 @@ class ChangeMergeManager {
257
419
  }
258
420
  }
259
421
  }
260
- exports.ChangeMergeManager = ChangeMergeManager;
422
+ exports.RebaseManager = RebaseManager;
261
423
  /** Manages local changes to a [[BriefcaseDb]] or [[StandaloneDb]] via [Txns]($docs/learning/InteractiveEditing.md)
262
424
  * @public @preview
263
425
  */
@@ -270,11 +432,11 @@ class TxnManager {
270
432
  return this._isDisposed;
271
433
  }
272
434
  /** @internal */
273
- changeMergeManager;
435
+ rebaser;
274
436
  /** @internal */
275
437
  constructor(_iModel) {
276
438
  this._iModel = _iModel;
277
- this.changeMergeManager = new ChangeMergeManager(_iModel);
439
+ this.rebaser = new RebaseManager(_iModel);
278
440
  _iModel.onBeforeClose.addOnce(() => {
279
441
  this._isDisposed = true;
280
442
  });
@@ -372,12 +534,6 @@ class TxnManager {
372
534
  this.onAfterUndoRedo.raiseEvent(isUndo);
373
535
  IpcHost_1.IpcHost.notifyTxns(this._iModel, "notifyAfterUndoRedo", isUndo);
374
536
  }
375
- _onRebaseTxnBegin(txn) {
376
- this.onRebaseTxnBegin.raiseEvent(txn);
377
- }
378
- _onRebaseTxnEnd(txn) {
379
- this.onRebaseTxnEnd.raiseEvent(txn);
380
- }
381
537
  _onRebaseLocalTxnConflict(internalArg) {
382
538
  const args = new ChangesetConflictArgs_1.RebaseChangesetConflictArgs(internalArg, this._iModel);
383
539
  const getChangeMetaData = () => {
@@ -409,7 +565,7 @@ class TxnManager {
409
565
  }
410
566
  }
411
567
  try {
412
- const resolution = this.changeMergeManager.onConflict(args);
568
+ const resolution = this.rebaser.onConflict(args);
413
569
  if (resolution !== undefined)
414
570
  return resolution;
415
571
  }
@@ -440,11 +596,43 @@ class TxnManager {
440
596
  return core_bentley_1.DbConflictResolution.Skip;
441
597
  }
442
598
  if (args.cause === "Constraint") {
443
- core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.BackendLoggerCategory.IModelDb, "Constraint voilation detected. Generally caused by db constraints like UNIQUE index. Skipping local change.", getChangeMetaData());
599
+ core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.BackendLoggerCategory.IModelDb, "Constraint violation detected. Generally caused by db constraints like UNIQUE index. Skipping local change.", getChangeMetaData());
444
600
  return core_bentley_1.DbConflictResolution.Skip;
445
601
  }
446
602
  return core_bentley_1.DbConflictResolution.Replace;
447
603
  }
604
+ /**
605
+ * @alpha
606
+ * Retrieves the txn properties for a given txn ID.
607
+ *
608
+ * @param id - The unique identifier of the transaction.
609
+ * @returns The properties of the transaction if found; otherwise, `undefined`.
610
+ */
611
+ getTxnProps(id) {
612
+ return this._iModel[Symbols_1._nativeDb].getTxnProps(id);
613
+ }
614
+ /**
615
+ * @alpha
616
+ * Iterates over all transactions in the sequence, yielding each transaction's properties.
617
+ *
618
+ * @yields {TxnProps} The properties of each transaction in the sequence.
619
+ */
620
+ *queryTxns() {
621
+ let txn = this.getTxnProps(this.queryFirstTxnId());
622
+ while (txn) {
623
+ yield txn;
624
+ txn = txn.nextId ? this.getTxnProps(txn.nextId) : undefined;
625
+ }
626
+ }
627
+ /**
628
+ * @alpha
629
+ * Retrieves the properties of the last saved txn via `IModelDb.saveChanges()`, if available.
630
+ *
631
+ * @returns The properties of the last saved txn, or `undefined` if none exist.
632
+ */
633
+ getLastSavedTxnProps() {
634
+ return this.getTxnProps(this.queryPreviousTxnId(this.getCurrentTxnId()));
635
+ }
448
636
  /** Dependency handlers may call method this to report a validation error.
449
637
  * @param error The error. If error.fatal === true, the transaction will cancel rather than commit.
450
638
  */
@@ -494,12 +682,18 @@ class TxnManager {
494
682
  * @see [[onReplayExternalTxns]] for the event raised before the changes are applied.
495
683
  */
496
684
  onReplayedExternalTxns = new core_bentley_1.BeEvent();
497
- /** @internal */
685
+ /**
686
+ * @alpha
687
+ * Event raised when a rebase transaction begins.
688
+ */
498
689
  onRebaseTxnBegin = new core_bentley_1.BeEvent();
499
- /** @internal */
690
+ /**
691
+ * @alpha
692
+ * Event raised when a rebase transaction ends.
693
+ */
500
694
  onRebaseTxnEnd = new core_bentley_1.BeEvent();
501
695
  /**
502
- * if handler is set and it does not return undefiend then default handler will not be called
696
+ * if handler is set and it does not return undefined then default handler will not be called
503
697
  * @internal
504
698
  * */
505
699
  appCustomConflictHandler;
@@ -514,7 +708,7 @@ class TxnManager {
514
708
  this._nativeDb.restartTxnSession();
515
709
  }
516
710
  /** Determine whether current txn is propagating indirect changes or not. */
517
- get isIndirectChanges() { return this._nativeDb.isIndirectChanges(); }
711
+ get isIndirectChanges() { return this.getMode() === "indirect"; }
518
712
  /** Determine if there are currently any reversible (undoable) changes from this editing session. */
519
713
  get isUndoPossible() { return this._nativeDb.isUndoPossible(); }
520
714
  /** Determine if there are currently any reinstatable (redoable) changes */
@@ -579,6 +773,11 @@ class TxnManager {
579
773
  queryPreviousTxnId(txnId) { return this._nativeDb.queryPreviousTxnId(txnId); }
580
774
  /** Get the Id of the current (tip) transaction. */
581
775
  getCurrentTxnId() { return this._nativeDb.getCurrentTxnId(); }
776
+ /**
777
+ * @alpha
778
+ * Get the Id of the current session.
779
+ */
780
+ getCurrentSessionId() { return this._nativeDb.currentTxnSessionId(); }
582
781
  /** Get the description that was supplied when the specified transaction was saved. */
583
782
  getTxnDescription(txnId) { return this._nativeDb.getTxnDescription(txnId); }
584
783
  /** Test if a TxnId is valid */
@@ -592,6 +791,11 @@ class TxnManager {
592
791
  * @see [[IModelDb.saveChanges]]
593
792
  */
594
793
  get hasUnsavedChanges() { return this._nativeDb.hasUnsavedChanges(); }
794
+ /**
795
+ * @alpha
796
+ * Query if there are any pending schema changes in this IModelDb.
797
+ */
798
+ get hasPendingSchemaChanges() { return this._nativeDb.hasPendingSchemaChanges(); }
595
799
  /**
596
800
  * Query if there are changes in memory that have not been saved to the iModelDb or if there are Txns that are waiting to be pushed.
597
801
  * @see [[IModelDb.saveChanges]]
@@ -621,6 +825,28 @@ class TxnManager {
621
825
  getChangeTrackingMemoryUsed() {
622
826
  return this._iModel[Symbols_1._nativeDb].getChangeTrackingMemoryUsed();
623
827
  }
828
+ /**
829
+ * @alpha
830
+ * Get the current transaction mode.
831
+ * @returns The current transaction mode, either "direct" or "indirect".
832
+ */
833
+ getMode() {
834
+ return this._nativeDb.getTxnMode();
835
+ }
836
+ /**
837
+ * @alpha
838
+ * Execute a series of changes in an indirect transaction.
839
+ * @param callback The function containing the changes to make.
840
+ */
841
+ withIndirectTxnMode(callback) {
842
+ this._nativeDb.setTxnMode("indirect");
843
+ try {
844
+ callback();
845
+ }
846
+ finally {
847
+ this._nativeDb.setTxnMode("direct");
848
+ }
849
+ }
624
850
  }
625
851
  exports.TxnManager = TxnManager;
626
852
  //# sourceMappingURL=TxnManager.js.map