@itwin/imodel-transformer 2.0.0-dev.7 → 2.0.0-dev.70

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 (132) hide show
  1. package/README.md +13 -27
  2. package/lib/cjs/Algo.d.ts +0 -4
  3. package/lib/cjs/Algo.d.ts.map +1 -1
  4. package/lib/cjs/Algo.js +0 -11
  5. package/lib/cjs/Algo.js.map +1 -1
  6. package/lib/cjs/BigMap.d.ts.map +1 -1
  7. package/lib/cjs/BigMap.js.map +1 -1
  8. package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
  9. package/lib/cjs/BranchProvenanceInitializer.js +26 -26
  10. package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
  11. package/lib/cjs/ChangedElementForest.d.ts +14 -0
  12. package/lib/cjs/ChangedElementForest.d.ts.map +1 -0
  13. package/lib/cjs/ChangedElementForest.js +86 -0
  14. package/lib/cjs/ChangedElementForest.js.map +1 -0
  15. package/lib/cjs/ChangesetScanner.d.ts +141 -0
  16. package/lib/cjs/ChangesetScanner.d.ts.map +1 -0
  17. package/lib/cjs/ChangesetScanner.js +187 -0
  18. package/lib/cjs/ChangesetScanner.js.map +1 -0
  19. package/lib/cjs/ECReferenceTypesCache.d.ts +0 -4
  20. package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
  21. package/lib/cjs/ECReferenceTypesCache.js +61 -111
  22. package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
  23. package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +1 -1
  24. package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
  25. package/lib/cjs/ElementAspectCleanup.d.ts +16 -0
  26. package/lib/cjs/ElementAspectCleanup.d.ts.map +1 -0
  27. package/lib/cjs/ElementAspectCleanup.js +87 -0
  28. package/lib/cjs/ElementAspectCleanup.js.map +1 -0
  29. package/lib/cjs/ElementAspectExportCoordinator.d.ts +44 -0
  30. package/lib/cjs/ElementAspectExportCoordinator.d.ts.map +1 -0
  31. package/lib/cjs/ElementAspectExportCoordinator.js +148 -0
  32. package/lib/cjs/ElementAspectExportCoordinator.js.map +1 -0
  33. package/lib/cjs/ElementAspectExportProcessor.d.ts +44 -0
  34. package/lib/cjs/ElementAspectExportProcessor.d.ts.map +1 -0
  35. package/lib/cjs/ElementAspectExportProcessor.js +152 -0
  36. package/lib/cjs/ElementAspectExportProcessor.js.map +1 -0
  37. package/lib/cjs/ElementBulkDelete.d.ts +30 -0
  38. package/lib/cjs/ElementBulkDelete.d.ts.map +1 -0
  39. package/lib/cjs/ElementBulkDelete.js +358 -0
  40. package/lib/cjs/ElementBulkDelete.js.map +1 -0
  41. package/lib/cjs/EntityExistenceCache.d.ts +43 -0
  42. package/lib/cjs/EntityExistenceCache.d.ts.map +1 -0
  43. package/lib/cjs/EntityExistenceCache.js +91 -0
  44. package/lib/cjs/EntityExistenceCache.js.map +1 -0
  45. package/lib/cjs/EntityUnifier.d.ts +7 -7
  46. package/lib/cjs/EntityUnifier.d.ts.map +1 -1
  47. package/lib/cjs/EntityUnifier.js +55 -24
  48. package/lib/cjs/EntityUnifier.js.map +1 -1
  49. package/lib/cjs/IModelCloneContext.d.ts +9 -3
  50. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  51. package/lib/cjs/IModelCloneContext.js +56 -22
  52. package/lib/cjs/IModelCloneContext.js.map +1 -1
  53. package/lib/cjs/IModelExporter.d.ts +171 -43
  54. package/lib/cjs/IModelExporter.d.ts.map +1 -1
  55. package/lib/cjs/IModelExporter.js +946 -247
  56. package/lib/cjs/IModelExporter.js.map +1 -1
  57. package/lib/cjs/IModelImporter.d.ts +75 -30
  58. package/lib/cjs/IModelImporter.d.ts.map +1 -1
  59. package/lib/cjs/IModelImporter.js +292 -132
  60. package/lib/cjs/IModelImporter.js.map +1 -1
  61. package/lib/cjs/IModelTransformContext.d.ts +54 -0
  62. package/lib/cjs/IModelTransformContext.d.ts.map +1 -0
  63. package/lib/cjs/IModelTransformContext.js +3 -0
  64. package/lib/cjs/IModelTransformContext.js.map +1 -0
  65. package/lib/cjs/IModelTransformer.d.ts +180 -206
  66. package/lib/cjs/IModelTransformer.d.ts.map +1 -1
  67. package/lib/cjs/IModelTransformer.js +811 -1278
  68. package/lib/cjs/IModelTransformer.js.map +1 -1
  69. package/lib/cjs/IModelTransformerError.d.ts +84 -0
  70. package/lib/cjs/IModelTransformerError.d.ts.map +1 -0
  71. package/lib/cjs/IModelTransformerError.js +93 -0
  72. package/lib/cjs/IModelTransformerError.js.map +1 -0
  73. package/lib/cjs/ProvenanceManager.d.ts +177 -0
  74. package/lib/cjs/ProvenanceManager.d.ts.map +1 -0
  75. package/lib/cjs/ProvenanceManager.js +719 -0
  76. package/lib/cjs/ProvenanceManager.js.map +1 -0
  77. package/lib/cjs/SourceClassKinds.d.ts +22 -0
  78. package/lib/cjs/SourceClassKinds.d.ts.map +1 -0
  79. package/lib/cjs/SourceClassKinds.js +60 -0
  80. package/lib/cjs/SourceClassKinds.js.map +1 -0
  81. package/lib/cjs/SyncTypeResolver.d.ts +32 -0
  82. package/lib/cjs/SyncTypeResolver.d.ts.map +1 -0
  83. package/lib/cjs/SyncTypeResolver.js +92 -0
  84. package/lib/cjs/SyncTypeResolver.js.map +1 -0
  85. package/lib/cjs/TransformerLoggerCategory.d.ts +1 -1
  86. package/lib/cjs/TransformerLoggerCategory.js +1 -1
  87. package/lib/cjs/TransformerLoggerCategory.js.map +1 -1
  88. package/lib/cjs/TransformerPackageMetadata.d.ts +8 -0
  89. package/lib/cjs/TransformerPackageMetadata.d.ts.map +1 -0
  90. package/lib/cjs/TransformerPackageMetadata.js +47 -0
  91. package/lib/cjs/TransformerPackageMetadata.js.map +1 -0
  92. package/lib/cjs/imodel-transformer.d.ts +28 -0
  93. package/lib/cjs/imodel-transformer.d.ts.map +1 -1
  94. package/lib/cjs/imodel-transformer.js +61 -34
  95. package/lib/cjs/imodel-transformer.js.map +1 -1
  96. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts +29 -0
  97. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +1 -0
  98. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js +212 -0
  99. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js.map +1 -0
  100. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts +25 -0
  101. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts.map +1 -0
  102. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js +196 -0
  103. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js.map +1 -0
  104. package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts +59 -0
  105. package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts.map +1 -0
  106. package/lib/cjs/schema-processing/SchemaProcessingStrategy.js +28 -0
  107. package/lib/cjs/schema-processing/SchemaProcessingStrategy.js.map +1 -0
  108. package/lib/cjs/schema-processing.d.ts +7 -0
  109. package/lib/cjs/schema-processing.d.ts.map +1 -0
  110. package/lib/cjs/schema-processing.js +27 -0
  111. package/lib/cjs/schema-processing.js.map +1 -0
  112. package/package.json +70 -57
  113. package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts +0 -16
  114. package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts.map +0 -1
  115. package/lib/cjs/DetachedExportElementAspectsStrategy.js +0 -106
  116. package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +0 -1
  117. package/lib/cjs/ElementCascadingDeleter.d.ts +0 -22
  118. package/lib/cjs/ElementCascadingDeleter.d.ts.map +0 -1
  119. package/lib/cjs/ElementCascadingDeleter.js +0 -57
  120. package/lib/cjs/ElementCascadingDeleter.js.map +0 -1
  121. package/lib/cjs/EntityMap.d.ts +0 -26
  122. package/lib/cjs/EntityMap.d.ts.map +0 -1
  123. package/lib/cjs/EntityMap.js +0 -54
  124. package/lib/cjs/EntityMap.js.map +0 -1
  125. package/lib/cjs/ExportElementAspectsStrategy.d.ts +0 -35
  126. package/lib/cjs/ExportElementAspectsStrategy.d.ts.map +0 -1
  127. package/lib/cjs/ExportElementAspectsStrategy.js +0 -52
  128. package/lib/cjs/ExportElementAspectsStrategy.js.map +0 -1
  129. package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts +0 -12
  130. package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts.map +0 -1
  131. package/lib/cjs/ExportElementAspectsWithElementsStrategy.js +0 -47
  132. package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +0 -1
