@itwin/core-backend 5.9.0-dev.8 → 5.10.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 (244) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +38 -0
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js.map +1 -1
  5. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  6. package/lib/cjs/BriefcaseManager.js +6 -3
  7. package/lib/cjs/BriefcaseManager.js.map +1 -1
  8. package/lib/cjs/ChangesetECAdaptor.d.ts +9 -1
  9. package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
  10. package/lib/cjs/ChangesetECAdaptor.js +7 -1
  11. package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
  12. package/lib/cjs/ChangesetReader.d.ts +186 -0
  13. package/lib/cjs/ChangesetReader.d.ts.map +1 -0
  14. package/lib/cjs/ChangesetReader.js +372 -0
  15. package/lib/cjs/ChangesetReader.js.map +1 -0
  16. package/lib/cjs/ChangesetReaderTypes.d.ts +120 -0
  17. package/lib/cjs/ChangesetReaderTypes.d.ts.map +1 -0
  18. package/lib/cjs/ChangesetReaderTypes.js +23 -0
  19. package/lib/cjs/ChangesetReaderTypes.js.map +1 -0
  20. package/lib/cjs/CloudSqlite.d.ts +1 -1
  21. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  22. package/lib/cjs/CloudSqlite.js +68 -13
  23. package/lib/cjs/CloudSqlite.js.map +1 -1
  24. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  25. package/lib/cjs/DevTools.js.map +1 -1
  26. package/lib/cjs/DisplayStyle.js.map +1 -1
  27. package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
  28. package/lib/cjs/ECSqlStatement.js.map +1 -1
  29. package/lib/cjs/EditTxn.d.ts +55 -1
  30. package/lib/cjs/EditTxn.d.ts.map +1 -1
  31. package/lib/cjs/EditTxn.js +43 -1
  32. package/lib/cjs/EditTxn.js.map +1 -1
  33. package/lib/cjs/Element.d.ts +69 -0
  34. package/lib/cjs/Element.d.ts.map +1 -1
  35. package/lib/cjs/Element.js +36 -0
  36. package/lib/cjs/Element.js.map +1 -1
  37. package/lib/cjs/ElementGraphics.js.map +1 -1
  38. package/lib/cjs/ExternalSource.js.map +1 -1
  39. package/lib/cjs/GeographicCRSServices.d.ts +15 -0
  40. package/lib/cjs/GeographicCRSServices.d.ts.map +1 -1
  41. package/lib/cjs/GeographicCRSServices.js +13 -4
  42. package/lib/cjs/GeographicCRSServices.js.map +1 -1
  43. package/lib/cjs/IModelDb.d.ts +9 -1
  44. package/lib/cjs/IModelDb.d.ts.map +1 -1
  45. package/lib/cjs/IModelDb.js +25 -6
  46. package/lib/cjs/IModelDb.js.map +1 -1
  47. package/lib/cjs/IModelIncrementalSchemaLocater.js.map +1 -1
  48. package/lib/cjs/IpcHost.d.ts.map +1 -1
  49. package/lib/cjs/IpcHost.js +33 -13
  50. package/lib/cjs/IpcHost.js.map +1 -1
  51. package/lib/cjs/LockControl.d.ts +85 -1
  52. package/lib/cjs/LockControl.d.ts.map +1 -1
  53. package/lib/cjs/LockControl.js.map +1 -1
  54. package/lib/cjs/Model.d.ts +34 -0
  55. package/lib/cjs/Model.d.ts.map +1 -1
  56. package/lib/cjs/Model.js +24 -0
  57. package/lib/cjs/Model.js.map +1 -1
  58. package/lib/cjs/PartialChangeUnifier.d.ts +77 -0
  59. package/lib/cjs/PartialChangeUnifier.d.ts.map +1 -0
  60. package/lib/cjs/PartialChangeUnifier.js +234 -0
  61. package/lib/cjs/PartialChangeUnifier.js.map +1 -0
  62. package/lib/cjs/SheetIndex.js.map +1 -1
  63. package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
  64. package/lib/cjs/SqliteChangesetReader.js +1 -1
  65. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  66. package/lib/cjs/TxnManager.d.ts +114 -4
  67. package/lib/cjs/TxnManager.d.ts.map +1 -1
  68. package/lib/cjs/TxnManager.js +196 -8
  69. package/lib/cjs/TxnManager.js.map +1 -1
  70. package/lib/cjs/ViewDefinition.d.ts +19 -7
  71. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  72. package/lib/cjs/ViewDefinition.js +77 -25
  73. package/lib/cjs/ViewDefinition.js.map +1 -1
  74. package/lib/cjs/ViewStore.d.ts.map +1 -1
  75. package/lib/cjs/ViewStore.js +63 -21
  76. package/lib/cjs/ViewStore.js.map +1 -1
  77. package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
  78. package/lib/cjs/core-backend.d.ts +3 -0
  79. package/lib/cjs/core-backend.d.ts.map +1 -1
  80. package/lib/cjs/core-backend.js +3 -0
  81. package/lib/cjs/core-backend.js.map +1 -1
  82. package/lib/cjs/internal/HubMock.d.ts +2 -0
  83. package/lib/cjs/internal/HubMock.d.ts.map +1 -1
  84. package/lib/cjs/internal/HubMock.js +7 -0
  85. package/lib/cjs/internal/HubMock.js.map +1 -1
  86. package/lib/cjs/internal/IntegrityCheck.d.ts +10 -10
  87. package/lib/cjs/internal/IntegrityCheck.js +22 -22
  88. package/lib/cjs/internal/IntegrityCheck.js.map +1 -1
  89. package/lib/cjs/internal/NoLocks.d.ts.map +1 -1
  90. package/lib/cjs/internal/NoLocks.js +6 -0
  91. package/lib/cjs/internal/NoLocks.js.map +1 -1
  92. package/lib/cjs/internal/ServerBasedLocks.d.ts +12 -0
  93. package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -1
  94. package/lib/cjs/internal/ServerBasedLocks.js +285 -4
  95. package/lib/cjs/internal/ServerBasedLocks.js.map +1 -1
  96. package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -1
  97. package/lib/cjs/workspace/Settings.d.ts +6 -4
  98. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  99. package/lib/cjs/workspace/Settings.js.map +1 -1
  100. package/lib/esm/BackendHubAccess.d.ts +38 -0
  101. package/lib/esm/BackendHubAccess.d.ts.map +1 -1
  102. package/lib/esm/BackendHubAccess.js.map +1 -1
  103. package/lib/esm/BriefcaseManager.d.ts.map +1 -1
  104. package/lib/esm/BriefcaseManager.js +6 -3
  105. package/lib/esm/BriefcaseManager.js.map +1 -1
  106. package/lib/esm/ChangesetECAdaptor.d.ts +9 -1
  107. package/lib/esm/ChangesetECAdaptor.d.ts.map +1 -1
  108. package/lib/esm/ChangesetECAdaptor.js +7 -1
  109. package/lib/esm/ChangesetECAdaptor.js.map +1 -1
  110. package/lib/esm/ChangesetReader.d.ts +186 -0
  111. package/lib/esm/ChangesetReader.d.ts.map +1 -0
  112. package/lib/esm/ChangesetReader.js +368 -0
  113. package/lib/esm/ChangesetReader.js.map +1 -0
  114. package/lib/esm/ChangesetReaderTypes.d.ts +120 -0
  115. package/lib/esm/ChangesetReaderTypes.d.ts.map +1 -0
  116. package/lib/esm/ChangesetReaderTypes.js +20 -0
  117. package/lib/esm/ChangesetReaderTypes.js.map +1 -0
  118. package/lib/esm/CloudSqlite.d.ts +1 -1
  119. package/lib/esm/CloudSqlite.d.ts.map +1 -1
  120. package/lib/esm/CloudSqlite.js +69 -14
  121. package/lib/esm/CloudSqlite.js.map +1 -1
  122. package/lib/esm/ConcurrentQuery.js.map +1 -1
  123. package/lib/esm/DevTools.js.map +1 -1
  124. package/lib/esm/DisplayStyle.js.map +1 -1
  125. package/lib/esm/ECSqlStatement.d.ts.map +1 -1
  126. package/lib/esm/ECSqlStatement.js.map +1 -1
  127. package/lib/esm/EditTxn.d.ts +55 -1
  128. package/lib/esm/EditTxn.d.ts.map +1 -1
  129. package/lib/esm/EditTxn.js +43 -1
  130. package/lib/esm/EditTxn.js.map +1 -1
  131. package/lib/esm/Element.d.ts +69 -0
  132. package/lib/esm/Element.d.ts.map +1 -1
  133. package/lib/esm/Element.js +36 -0
  134. package/lib/esm/Element.js.map +1 -1
  135. package/lib/esm/ElementGraphics.js.map +1 -1
  136. package/lib/esm/ExternalSource.js.map +1 -1
  137. package/lib/esm/GeographicCRSServices.d.ts +15 -0
  138. package/lib/esm/GeographicCRSServices.d.ts.map +1 -1
  139. package/lib/esm/GeographicCRSServices.js +12 -4
  140. package/lib/esm/GeographicCRSServices.js.map +1 -1
  141. package/lib/esm/IModelDb.d.ts +9 -1
  142. package/lib/esm/IModelDb.d.ts.map +1 -1
  143. package/lib/esm/IModelDb.js +26 -7
  144. package/lib/esm/IModelDb.js.map +1 -1
  145. package/lib/esm/IModelIncrementalSchemaLocater.js.map +1 -1
  146. package/lib/esm/IpcHost.d.ts.map +1 -1
  147. package/lib/esm/IpcHost.js +33 -13
  148. package/lib/esm/IpcHost.js.map +1 -1
  149. package/lib/esm/LockControl.d.ts +85 -1
  150. package/lib/esm/LockControl.d.ts.map +1 -1
  151. package/lib/esm/LockControl.js.map +1 -1
  152. package/lib/esm/Model.d.ts +34 -0
  153. package/lib/esm/Model.d.ts.map +1 -1
  154. package/lib/esm/Model.js +24 -0
  155. package/lib/esm/Model.js.map +1 -1
  156. package/lib/esm/PartialChangeUnifier.d.ts +77 -0
  157. package/lib/esm/PartialChangeUnifier.d.ts.map +1 -0
  158. package/lib/esm/PartialChangeUnifier.js +230 -0
  159. package/lib/esm/PartialChangeUnifier.js.map +1 -0
  160. package/lib/esm/SheetIndex.js.map +1 -1
  161. package/lib/esm/SqliteChangesetReader.d.ts.map +1 -1
  162. package/lib/esm/SqliteChangesetReader.js +1 -1
  163. package/lib/esm/SqliteChangesetReader.js.map +1 -1
  164. package/lib/esm/TxnManager.d.ts +114 -4
  165. package/lib/esm/TxnManager.d.ts.map +1 -1
  166. package/lib/esm/TxnManager.js +196 -8
  167. package/lib/esm/TxnManager.js.map +1 -1
  168. package/lib/esm/ViewDefinition.d.ts +19 -7
  169. package/lib/esm/ViewDefinition.d.ts.map +1 -1
  170. package/lib/esm/ViewDefinition.js +78 -26
  171. package/lib/esm/ViewDefinition.js.map +1 -1
  172. package/lib/esm/ViewStore.d.ts.map +1 -1
  173. package/lib/esm/ViewStore.js +64 -22
  174. package/lib/esm/ViewStore.js.map +1 -1
  175. package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
  176. package/lib/esm/core-backend.d.ts +3 -0
  177. package/lib/esm/core-backend.d.ts.map +1 -1
  178. package/lib/esm/core-backend.js +3 -0
  179. package/lib/esm/core-backend.js.map +1 -1
  180. package/lib/esm/internal/HubMock.d.ts +2 -0
  181. package/lib/esm/internal/HubMock.d.ts.map +1 -1
  182. package/lib/esm/internal/HubMock.js +7 -0
  183. package/lib/esm/internal/HubMock.js.map +1 -1
  184. package/lib/esm/internal/IntegrityCheck.d.ts +10 -10
  185. package/lib/esm/internal/IntegrityCheck.js +22 -22
  186. package/lib/esm/internal/IntegrityCheck.js.map +1 -1
  187. package/lib/esm/internal/NoLocks.d.ts.map +1 -1
  188. package/lib/esm/internal/NoLocks.js +6 -0
  189. package/lib/esm/internal/NoLocks.js.map +1 -1
  190. package/lib/esm/internal/ServerBasedLocks.d.ts +12 -0
  191. package/lib/esm/internal/ServerBasedLocks.d.ts.map +1 -1
  192. package/lib/esm/internal/ServerBasedLocks.js +286 -5
  193. package/lib/esm/internal/ServerBasedLocks.js.map +1 -1
  194. package/lib/esm/internal/workspace/WorkspaceImpl.js.map +1 -1
  195. package/lib/esm/test/ElementDrivesElement.test.d.ts.map +1 -1
  196. package/lib/esm/test/ElementDrivesElement.test.js.map +1 -1
  197. package/lib/esm/test/IModelTestUtils.d.ts +1 -0
  198. package/lib/esm/test/IModelTestUtils.d.ts.map +1 -1
  199. package/lib/esm/test/IModelTestUtils.js +5 -0
  200. package/lib/esm/test/IModelTestUtils.js.map +1 -1
  201. package/lib/esm/test/IpcHost.test.js +112 -0
  202. package/lib/esm/test/IpcHost.test.js.map +1 -1
  203. package/lib/esm/test/annotations/LeaderGeometry.test.js +0 -1
  204. package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
  205. package/lib/esm/test/ecsql/dataset/ECSqlDatasets.js.map +1 -1
  206. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.js.map +1 -1
  207. package/lib/esm/test/element/DeleteDefinitionElements.test.js +819 -26
  208. package/lib/esm/test/element/DeleteDefinitionElements.test.js.map +1 -1
  209. package/lib/esm/test/element/ElementRoundTrip.test.js +144 -3
  210. package/lib/esm/test/element/ElementRoundTrip.test.js.map +1 -1
  211. package/lib/esm/test/element/SheetInformationAspect.test.js.map +1 -1
  212. package/lib/esm/test/hubaccess/Rebase.test.js +1 -1
  213. package/lib/esm/test/hubaccess/Rebase.test.js.map +1 -1
  214. package/lib/esm/test/imodel/IModel.test.js +1 -1
  215. package/lib/esm/test/imodel/IModel.test.js.map +1 -1
  216. package/lib/esm/test/imodel/SchemaXmlImport.test.js +64 -0
  217. package/lib/esm/test/imodel/SchemaXmlImport.test.js.map +1 -1
  218. package/lib/esm/test/misc/GeoServices.test.js +43 -1
  219. package/lib/esm/test/misc/GeoServices.test.js.map +1 -1
  220. package/lib/esm/test/sheetindex/SheetIndex.test.js.map +1 -1
  221. package/lib/esm/test/standalone/ChangesetReader.test.js +4184 -1654
  222. package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
  223. package/lib/esm/test/standalone/DeleteElements.test.d.ts +2 -0
  224. package/lib/esm/test/standalone/DeleteElements.test.d.ts.map +1 -0
  225. package/lib/esm/test/standalone/DeleteElements.test.js +625 -0
  226. package/lib/esm/test/standalone/DeleteElements.test.js.map +1 -0
  227. package/lib/esm/test/standalone/GeometryStream.test.js.map +1 -1
  228. package/lib/esm/test/standalone/IntegrityCheck.test.js +214 -5
  229. package/lib/esm/test/standalone/IntegrityCheck.test.js.map +1 -1
  230. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.d.ts +2 -0
  231. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.d.ts.map +1 -0
  232. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.js +1862 -0
  233. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.js.map +1 -0
  234. package/lib/esm/test/standalone/ServerBasedLocks.test.js +907 -3
  235. package/lib/esm/test/standalone/ServerBasedLocks.test.js.map +1 -1
  236. package/lib/esm/test/standalone/TxnManager.test.js +90 -0
  237. package/lib/esm/test/standalone/TxnManager.test.js.map +1 -1
  238. package/lib/esm/test/standalone/ViewDefinition.test.js +18 -7
  239. package/lib/esm/test/standalone/ViewDefinition.test.js.map +1 -1
  240. package/lib/esm/test/standalone/Workspace.test.js.map +1 -1
  241. package/lib/esm/workspace/Settings.d.ts +6 -4
  242. package/lib/esm/workspace/Settings.d.ts.map +1 -1
  243. package/lib/esm/workspace/Settings.js.map +1 -1
  244. package/package.json +15 -15
