@itwin/imodel-transformer 1.0.1-dev.0 → 1.1.1-dev.0

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 (50) hide show
  1. package/CHANGELOG.md +49 -1
  2. package/README.md +17 -0
  3. package/lib/cjs/Algo.d.ts +7 -0
  4. package/lib/cjs/Algo.d.ts.map +1 -1
  5. package/lib/cjs/Algo.js +7 -0
  6. package/lib/cjs/Algo.js.map +1 -1
  7. package/lib/cjs/BigMap.d.ts +6 -1
  8. package/lib/cjs/BigMap.d.ts.map +1 -1
  9. package/lib/cjs/BigMap.js +28 -2
  10. package/lib/cjs/BigMap.js.map +1 -1
  11. package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
  12. package/lib/cjs/BranchProvenanceInitializer.js +2 -0
  13. package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
  14. package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +1 -1
  15. package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
  16. package/lib/cjs/ECReferenceTypesCache.js +8 -0
  17. package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
  18. package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
  19. package/lib/cjs/ElementCascadingDeleter.js.map +1 -1
  20. package/lib/cjs/EntityUnifier.d.ts.map +1 -1
  21. package/lib/cjs/EntityUnifier.js.map +1 -1
  22. package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
  23. package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +1 -1
  24. package/lib/cjs/IModelCloneContext.d.ts +1 -4
  25. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  26. package/lib/cjs/IModelCloneContext.js +16 -31
  27. package/lib/cjs/IModelCloneContext.js.map +1 -1
  28. package/lib/cjs/IModelExporter.d.ts +67 -62
  29. package/lib/cjs/IModelExporter.d.ts.map +1 -1
  30. package/lib/cjs/IModelExporter.js +173 -83
  31. package/lib/cjs/IModelExporter.js.map +1 -1
  32. package/lib/cjs/IModelImporter.d.ts +31 -47
  33. package/lib/cjs/IModelImporter.d.ts.map +1 -1
  34. package/lib/cjs/IModelImporter.js +62 -72
  35. package/lib/cjs/IModelImporter.js.map +1 -1
  36. package/lib/cjs/IModelTransformer.d.ts +146 -210
  37. package/lib/cjs/IModelTransformer.d.ts.map +1 -1
  38. package/lib/cjs/IModelTransformer.js +515 -657
  39. package/lib/cjs/IModelTransformer.js.map +1 -1
  40. package/lib/cjs/{transformer.d.ts → imodel-transformer.d.ts} +1 -1
  41. package/lib/cjs/imodel-transformer.d.ts.map +1 -0
  42. package/lib/cjs/{transformer.js → imodel-transformer.js} +13 -3
  43. package/lib/cjs/imodel-transformer.js.map +1 -0
  44. package/package.json +22 -20
  45. package/lib/cjs/PendingReferenceMap.d.ts +0 -37
  46. package/lib/cjs/PendingReferenceMap.d.ts.map +0 -1
  47. package/lib/cjs/PendingReferenceMap.js +0 -92
  48. package/lib/cjs/PendingReferenceMap.js.map +0 -1
  49. package/lib/cjs/transformer.d.ts.map +0 -1
  50. package/lib/cjs/transformer.js.map +0 -1
