@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
@@ -219,6 +219,7 @@ class RebaseManager {
219
219
  _conflictHandlers;
220
220
  _customHandler;
221
221
  _aborting = false;
222
+ _disposed = false;
222
223
  /** Event raised before pull merge process begins.
223
224
  * @alpha
224
225
  */
@@ -330,6 +331,29 @@ class RebaseManager {
330
331
  constructor(_iModel) {
331
332
  this._iModel = _iModel;
332
333
  }
334
+ /** Disposes of this RebaseManager, clearing all event listeners.
335
+ * Also calls [[RebaseHandler.dispose]] on the registered custom handler, if any.
336
+ * Subsequent calls are ignored.
337
+ * @alpha
338
+ */
339
+ dispose() {
340
+ if (this._disposed)
341
+ return;
342
+ this._disposed = true;
343
+ this._customHandler?.dispose?.();
344
+ this.onPullMergeBegin.clear();
345
+ this.onRebaseBegin.clear();
346
+ this.onRebaseTxnBegin.clear();
347
+ this.onRebaseTxnEnd.clear();
348
+ this.onRebaseEnd.clear();
349
+ this.onPullMergeEnd.clear();
350
+ this.onApplyIncomingChangesBegin.clear();
351
+ this.onApplyIncomingChangesEnd.clear();
352
+ this.onReverseLocalChangesBegin.clear();
353
+ this.onReverseLocalChangesEnd.clear();
354
+ this.onDownloadChangesetsBegin.clear();
355
+ this.onDownloadChangesetsEnd.clear();
356
+ }
333
357
  /**
334
358
  * Resumes the rebase process for the current iModel, applying any pending local changes
335
359
  * on top of the latest pulled changes from the remote source.
@@ -720,6 +744,7 @@ class TxnManager {
720
744
  this.rebaser = new RebaseManager(_iModel);
721
745
  _iModel.onBeforeClose.addOnce(() => {
722
746
  this._isDisposed = true;
747
+ this.rebaser.dispose();
723
748
  });
724
749
  }
725
750
  /** Array of errors from dependency propagation */
@@ -1041,6 +1066,7 @@ class TxnManager {
1041
1066
  /** Return the depth of the multi-Txn stack. Generally for diagnostic use only. */
1042
1067
  getMultiTxnOperationDepth() { return this._nativeDb.getMultiTxnOperationDepth(); }
1043
1068
  /** Reverse (undo) the most recent operation(s) to this IModelDb.
1069
+ * @note Consider using [[reverseTxnsAsync]] instead.
1044
1070
  * @param numOperations the number of operations to reverse. If this is greater than 1, the entire set of operations will
1045
1071
  * be reinstated together when/if ReinstateTxn is called.
1046
1072
  * @note If there are any outstanding uncommitted changes, they are reversed.
@@ -1053,27 +1079,189 @@ class TxnManager {
1053
1079
  this._nativeDb.abandonChanges();
1054
1080
  return this._nativeDb.reverseTxns(numOperations);
1055
1081
  }
1056
- /** Reverse the most recent operation. */
1057
- reverseSingleTxn() { return this.reverseTxns(1); }
1058
- /** Reverse all changes back to the beginning of the session. */
1059
- reverseAll() { return this._nativeDb.reverseAll(); }
1082
+ /** Reverse the most recent operation.
1083
+ * @note Consider using [[reverseSingleTxnAsync]] instead.
1084
+ */
1085
+ reverseSingleTxn() {
1086
+ return this.reverseTxns(1);
1087
+ }
1088
+ /** Reverse all changes back to the beginning of the session.
1089
+ * @note Consider using [[reverseAllTxnsAsync]] instead.
1090
+ */
1091
+ reverseAll() {
1092
+ return this._nativeDb.reverseAll();
1093
+ }
1060
1094
  /** Reverse all changes back to a previously saved TxnId.
1095
+ * @note Consider using [[reverseToTxnAsync]] instead.
1061
1096
  * @param txnId a TxnId obtained from a previous call to GetCurrentTxnId.
1062
1097
  * @returns Success if the transactions were reversed, error status otherwise.
1063
1098
  * @see [[getCurrentTxnId]] [[cancelTo]]
1064
1099
  */
1065
- reverseTo(txnId) { return this._nativeDb.reverseTo(txnId); }
1100
+ reverseTo(txnId) {
1101
+ return this._nativeDb.reverseTo(txnId);
1102
+ }
1066
1103
  /** Reverse and then cancel (make non-reinstatable) all changes back to a previous TxnId.
1104
+ * @note Consider using [[cancelToTxnAsync]] instead.
1067
1105
  * @param txnId a TxnId obtained from a previous call to [[getCurrentTxnId]]
1068
1106
  * @returns Success if the transactions were reversed and cleared, error status otherwise.
1069
1107
  */
1070
- cancelTo(txnId) { return this._nativeDb.cancelTo(txnId); }
1108
+ cancelTo(txnId) {
1109
+ return this._nativeDb.cancelTo(txnId);
1110
+ }
1111
+ /** Reverse (undo) the most recent operation(s) to this IModelDb. By default, this method also
1112
+ * abandons the locks that were acquired for those operations.
1113
+ * @beta
1114
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1115
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1116
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1117
+ * with _both_ Txn 1 and Txn 2.
1118
+ * @note If you do not want to abandon any locks, set [ReverseTxnArgs.retainLocks]($common) to true.
1119
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1120
+ * @note The term "operation" is used rather than Txn, since multiple Txns can be grouped together via [[beginMultiTxnOperation]]. So,
1121
+ * even if numOperations is 1, multiple Txns may be reversed if they were grouped together when they were made.
1122
+ * @note If numOperations is too large only the operations are reversible are reversed.
1123
+ * @param numOperations the number of operations to reverse. If this is greater than 1, the entire set of operations will
1124
+ * be reinstated together when/if ReinstateTxn is called.
1125
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to retain locks.
1126
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1127
+ */
1128
+ async reverseTxnsAsync(numOperations, args) {
1129
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseTxns(numOperations));
1130
+ }
1131
+ /** Reverse (undo) the most recent operation to this IModelDb. By default, this method also
1132
+ * abandons the locks that were acquired for that operation.
1133
+ * @beta
1134
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1135
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1136
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1137
+ * with _both_ Txn 1 and Txn 2.
1138
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1139
+ * @note The term "operation" is used rather than Txn, since multiple Txns can be grouped together via [[beginMultiTxnOperation]]. So,
1140
+ * even though this method reverses only one operation, multiple Txns may be reversed if they were grouped together when they were made.
1141
+ * @note If there are no reversible operations, this method does nothing and returns Success.
1142
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to retain locks.
1143
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1144
+ */
1145
+ async reverseSingleTxnAsync(args) {
1146
+ await this.reverseTxnsAsync(1, args);
1147
+ }
1148
+ /** Reverse (undo) all operations back to the beginning of the session. By default, this method also
1149
+ * abandons the locks that were acquired for those operations.
1150
+ * @beta
1151
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1152
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1153
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1154
+ * with _both_ Txn 1 and Txn 2.
1155
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1156
+ * @note If there are no reversible operations, this method does nothing and returns Success.
1157
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to retain locks.
1158
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1159
+ */
1160
+ async reverseAllTxnsAsync(args) {
1161
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseAll());
1162
+ }
1163
+ /** Reverse (undo) all operations back to a previously saved TxnId. By default, this method also
1164
+ * abandons the locks that were acquired for those operations.
1165
+ * @beta
1166
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1167
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1168
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1169
+ * with _both_ Txn 1 and Txn 2.
1170
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1171
+ * @param txnId a TxnId obtained from a previous call to GetCurrentTxnId.
1172
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to abandon locks.
1173
+ * @returns A Promise that resolves to success if the transactions were reversed, or rejects with an IModelError otherwise.
1174
+ * @see [[getCurrentTxnId]] [[cancelTo]]
1175
+ */
1176
+ async reverseToTxnAsync(txnId, args) {
1177
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseTo(txnId));
1178
+ }
1179
+ /** Reverse and then cancel (make non-reinstatable) all operations back to a previous TxnId. By default, this
1180
+ * method also abandons the locks that were acquired for those operations.
1181
+ * @beta
1182
+ * @note This method will also abandon locks associated with any later, reversed Txns, if they have not
1183
+ * already been abandoned. For example, if a call to [[reverseTxns]] reverses Txn 2 without abandoning
1184
+ * its locks, and then this method is called to reverse Txn 1, it will abandon the locks associated
1185
+ * with _both_ Txn 1 and Txn 2.
1186
+ * @note If there are any outstanding uncommitted changes, they are reversed.
1187
+ * @param txnId a TxnId obtained from a previous call to [[getCurrentTxnId]]
1188
+ * @param args Optional arguments to control the behavior of the reverse operation, such as whether to abandon locks.
1189
+ * @returns A promise that resolves to success if the transactions were reversed and cleared, or rejects with an IModelError otherwise.
1190
+ */
1191
+ async cancelToTxnAsync(txnId, args) {
1192
+ // First reverse and abandon locks. Only cancel if that succeeds.
1193
+ // This is important because the locks would become unabandonable if we canceled first and
1194
+ // _then_ the abandonment failed. We expect the call to cancelTo to return "NothingToUndo",
1195
+ // but that's ok - it will still clear the already-reversed txns.
1196
+ await this.withLockAbandonment(args, () => this._nativeDb.reverseTo(txnId));
1197
+ const status = this._nativeDb.cancelTo(txnId);
1198
+ if (status !== core_bentley_1.IModelStatus.Success && status !== core_bentley_1.IModelStatus.NothingToUndo)
1199
+ throw new core_common_1.IModelError(status, core_common_1.IModelError.getErrorKey(status));
1200
+ this._iModel.locks.clearTxnLockRecords(txnId);
1201
+ }
1202
+ async withLockAbandonment(args, doReverseCallback) {
1203
+ const result = doReverseCallback();
1204
+ if (result === core_bentley_1.IModelStatus.Success) {
1205
+ if (!args?.retainLocks) {
1206
+ // Abandon locks for the earliest txn, which abandons locks for the later ones, too.
1207
+ await this._iModel.locks.abandonLocksForReversedTxn(this.getCurrentTxnId());
1208
+ }
1209
+ }
1210
+ else {
1211
+ throw new core_common_1.IModelError(result, core_common_1.IModelError.getErrorKey(result));
1212
+ }
1213
+ }
1071
1214
  /** Reinstate the most recently reversed transaction. Since at any time multiple transactions can be reversed, it
1072
1215
  * may take multiple calls to this method to reinstate all reversed operations.
1073
1216
  * @returns Success if a reversed transaction was reinstated, error status otherwise.
1074
1217
  * @note If there are any outstanding uncommitted changes, they are canceled before the Txn is reinstated.
1218
+ * @note This method will return [[IModelStatus.LockNotHeld]] and will not reinstate the Txn if the locks
1219
+ * originally acquired by the Txn have been abandoned. Use [[reinstateTxnAsync]] to re-acquire the locks
1220
+ * and reinstate the Txn in a single operation.
1075
1221
  */