@@ -215,6 +215,7 @@ export class RebaseManager {
215
215
  _conflictHandlers;
216
216
  _customHandler;
217
217
  _aborting = false;
218
+ _disposed = false;
218
219
  /** Event raised before pull merge process begins.
219
220
  * @alpha
220
221
  */
@@ -326,6 +327,29 @@ export class RebaseManager {
326
327
  constructor(_iModel) {
327
328
  this._iModel = _iModel;
328
329
  }
330
+ /** Disposes of this RebaseManager, clearing all event listeners.
331
+ * Also calls [[RebaseHandler.dispose]] on the registered custom handler, if any.
332
+ * Subsequent calls are ignored.
333
+ * @alpha
334
+ */
335
+ dispose() {
336
+ if (this._disposed)
337
+ return;
338
+ this._disposed = true;
339
+ this._customHandler?.dispose?.();
340
+ this.onPullMergeBegin.clear();
341
+ this.onRebaseBegin.clear();
342
+ this.onRebaseTxnBegin.clear();
343
+ this.onRebaseTxnEnd.clear();
344
+ this.onRebaseEnd.clear();
345
+ this.onPullMergeEnd.clear();
346
+ this.onApplyIncomingChangesBegin.clear();
347
+ this.onApplyIncomingChangesEnd.clear();
348
+ this.onReverseLocalChangesBegin.clear();
349
+ this.onReverseLocalChangesEnd.clear();
350
+ this.onDownloadChangesetsBegin.clear();
351
+ this.onDownloadChangesetsEnd.clear();
352
+ }
329
353
  /**
330
354
  * Resumes the rebase process for the current iModel, applying any pending local changes
331
355
  * on top of the latest pulled changes from the remote source.
@@ -715,6 +739,7 @@ export class TxnManager {
715
739
  this.rebaser = new RebaseManager(_iModel);
716
740
  _iModel.onBeforeClose.addOnce(() => {
717
741
  this._isDisposed = true;
742
+ this.rebaser.dispose();
718
743
  });
719
744
  }
720
745
  /** Array of errors from dependency propagation */
@@ -1036,6 +1061,7 @@ export class TxnManager {
1036
1061
  /** Return the depth of the multi-Txn stack. Generally for diagnostic use only. */
1037
1062
  getMultiTxnOperationDepth() { return this._nativeDb.getMultiTxnOperationDepth(); }
1038
1063
  /** Reverse (undo) the most recent operation(s) to this IModelDb.
1064
+ * @note Consider using [[reverseTxnsAsync]] instead.
1039
1065
  * @param numOperations the number of operations to reverse. If this is greater than 1, the entire set of operations will
1040
1066
  * be reinstated together when/if ReinstateTxn is called.
1041
1067
  * @note If there are any outstanding uncommitted changes, they are reversed.
@@ -1048,27 +1074,189 @@ export class TxnManager {
1048
1074
  this._nativeDb.abandonChanges();
1049
1075
  return this._nativeDb.reverseTxns(numOperations);
1050
1076
  }
1051
- /** Reverse the most recent operation. */
1052
- reverseSingleTxn() { return this.reverseTxns(1); }
1053
- /** Reverse all changes back to the beginning of the session. */
1054
- reverseAll() { return this._nativeDb.reverseAll(); }
1077
+ /** Reverse the most recent operation.
1078
+ * @note Consider using [[reverseSingleTxnAsync]] instead.
1079
+ */
1080
+ reverseSingleTxn() {
1081
+ return this.reverseTxns(1);
1082
+ }
1083
+ /** Reverse all changes back to the beginning of the session.
1084
+ * @note Consider using [[reverseAllTxnsAsync]] instead.
1085
+ */
1086
+ reverseAll() {
1087
+ return this._nativeDb.reverseAll();
1088
+ }
1055
1089
  /** Reverse all changes back to a previously saved TxnId.
1090
+ * @note Consider using [[reverseToTxnAsync]] instead.
1056
1091
  * @param txnId a TxnId obtained from a previous call to GetCurrentTxnId.
1057
1092
  * @returns Success if the transactions were reversed, error status otherwise.
1058
1093
  * @see [[getCurrentTxnId]] [[cancelTo]]
1059
1094
  */
1060
- reverseTo(txnId) { return this._nativeDb.reverseTo(txnId); }
1095
+ reverseTo(txnId) {
1096
+ return this._nativeDb.reverseTo(txnId);
1097
+ }
1061
1098
  /** Reverse and then cancel (make non-reinstatable) all changes back to a previous TxnId.
1099
+ * @note Consider using [[cancelToTxnAsync]] instead.
1062
1100
  * @param txnId a TxnId obtained from a previous call to [[getCurrentTxnId]]
1063
1101
  * @returns Success if the transactions were reversed and cleared, error status otherwise.
1064
1102
  */
1065
- cancelTo(txnId) { return this._nativeDb.cancelTo(txnId); }
1103
+ cancelTo(txnId) {
1104
+ return this._nativeDb.cancelTo(txnId);
1105
+ }
1106
+ /** Reverse (undo) the most recent operation(s) to this IModelDb. By default, this method also
1107
+ * abandons the locks that were acquired for those operations.
1108
+ * @beta
1109
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1110
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1111
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1112
+ * with _both_ Txn 1 and Txn 2.
1113
+ * @note If you do not want to abandon any locks, set [ReverseTxnArgs.retainLocks]($common) to true.
1114
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1115
+ * @note The term "operation" is used rather than Txn, since multiple Txns can be grouped together via [[beginMultiTxnOperation]]. So,
1116
+ * even if numOperations is 1, multiple Txns may be reversed if they were grouped together when they were made.
1117
+ * @note If numOperations is too large only the operations are reversible are reversed.
1118
+ * @param numOperations the number of operations to reverse. If this is greater than 1, the entire set of operations will
1119
+ * be reinstated together when/if ReinstateTxn is called.
1120
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to retain locks.
1121
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1122
+ */
1123
+ async reverseTxnsAsync(numOperations, args) {
1124
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseTxns(numOperations));
1125
+ }
1126
+ /** Reverse (undo) the most recent operation to this IModelDb. By default, this method also
1127
+ * abandons the locks that were acquired for that operation.
1128
+ * @beta
1129
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1130
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1131
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1132
+ * with _both_ Txn 1 and Txn 2.
1133
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1134
+ * @note The term "operation" is used rather than Txn, since multiple Txns can be grouped together via [[beginMultiTxnOperation]]. So,
1135
+ * even though this method reverses only one operation, multiple Txns may be reversed if they were grouped together when they were made.
1136
+ * @note If there are no reversible operations, this method does nothing and returns Success.
1137
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to retain locks.
1138
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1139
+ */
1140
+ async reverseSingleTxnAsync(args) {
1141
+ await this.reverseTxnsAsync(1, args);
1142
+ }
1143
+ /** Reverse (undo) all operations back to the beginning of the session. By default, this method also
1144
+ * abandons the locks that were acquired for those operations.
1145
+ * @beta
1146
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1147
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1148
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1149
+ * with _both_ Txn 1 and Txn 2.
1150
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1151
+ * @note If there are no reversible operations, this method does nothing and returns Success.
1152
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to retain locks.
1153
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1154
+ */
1155
+ async reverseAllTxnsAsync(args) {
1156
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseAll());
1157
+ }
1158
+ /** Reverse (undo) all operations back to a previously saved TxnId. By default, this method also
1159
+ * abandons the locks that were acquired for those operations.
1160
+ * @beta
1161
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1162
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1163
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1164
+ * with _both_ Txn 1 and Txn 2.
1165
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1166
+ * @param txnId a TxnId obtained from a previous call to GetCurrentTxnId.
1167
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to abandon locks.
1168
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1169
+ * @see [[getCurrentTxnId]] [[cancelTo]]
1170
+ */
1171
+ async reverseToTxnAsync(txnId, args) {
1172
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseTo(txnId));
1173
+ }
1174
+ /** Reverse and then cancel (make non-reinstatable) all operations back to a previous TxnId. By default, this
1175
+ * method also abandons the locks that were acquired for those operations.
1176
+ * @beta
1177
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1178
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1179
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1180
+ * with _both_ Txn 1 and Txn 2.
1181
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1182
+ * @param txnId a TxnId obtained from a previous call to [[getCurrentTxnId]]
1183
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to abandon locks.
1184
+ * @returns A promise that resolves to success if the transactions were reversed and cleared, or rejects with an IModelError otherwise.
1185
+ */
1186
+ async cancelToTxnAsync(txnId, args) {
1187
+ // First reverse and abandon locks. Only cancel if that succeeds.
1188
+ // This is important because the locks would become unabandonable if we canceled first and
1189
+ // _then_ the abandonment failed. We expect the call to cancelTo to return "NothingToUndo",
1190
+ // but that's ok - it will still clear the already-reversed txns.
1191
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseTo(txnId));
1192
+ const status = this._nativeDb.cancelTo(txnId);
1193
+ if (status !== IModelStatus.Success && status !== IModelStatus.NothingToUndo)
1194
+ throw new IModelError(status, IModelError.getErrorKey(status));
1195
+ this._iModel.locks.clearTxnLockRecords(txnId);
1196
+ }
1197
+ async withLockAbandonment(args, doReverseCallback) {
1198
+ const result = doReverseCallback();
1199
+ if (result === IModelStatus.Success) {
1200
+ if (!args?.retainLocks) {
1201
+ // Abandon locks for the earliest txn, which abandons locks for the later ones, too.
1202
+ await this._iModel.locks.abandonLocksForReversedTxn(this.getCurrentTxnId());
1203
+ }
1204
+ }
1205
+ else {
1206
+ throw new IModelError(result, IModelError.getErrorKey(result));
1207
+ }
1208
+ }
1066
1209
  /** Reinstate the most recently reversed transaction. Since at any time multiple transactions can be reversed, it
1067
1210
  * may take multiple calls to this method to reinstate all reversed operations.
1068
1211
  * @returns Success if a reversed transaction was reinstated, error status otherwise.
1069
1212
  * @note If there are any outstanding uncommitted changes, they are canceled before the Txn is reinstated.
1213
+ * @note This method will return [[IModelStatus.LockNotHeld]] and will not reinstate the Txn if the locks
1214
+ * originally acquired by the Txn have been abandoned. Use [[reinstateTxnAsync]] to re-acquire the locks
1215
+ * and reinstate the Txn in a single operation.
1070
1216
  */
