@itwin/core-backend 5.2.0-dev.8 → 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.
- package/CHANGELOG.md +31 -1
- package/lib/cjs/BackendHubAccess.d.ts +2 -0
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BackendLoggerCategory.d.ts +6 -0
- package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/BackendLoggerCategory.js +6 -0
- package/lib/cjs/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts +57 -3
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +151 -42
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +4 -0
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +8 -0
- package/lib/cjs/ECDb.d.ts.map +1 -1
- package/lib/cjs/ECDb.js +22 -0
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +54 -3
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +87 -9
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +11 -1
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +5 -0
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IModelIncrementalSchemaLocater.d.ts +1 -5
- package/lib/cjs/IModelIncrementalSchemaLocater.d.ts.map +1 -1
- package/lib/cjs/IModelIncrementalSchemaLocater.js +0 -6
- package/lib/cjs/IModelIncrementalSchemaLocater.js.map +1 -1
- package/lib/cjs/SqliteChangesetReader.d.ts +8 -0
- package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
- package/lib/cjs/SqliteChangesetReader.js +11 -0
- package/lib/cjs/SqliteChangesetReader.js.map +1 -1
- package/lib/cjs/StashManager.d.ts +175 -0
- package/lib/cjs/StashManager.d.ts.map +1 -0
- package/lib/cjs/StashManager.js +306 -0
- package/lib/cjs/StashManager.js.map +1 -0
- package/lib/cjs/TxnManager.d.ts +226 -15
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +249 -23
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts +10 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.js +15 -6
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
- package/lib/cjs/annotations/LeaderGeometry.d.ts +3 -2
- package/lib/cjs/annotations/LeaderGeometry.d.ts.map +1 -1
- package/lib/cjs/annotations/LeaderGeometry.js +5 -4
- package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts +52 -24
- package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.js +49 -59
- package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationGeometry.d.ts +2 -0
- package/lib/cjs/annotations/TextAnnotationGeometry.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationGeometry.js +26 -19
- package/lib/cjs/annotations/TextAnnotationGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextBlockGeometry.d.ts.map +1 -1
- package/lib/cjs/annotations/TextBlockGeometry.js +8 -0
- package/lib/cjs/annotations/TextBlockGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextBlockLayout.d.ts +49 -36
- package/lib/cjs/annotations/TextBlockLayout.d.ts.map +1 -1
- package/lib/cjs/annotations/TextBlockLayout.js +204 -135
- package/lib/cjs/annotations/TextBlockLayout.js.map +1 -1
- package/lib/cjs/internal/ChannelAdmin.js +1 -1
- package/lib/cjs/internal/ChannelAdmin.js.map +1 -1
- package/lib/cjs/internal/Symbols.d.ts +1 -0
- package/lib/cjs/internal/Symbols.d.ts.map +1 -1
- package/lib/cjs/internal/Symbols.js +2 -1
- package/lib/cjs/internal/Symbols.js.map +1 -1
- package/lib/cjs/internal/annotations/fields.d.ts +2 -12
- package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
- package/lib/cjs/internal/annotations/fields.js +49 -45
- package/lib/cjs/internal/annotations/fields.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +1 -1
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/lib/esm/BackendHubAccess.d.ts +2 -0
- package/lib/esm/BackendHubAccess.d.ts.map +1 -1
- package/lib/esm/BackendHubAccess.js.map +1 -1
- package/lib/esm/BackendLoggerCategory.d.ts +6 -0
- package/lib/esm/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/esm/BackendLoggerCategory.js +6 -0
- package/lib/esm/BackendLoggerCategory.js.map +1 -1
- package/lib/esm/BriefcaseManager.d.ts +57 -3
- package/lib/esm/BriefcaseManager.d.ts.map +1 -1
- package/lib/esm/BriefcaseManager.js +152 -43
- package/lib/esm/BriefcaseManager.js.map +1 -1
- package/lib/esm/CloudSqlite.d.ts +4 -0
- package/lib/esm/CloudSqlite.d.ts.map +1 -1
- package/lib/esm/CloudSqlite.js.map +1 -1
- package/lib/esm/ECDb.d.ts +8 -0
- package/lib/esm/ECDb.d.ts.map +1 -1
- package/lib/esm/ECDb.js +22 -0
- package/lib/esm/ECDb.js.map +1 -1
- package/lib/esm/IModelDb.d.ts +54 -3
- package/lib/esm/IModelDb.d.ts.map +1 -1
- package/lib/esm/IModelDb.js +88 -10
- package/lib/esm/IModelDb.js.map +1 -1
- package/lib/esm/IModelHost.d.ts +11 -1
- package/lib/esm/IModelHost.d.ts.map +1 -1
- package/lib/esm/IModelHost.js +5 -0
- package/lib/esm/IModelHost.js.map +1 -1
- package/lib/esm/IModelIncrementalSchemaLocater.d.ts +1 -5
- package/lib/esm/IModelIncrementalSchemaLocater.d.ts.map +1 -1
- package/lib/esm/IModelIncrementalSchemaLocater.js +0 -6
- package/lib/esm/IModelIncrementalSchemaLocater.js.map +1 -1
- package/lib/esm/SqliteChangesetReader.d.ts +8 -0
- package/lib/esm/SqliteChangesetReader.d.ts.map +1 -1
- package/lib/esm/SqliteChangesetReader.js +11 -0
- package/lib/esm/SqliteChangesetReader.js.map +1 -1
- package/lib/esm/StashManager.d.ts +175 -0
- package/lib/esm/StashManager.d.ts.map +1 -0
- package/lib/esm/StashManager.js +301 -0
- package/lib/esm/StashManager.js.map +1 -0
- package/lib/esm/TxnManager.d.ts +226 -15
- package/lib/esm/TxnManager.d.ts.map +1 -1
- package/lib/esm/TxnManager.js +247 -21
- package/lib/esm/TxnManager.js.map +1 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts +10 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.js +13 -5
- package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
- package/lib/esm/annotations/LeaderGeometry.d.ts +3 -2
- package/lib/esm/annotations/LeaderGeometry.d.ts.map +1 -1
- package/lib/esm/annotations/LeaderGeometry.js +5 -4
- package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts +52 -24
- package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.js +51 -61
- package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationGeometry.d.ts +2 -0
- package/lib/esm/annotations/TextAnnotationGeometry.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationGeometry.js +26 -19
- package/lib/esm/annotations/TextAnnotationGeometry.js.map +1 -1
- package/lib/esm/annotations/TextBlockGeometry.d.ts.map +1 -1
- package/lib/esm/annotations/TextBlockGeometry.js +8 -0
- package/lib/esm/annotations/TextBlockGeometry.js.map +1 -1
- package/lib/esm/annotations/TextBlockLayout.d.ts +49 -36
- package/lib/esm/annotations/TextBlockLayout.d.ts.map +1 -1
- package/lib/esm/annotations/TextBlockLayout.js +205 -136
- package/lib/esm/annotations/TextBlockLayout.js.map +1 -1
- package/lib/esm/internal/ChannelAdmin.js +1 -1
- package/lib/esm/internal/ChannelAdmin.js.map +1 -1
- package/lib/esm/internal/Symbols.d.ts +1 -0
- package/lib/esm/internal/Symbols.d.ts.map +1 -1
- package/lib/esm/internal/Symbols.js +1 -0
- package/lib/esm/internal/Symbols.js.map +1 -1
- package/lib/esm/internal/annotations/fields.d.ts +2 -12
- package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
- package/lib/esm/internal/annotations/fields.js +51 -47
- package/lib/esm/internal/annotations/fields.js.map +1 -1
- package/lib/esm/test/AnnotationTestUtils.d.ts +5 -1
- package/lib/esm/test/AnnotationTestUtils.d.ts.map +1 -1
- package/lib/esm/test/AnnotationTestUtils.js +6 -1
- package/lib/esm/test/AnnotationTestUtils.js.map +1 -1
- package/lib/esm/test/annotations/Fields.test.js +163 -46
- package/lib/esm/test/annotations/Fields.test.js.map +1 -1
- package/lib/esm/test/annotations/LeaderGeometry.test.js +12 -10
- package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
- package/lib/esm/test/annotations/TextAnnotation.test.js +299 -43
- package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
- package/lib/esm/test/annotations/TextBlock.test.js +453 -86
- package/lib/esm/test/annotations/TextBlock.test.js.map +1 -1
- package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.d.ts +46 -0
- package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.d.ts.map +1 -1
- package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.js +20 -2
- package/lib/esm/test/assets/IncrementalSchemaLocater/configs/simple.config.js.map +1 -1
- package/lib/esm/test/ecdb/ECDb.test.js +71 -1
- package/lib/esm/test/ecdb/ECDb.test.js.map +1 -1
- package/lib/esm/test/hubaccess/Rebase.test.d.ts +2 -0
- package/lib/esm/test/hubaccess/Rebase.test.d.ts.map +1 -0
- package/lib/esm/test/hubaccess/Rebase.test.js +640 -0
- package/lib/esm/test/hubaccess/Rebase.test.js.map +1 -0
- package/lib/esm/test/incrementalSchemaLocater/ECSqlQueries.test.js +20 -20
- package/lib/esm/test/incrementalSchemaLocater/ECSqlQueries.test.js.map +1 -1
- package/lib/esm/test/incrementalSchemaLocater/IncrementalLoading.test.js +3 -3
- package/lib/esm/test/incrementalSchemaLocater/IncrementalLoading.test.js.map +1 -1
- package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.d.ts +16 -1
- package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.d.ts.map +1 -1
- package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.js +47 -0
- package/lib/esm/test/incrementalSchemaLocater/utils/TestSqlSchemaLocater.js.map +1 -1
- package/lib/esm/test/standalone/ChangeMerge.test.js +15 -19
- package/lib/esm/test/standalone/ChangeMerge.test.js.map +1 -1
- package/lib/esm/test/standalone/ChangesetReader.test.js +131 -1
- package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
- package/lib/esm/test/standalone/MergeConflict.test.js +3 -3
- package/lib/esm/test/standalone/MergeConflict.test.js.map +1 -1
- package/lib/esm/workspace/Workspace.d.ts +1 -1
- package/lib/esm/workspace/Workspace.js.map +1 -1
- package/package.json +13 -13
package/lib/cjs/TxnManager.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module iModels
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TxnManager = exports.
|
|
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
|
-
*
|
|
201
|
-
*
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
210
|
-
|
|
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].
|
|
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.
|
|
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
|
-
|
|
435
|
+
rebaser;
|
|
274
436
|
/** @internal */
|
|
275
437
|
constructor(_iModel) {
|
|
276
438
|
this._iModel = _iModel;
|
|
277
|
-
this.
|
|
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.
|
|
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
|
|
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
|
-
/**
|
|
685
|
+
/**
|
|
686
|
+
* @alpha
|
|
687
|
+
* Event raised when a rebase transaction begins.
|
|
688
|
+
*/
|
|
498
689
|
onRebaseTxnBegin = new core_bentley_1.BeEvent();
|
|
499
|
-
/**
|
|
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
|
|
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.
|
|
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
|