1076
- reinstateTxn() { return this._iModel.reinstateTxn(); }
1222
+ reinstateTxn() {
1223
+ // Verify that the locks required by this txn have not been abandoned.
1224
+ // If so, this method has no way to re-acquire them because it is synchronous. This
1225
+ // is basically a developer error, mixing reverseTxnAsync with reinstateTxn (non-Async).
1226
+ const reinstateRange = this._nativeDb.getNextReinstateTxnRange();
1227
+ if (this.isTxnIdValid(reinstateRange.firstTxnId) &&
1228
+ !this._iModel.locks.holdsNecessaryLocksForReinstatingTxn(this.queryPreviousTxnId(reinstateRange.lastTxnId))) {
1229
+ return core_bentley_1.IModelStatus.LockNotHeld;
1230
+ }
1231
+ return this._iModel.reinstateTxn();
1232
+ }
1233
+ /** Reinstate the most recently reversed transaction. This method will first attempt
1234
+ * to re-acquire the required locks, if they were abandoned after the operation was reversed.
1235
+ * Since at any time multiple transactions can be reversed, it may take multiple calls to this
1236
+ * method to reinstate all reversed operations.
1237
+ * @beta
1238
+ * @note If there are any outstanding unsaved changes, they are canceled before the Txn is reinstated. Unless
1239
+ * [ReinstateTxnArgs.retainLocks]($common) is true, the locks associated with the unsaved changes are also abandoned.
1240
+ * @param args Optional arguments to control the behavior of the reinstate operation, such as whether to retain
1241
+ * locks when abandoning unsaved changes.
1242
+ * @returns A Promise that resolves to success if a reversed transaction was reinstated, or rejects with an IModelError otherwise.
1243
+ */
1244
+ async reinstateTxnAsync(args) {
1245
+ // We must abandon any unsaved changes here because it will be too late
1246
+ // when reinstateTxn does it.
1247
+ if (this.hasUnsavedChanges) {
1248
+ this._iModel.clearCaches({ instanceCachesOnly: true });
1249
+ this._iModel[Symbols_1._nativeDb].abandonChanges();
1250
+ }
1251
+ if (!args?.retainLocks) {
1252
+ await this._iModel.locks.abandonLocksForCurrentUnsavedTxn();
1253
+ }
1254
+ const reinstateRange = this._nativeDb.getNextReinstateTxnRange();
1255
+ if (!this.isTxnIdValid(reinstateRange.firstTxnId)) {
1256
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NothingToRedo, core_common_1.IModelError.getErrorKey(core_bentley_1.IModelStatus.NothingToRedo));
1257
+ }
1258
+ // Reacquire locks for the latest txn in the range, which will reacquire locks for all earlier txns, too.
1259
+ await this._iModel.locks.acquireLocksForReinstatingTxn(this.queryPreviousTxnId(reinstateRange.lastTxnId));
1260
+ const status = this.reinstateTxn();
1261
+ if (status !== core_bentley_1.IModelStatus.Success) {
1262
+ throw new core_common_1.IModelError(status, core_common_1.IModelError.getErrorKey(status));
1263
+ }
1264
+ }
1077
1265
  /** Get the Id of the first transaction, if any.
1078
1266
  */
1079
1267
  queryFirstTxnId() { return this._nativeDb.queryFirstTxnId(); }
@@ -1114,7 +1302,7 @@ class TxnManager {
1114
1302
  get hasLocalChanges() { return this.hasUnsavedChanges || this.hasPendingTxns; }
1115
1303
  /** Destroy the record of all local changes that have yet to be saved and/or pushed.
1116
1304
  * This permanently eradicates your changes - use with caution!
1117
- * Typically, callers will want to subsequently use [[LockControl.releaseAllLocks]].
1305
+ * Typically, callers will want to subsequently use [[LockControl.abandonAllLocks]].
1118
1306
  * After calling this function, [[hasLocalChanges]], [[hasPendingTxns]], and [[hasUnsavedChanges]] will all be `false`.
1119
1307
  */
1120
1308
  deleteAllTxns() {