1071
- reinstateTxn() { return this._iModel.reinstateTxn(); }
1217
+ reinstateTxn() {
1218
+ // Verify that the locks required by this txn have not been abandoned.
1219
+ // If so, this method has no way to re-acquire them because it is synchronous. This
1220
+ // is basically a developer error, mixing reverseTxnAsync with reinstateTxn (non-Async).
1221
+ const reinstateRange = this._nativeDb.getNextReinstateTxnRange();
1222
+ if (this.isTxnIdValid(reinstateRange.firstTxnId) &&
1223
+ !this._iModel.locks.holdsNecessaryLocksForReinstatingTxn(this.queryPreviousTxnId(reinstateRange.lastTxnId))) {
1224
+ return IModelStatus.LockNotHeld;
1225
+ }
1226
+ return this._iModel.reinstateTxn();
1227
+ }
1228
+ /** Reinstate the most recently reversed transaction. This method will first attempt
1229
+ * to re-acquire the required locks, if they were abandoned after the operation was reversed.
1230
+ * Since at any time multiple transactions can be reversed, it may take multiple calls to this
1231
+ * method to reinstate all reversed operations.
1232
+ * @beta
1233
+ * @note If there are any outstanding unsaved changes, they are canceled before the Txn is reinstated. Unless
1234
+ * [ReinstateTxnArgs.retainLocks]($common) is true, the locks associated with the unsaved changes are also abandoned.
1235
+ * @param args Optional arguments to control the behavior of the reinstate operation, such as whether to retain
1236
+ * locks when abandoning unsaved changes.
1237
+ * @returns A Promise that resolves to success if a reversed transaction was reinstated, or rejects with an IModelError otherwise.
1238
+ */
1239
+ async reinstateTxnAsync(args) {
1240
+ // We must abandon any unsaved changes here because it will be too late
1241
+ // when reinstateTxn does it.
1242
+ if (this.hasUnsavedChanges) {
1243
+ this._iModel.clearCaches({ instanceCachesOnly: true });
1244
+ this._iModel[_nativeDb].abandonChanges();
1245
+ }
1246
+ if (!args?.retainLocks) {
1247
+ await this._iModel.locks.abandonLocksForCurrentUnsavedTxn();
1248
+ }
1249
+ const reinstateRange = this._nativeDb.getNextReinstateTxnRange();
1250
+ if (!this.isTxnIdValid(reinstateRange.firstTxnId)) {
1251
+ throw new IModelError(IModelStatus.NothingToRedo, IModelError.getErrorKey(IModelStatus.NothingToRedo));
1252
+ }
1253
+ // Reacquire locks for the latest txn in the range, which will reacquire locks for all earlier txns, too.
1254
+ await this._iModel.locks.acquireLocksForReinstatingTxn(this.queryPreviousTxnId(reinstateRange.lastTxnId));
1255
+ const status = this.reinstateTxn();
1256
+ if (status !== IModelStatus.Success) {
1257
+ throw new IModelError(status, IModelError.getErrorKey(status));
1258
+ }
1259
+ }
1072
1260
  /** Get the Id of the first transaction, if any.
1073
1261
  */
1074
1262
  queryFirstTxnId() { return this._nativeDb.queryFirstTxnId(); }
@@ -1109,7 +1297,7 @@ export class TxnManager {
1109
1297
  get hasLocalChanges() { return this.hasUnsavedChanges || this.hasPendingTxns; }
1110
1298
  /** Destroy the record of all local changes that have yet to be saved and/or pushed.
1111
1299
  * This permanently eradicates your changes - use with caution!
1112
- * Typically, callers will want to subsequently use [[LockControl.releaseAllLocks]].
1300
+ * Typically, callers will want to subsequently use [[LockControl.abandonAllLocks]].
1113
1301
  * After calling this function, [[hasLocalChanges]], [[hasPendingTxns]], and [[hasUnsavedChanges]] will all be `false`.
1114
1302
  */
1115
1303
  deleteAllTxns() {