@@ -1,11 +1,9 @@
1
- import { AccessToken, Id64Array, Id64String } from "@itwin/core-bentley";
1
+ import { Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
2
2
  import * as ECSchemaMetaData from "@itwin/ecschema-metadata";
3
- import { Element, ElementAspect, ElementMultiAspect, ElementUniqueAspect, Entity, ExternalSourceAspect, IModelDb, Model, Relationship, RelationshipProps, SQLiteDb } from "@itwin/core-backend";
4
- import { ChangesetIndexAndId, CodeSpec, ElementAspectProps, ElementProps, EntityReference, EntityReferenceSet, ExternalSourceAspectProps, FontProps, ModelProps, Placement2d, Placement3d } from "@itwin/core-common";
5
- import { ExportChangesOptions, ExportSchemaResult, IModelExporter, IModelExportHandler } from "./IModelExporter";
3
+ import { Element, ElementAspect, ElementMultiAspect, ElementUniqueAspect, Entity, ExternalSourceAspect, IModelDb, Model, Relationship, RelationshipProps } from "@itwin/core-backend";
4
+ import { ChangesetIndexAndId, CodeSpec, ElementAspectProps, ElementProps, ExternalSourceAspectProps, FontProps, ModelProps, Placement2d, Placement3d } from "@itwin/core-common";
5
+ import { ChangedInstanceIds, ExportChangesOptions, ExportSchemaResult, IModelExporter, IModelExportHandler } from "./IModelExporter";
6
6
  import { IModelImporter, OptimizeGeometryOptions } from "./IModelImporter";
7
- import { PendingReferenceMap } from "./PendingReferenceMap";
8
- import { EntityMap } from "./EntityMap";
9
7
  import { IModelCloneContext } from "./IModelCloneContext";
10
8
  /** Options provided to the [[IModelTransformer]] constructor.
11
9
  * @beta
@@ -18,7 +16,7 @@ export interface IModelTransformOptions {
18
16
  */
19
17
  targetScopeElementId?: Id64String;
20
18
  /** Set to `true` if IModelTransformer should not record its provenance.
21
- * Provenance tracks a target element back to its corresponding source element and is essential for [[IModelTransformer.processChanges]] to work properly.
19
+ * Provenance tracks a target element back to its corresponding source element and is essential for [[IModelTransformer.process]] to work properly when [[IModelTransformOptions.argsForProcessChanges]] are provided.
22
20
  * Turning off IModelTransformer provenance is really only relevant for producing snapshots or another one time transformations.
23
21
  * @note See the [[includeSourceProvenance]] option for determining whether existing source provenance is cloned into the target.
24
22
  * @note The default is `false` which means that new IModelTransformer provenance will be recorded.
@@ -35,13 +33,6 @@ export interface IModelTransformOptions {
35
33
  * @note This *hint* is typically only set for the first synchronization after the iModel was copied since every other synchronization can utilize the provenance.
36
34
  */
37
35
  wasSourceIModelCopiedToTarget?: boolean;
38
- /** Flag that indicates that the current source and target iModels are now synchronizing in the reverse direction from a prior synchronization.
39
- * The most common example is to first synchronize master to branch, make changes to the branch, and then reverse directions to synchronize from branch to master.
40
- * This means that the provenance on the (current) source is used instead.
41
- * @note This also means that only [[IModelTransformer.processChanges]] can detect deletes.
42
- * @deprecated in 1.x this option is ignored and the transformer now detects synchronization direction using the target scope element
43
- */
44
- isReverseSynchronization?: boolean;
45
36
  /** Flag that indicates whether or not the transformation process needs to consider the source geometry before cloning/transforming.
46
37
  * For standard cases, it is not required to load the source GeometryStream in JavaScript since the cloning happens in native code.
47
38
  * Also, the target GeometryStream will be available in JavaScript prior to insert.
@@ -70,20 +61,6 @@ export interface IModelTransformOptions {
70
61
  * @beta
71
62
  */
72
63
  preserveElementIdsForFiltering?: boolean;
73
- /** The behavior to use when an element reference (id) is found stored as a reference on an element in the source,
74
- * but the referenced element does not actually exist in the source.
75
- * It is possible to craft an iModel with dangling references/invalidated relationships by, e.g., deleting certain
76
- * elements without fixing up references.
77
- *
78
- * @note "reject" will throw an error and reject the transformation upon finding this case.
79
- * @note "ignore" passes the issue down to consuming applications, iModels that have invalid element references
80
- * like this can cause errors, and you should consider adding custom logic in your transformer to remove the
81
- * reference depending on your use case.
82
- * @default "reject"
83
- * @beta
84
- * @deprecated in 3.x. use [[danglingReferencesBehavior]] instead, the use of the term *predecessors* was confusing and became inaccurate when the transformer could handle cycles
85
- */
86
- danglingPredecessorsBehavior?: "reject" | "ignore";
87
64
  /** The behavior to use when an element reference (id) is found stored as a reference on an element in the source,
88
65
  * but the referenced element does not actually exist in the source.
89
66
  * It is possible to craft an iModel with dangling references/invalidated relationships by, e.g., deleting certain
@@ -97,7 +74,7 @@ export interface IModelTransformOptions {
97
74
  * @beta
98
75
  */
99
76
  danglingReferencesBehavior?: "reject" | "ignore";
100
- /** If defined, options to be supplied to [[IModelImporter.optimizeGeometry]] by [[IModelTransformer.processChanges]] and [[IModelTransformer.processAll]]
77
+ /** If defined, options to be supplied to [[IModelImporter.optimizeGeometry]] by [[IModelTransformer.process]]
101
78
  * as a post-processing step to optimize the geometry in the iModel.
102
79
  * @beta
103
80
  */
@@ -117,13 +94,6 @@ export interface IModelTransformOptions {
117
94
  * @default false
118
95
  */
119
96
  noDetachChangeCache?: boolean;
120
- /**
121
- * Do not check that processChanges is called from the next changeset index.
122
- * This is an unsafe option (e.g. it can cause data loss in future branch operations)
123
- * and you should not use it.
124
- * @default false
125
- */
126
- ignoreMissingChangesetsInSynchronizations?: boolean;
127
97
  /**
128
98
  * Do not error out if a scoping ESA @see ExternalSourceAspectProps is found without a version or jsonProperties defined on that scoping ESA.
129
99
  * If true, the version and jsonproperties will be properly set on the scoping ESA @see TargetScopeProvenanceJsonProps after the transformer is complete.
@@ -135,31 +105,15 @@ export interface IModelTransformOptions {
135
105
  branchRelationshipDataBehavior?: "unsafe-migrate" | "reject";
136
106
  /**
137
107
  * Skip propagating changes made to the root subject, dictionaryModel and IModelImporter._realityDataSourceLinkPartitionStaticId (0xe)
138
- * @default false
108
+ * If it is set to false, changes to root elements are propagated, the root subject name gets changed and leads to the iModelDb.name property being updated in .initializeiModelDb
109
+ * @default true
139
110
  */
140
111
  skipPropagateChangesToRootElements?: boolean;
141
- }
142
- /**
143
- * A container for tracking the state of a partially committed entity and finalizing it when it's ready to be fully committed
144
- * @internal
145
- */
146
- declare class PartiallyCommittedEntity {
147
112
  /**
148
- * A set of "model|element ++ ID64" pairs, (e.g. `model0x11` or `element0x12`)
149
- * It is possible for the submodel of an element to be separately resolved from the actual element,
150
- * so its resolution must be tracked separately
113
+ * Arguments to use for the processing of changes. The args being defined or not defined will influence the behavior of @see [[IModelTransformer.process]].
114
+ * @default undefined
151
115
  */
152
- private _missingReferences;
153
- private _onComplete;
154
- constructor(
155
- /**
156
- * A set of "model|element ++ ID64" pairs, (e.g. `model0x11` or `element0x12`)
157
- * It is possible for the submodel of an element to be separately resolved from the actual element,
158
- * so its resolution must be tracked separately
159
- */
160
- _missingReferences: EntityReferenceSet, _onComplete: () => void);
161
- resolveReference(id: EntityReference): void;
162
- forceComplete(): void;
116
+ argsForProcessChanges?: ProcessChangesOptions;
163
117
  }
164
118
  /**
165
119
  * Data type for persisting change version information within provenance Scope ExternalSourceAspect.
@@ -186,7 +140,6 @@ export interface TargetScopeProvenanceJsonProps {
186
140
  * @beta
187
141
  */
188
142
  export interface InitOptions {
189
- accessToken?: AccessToken;
190
143
  /**
191
144
  * Include changes from this changeset up through and including the current changeset.
192
145
  * @note To form a range of versions to process, set `startChangeset` for the start (inclusive)
@@ -199,41 +152,41 @@ export interface InitOptions {
199
152
  };
200
153
  }
201
154
  /**
202
- * Arguments for [[IModelTransformer.processChanges]]
203
- */
204
- export type ProcessChangesOptions = ExportChangesOptions & FinalizeTransformationOptions;
205
- /**
206
- * Options which modify the behavior of [[IModelTransformer.finalizeTransformation]], called at the end of [[IModelTransformer.processAll]] and [[IModelTransformer.processChanges]].
155
+ * Arguments used during [[IModelTransformer.process]] if provided in [[IModelTransformOptions.argsForProcessChanges]].
207
156
  * @beta
208
157
  */
209
- export interface FinalizeTransformationOptions {
210
- /**
211
- * This description will be used when the transformer needs to push changes to the branch during a reverse sync.
212
- * @default `Update provenance in response to a reverse sync to iModel: ${this.targetDb.iModelId}`
213
- */
214
- reverseSyncBranchChangesetDescription?: string;
158
+ export type ProcessChangesOptions = ExportChangesOptions & {
159
+ /** how to call saveChanges on the target. Must call targetDb.saveChanges, should not edit the iModel */
160
+ saveTargetChanges?: (transformer: IModelTransformer) => Promise<void>;
215
161
  /**
216
- * This description will be used when the transformer needs to push changes to master during a reverse sync.
217
- * @default `Reverse sync of iModel: ${this.sourceDb.iModelId}`
162
+ * 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.
163
+ * @note This option is not without risk! You must also set @see branchRelationshipDataBehavior to "unsafe-migrate".
164
+ * @note This value is ignored if the version property on the scoping ESA is NOT undefined or empty string.
165
+ * @default ""
218
166
  */
219
- reverseSyncMasterChangesetDescription?: string;
167
+ unsafeFallbackSyncVersion?: string;
220
168
  /**
221
- * This description will be used when the transformer needs to push changes to the branch during a forward sync.
222
- * @default `Forward sync of iModel: ${this.sourceDb.iModelId}`
169
+ * The reverse sync version to set on the scoping ESA @see TargetScopeProvenanceJsonProps upon startup, if the reverseSync property on the scoping ESA is undefined or empty string.
170
+ * @note This option is not without risk! You must also set @see branchRelationshipDataBehavior to "unsafe-migrate".
171
+ * @note This value is ignored if the reverseSyncVersion property on the scoping ESA is NOT undefined or empty string.
172
+ * @default ""
223
173
  */
224
- forwardSyncBranchChangesetDescription?: string;
174
+ unsafeFallbackReverseSyncVersion?: string;
225
175
  /**
226
- * This description will be used when the transformer needs to push changes to the branch during a provenance init transform.
227
- * @default `initialized branch provenance with master iModel: ${this.sourceDb.iModelId}`
176
+ * Do not check that process (with [[IModelTransformOptions.argsForProcessChanges]] provided) is called from the next changeset index.
177
+ * This is an unsafe option (e.g. it can cause data loss in future branch operations)
178
+ * and you should not use it.
179
+ * @default false
228
180
  */
229
- provenanceInitTransformChangesetDescription?: string;
230
- /** how to call saveChanges on the target. Must call targetDb.saveChanges, should not edit the iModel */
231
- saveTargetChanges?: (transformer: IModelTransformer) => Promise<void>;
232
- }
233
- /** Arguments you can pass to [[IModelTransformer.initExternalSourceAspects]]
234
- * @deprecated in 0.1.0. Use [[InitOptions]] (and [[IModelTransformer.initialize]]) instead.
181
+ ignoreMissingChangesetsInSynchronizations?: boolean;
182
+ };
183
+ /**
184
+ * @beta
235
185
  */
236
- export type InitFromExternalSourceAspectsArgs = InitOptions;
186
+ export interface RelationshipPropsForDelete {
187
+ id: Id64String;
188
+ classFullName: string;
189
+ }
237
190
  /** Base class used to transform a source iModel into a different target iModel.
238
191
  * @see [iModel Transformation and Data Exchange]($docs/learning/transformer/index.md), [IModelExporter]($transformer), [IModelImporter]($transformer)
239
192
  * @beta
@@ -254,16 +207,14 @@ export declare class IModelTransformer extends IModelExportHandler {
254
207
  private _syncType?;
255
208
  /** The Id of the Element in the **target** iModel that represents the **source** repository as a whole and scopes its [ExternalSourceAspect]($backend) instances. */
256
209
  get targetScopeElementId(): Id64String;
257
- /** map of (unprocessed element, referencing processed element) pairs to the partially committed element that needs the reference resolved
258
- * and have some helper methods below for now */
259
- protected _pendingReferences: PendingReferenceMap<PartiallyCommittedEntity>;
260
210
  /** a set of elements for which source provenance will be explicitly tracked by ExternalSourceAspects */
261
211
  protected _elementsWithExplicitlyTrackedProvenance: Set<string>;
262
- /** map of partially committed entities to their partial commit progress */
263
- protected _partiallyCommittedEntities: EntityMap<PartiallyCommittedEntity>;
212
+ protected _partiallyCommittedElementIds: Id64Set;
213
+ protected _partiallyCommittedAspectIds: Id64Set;
264
214
  /** the options that were used to initialize this transformer */
265
215
  private readonly _options;
266
- private _isSynchronization;
216
+ /** @see hasDefinitionContainerDeletionFeature */
217
+ private _hasDefinitionContainerDeletionFeature?;
267
218
  /**
268
219
  * 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.
269
220
  * 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.
@@ -306,10 +257,6 @@ export declare class IModelTransformer extends IModelExportHandler {
306
257
  static get provenanceElementClasses(): (typeof Entity)[];
307
258
  /** The element aspect classes that are considered to define provenance in the iModel */
308
259
  static get provenanceElementAspectClasses(): (typeof Entity)[];
309
- /** Set of entity keys which were not exported and don't need to be tracked for pending reference resolution.
310
- * @note Currently only tracks elements which were not exported.
311
- */
312
- protected _skippedEntities: Set<`m${string}` | `e${string}` | `a${string}` | `r${string}`>;
313
260
  /** Construct a new IModelTransformer
314
261
  * @param source Specifies the source IModelExporter or the source IModelDb that will be used to construct the source IModelExporter.
315
262
  * @param target Specifies the target IModelImporter or the target IModelDb that will be used to construct the target IModelImporter.
@@ -369,17 +316,23 @@ export declare class IModelTransformer extends IModelExportHandler {
369
316
  */
370
317
  private _startingChangesetIndices;
371
318
  private _cachedSynchronizationVersion;
372
- /** the changeset in the scoping element's source version found for this transformation
373
- * @note: the version depends on whether this is a reverse synchronization or not, as
374
- * it is stored separately for both synchronization directions.
375
- * @note: must call [[initScopeProvenance]] before using this property.
376
- * @note: empty string and -1 for changeset and index if it has never been transformed or was transformed before federation guid update (pre 1.x).
319
+ /**
320
+ * As of itwinjs 4.6.0, definitionContainers are now deleted as if they were DefinitionPartitions as opposed to Definitions.
321
+ * This variable being true will be used to special case the deletion of DefinitionContainers the same way DefinitionPartitions are deleted.
322
+ */
323
+ protected get hasDefinitionContainerDeletionFeature(): boolean;
324
+ /**
325
+ * We cache the synchronization version to avoid querying the target scoping ESA multiple times.
326
+ * If the target scoping ESA is ever updated we need to clear any potentially cached sync version otherwise we will get stale values.
327
+ * Sets this._cachedSynchronizationVersion to undefined.
377
328
  */
378
- private get _synchronizationVersion();
329
+ private clearCachedSynchronizationVersion;
379
330
  /** the changeset in the scoping element's source version found for this transformation
380
- * @note: the version depends on whether this is a reverse synchronization or not, as
331
+ * @note the version depends on whether this is a reverse synchronization or not, as
381
332
  * it is stored separately for both synchronization directions.
382
- * @note: empty string and -1 for changeset and index if it has never been transformed, or was transformed before federation guid update (pre 1.x).
333
+ * @note empty string and -1 for changeset and index if it has never been transformed
334
+ * @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".
335
+ * @throws if the version is not found in a preexisting scope aspect and @see [[IModelTransformOptions.branchRelationshipDataBehavior]] !== "unsafe-migrate"
383
336
  */
384
337
  protected get synchronizationVersion(): ChangesetIndexAndId;
385
338
  /**
@@ -394,6 +347,8 @@ export declare class IModelTransformer extends IModelExportHandler {
394
347
  * if this was a [BriefcaseDb]($backend)
395
348
  */
396
349
  protected initScopeProvenance(): void;
350
+ /** Returns true if a change was made to the aspectProps. */
351
+ private handleUnsafeMigrate;
397
352
  /**
398
353
  * Iterate all matching federation guids and ExternalSourceAspects in the provenance iModel (target unless reverse sync)
399
354
  * and call a function for each one.
@@ -409,7 +364,21 @@ export declare class IModelTransformer extends IModelExportHandler {
409
364
  skipPropagateChangesToRootElements: boolean;
410
365
  }): void;
411
366
  private forEachTrackedElement;
367
+ /**
368
+ * Queries the provenanceDb for an ESA whose identifier is equal to the provided 'entityInProvenanceSourceId'.
369
+ * The identifier on the ESA is the id of the element in the [[IModelTransformer.provenanceSourceDb]]
370
+ * Therefore it only makes sense to call this function when you have an id in the provenanceSourceDb.
371
+ * @param entityInProvenanceSourceId
372
+ * @returns the elementId that the ESA is stored on, esa.Element.Id
373
+ */
412
374
  private _queryProvenanceForElement;
375
+ /**
376
+ * Queries the provenanceDb for an ESA whose identifier is equal to the provided 'entityInProvenanceSourceId'.
377
+ * The identifier on the ESA is the id of the relationship in the [[IModelTransformer.provenanceSourceDb]]
378
+ * Therefore it only makes sense to call this function when you have an id in the provenanceSourceDb.
379
+ * @param entityInProvenanceSourceId
380
+ * @returns
381
+ */
413
382
  private _queryProvenanceForRelationship;
414
383
  private _queryTargetRelId;
415
384
  private _targetClassNameToClassIdCache;
@@ -418,24 +387,20 @@ export declare class IModelTransformer extends IModelExportHandler {
418
387
  private _queryElemIdByFedGuid;
419
388
  /** Returns `true` if *brute force* delete detections should be run.
420
389
  * @note This is only called if [[IModelTransformOptions.forceExternalSourceAspectProvenance]] option is true
421
- * @note Not relevant for processChanges when change history is known.
390
+ * @note Not relevant for [[process]] when [[IModelTransformOptions.argsForProcessChanges]] are provided and change history is known.
422
391
  */
423
392
  protected shouldDetectDeletes(): boolean;
424
393
  /**
425
394
  * Detect Element deletes using ExternalSourceAspects in the target iModel and a *brute force* comparison against Elements
426
395
  * in the source iModel.
427
396
  * @deprecated in 1.x. Do not use this. // FIXME<MIKE>: how to better explain this?
428
- * This method is only called during [[processAll]] when the option
397
+ * This method is only called during [[process]] when [[IModelTransformOptions.argsForProcessChanges]] is undefined and the option
429
398
  * [[IModelTransformOptions.forceExternalSourceAspectProvenance]] is enabled. It is not
430
- * necessary when using [[processChanges]] since changeset information is sufficient.
399
+ * necessary when calling [[process]] with [[IModelTransformOptions.argsForProcessChanges]] defined, since changeset information is sufficient.
431
400
  * @note you do not need to call this directly unless processing a subset of an iModel.
432
401
  * @throws [[IModelError]] If the required provenance information is not available to detect deletes.
433
402
  */
434
403
  detectElementDeletes(): Promise<void>;
435
- /**
436
- * @deprecated in 3.x, this no longer has any effect except emitting a warning
437
- */
438
- protected skipElement(_sourceElement: Element): void;
439
404
  /** Transform the specified sourceElement into ElementProps for the target iModel.
440
405
  * @param sourceElement The Element from the source iModel to transform.
441
406
  * @returns ElementProps for the target iModel.
@@ -443,38 +408,30 @@ export declare class IModelTransformer extends IModelExportHandler {
443
408
  * @note This can be called more than once for an element in arbitrary order, so it should not have side-effects.
444
409
  */
445
410
  onTransformElement(sourceElement: Element): ElementProps;
446
- private _hasElementChangedCache?;
447
411
  private _deletedSourceRelationshipData?;
448
412
  /** Returns true if a change within sourceElement is detected.
449
413
  * @param sourceElement The Element from the source iModel
450
- * @param targetElementId The Element from the target iModel to compare against.
451
414
  * @note A subclass can override this method to provide custom change detection behavior.
452
415
  */
453
- protected hasElementChanged(sourceElement: Element, _targetElementId: Id64String): boolean;
454
- private static transformCallbackFor;
455
- /** callback to perform when a partial element says it's ready to be completed
456
- * transforms the source element with all references now valid, then updates the partial element with the results
457
- */
458
- private makePartialEntityCompleter;
459
- /** collect references this entity has that are yet to be mapped, and if there are any
460
- * create a [[PartiallyCommittedEntity]] to track resolution of those references
461
- */
462
- private collectUnmappedReferences;
416
+ protected hasElementChanged(sourceElement: Element): boolean;
417
+ protected completePartiallyCommittedElements(): void;
418
+ protected completePartiallyCommittedAspects(): void;
419
+ private doAllReferencesExistInTarget;
420
+ private assertReferenceExistsInSource;
463
421
  /** Cause the specified Element and its child Elements (if applicable) to be exported from the source iModel and imported into the target iModel.
464
422
  * @param sourceElementId Identifies the Element from the source iModel to import.
465
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
423
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
466
424
  */
467
425
  processElement(sourceElementId: Id64String): Promise<void>;
468
426
  /** Import child elements into the target IModelDb
469
427
  * @param sourceElementId Import the child elements of this element in the source IModelDb.
470
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
428
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
471
429
  */
472
430
  processChildElements(sourceElementId: Id64String): Promise<void>;
473
431
  /** Override of [IModelExportHandler.shouldExportElement]($transformer) that is called to determine if an element should be exported from the source iModel.
474
432
  * @note Reaching this point means that the element has passed the standard exclusion checks in IModelExporter.
475
433
  */
476
434
  shouldExportElement(_sourceElement: Element): boolean;
477
- onSkipElement(sourceElementId: Id64String): void;
478
435
  /**
479
436
  * If they haven't been already, import all of the required references
480
437
  * @internal do not call, override or implement this, it will be removed
@@ -485,7 +442,6 @@ export declare class IModelTransformer extends IModelExportHandler {
485
442
  * This override calls [[onTransformElement]] and then [IModelImporter.importElement]($transformer) to update the target iModel.
486
443
  */
487
444
  onExportElement(sourceElement: Element): void;
488
- private resolvePendingReferences;
489
445
  /** Override of [IModelExportHandler.onDeleteElement]($transformer) that is called when [IModelExporter]($transformer) detects that an Element has been deleted from the source iModel.
490
446
  * This override propagates the delete to the target iModel via [IModelImporter.deleteElement]($transformer).
491
447
  */
@@ -500,14 +456,14 @@ export declare class IModelTransformer extends IModelExportHandler {
500
456
  private scheduleModeledPartitionDeletion;
501
457
  /** Cause the model container, contents, and sub-models to be exported from the source iModel and imported into the target iModel.
502
458
  * @param sourceModeledElementId Import this [Model]($backend) from the source IModelDb.
503
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
459
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
504
460
  */
505
461
  processModel(sourceModeledElementId: Id64String): Promise<void>;
506
462
  /** Cause the model contents to be exported from the source iModel and imported into the target iModel.
507
463
  * @param sourceModelId Import the contents of this model from the source IModelDb.
508
464
  * @param targetModelId Import into this model in the target IModelDb. The target model must exist prior to this call.
509
465
  * @param elementClassFullName Optional classFullName of an element subclass to limit import query against the source model.
510
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
466
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
511
467
  */
512
468
  processModelContents(sourceModelId: Id64String, targetModelId: Id64String, elementClassFullName?: string): Promise<void>;
513
469
  /** Cause all sub-models that recursively descend from the specified Subject to be exported from the source iModel and imported into the target iModel. */
@@ -519,27 +475,31 @@ export declare class IModelTransformer extends IModelExportHandler {
519
475
  * @note A subclass can override this method to provide custom transform behavior.
520
476
  */
521
477
  onTransformModel(sourceModel: Model, targetModeledElementId: Id64String): ModelProps;
522
- /** Import elements that were deferred in a prior pass.
523
- * @deprecated in 3.x. This method is no longer necessary since the transformer no longer needs to defer elements
524
- */
525
- processDeferredElements(_numRetries?: number): Promise<void>;
526
- /** called at the end ([[finalizeTransformation]]) of a transformation,
478
+ /**
479
+ * Called at the end of a transformation,
527
480
  * updates the target scope element to say that transformation up through the
528
481
  * source's changeset has been performed. Also stores all changesets that occurred
529
482
  * during the transformation as "pending synchronization changeset indices" @see TargetScopeProvenanceJsonProps
530
483
  *
531
- * You generally should not call this function yourself and use [[processChanges]] instead.
484
+ * You generally should not call this function yourself and use [[process]] with [[IModelTransformOptions.argsForProcessChanges]] provided instead.
532
485
  * It is public for unsupported use cases of custom synchronization transforms.
533
- * @note if you are not running processChanges in this transformation, this will fail
534
- * without setting the `force` option to `true`
486
+ * @note If [[IModelTransformOptions.argsForProcessChanges]] is not defined in this transformation, this function will return early without updating the sync version,
487
+ * unless the `initializeReverseSyncVersion` option is set to `true`
488
+ *
489
+ * The `initializeReverseSyncVersion` is added to set the reverse synchronization version during a forward synchronization.
490
+ * 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.
491
+ * 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.
492
+ *
493
+ * Note that typically, the reverseSyncVersion is saved as the last changeset merged from the branch into master.
494
+ * 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.
535
495
  */
536
- updateSynchronizationVersion({ force }?: {
537
- force?: boolean | undefined;
496
+ updateSynchronizationVersion({ initializeReverseSyncVersion, }?: {
497
+ initializeReverseSyncVersion?: boolean | undefined;
538
498
  }): void;
539
499
  private finalizeTransformation;
540
500
  /** Imports all relationships that subclass from the specified base class.
541
501
  * @param baseRelClassFullName The specified base relationship class.
542
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
502
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
543
503
  */
544
504
  processRelationships(baseRelClassFullName: string): Promise<void>;
545
505
  /** Override of [IModelExportHandler.shouldExportRelationship]($transformer) that is called to determine if a [Relationship]($backend) should be exported.
@@ -557,8 +517,8 @@ export declare class IModelTransformer extends IModelExportHandler {
557
517
  private _yieldManager;
558
518
  /** Detect Relationship deletes using ExternalSourceAspects in the target iModel and a *brute force* comparison against relationships in the source iModel.
559
519
  * @deprecated in 1.x. Don't use this anymore
560
- * @see processChanges
561
- * @note This method is called from [[processAll]] and is not needed by [[processChanges]], so it only needs to be called directly when processing a subset of an iModel.
520
+ * @see [[process]] with [[IModelTransformOptions.argsForProcessChanges]] provided.
521
+ * @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.
562
522
  * @throws [[IModelError]] If the required provenance information is not available to detect deletes.
563
523
  */
564
524
  detectRelationshipDeletes(): Promise<void>;
@@ -580,11 +540,10 @@ export declare class IModelTransformer extends IModelExportHandler {
580
540
  onExportElementMultiAspects(sourceAspects: ElementMultiAspect[]): void;
581
541
  /** Transform the specified sourceElementAspect into ElementAspectProps for the target iModel.
582
542
  * @param sourceElementAspect The ElementAspect from the source iModel to be transformed.
583
- * @param _targetElementId The ElementId of the target Element that will own the ElementAspects after transformation.
584
543
  * @returns ElementAspectProps for the target iModel.
585
544
  * @note A subclass can override this method to provide custom transform behavior.
586
545
  */
587
- protected onTransformElementAspect(sourceElementAspect: ElementAspect, _targetElementId: Id64String): ElementAspectProps;
546
+ protected onTransformElementAspect(sourceElementAspect: ElementAspect): ElementAspectProps;
588
547
  /** The directory where schemas will be exported, a random temporary directory */
589
548
  protected _schemaExportDir: string;
590
549
  /** Override of [IModelExportHandler.shouldExportSchema]($transformer) that is called to determine if a schema should be exported
@@ -608,17 +567,17 @@ export declare class IModelTransformer extends IModelExportHandler {
608
567
  */
609
568
  processSchemas(): Promise<void>;
610
569
  /** Cause all fonts to be exported from the source iModel and imported into the target iModel.
611
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
570
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
612
571
  */
613
572
  processFonts(): Promise<void>;
614
573
  /** Override of [IModelExportHandler.onExportFont]($transformer) that imports a font into the target iModel when it is exported from the source iModel. */
615
574
  onExportFont(font: FontProps, _isUpdate: boolean | undefined): void;
616
575
  /** Cause all CodeSpecs to be exported from the source iModel and imported into the target iModel.
617
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
576
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
618
577
  */
619
578
  processCodeSpecs(): Promise<void>;
620
579
  /** Cause a single CodeSpec to be exported from the source iModel and imported into the target iModel.
621
- * @note This method is called from [[processChanges]] and [[processAll]], so it only needs to be called directly when processing a subset of an iModel.
580
+ * @note This method is called from [[process]], so it only needs to be called directly when processing a subset of an iModel.
622
581
  */
623
582
  processCodeSpec(codeSpecName: string): Promise<void>;
624
583
  /** Override of [IModelExportHandler.shouldExportCodeSpec]($transformer) that is called to determine if a CodeSpec should be exported from the source iModel.
@@ -636,19 +595,27 @@ export declare class IModelTransformer extends IModelExportHandler {
636
595
  private _csFileProps?;
637
596
  /**
638
597
  * Initialize prerequisites of processing, you must initialize with an [[InitOptions]] if you
639
- * are intending to process changes, but prefer using [[processChanges]] explicitly since it calls this.
598
+ * 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.
640
599
  * @note Called by all `process*` functions implicitly.
641
600
  * Overriders must call `super.initialize()` first
642
601
  */
643
- initialize(args?: InitOptions): Promise<void>;
602
+ initialize(): Promise<void>;
644
603
  /**
645
- * Reads all the changeset files in the private member of the transformer: _csFileProps and does two things with these changesets.
646
- * Finds the corresponding target entity for any deleted source entities and remaps the sourceId to the targetId.
647
- * Populates this._hasElementChangedCache with a set of elementIds that have been updated or inserted into the database.
604
+ * Reads all the changeset files in the private member of the transformer: _csFileProps
605
+ * and finds the corresponding target entity for any deleted source entities and remaps the sourceId to the targetId.
648
606
  * This function returns early if csFileProps is undefined or is of length 0.
649
607
  * @returns void
650
608
  */
651
609
  private processChangesets;
610
+ /**
611
+ * This will be called when transformer is called with [[IModelTransformOptions.argsForProcessChanges]] to process changes.
612
+ * It will be executed after changes in changesets are populated into `sourceDbChanges` and before data processing begins.
613
+ * Remap table between the source and target iModels will be built at that time, meaning that functions like [[IModelTransformer.context.findTargetElementId]] will return meaningful results.
614
+ * This function should be used to modify the `sourceDbChanges`, if necessary, using `add custom change` methods in [[ChangedInstanceIds]], such as [[ChangedInstanceIds.addCustomElementChange]], [[ChangedInstanceIds.addCustomModelChange]] and other.
615
+ * @param sourceDbChanges the ChangedInstanceIds already populated by the exporter with the changes in source changesets, if any, passed to the transformer.
616
+ * @note Its expected that this function be overridden by a subclass of transformer if it needs to modify sourceDbChanges.
617
+ */
618
+ protected addCustomChanges(_sourceDbChanges: ChangedInstanceIds): Promise<void>;
652
619
  /**
653
620
  * Helper function for processChangesets. Remaps the id of element deleted found in the 'change' to an element in the targetDb.
654
621
  * @param change the change to process, must be of changeType "Deleted"
@@ -661,77 +628,47 @@ export declare class IModelTransformer extends IModelExportHandler {
661
628
  */
662
629
  private processDeletedOp;
663
630
  private _tryInitChangesetData;
631
+ /**
632
+ * The behavior of process is influenced by [[IModelTransformOptions.argsForProcessChanges]] being defined or not defined during construction passed of the IModelTransformer.
633
+ * @section When argsForProcessChanges are defined:
634
+ *
635
+ * Export changes from the source iModel and import the transformed entities into the target iModel.
636
+ * Inserts, updates, and deletes are determined by inspecting the changeset(s).
637
+ *
638
+ * Notes:
639
+ * - the transformer assumes that you saveChanges after processing changes. You should not modify the iModel after processChanges until saveChanges,
640
+ * failure to do so may result in corrupted
641
+ * data loss in future branch operations
642
+ * - if no startChangesetId or startChangeset option is provided as part of the ProcessChangesOptions, the next unsynchronized changeset
643
+ * will automatically be determined and used
644
+ * - To form a range of versions to process, set `startChangesetId` for the start (inclusive) of the desired range and open the source iModel as of the end (inclusive) of the desired range.
645
+ *
646
+ * @section When argsForProcessChanges are undefined:
647
+ *
648
+ * Export everything from the source iModel and import the transformed entities into the target iModel.
649
+ *
650
+ * Notes:
651
+ * - [[processSchemas]] is not called automatically since the target iModel may want a different collection of schemas.
652
+ *
653
+ */
654
+ process(): Promise<void>;
664
655
  /** Export everything from the source iModel and import the transformed entities into the target iModel.
665
656
  * @note [[processSchemas]] is not called automatically since the target iModel may want a different collection of schemas.
666
657
  */
667
- processAll(options?: FinalizeTransformationOptions): Promise<void>;
658
+ private processAll;
668
659
  /** previous provenance, either a federation guid, a `${sourceFedGuid}/${targetFedGuid}` pair, or required aspect props */
669
660
  private _lastProvenanceEntityInfo;
670
661
  private markLastProvenance;
671
- /** @internal the name of the table where javascript state of the transformer is serialized in transformer state dumps */
672
- static readonly jsStateTable = "TransformerJsState";
673
- /** @internal the name of the table where the target state heuristics is serialized in transformer state dumps */
674
- static readonly lastProvenanceEntityInfoTable = "LastProvenanceEntityInfo";
675
- /**
676
- * Load the state of the active transformation from an open SQLiteDb
677
- * You can override this if you'd like to load from custom tables in the resumable dump state, but you should call
678
- * this super implementation
679
- * @note the SQLiteDb must be open
680
- */
681
- protected loadStateFromDb(db: SQLiteDb): void;
682
- /**
683
- * @deprecated in 0.1.x, this is buggy, and it is now equivalently efficient to simply restart the transformation
684
- * from the original changeset
685
- *
686
- * Return a new transformer instance with the same remappings state as saved from a previous [[IModelTransformer.saveStateToFile]] call.
687
- * This allows you to "resume" an iModel transformation, you will have to call [[IModelTransformer.processChanges]]/[[IModelTransformer.processAll]]
688
- * again but the remapping state will cause already mapped elements to be skipped.
689
- * To "resume" an iModel Transformation you need:
690
- * - the sourceDb at the same changeset
691
- * - the same targetDb in the state in which it was before
692
- * @param statePath the path to the serialized state of the transformer, use [[IModelTransformer.saveStateToFile]] to get this from an existing transformer instance
693
- * @param constructorArgs remaining arguments that you would normally pass to the Transformer subclass you are using, usually (sourceDb, targetDb)
694
- * @note custom transformers with custom state may need to override this method in order to handle loading their own custom state somewhere
695
- */
696
- static resumeTransformation<SubClass extends new (...a: any[]) => IModelTransformer = typeof IModelTransformer>(this: SubClass, statePath: string, ...constructorArgs: ConstructorParameters<SubClass>): InstanceType<SubClass>;
697
- /**
698
- * You may override this to store arbitrary json state in a transformer state dump, useful for some resumptions
699
- * @see [[IModelTransformer.saveStateToFile]]
700
- */
701
- protected getAdditionalStateJson(): any;
702
- /**
703
- * You may override this to load arbitrary json state in a transformer state dump, useful for some resumptions
704
- * @see [[IModelTransformer.loadStateFromFile]]
705
- */
706
- protected loadAdditionalStateJson(_additionalState: any): void;
707
- /**
708
- * Save the state of the active transformation to an open SQLiteDb
709
- * You can override this if you'd like to write custom tables to the resumable dump state, but you should call
710
- * this super implementation
711
- * @note the SQLiteDb must be open
712
- */
713
- protected saveStateToDb(db: SQLiteDb): void;
714
- /**
715
- * @deprecated in 0.1.x, this is buggy, and it is now equivalently efficient to simply restart the transformation
716
- * from the original changeset
717
- *
718
- * Save the state of the active transformation to a file path, if a file at the path already exists, it will be overwritten
719
- * This state can be used by [[IModelTransformer.resumeTransformation]] to resume a transformation from this point.
720
- * The serialization format is a custom sqlite database.
721
- * @note custom transformers with custom state may override [[IModelTransformer.saveStateToDb]] or [[IModelTransformer.getAdditionalStateJson]]
722
- * and [[IModelTransformer.loadStateFromDb]] (with a super call) or [[IModelTransformer.loadAdditionalStateJson]]
723
- * if they have custom state that needs to be stored with
724
- * potentially inside the same sqlite file in separate tables
725
- */
726
- saveStateToFile(nativeStatePath: string): void;
727
662
  /** Export changes from the source iModel and import the transformed entities into the target iModel.
728
663
  * Inserts, updates, and deletes are determined by inspecting the changeset(s).
729
- * @note the transformer saves and pushes changes when its work is complete.
664
+ * @note the transformer assumes that you saveChanges after processing changes. You should not
665
+ * modify the iModel after processChanges until saveChanges, failure to do so may result in corrupted
666
+ * data loss in future branch operations
730
667
  * @note if no startChangesetId or startChangeset option is provided as part of the ProcessChangesOptions, the next unsynchronized changeset
731
668
  * will automatically be determined and used
732
669
  * @note To form a range of versions to process, set `startChangesetId` for the start (inclusive) of the desired range and open the source iModel as of the end (inclusive) of the desired range.
733
670
  */
734
- processChanges(options: ProcessChangesOptions): Promise<void>;
671
+ private processChanges;
735
672
  /** Changeset data must be initialized in order to build correct changeOptions.
736
673
  * Call [[IModelTransformer.initialize]] for initialization of synchronization provenance data
737
674
  */
@@ -777,5 +714,4 @@ export declare class TemplateModelCloner extends IModelTransformer {
777
714
  /** Cloning from a template requires this override of onTransformElement. */
778
715
  onTransformElement(sourceElement: Element): ElementProps;
779
716
  }
780
- export {};
781
717
  //# sourceMappingURL=IModelTransformer.d.ts.map