@@ -1,11 +1,23 @@
1
- import { Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
1
+ import { GuidString, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
2
2
  import * as ECSchemaMetaData from "@itwin/ecschema-metadata";
3
3
  import { Transform } from "@itwin/core-geometry";
4
- import { Element, ElementAspect, ElementMultiAspect, ElementUniqueAspect, Entity, ExternalSourceAspect, IModelDb, Model, Relationship, RelationshipProps } from "@itwin/core-backend";
4
+ import { EditTxn, Element, ElementAspect, ElementMultiAspect, ElementUniqueAspect, Entity, ExternalSourceAspect, IModelDb, Model, Relationship, RelationshipProps } from "@itwin/core-backend";
5
5
  import { ChangesetIndexAndId, CodeSpec, ElementAspectProps, ElementProps, ExternalSourceAspectProps, FontProps, Helmert2DWithZOffset, ModelProps, Placement2d, Placement3d } from "@itwin/core-common";
6
6
  import { ChangedInstanceIds, ExportChangesOptions, ExportSchemaResult, IModelExporter, IModelExportHandler } from "./IModelExporter";
7
7
  import { IModelImporter, OptimizeGeometryOptions } from "./IModelImporter";
8
- import { IModelCloneContext } from "./IModelCloneContext";
8
+ import type { IModelTransformContext } from "./IModelTransformContext";
9
+ import { ProvenanceManager } from "./ProvenanceManager";
10
+ import { ProcessSchemasOptions } from "./schema-processing/SchemaProcessingStrategy";
11
+ import { CollectedChanges } from "./ChangesetScanner";
12
+ /** Required arguments for the [[IModelTransformer]] constructor.
13
+ * @beta
14
+ */
15
+ export interface IModelTransformArgs {
16
+ /** The source iModel or exporter to read elements from. */
17
+ source: IModelDb | IModelExporter;
18
+ /** The target for the transformation. Pass an [[EditTxn]] to have the transformer create a default [[IModelImporter]], or pass a pre-configured [[IModelImporter]]. */
19
+ target: EditTxn | IModelImporter;
20
+ }
9
21
  /** Options provided to the [[IModelTransformer]] constructor.
10
22
  * @beta
11
23
  * @note if adding an option, you must explicitly add its serialization to [[IModelTransformer.saveStateToFile]]!
@@ -122,6 +134,13 @@ export interface IModelTransformOptions {
122
134
  * @default false
123
135
  */
124
136
  tryAlignGeolocation?: boolean;
137
+ /** An optional [[EditTxn]] for write operations on the **source** iModel.
138
+ * Only needed for reverse synchronization workflows where provenance must be written back to the source.
139
+ * If not provided, the source iModel is treated as read-only.
140
+ * Must be started before calling [[IModelTransformer.process]].
141
+ * @beta
142
+ */
143
+ sourceEditTxn?: EditTxn;
125
144
  }
126
145
  /**
127
146
  * Data type for persisting change version information within provenance Scope ExternalSourceAspect.
@@ -164,7 +183,7 @@ export interface InitOptions {
164
183
  * @beta
165
184
  */
166
185
  export type ProcessChangesOptions = ExportChangesOptions & {
167
- /** how to call saveChanges on the target. Must call targetDb.saveChanges, should not edit the iModel */
186
+ /** how to save changes on the target. Must call `editTxn.saveChanges()` on the target EditTxn, should not edit the iModel */
168
187
  saveTargetChanges?: (transformer: IModelTransformer) => Promise<void>;
169
188
  /**
170
189
  * The forward sync 'version' to set on the scoping ESA @see ExternalSourceAspectProps upon startup, if the version property on the scoping ESA is undefined or empty string.
@@ -202,6 +221,7 @@ export interface RelationshipPropsForDelete {
202
221
  export declare class IModelTransformer extends IModelExportHandler {
203
222
  /** The IModelExporter that will export from the source iModel. */
204
223
  readonly exporter: IModelExporter;
224
+ private readonly _schemaProcessingCoordinator;
205
225
  /** The IModelImporter that will import into the target iModel. */
206
226
  readonly importer: IModelImporter;
207
227
  /** The normally read-only source iModel.
@@ -210,8 +230,10 @@ export declare class IModelTransformer extends IModelExportHandler {
210
230
  readonly sourceDb: IModelDb;
211
231
  /** The read/write target iModel. */
212
232
  readonly targetDb: IModelDb;
213
- /** The IModelTransformContext for this IModelTransformer. */
214
- readonly context: IModelCloneContext;
233
+ /** The supported transformation context for this transformer. */
234
+ get context(): IModelTransformContext;
235
+ /** The clone context used by the transformer implementation. */
236
+ private readonly _cloneContext;
215
237
  /** The transform to be applied to the placement of spatial elements
216
238
  * This transform should be applied when:
217
239
  * - source and target db have different ECEF locations
@@ -221,47 +243,38 @@ export declare class IModelTransformer extends IModelExportHandler {
221
243
  * @beta
222
244
  */
223
245
  private _linearSpatialTransform?;
224
- private _syncType?;
246
+ /** The [[EditTxn]] used for write operations on the target iModel.
247
+ * The caller is responsible for starting, committing or abandoning this transaction.
248
+ * @beta
249
+ */
250
+ protected readonly _targetEditTxn: EditTxn;
251
+ /** The optional [[EditTxn]] used for write operations on the source iModel during reverse synchronization.
252
+ * @beta
253
+ */
254
+ protected readonly _sourceEditTxn?: EditTxn;
255
+ private _syncTypeResolver;
256
+ protected _provenanceManager: ProvenanceManager;
225
257
  /** The Id of the Element in the **target** iModel that represents the **source** repository as a whole and scopes its [ExternalSourceAspect]($backend) instances. */
226
258
  get targetScopeElementId(): Id64String;
227
259
  /** a set of elements for which source provenance will be explicitly tracked by ExternalSourceAspects */
228
260
  protected _elementsWithExplicitlyTrackedProvenance: Set<string>;
229
261
  protected _partiallyCommittedElementIds: Id64Set;
230
262
  protected _partiallyCommittedAspectIds: Id64Set;
231
- /** the options that were used to initialize this transformer */
232
- private readonly _options;
233
263
  /**
234
- * A private variable meant to be set by tests which have an outdated way of setting up transforms. In all synchronizations today we expect to find an ESA in the branch db which describes the master -> branch relationship.
235
- * The exception to this is the first transform aka the provenance initializing transform which requires that the master imodel and the branch imodel are identical at the time of provenance initialization.
236
- * A couple ofoutdated tests run their first transform providing a source and targetdb that are slightly different which is no longer supported. In order to not remove these tests which are still providing value
237
- * this private property on the IModelTransformer exists.
264
+ * Tracks target element IDs that were remapped by Code during the current
265
+ * transformation pass. Used to prevent deletion of target elements that have been remapped
266
+ * to a new source element in the same pass (e.g., when a source element is deleted and a
267
+ * new one with the same properties is added, causing a remap to the same target).
238
268
  */
239
- private _allowNoScopingESA;
240
- static noEsaSyncDirectionErrorMessage: string;
241
- /**
242
- * Queries for an esa which matches the props in the provided aspectProps.
243
- * @param dbToQuery db to run the query on for scope external source
244
- * @param aspectProps aspectProps to search for @see ExternalSourceAspectProps
245
- */
246
- static queryScopeExternalSourceAspect(dbToQuery: IModelDb, aspectProps: ExternalSourceAspectProps): Promise<{
247
- aspectId: Id64String;
248
- version?: string;
249
- /** stringified json */
250
- jsonProperties?: string;
251
- } | undefined>;
269
+ private _targetElementIdsRemappedByCode;
252
270
  /**
253
- * Determines the sync direction "forward" or "reverse" of a given sourceDb and targetDb by looking for the scoping ESA.
254
- * If the sourceDb's iModelId is found as the identifier of the expected scoping ESA in the targetDb, then it is a forward synchronization.
255
- * If the targetDb's iModelId is found as the identifier of the expected scoping ESA in the sourceDb, then it is a reverse synchronization.
256
- * @throws if no scoping ESA can be found in either the sourceDb or targetDb which describes a master branch relationship between the two databases.
257
- * @returns "forward" or "reverse"
258
- */
259
- static determineSyncType(sourceDb: IModelDb, targetDb: IModelDb,
260
- /** @see [[IModelTransformOptions.targetScopeElementId]] */
261
- targetScopeElementId: Id64String): Promise<"forward" | "reverse">;
262
- private determineSyncType;
263
- getIsReverseSynchronization(): Promise<boolean>;
264
- getIsForwardSynchronization(): Promise<boolean>;
271
+ * Tracks target model IDs that were imported (inserted or updated) during the current
272
+ * transformation pass. Used to prevent deletion of target models that have been recreated
273
+ * in the same pass (e.g. when a partition element is recreated with a new model).
274
+ */
275
+ private _targetModelsImportedInCurrentTransform;
276
+ /** the options that were used to initialize this transformer */
277
+ private readonly _options;
265
278
  private _changesetRanges;
266
279
  /**
267
280
  * Set if the transformer is being used to perform the provenance initialization step of a fork initialization.
@@ -273,11 +286,10 @@ export declare class IModelTransformer extends IModelExportHandler {
273
286
  /** The element aspect classes that are considered to define provenance in the iModel */
274
287
  static get provenanceElementAspectClasses(): (typeof Entity)[];
275
288
  /** Construct a new IModelTransformer
276
- * @param source Specifies the source IModelExporter or the source IModelDb that will be used to construct the source IModelExporter.
277
- * @param target Specifies the target IModelImporter or the target IModelDb that will be used to construct the target IModelImporter.
289
+ * @param args The required arguments including source and target.
278
290
  * @param options The options that specify how the transformation should be done.
279
291
  */
280
- constructor(source: IModelDb | IModelExporter, target: IModelDb | IModelImporter, options?: IModelTransformOptions);
292
+ constructor(args: IModelTransformArgs, options?: IModelTransformOptions);
281
293
  /** validates that the importer set on the transformer has the same values for its shared options as the transformer.
282
294
  * @note This expects that the importer is already set on the transformer.
283
295
  */
@@ -286,28 +298,6 @@ export declare class IModelTransformer extends IModelExportHandler {
286
298
  dispose(): void;
287
299
  /** Log current settings that affect IModelTransformer's behavior. */
288
300
  private logSettings;
289
- /** Return the IModelDb where IModelTransformer will store its provenance.
290
- * @note This will be [[targetDb]] except when it is a reverse synchronization. In that case it be [[sourceDb]].
291
- */
292
- provenanceDb(): Promise<IModelDb>;
293
- /** Return the IModelDb where IModelTransformer looks for entities referred to by stored provenance.
294
- * @note This will be [[sourceDb]] except when it is a reverse synchronization. In that case it be [[targetDb]].
295
- */
296
- provenanceSourceDb(): Promise<IModelDb>;
297
- /** Create an ExternalSourceAspectProps in a standard way for an Element in an iModel --> iModel transformation. */
298
- static initElementProvenanceOptions(sourceElementId: Id64String, targetElementId: Id64String, args: {
299
- sourceDb: IModelDb;
300
- targetDb: IModelDb;
301
- isReverseSynchronization: boolean;
302
- targetScopeElementId: Id64String;
303
- }): ExternalSourceAspectProps;
304
- static initRelationshipProvenanceOptions(sourceRelInstanceId: Id64String, targetRelInstanceId: Id64String, args: {
305
- sourceDb: IModelDb;
306
- targetDb: IModelDb;
307
- isReverseSynchronization: boolean;
308
- targetScopeElementId: Id64String;
309
- forceOldRelationshipProvenanceMethod: boolean;
310
- }): Promise<ExternalSourceAspectProps>;
311
301
  /**
312
302
  * Previously the transformer would insert provenance always pointing to the "target" relationship.
313
303
  * It should (and now by default does) instead insert provenance pointing to the provenanceSource
@@ -317,26 +307,6 @@ export declare class IModelTransformer extends IModelExportHandler {
317
307
  private _forceOldRelationshipProvenanceMethod;
318
308
  /** Create an ExternalSourceAspectProps in a standard way for an Element in an iModel --> iModel transformation. */
319
309
  initElementProvenance(sourceElementId: Id64String, targetElementId: Id64String): Promise<ExternalSourceAspectProps>;
320
- /** Create an ExternalSourceAspectProps in a standard way for a Relationship in an iModel --> iModel transformations.
321
- * The ExternalSourceAspect is meant to be owned by the Element in the target iModel that is the `sourceId` of transformed relationship.
322
- * The `identifier` property of the ExternalSourceAspect will be the ECInstanceId of the relationship in the master iModel.
323
- * The ECInstanceId of the relationship in the branch iModel will be stored in the JsonProperties of the ExternalSourceAspect.
324
- */
325
- private initRelationshipProvenance;
326
- /** NOTE: the json properties must be converted to string before insertion */
327
- private _targetScopeProvenanceProps;
328
- /**
329
- * Index of the changeset that the transformer was at when the transformation begins (was constructed).
330
- * Used to determine at the end which changesets were part of a synchronization.
331
- */
332
- private _startingChangesetIndices;
333
- private _cachedSynchronizationVersion;
334
- /**
335
- * We cache the synchronization version to avoid querying the target scoping ESA multiple times.
336
- * If the target scoping ESA is ever updated we need to clear any potentially cached sync version otherwise we will get stale values.
337
- * Sets this._cachedSynchronizationVersion to undefined.
338
- */
339
- private clearCachedSynchronizationVersion;
340
310
  /** the changeset in the scoping element's source version found for this transformation
341
311
  * @note the version depends on whether this is a reverse synchronization or not, as
342
312
  * it is stored separately for both synchronization directions.
@@ -344,7 +314,7 @@ export declare class IModelTransformer extends IModelExportHandler {
344
314
  * @note empty string and -1 for changeset and index if it was transformed before federation guid update (pre 1.x) and @see [[IModelTransformOptions.branchRelationshipDataBehavior]] === "unsafe-migrate".
345
315
  * @throws if the version is not found in a preexisting scope aspect and @see [[IModelTransformOptions.branchRelationshipDataBehavior]] !== "unsafe-migrate"
346
316
  */
347
- protected synchronizationVersion(): Promise<ChangesetIndexAndId>;
317
+ protected getSynchronizationVersion(): Promise<ChangesetIndexAndId>;
348
318
  /**
349
319
  * @returns provenance scope aspect if it exists in the provenanceDb.
350
320
  * Provenance scope aspect is created and inserted into provenanceDb when [[initScopeProvenance]] is invoked.
@@ -353,63 +323,32 @@ export declare class IModelTransformer extends IModelExportHandler {
353
323
  /**
354
324
  * Make sure there are no conflicting other scope-type external source aspects on the *target scope element*,
355
325
  * If there are none at all, insert one, then this must be a first synchronization.
356
- * @returns the last synced version (changesetId) on the target scope's external source aspect,
357
- * if this was a [BriefcaseDb]($backend)
358
326
  */
359
327
  protected initScopeProvenance(): Promise<void>;
360
- /** Returns true if a change was made to the aspectProps. */
361
- private handleUnsafeMigrate;
362
328
  /**
363
- * Iterate all matching federation guids and ExternalSourceAspects in the provenance iModel (target unless reverse sync)
364
- * and call a function for each one.
365
- * @note provenance is done by federation guids where possible
366
- * @note this may execute on each element more than once! Only use in cases where that is handled
367
- */
368
- static forEachTrackedElement(args: {
369
- provenanceSourceDb: IModelDb;
370
- provenanceDb: IModelDb;
371
- targetScopeElementId: Id64String;
372
- isReverseSynchronization: boolean;
373
- fn: (sourceElementId: Id64String, targetElementId: Id64String) => void;
374
- skipPropagateChangesToRootElements: boolean;
375
- }): Promise<void>;
376
- private forEachTrackedElement;
329
+ * Get the IModelDb where provenance (ExternalSourceAspects) is stored.
330
+ * This will be targetDb except when it is a reverse synchronization, in which case it will be sourceDb.
331
+ */
332
+ getProvenanceDb(): Promise<IModelDb>;
377
333
  /**
378
- * Queries the provenanceDb for an ESA whose identifier is equal to the provided 'entityInProvenanceSourceId'.
379
- * The identifier on the ESA is the id of the element in the [[IModelTransformer.provenanceSourceDb]]
380
- * Therefore it only makes sense to call this function when you have an id in the provenanceSourceDb.
381
- * @param entityInProvenanceSourceId
382
- * @returns the elementId that the ESA is stored on, esa.Element.Id
334
+ * Get whether this is a reverse synchronization.
383
335
  */
384
- private _queryProvenanceForElement;
336
+ getIsReverseSynchronization(): Promise<boolean>;
337
+ /**
338
+ * Get whether this is a forward synchronization.
339
+ */
340
+ getIsForwardSynchronization(): Promise<boolean>;
385
341
  /**
386
- * Queries the provenanceDb for an ESA whose identifier is equal to the provided 'entityInProvenanceSourceId'.
387
- * The identifier on the ESA is the id of the relationship in the [[IModelTransformer.provenanceSourceDb]]
388
- * Therefore it only makes sense to call this function when you have an id in the provenanceSourceDb.
389
- * @param entityInProvenanceSourceId
390
- * @returns
391
- */
392
- private _queryProvenanceForRelationship;
393
- private _queryTargetRelId;
394
- private _targetClassNameToClassIdCache;
395
- private _targetClassNameToClassId;
396
- private _getRelClassId;
397
- private _queryElemIdByFedGuid;
342
+ * Updates the synchronization version on the scope ESA.
343
+ */
344
+ updateSynchronizationVersion({ initializeReverseSyncVersion, }?: {
345
+ initializeReverseSyncVersion?: boolean | undefined;
346
+ }): Promise<void>;
398
347
  /** Returns `true` if *brute force* delete detections should be run.
399
348
  * @note This is only called if [[IModelTransformOptions.forceExternalSourceAspectProvenance]] option is true
400
349
  * @note Not relevant for [[process]] when [[IModelTransformOptions.argsForProcessChanges]] are provided and change history is known.
401
350
  */
402
- protected shouldDetectDeletes(): boolean;
403
- /**
404
- * Detect Element deletes using ExternalSourceAspects in the target iModel and a *brute force* comparison against Elements
405
- * in the source iModel.
406
- * deprecated in 1.x. Do not use this. // FIXME<MIKE>: how to better explain this?
407
- * This method is only called during [[process]] when [[IModelTransformOptions.argsForProcessChanges]] is undefined and the option
408
- * [[IModelTransformOptions.forceExternalSourceAspectProvenance]] is enabled. It is not
409
- * necessary when calling [[process]] with [[IModelTransformOptions.argsForProcessChanges]] defined, since changeset information is sufficient.
410
- * @note you do not need to call this directly unless processing a subset of an iModel.
411
- * @throws [[IModelError]] If the required provenance information is not available to detect deletes.
412
- */
351
+ protected shouldDetectDeletes(): Promise<boolean>;
413
352
  /** Transform the specified sourceElement into ElementProps for the target iModel.
414
353
  * @param sourceElement The Element from the source iModel to transform.
415
354
  * @returns ElementProps for the target iModel.
@@ -428,47 +367,75 @@ export declare class IModelTransformer extends IModelExportHandler {
428
367
  static convertHelmertToTransform(helmert: Helmert2DWithZOffset | undefined): Transform;
429
368
  calculateTransformFromHelmertTransforms(): Transform | undefined;
430
369
  private _deletedSourceRelationshipData?;
370
+ /** Target relationship ids and target endpoint keys of [[_deletedSourceRelationshipData]] entries, for fast matching in [[onExportRelationship]]. */
371
+ private _pendingRelationshipDeleteTargets;
372
+ /** Target relationships that this run imported from a source relationship and that a pending relationship delete also resolves to.
373
+ * A source relationship deleted and recreated with the same endpoints maps to the same target relationship, which must not be deleted.
374
+ */
375
+ private _reimportedTargetRelationshipIds;
431
376
  /** Returns true if a change within sourceElement is detected.
432
377
  * @param sourceElement The Element from the source iModel
433
378
  * @note A subclass can override this method to provide custom change detection behavior.
379
+ * @note During change processing, elements not present in the changeset are short-circuited
380
+ * in the exporter before reaching this method. To add elements to the changeset programmatically,
381
+ * use [[addCustomChanges]] rather than overriding this method to expand processing.
434
382
  */
435
383
  protected hasElementChanged(sourceElement: Element): boolean;
436
384
  protected completePartiallyCommittedElements(): Promise<void>;
437
385
  protected completePartiallyCommittedAspects(): Promise<void>;
386
+ /** An exported source element or model exists, so later references to it need no source query.
387
+ * Aspects are not recorded: they are rarely referenced, and they are usually the largest group.
388
+ */
389
+ private markSourceEntityExists;
438
390
  private doAllReferencesExistInTarget;
439
- private assertReferenceExistsInSource;
391
+ /** Assert that all `referenceIds` exist in the source iModel, batching the existence
392
+ * queries by entity type and caching positive results for the rest of the run.
393
+ */
394
+ private assertReferencesExistInSource;
440
395
  /** Cause the specified Element and its child Elements (if applicable) to be exported from the source iModel and imported into the target iModel.
441
396
  * @param sourceElementId Identifies the Element from the source iModel to import.
442
397
  * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
398
+ * @note After composing subset processing calls, call [[IModelImporter.finalize]] before saving target changes.
443
399
  */
444
400
  processElement(sourceElementId: Id64String): Promise<void>;
445
401
  /** Import child elements into the target IModelDb
446
402
  * @param sourceElementId Import the child elements of this element in the source IModelDb.
447
403
  * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
404
+ * @note After composing subset processing calls, call [[IModelImporter.finalize]] before saving target changes.
448
405
  */
449
406
  processChildElements(sourceElementId: Id64String): Promise<void>;
407
+ private processScopedElementExport;
450
408
  /** Override of [IModelExportHandler.shouldExportElement]($transformer) that is called to determine if an element should be exported from the source iModel.
451
409
  * @note Reaching this point means that the element has passed the standard exclusion checks in IModelExporter.
452
410
  */
453
- shouldExportElement(_sourceElement: Element): boolean;
411
+ shouldExportElement(_sourceElement: Element): Promise<boolean>;
454
412
  /**
455
413
  * If they haven't been already, import all of the required references
456
414
  * @internal do not call, override or implement this, it will be removed
457
415
  */
458
416
  preExportElement(sourceElement: Element): Promise<void>;
417
+ /** Makes sure an element that a changed element requires is mapped in the target before the changed element is imported.
418
+ * A changed required element is exported. An unchanged one is only looked up in the target: change processing does not insert it, and exporting it would visit its children, which can include the element that requires it.
419
+ * @throws [[IModelTransformerError.DependencyMappingMissing]] if the required element is still not mapped.
420
+ */
421
+ private resolveRequiredElement;
422
+ /** Finds the existing target element for a source element by FederationGuid, then by Code, and records the mapping.
423
+ * @note Updates `targetElementProps.code` as the Code lookup requires.
424
+ * @returns the target element's id, or `Id64.invalid` if none is found.
425
+ */
426
+ private findExistingTargetElement;
459
427
  private getElemTransformState;
428
+ private queryElementIdByCode;
460
429
  /** Override of [IModelExportHandler.onExportElement]($transformer) that imports an element into the target iModel when it is exported from the source iModel.
461
430
  * This override calls [[onTransformElement]] and then [IModelImporter.importElement]($transformer) to update the target iModel.
462
431
  */
463
432
  onExportElement(sourceElement: Element): Promise<void>;
464
- /** Override of [IModelExportHandler.onDeleteElement]($transformer) that is called when [IModelExporter]($transformer) detects that an Element has been deleted from the source iModel.
465
- * This override propagates the delete to the target iModel via [IModelImporter.deleteElement]($transformer).
466
- */
467
- onDeleteElement(sourceElementId: Id64String): void;
433
+ /** Maps the deleted source element IDs and passes the target IDs to the importer as one set. */
434
+ onDeleteElements(sourceElementIds: ReadonlySet<Id64String>): Promise<void>;
468
435
  /** Override of [IModelExportHandler.onExportModel]($transformer) that is called when a Model should be exported from the source iModel.
469
436
  * This override calls [[onTransformModel]] and then [IModelImporter.importModel]($transformer) to update the target iModel.
470
437
  */
471
- onExportModel(sourceModel: Model): void;
438
+ onExportModel(sourceModel: Model): Promise<void>;
472
439
  /** Override of [IModelExportHandler.onDeleteModel]($transformer) that is called when [IModelExporter]($transformer) detects that a [Model]($backend) has been deleted from the source iModel. */
473
440
  onDeleteModel(sourceModelId: Id64String): Promise<void>;
474
441
  /** Schedule modeled partition deletion */
@@ -476,6 +443,7 @@ export declare class IModelTransformer extends IModelExportHandler {
476
443
  /** Cause the model container, contents, and sub-models to be exported from the source iModel and imported into the target iModel.
477
444
  * @param sourceModeledElementId Import this [Model]($backend) from the source IModelDb.
478
445
  * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
446
+ * @note After composing subset processing calls, call [[IModelImporter.finalize]] before saving target changes.
479
447
  */
480
448
  processModel(sourceModeledElementId: Id64String): Promise<void>;
481
449
  /** Cause the model contents to be exported from the source iModel and imported into the target iModel.
@@ -483,6 +451,7 @@ export declare class IModelTransformer extends IModelExportHandler {
483
451
  * @param targetModelId Import into this model in the target IModelDb. The target model must exist prior to this call.
484
452
  * @param elementClassFullName Optional classFullName of an element subclass to limit import query against the source model.
485
453
  * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
454
+ * @note After composing subset processing calls, call [[IModelImporter.finalize]] before saving target changes.
486
455
  */
487
456
  processModelContents(sourceModelId: Id64String, targetModelId: Id64String, elementClassFullName?: string): Promise<void>;
488
457
  /** Cause all sub-models that recursively descend from the specified Subject to be exported from the source iModel and imported into the target iModel. */
@@ -494,59 +463,35 @@ export declare class IModelTransformer extends IModelExportHandler {
494
463
  * @note A subclass can override this method to provide custom transform behavior.
495
464
  */
496
465
  onTransformModel(sourceModel: Model, targetModeledElementId: Id64String): ModelProps;
497
- /**
498
- * Called at the end of a transformation,
499
- * updates the target scope element to say that transformation up through the
500
- * source's changeset has been performed. Also stores all changesets that occurred
501
- * during the transformation as "pending synchronization changeset indices" @see TargetScopeProvenanceJsonProps
502
- *
503
- * You generally should not call this function yourself and use [[process]] with [[IModelTransformOptions.argsForProcessChanges]] provided instead.
504
- * It is public for unsupported use cases of custom synchronization transforms.
505
- * @note If [[IModelTransformOptions.argsForProcessChanges]] is not defined in this transformation, this function will return early without updating the sync version,
506
- * unless the `initializeReverseSyncVersion` option is set to `true`
507
- *
508
- * The `initializeReverseSyncVersion` is added to set the reverse synchronization version during a forward synchronization.
509
- * When set to `true`, it saves the reverse sync version as the current changeset of the targetDb. This is typically used for the first transformation between a master and branch iModel.
510
- * Setting `initializeReverseSyncVersion` to `true` has the effect of making it so any changesets in the branch iModel at the time of the first transformation will be ignored during any future reverse synchronizations from the branch to the master iModel.
511
- *
512
- * Note that typically, the reverseSyncVersion is saved as the last changeset merged from the branch into master.
513
- * Setting initializeReverseSyncVersion to true during a forward transformation could overwrite this correct reverseSyncVersion and should only be done during the first transformation between a master and branch iModel.
514
- */
515
- updateSynchronizationVersion({ initializeReverseSyncVersion, }?: {
516
- initializeReverseSyncVersion?: boolean | undefined;
517
- }): Promise<void>;
466
+ /** Complete a high-level transformation after all export operations finish. */
518
467
  private finalizeTransformation;
468
+ private setCodeValueBehavior;
519
469
  /** Imports all relationships that subclass from the specified base class.
520
470
  * @param baseRelClassFullName The specified base relationship class.
521
471
  * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
472
+ * @note After composing subset processing calls, call [[IModelImporter.finalize]] before saving target changes.
522
473
  */
523
474
  processRelationships(baseRelClassFullName: string): Promise<void>;
524
475
  /** Override of [IModelExportHandler.shouldExportRelationship]($transformer) that is called to determine if a [Relationship]($backend) should be exported.
525
476
  * @note Reaching this point means that the relationship has passed the standard exclusion checks in [IModelExporter]($transformer).
526
477
  */
527
- shouldExportRelationship(_sourceRelationship: Relationship): boolean;
478
+ shouldExportRelationship(_sourceRelationship: Relationship): Promise<boolean>;
528
479
  /** Override of [IModelExportHandler.onExportRelationship]($transformer) that imports a relationship into the target iModel when it is exported from the source iModel.
529
480
  * This override calls [[onTransformRelationship]] and then [IModelImporter.importRelationship]($transformer) to update the target iModel.
530
481
  */
531
- onExportRelationship(sourceRelationship: Relationship): Promise<void>;
482
+ onExportRelationship(sourceRelationship: Relationship, _isUpdate?: boolean, sourceFedGuid?: GuidString, targetFedGuid?: GuidString): Promise<void>;
532
483
  /** Override of [IModelExportHandler.onDeleteRelationship]($transformer) that is called when [IModelExporter]($transformer) detects that a [Relationship]($backend) has been deleted from the source iModel.
533
484
  * This override propagates the delete to the target iModel via [IModelImporter.deleteRelationship]($transformer).
534
485
  */
535
486
  onDeleteRelationship(sourceRelInstanceId: Id64String): Promise<void>;
536
- private _yieldManager;
537
- /** Detect Relationship deletes using ExternalSourceAspects in the target iModel and a *brute force* comparison against relationships in the source iModel.
538
- * @deprecated in 1.x. Don't use this anymore
539
- * @see [[process]] with [[IModelTransformOptions.argsForProcessChanges]] provided.
540
- * @note This method is called from [[process]] when [[IModelTransformOptions.argsForProcessChanges]] are undefined, so it only needs to be called directly when processing a subset of an iModel.
541
- * @throws [[IModelError]] If the required provenance information is not available to detect deletes.
542
- */
543
487
  /** Transform the specified sourceRelationship into RelationshipProps for the target iModel.
544
488
  * @param sourceRelationship The Relationship from the source iModel to be transformed.
545
489
  * @returns RelationshipProps for the target iModel.
546
490
  * @note A subclass can override this method to provide custom transform behavior.
547
491
  */
548
492
  protected onTransformRelationship(sourceRelationship: Relationship): RelationshipProps;
549
- shouldExportElementAspect(aspect: ElementAspect): boolean;
493
+ shouldExportElementAspect(aspect: ElementAspect): Promise<boolean>;
494
+ private prepareElementAspects;
550
495
  /** Override of [IModelExportHandler.onExportElementUniqueAspect]($transformer) that imports an ElementUniqueAspect into the target iModel when it is exported from the source iModel.
551
496
  * This override calls [[onTransformElementAspect]] and then [IModelImporter.importElementUniqueAspect]($transformer) to update the target iModel.
552
497
  */
@@ -567,29 +512,25 @@ export declare class IModelTransformer extends IModelExportHandler {
567
512
  /** Override of [IModelExportHandler.shouldExportSchema]($transformer) that is called to determine if a schema should be exported
568
513
  * @note the default behavior doesn't import schemas older than those already in the target
569
514
  */
570
- shouldExportSchema(schemaKey: ECSchemaMetaData.SchemaKey): boolean;
571
- private _longNamedSchemasMap;
572
- /** Override of [IModelExportHandler.onExportSchema]($transformer) that serializes a schema to disk for [[processSchemas]] to import into
573
- * the target iModel when it is exported from the source iModel.
574
- * @returns {Promise<ExportSchemaResult>} Although the type is possibly void for backwards compatibility of subclasses,
575
- * `IModelTransformer.onExportSchema` always returns an[[IModelExportHandler.ExportSchemaResult]]
576
- * with a defined `schemaPath` property, for subclasses to know where the schema was written.
577
- * Schemas are *not* guaranteed to be written to [[IModelTransformer._schemaExportDir]] by a
578
- * known pattern derivable from the schema's name, so you must use this to find it.
515
+ shouldExportSchema(schemaKey: ECSchemaMetaData.SchemaKey): Promise<boolean>;
516
+ /** Serialize a source schema to the temporary directory used by [[processSchemas]].
517
+ * @returns A path to the serialized schema file.
518
+ * @note The file name is not derived reliably from the schema name. Use the returned path when a subclass calls `super`.
579
519
  */
580
520
  onExportSchema(schema: ECSchemaMetaData.Schema): Promise<void | ExportSchemaResult>;
581
- private _makeLongNameResolvingSchemaCtx;
582
- /** Cause all schemas to be exported from the source iModel and imported into the target iModel.
521
+ /** Process source schemas and import selected or generated definitions into the target iModel.
522
+ * @param options Selects the schema processing strategy.
523
+ * @note When no strategy is supplied, [[NewerVersionSchemaImportStrategy]] is used.
583
524
  * @note For performance reasons, it is recommended that [IModelDb.saveChanges]($backend) be called after `processSchemas` is complete.
584
525
  * It is more efficient to process *data* changes after the schema changes have been saved.
585
526
  */
586
- processSchemas(): Promise<void>;
527
+ processSchemas(options?: ProcessSchemasOptions): Promise<void>;
587
528
  /** Cause all fonts to be exported from the source iModel and imported into the target iModel.
588
529
  * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
589
530
  */
590
531
  processFonts(): Promise<void>;
591
532
  /** Override of [IModelExportHandler.onExportFont]($transformer) that imports a font into the target iModel when it is exported from the source iModel. */
592
- onExportFont(font: FontProps, _isUpdate: boolean | undefined): void;
533
+ onExportFont(font: FontProps, _isUpdate: boolean | undefined): Promise<void>;
593
534
  /** Cause all CodeSpecs to be exported from the source iModel and imported into the target iModel.
594
535
  * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
595
536
  */
@@ -601,16 +542,17 @@ export declare class IModelTransformer extends IModelExportHandler {
601
542
  /** Override of [IModelExportHandler.shouldExportCodeSpec]($transformer) that is called to determine if a CodeSpec should be exported from the source iModel.
602
543
  * @note Reaching this point means that the CodeSpec has passed the standard exclusion checks in [IModelExporter]($transformer).
603
544
  */
604
- shouldExportCodeSpec(_sourceCodeSpec: CodeSpec): boolean;
545
+ shouldExportCodeSpec(_sourceCodeSpec: CodeSpec): Promise<boolean>;
605
546
  /** Override of [IModelExportHandler.onExportCodeSpec]($transformer) that imports a CodeSpec into the target iModel when it is exported from the source iModel. */
606
- onExportCodeSpec(sourceCodeSpec: CodeSpec): void;
607
- /** Recursively import all Elements and sub-Models that descend from the specified Subject */
547
+ onExportCodeSpec(sourceCodeSpec: CodeSpec): Promise<void>;
548
+ /** Recursively import all Elements and sub-Models that descend from the specified Subject.
549
+ * @note After composing subset processing calls, call [[IModelImporter.finalize]] before saving target changes.
550
+ */
608
551
  processSubject(sourceSubjectId: Id64String, targetSubjectId: Id64String): Promise<void>;
609
552
  /** state to prevent reinitialization, @see [[initialize]] */
610
553
  private _initialized;
611
554
  private _sourceChangeDataState;
612
- /** length === 0 when _changeDataState = "no-change", length > 0 means "has-changes", otherwise undefined */
613
- private _csFileProps?;
555
+ private _deletionBatches?;
614
556
  /**
615
557
  * Initialize prerequisites of processing, you must initialize with an [[InitOptions]] if you
616
558
  * are intending to process changes. Callers may wish to explicitly call initialize if they need to execute code after initialize but before [[process]] is called.
@@ -618,13 +560,34 @@ export declare class IModelTransformer extends IModelExportHandler {
618
560
  * Overriders must call `super.initialize()` first
619
561
  */
620
562
  initialize(): Promise<void>;
563
+ private initializeChangesetScanAndExporter;
621
564
  /**
622
- * Reads all the changeset files in the private member of the transformer: _csFileProps
623
- * and finds the corresponding target entity for any deleted source entities and remaps the sourceId to the targetId.
624
- * This function returns early if csFileProps is undefined or is of length 0.
625
- * @returns void
565
+ * Reads the source changes for the changeset ranges being processed. Override to supply changes from another
566
+ * source, such as a precomputed cache, instead of downloading and reading changesets.
567
+ *
568
+ * An override can supply some ranges itself and pass the rest to `super.collectChanges()`. Pass the same
569
+ * `changedInstanceIds` to every call and handle the ranges in order, so that changes to the same instance in
570
+ * different ranges combine correctly. Use [[ChangedInstanceIds.addChangeRecord]] to add each supplied change.
571
+ * See [Supplying source changes]($docs/learning/transformer/change-scanning.md) for the full contract and an example.
572
+ * @param ranges Ordered, inclusive `[first, last]` changeset index ranges. They already exclude changesets
573
+ * that must be skipped, such as those pushed by a previous synchronization in the other direction, so an
574
+ * override must cover exactly these ranges.
575
+ * @param changedInstanceIds Receives the changes read from the ranges. Defaults to a new, empty instance.
576
+ * @returns The changed instance IDs to export and the records used to find the targets of deleted instances.
577
+ * See [[CollectedChanges]] for what the result must include.
578
+ * @note The default implementation downloads the changesets, reads them with `ChangesetReader`, and returns one
579
+ * deletion batch per range.
580
+ * @note Not called when the exporter already has changed instance IDs, for example when `changedInstanceIds`
581
+ * is passed in [[IModelTransformOptions.argsForProcessChanges]]. The transformer then still downloads and reads
582
+ * the changesets to find deletion records.
583
+ * @beta
584
+ */
585
+ protected collectChanges(ranges: readonly (readonly [number, number])[], changedInstanceIds?: ChangedInstanceIds): Promise<CollectedChanges>;
586
+ /**
587
+ * Remaps tracked elements, adds custom changes, and remaps deleted source entities to their targets using the
588
+ * deletion batches read for the changeset ranges being processed.
626
589
  */
627
- private processChangesets;
590
+ private prepareSourceChanges;
628
591
  /**
629
592
  * This will be called when transformer is called with [[IModelTransformOptions.argsForProcessChanges]] to process changes.
630
593
  * It will be executed after changes in changesets are populated into `sourceDbChanges` and before data processing begins.
@@ -635,17 +598,33 @@ export declare class IModelTransformer extends IModelExportHandler {
635
598
  */
636
599
  protected addCustomChanges(_sourceDbChanges: ChangedInstanceIds): Promise<void>;
637
600
  /**
638
- * Helper function for processChangesets. Remaps the id of element deleted found in the 'change' to an element in the targetDb.
639
- * @param change the change to process, must be of changeType "Deleted"
640
- * @param mapOfDeletedElemIdToScopeEsas a map of elementIds to changedECInstances (which are ESAs). the elementId is not the id of the esa itself, but the elementid that the esa was stored on before the esa's deletion.
641
- * All ESAs in this map are part of the transformer's scope / ESA data and are tracked in case the ESA is deleted in the target.
642
- * @param isRelationship is relationship or not
601
+ * Finds the target ID of a source element while processing deletions, first through the transformation's
602
+ * ExternalSourceAspects when the source holds the provenance, then through the federation GUID. The element may be
603
+ * deleted itself, or be a surviving endpoint of a deleted relationship.
604
+ * @param sourceId the source element ID.
605
+ * @param federationGuid the source element's federation GUID, if known.
606
+ * @param deletedScopeEsaByElementId this transformation scope's deleted ESAs in the same batch, keyed by the ID of the element that owned each one.
607
+ */
608
+ private findTargetElementIdForDeletion;
609
+ /**
610
+ * Helper function for [[prepareSourceChanges]]. Records how to find the target relationship of a deleted source relationship.
611
+ * @param deletion the deleted source relationship.
612
+ * @param deletedScopeEsaByElementId this transformation scope's deleted ESAs in the same batch, keyed by the ID of the element that owned each one.
613
+ * @param deletedFederationGuidByElementId federation GUIDs of the elements deleted in the same batch, for endpoints that no longer exist in the source.
614
+ */
615
+ private processDeletedRelationship;
616
+ /**
617
+ * Helper function for [[prepareSourceChanges]]. Remaps a deleted source element or model to its target.
618
+ * @param sourceId the deleted source element or model.
619
+ * @param federationGuid the deleted source element's federation GUID, if it had one. Undefined for models.
620
+ * @param deletedScopeEsaByElementId this transformation scope's deleted ESAs in the same batch, keyed by the ID of the element that owned each one.
643
621
  * @param alreadyImportedElementInserts used to handle entity recreation and not delete already handled element inserts.
644
622
  * @param alreadyImportedModelInserts used to handle entity recreation and not delete already handled model inserts.
645
- * @returns void
646
623
  */
647
- private processDeletedOp;
624
+ private processDeletedElement;
648
625
  private _tryInitChangesetData;
626
+ /** Asserts that the EditTxn is active before any write operations. */
627
+ private assertEditTxnActive;
649
628
  /**
650
629
  * The behavior of process is influenced by [[IModelTransformOptions.argsForProcessChanges]] being defined or not defined during construction passed of the IModelTransformer.
651
630
  * @section When argsForProcessChanges are defined:
@@ -674,9 +653,6 @@ export declare class IModelTransformer extends IModelExportHandler {
674
653
  * @note [[processSchemas]] is not called automatically since the target iModel may want a different collection of schemas.
675
654
  */
676
655
  private processAll;
677
- /** previous provenance, either a federation guid, a `${sourceFedGuid}/${targetFedGuid}` pair, or required aspect props */
678
- private _lastProvenanceEntityInfo;
679
- private markLastProvenance;
680
656
  /** Export changes from the source iModel and import the transformed entities into the target iModel.
681
657
  * Inserts, updates, and deletes are determined by inspecting the changeset(s).
682
658
  * @note the transformer assumes that you saveChanges after processing changes. You should not
@@ -707,12 +683,10 @@ export declare class TemplateModelCloner extends IModelTransformer {
707
683
  /** Accumulates the mapping of sourceElementIds to targetElementIds from the elements in the template model that were cloned. */
708
684
  private _sourceIdToTargetIdMap?;
709
685
  /** Construct a new TemplateModelCloner
710
- * @param sourceDb The source IModelDb that contains the templates to clone
711
- * @param targetDb Optionally specify the target IModelDb where the cloned template will be inserted.
712
- * Typically this is left unspecified, and the default is to use the sourceDb as the target
686
+ * @param editTxn The [[EditTxn]] to use for all read and write operations. The source and target db are both derived from `editTxn.iModel`. Must be started before constructing.
713
687
  * @note The expectation is that the template definitions are within the same iModel where instances will be placed.
714
688
  */
715
- constructor(sourceDb: IModelDb, targetDb?: IModelDb);
689
+ constructor(editTxn: EditTxn);
716
690
  /** Place a template from the sourceDb at the specified placement in the target model within the targetDb.
717
691
  * @param sourceTemplateModelId The Id of the template model in the sourceDb
718
692
  * @param targetModelId The Id of the target model (must be a subclass of GeometricModel3d) where the cloned component will be inserted.