Skip to content

Commit c2b4c49

Browse files
committed
support some edge cases that svcs supports
1 parent d6afe30 commit c2b4c49

File tree

2 files changed

+336
-12
lines changed

2 files changed

+336
-12
lines changed

packages/transformer/src/IModelTransformer.ts

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,23 @@ export interface IModelTransformOptions {
247247
* @default "reject"
248248
*/
249249
branchRelationshipDataBehavior?: "unsafe-migrate" | "reject";
250+
251+
/**
252+
* 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.
253+
* @note This option is not without risk! You must also set @see branchRelationshipDataBehavior to "unsafe-migrate".
254+
* @note This value is ignored if the version property on the scoping ESA is NOT undefined or empty string.
255+
* @default ""
256+
*/
257+
unsafeSyncVersion?: string;
258+
259+
/**
260+
* 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.
261+
* @note This option is not without risk! You must also set @see branchRelationshipDataBehavior to "unsafe-migrate".
262+
* @note This value is ignored if the reverseSyncVersion property on the scoping ESA is NOT undefined or empty string.
263+
* @default ""
264+
*/
265+
unsafeReverseSyncVersion?: string;
266+
250267
/**
251268
* Skip propagating changes made to the root subject, dictionaryModel and IModelImporter._realityDataSourceLinkPartitionStaticId (0xe)
252269
* @default false
@@ -779,7 +796,9 @@ export class IModelTransformer extends IModelExportHandler {
779796
);
780797
Logger.logInfo(
781798
TransformerLoggerCategory.IModelImporter,
782-
`this.importer.autoExtendProjectExtents=${JSON.stringify(this.importer.options.autoExtendProjectExtents)}`
799+
`this.importer.autoExtendProjectExtents=${JSON.stringify(
800+
this.importer.options.autoExtendProjectExtents
801+
)}`
783802
);
784803
Logger.logInfo(
785804
TransformerLoggerCategory.IModelImporter,
@@ -1119,6 +1138,52 @@ export class IModelTransformer extends IModelExportHandler {
11191138
reverseSyncVersion: "",
11201139
}
11211140
: undefined;
1141+
1142+
if (this._options.branchRelationshipDataBehavior === "unsafe-migrate") {
1143+
// Only propagate the unsafeSyncVersion and unsafeReverseSyncVersion if the currently stored versions are empty string.
1144+
// Note that in the unsafe-migrate case these may have just been set to empty string, if they were previously undefined.
1145+
aspectProps.version =
1146+
aspectProps.version === ""
1147+
? this._options.unsafeSyncVersion ?? ""
1148+
: aspectProps.version;
1149+
aspectProps.jsonProperties!.reverseSyncVersion =
1150+
aspectProps.jsonProperties!.reverseSyncVersion === ""
1151+
? this._options.unsafeReverseSyncVersion ?? ""
1152+
: aspectProps.jsonProperties!.reverseSyncVersion;
1153+
}
1154+
1155+
/**
1156+
* This case will only be hit when:
1157+
* - first transformation was performed on pre-fedguid transformer.
1158+
* - a second processAll transformation was performed on the same target-source iModels post-fedguid transformer.
1159+
* - change processing was invoked on for the second 'initial' transformation.
1160+
* NOTE: This case likely does not exist anymore, but we will keep it just to be sure.
1161+
*/
1162+
1163+
if (
1164+
aspectProps.jsonProperties !== undefined &&
1165+
this._options.branchRelationshipDataBehavior === "unsafe-migrate"
1166+
) {
1167+
if (
1168+
aspectProps.jsonProperties.pendingReverseSyncChangesetIndices ===
1169+
undefined
1170+
) {
1171+
Logger.logWarning(
1172+
loggerCategory,
1173+
"Property pendingReverseSyncChangesetIndices missing on the jsonProperties of the scoping ESA. Setting to []."
1174+
);
1175+
aspectProps.jsonProperties.pendingReverseSyncChangesetIndices = [];
1176+
}
1177+
if (
1178+
aspectProps.jsonProperties.pendingSyncChangesetIndices === undefined
1179+
) {
1180+
Logger.logWarning(
1181+
loggerCategory,
1182+
"Property pendingSyncChangesetIndices missing on the jsonProperties of the scoping ESA. Setting to []."
1183+
);
1184+
aspectProps.jsonProperties.pendingSyncChangesetIndices = [];
1185+
}
1186+
}
11221187
}
11231188

11241189
this._targetScopeProvenanceProps =
@@ -1550,13 +1615,9 @@ export class IModelTransformer extends IModelExportHandler {
15501615

15511616
/** Returns true if a change within sourceElement is detected.
15521617
* @param sourceElement The Element from the source iModel
1553-
* @param targetElementId The Element from the target iModel to compare against.
15541618
* @note A subclass can override this method to provide custom change detection behavior.
15551619
*/
1556-
protected hasElementChanged(
1557-
sourceElement: Element,
1558-
_targetElementId: Id64String
1559-
): boolean {
1620+
protected hasElementChanged(sourceElement: Element): boolean {
15601621
if (this._sourceChangeDataState === "no-changes") return false;
15611622
if (this._sourceChangeDataState === "unconnected") return true;
15621623
nodeAssert(
@@ -1882,11 +1943,7 @@ export class IModelTransformer extends IModelExportHandler {
18821943
}
18831944
}
18841945

1885-
if (
1886-
Id64.isValid(targetElementId) &&
1887-
!this.hasElementChanged(sourceElement, targetElementId)
1888-
)
1889-
return;
1946+
if (!this.hasElementChanged(sourceElement)) return;
18901947

18911948
this.collectUnmappedReferences(sourceElement);
18921949

@@ -2848,6 +2905,12 @@ export class IModelTransformer extends IModelExportHandler {
28482905
)) {
28492906
relationshipECClassIds.add(row.ECInstanceId);
28502907
}
2908+
const elementECClassIds = new Set<string>();
2909+
for await (const row of this.sourceDb.createQueryReader(
2910+
"SELECT ECInstanceId FROM ECDbMeta.ECClassDef where ECInstanceId IS (BisCore.Element)"
2911+
)) {
2912+
elementECClassIds.add(row.ECInstanceId);
2913+
}
28512914

28522915
// For later use when processing deletes.
28532916
const alreadyImportedElementInserts = new Set<Id64String>();
@@ -2900,7 +2963,12 @@ export class IModelTransformer extends IModelExportHandler {
29002963
change.Scope.Id === this.targetScopeElementId
29012964
) {
29022965
elemIdToScopeEsa.set(change.Element.Id, change);
2903-
} else if (changeType === "Inserted" || changeType === "Updated")
2966+
} else if (
2967+
changeType === "Inserted" ||
2968+
(changeType === "Updated" &&
2969+
change.ECClassId !== undefined &&
2970+
elementECClassIds.has(change.ECClassId))
2971+
)
29042972
hasElementChangedCache.add(change.ECInstanceId);
29052973
}
29062974

0 commit comments

Comments
 (0)