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

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.
@@ -365,7 +365,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
365
365
  /** Return the IModelDb where IModelTransformer will store its provenance.
366
366
  * @note This will be [[targetDb]] except when it is a reverse synchronization. In that case it be [[sourceDb]].
367
367
  */
368
- async provenanceDb() {
368
+ async getProvenanceDb() {
369
369
  return (await this.getIsReverseSynchronization())
370
370
  ? this.sourceDb
371
371
  : this.targetDb;
@@ -373,7 +373,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
373
373
  /** Return the IModelDb where IModelTransformer looks for entities referred to by stored provenance.
374
374
  * @note This will be [[sourceDb]] except when it is a reverse synchronization. In that case it be [[targetDb]].
375
375
  */
376
- async provenanceSourceDb() {
376
+ async getProvenanceSourceDb() {
377
377
  return (await this.getIsReverseSynchronization())
378
378
  ? this.targetDb
379
379
  : this.sourceDb;
@@ -488,7 +488,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
488
488
  * @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".
489
489
  * @throws if the version is not found in a preexisting scope aspect and @see [[IModelTransformOptions.branchRelationshipDataBehavior]] !== "unsafe-migrate"
490
490
  */
491
- async synchronizationVersion() {
491
+ async getSynchronizationVersion() {
492
492
  if (this._cachedSynchronizationVersion === undefined) {
493
493
  const provenanceScopeAspect = await this.tryGetProvenanceScopeAspect();
494
494
  if (!provenanceScopeAspect) {
@@ -517,16 +517,16 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
517
517
  * Provenance scope aspect is created and inserted into provenanceDb when [[initScopeProvenance]] is invoked.
518
518
  */
519
519
  async tryGetProvenanceScopeAspect() {
520
- const scopeProvenanceAspectProps = await IModelTransformer.queryScopeExternalSourceAspect(await this.provenanceDb(), {
520
+ const scopeProvenanceAspectProps = await IModelTransformer.queryScopeExternalSourceAspect(await this.getProvenanceDb(), {
521
521
  id: undefined,
522
522
  classFullName: core_backend_1.ExternalSourceAspect.classFullName,
523
523
  scope: { id: core_common_1.IModel.rootSubjectId },
524
524
  kind: core_backend_1.ExternalSourceAspect.Kind.Scope,
525
525
  element: { id: this.targetScopeElementId ?? core_common_1.IModel.rootSubjectId },
526
- identifier: (await this.provenanceSourceDb()).iModelId,
526
+ identifier: (await this.getProvenanceSourceDb()).iModelId,
527
527
  });
528
528
  return scopeProvenanceAspectProps !== undefined
529
- ? (await this.provenanceDb()).elements.getAspect(scopeProvenanceAspectProps.aspectId)
529
+ ? (await this.getProvenanceDb()).elements.getAspect(scopeProvenanceAspectProps.aspectId)
530
530
  : undefined;
531
531
  }
532
532
  /**
@@ -536,8 +536,8 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
536
536
  * if this was a [BriefcaseDb]($backend)
537
537
  */
538
538
  async initScopeProvenance() {
539
- const provenanceDb = await this.provenanceDb();
540
- const sourceProvenanceDb = await this.provenanceSourceDb();
539
+ const provenanceDb = await this.getProvenanceDb();
540
+ const sourceProvenanceDb = await this.getProvenanceSourceDb();
541
541
  const aspectProps = {
542
542
  id: undefined,
543
543
  version: undefined,
@@ -692,8 +692,8 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
692
692
  // NOTE: if we exposed the native attach database support,
693
693
  // we could get the intersection of fed guids in one query, not sure if it would be faster
694
694
  // OR we could do a raw sqlite query...
695
- const sourceReader = sourceDb.createQueryReader(elementIdByFedGuidQuery);
696
- const targetReader = targetDb.createQueryReader(elementIdByFedGuidQuery);
695
+ const sourceReader = sourceDb.createQueryReader(elementIdByFedGuidQuery, undefined, { usePrimaryConn: true });
696
+ const targetReader = targetDb.createQueryReader(elementIdByFedGuidQuery, undefined, { usePrimaryConn: true });
697
697
  let hasSourceRow = await sourceReader.step();
698
698
  let hasTargetRow = await targetReader.step();
699
699
  while (hasSourceRow && hasTargetRow) {
@@ -730,7 +730,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
730
730
  const params = new core_common_1.QueryBinder();
731
731
  params.bindId("scopeId", args.targetScopeElementId);
732
732
  params.bindString("kind", core_backend_1.ExternalSourceAspect.Kind.Element);
733
- const provenanceReader = args.provenanceDb.createQueryReader(provenanceAspectsQuery, params);
733
+ const provenanceReader = args.provenanceDb.createQueryReader(provenanceAspectsQuery, params, { usePrimaryConn: true });
734
734
  for await (const row of provenanceReader) {
735
735
  // ExternalSourceAspect.Identifier is of type string
736
736
  const aspectIdentifier = row[0];
@@ -740,8 +740,8 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
740
740
  }
741
741
  async forEachTrackedElement(fn) {
742
742
  return IModelTransformer.forEachTrackedElement({
743
- provenanceSourceDb: await this.provenanceSourceDb(),
744
- provenanceDb: await this.provenanceDb(),
743
+ provenanceSourceDb: await this.getProvenanceSourceDb(),
744
+ provenanceDb: await this.getProvenanceDb(),
745
745
  targetScopeElementId: this.targetScopeElementId,
746
746
  isReverseSynchronization: await this.getIsReverseSynchronization(),
747
747
  fn,
@@ -767,7 +767,9 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
767
767
  params.bindString(1, core_backend_1.ExternalSourceAspect.Kind.Element);
768
768
  params.bindId(2, this.targetScopeElementId);
769
769
  params.bindString(3, entityInProvenanceSourceId);
770
- const result = (await this.provenanceDb()).createQueryReader(sql, params);
770
+ const result = (await this.getProvenanceDb()).createQueryReader(sql, params, {
771
+ usePrimaryConn: true,
772
+ });
771
773
  if (await result.step()) {
772
774
  return result.current.id;
773
775
  }
@@ -795,7 +797,9 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
795
797
  params.bindString(1, core_backend_1.ExternalSourceAspect.Kind.Relationship);
796
798
  params.bindId(2, this.targetScopeElementId);
797
799
  params.bindString(3, entityInProvenanceSourceId);
798
- const result = (await this.provenanceDb()).createQueryReader(sql, params);
800
+ const result = (await this.getProvenanceDb()).createQueryReader(sql, params, {
801
+ usePrimaryConn: true,
802
+ });
799
803
  if (await result.step()) {
800
804
  const aspectId = result.current.id;
801
805
  const provenanceRelInstId = result.current.provenanceRelInstId;
@@ -829,7 +833,9 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
829
833
  params.bindId(1, targetRelInfo.sourceId);
830
834
  params.bindId(2, targetRelInfo.targetId);
831
835
  params.bindId(3, await this._targetClassNameToClassId(sourceRelInfo.classFullName));
832
- const result = this.targetDb.createQueryReader(sql, params);
836
+ const result = this.targetDb.createQueryReader(sql, params, {
837
+ usePrimaryConn: true,
838
+ });
833
839
  if (await result.step())
834
840
  return result.current.id;
835
841
  else
@@ -859,21 +865,11 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
859
865
  : classFullName.split(":");
860
866
  params.bindString(1, schemaName);
861
867
  params.bindString(2, className);
862
- const result = db.createQueryReader(sql, params);
868
+ const result = db.createQueryReader(sql, params, { usePrimaryConn: true });
863
869
  if (await result.step())
864
870
  return result.current.id;
865
871
  (0, core_bentley_1.assert)(false, "relationship was not found");
866
872
  }
867
- // Deprecate?
868
- async _queryElemIdByFedGuid(db, fedGuid) {
869
- const sql = "SELECT ECInstanceId FROM Bis.Element WHERE FederationGuid=:fedGuid";
870
- const params = new core_common_1.QueryBinder().bindString("fedGuid", fedGuid);
871
- const reader = db.createQueryReader(sql, params);
872
- if (await reader.step()) {
873
- return reader.current.ecinstanceid;
874
- }
875
- return undefined;
876
- }
877
873
  /** Returns `true` if *brute force* delete detections should be run.
878
874
  * @note This is only called if [[IModelTransformOptions.forceExternalSourceAspectProvenance]] option is true
879
875
  * @note Not relevant for [[process]] when [[IModelTransformOptions.argsForProcessChanges]] are provided and change history is known.
@@ -882,45 +878,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
882
878
  nodeAssert(this._syncType !== undefined);
883
879
  return this._syncType === "not-sync";
884
880
  }
885
- /**
886
- * Detect Element deletes using ExternalSourceAspects in the target iModel and a *brute force* comparison against Elements
887
- * in the source iModel.
888
- * deprecated in 1.x. Do not use this. // FIXME<MIKE>: how to better explain this?
889
- * This method is only called during [[process]] when [[IModelTransformOptions.argsForProcessChanges]] is undefined and the option
890
- * [[IModelTransformOptions.forceExternalSourceAspectProvenance]] is enabled. It is not
891
- * necessary when calling [[process]] with [[IModelTransformOptions.argsForProcessChanges]] defined, since changeset information is sufficient.
892
- * @note you do not need to call this directly unless processing a subset of an iModel.
893
- * @throws [[IModelError]] If the required provenance information is not available to detect deletes.
894
- */
895
- // public async detectElementDeletes(): Promise<void> {
896
- // const sql = `
897
- // SELECT Identifier, Element.Id
898
- // FROM BisCore.ExternalSourceAspect
899
- // WHERE Scope.Id=:scopeId
900
- // AND Kind=:kind
901
- // `;
902
- // nodeAssert(
903
- // !this.isReverseSynchronization,
904
- // "synchronizations with processChanges already detect element deletes, don't call detectElementDeletes"
905
- // );
906
- // // Reported issue: https://github.com/iTwin/itwinjs-core/issues/7989
907
- // this.provenanceDb.withPreparedStatement(sql, (stmt) => {
908
- // stmt.bindId("scopeId", this.targetScopeElementId);
909
- // stmt.bindString("kind", ExternalSourceAspect.Kind.Element);
910
- // while (DbResult.BE_SQLITE_ROW === stmt.step()) {
911
- // // ExternalSourceAspect.Identifier is of type string
912
- // const aspectIdentifier = stmt.getValue(0).getString();
913
- // if (!Id64.isValidId64(aspectIdentifier)) {
914
- // continue;
915
- // }
916
- // const targetElemId = stmt.getValue(1).getId();
917
- // const wasDeletedInSource = !EntityUnifier.exists(this.sourceDb, {
918
- // entityReference: `e${aspectIdentifier}`,
919
- // });
920
- // if (wasDeletedInSource) this.importer.deleteElement(targetElemId);
921
- // }
922
- // });
923
- // }
924
881
  /** Transform the specified sourceElement into ElementProps for the target iModel.
925
882
  * @param sourceElement The Element from the source iModel to transform.
926
883
  * @returns ElementProps for the target iModel.
@@ -929,7 +886,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
929
886
  */
930
887
  async onTransformElement(sourceElement) {
931
888
  core_bentley_1.Logger.logTrace(loggerCategory, `onTransformElement(${sourceElement.id}) "${sourceElement.getDisplayLabel()}"`);
932
- const targetElementProps = this.context.cloneElement(sourceElement, { binaryGeometry: this._options.cloneUsingBinaryGeometry });
889
+ const targetElementProps = await this.context.cloneElement(sourceElement, { binaryGeometry: this._options.cloneUsingBinaryGeometry });
933
890
  // Special case: source element is the root subject
934
891
  if (sourceElement.id === core_common_1.IModel.rootSubjectId) {
935
892
  const targetElementId = this.context.findTargetElementId(sourceElement.id);
@@ -1288,7 +1245,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1288
1245
  // physical consolidation is an example of a 'joining' transform
1289
1246
  // FIXME: verify at finalization time that we don't lose provenance on new elements
1290
1247
  // FIXME: make public and improve `initElementProvenance` API for usage by consolidators
1291
- const provenanceDb = await this.provenanceDb();
1248
+ const provenanceDb = await this.getProvenanceDb();
1292
1249
  if (!this._options.noProvenance) {
1293
1250
  let provenance = this._options.forceExternalSourceAspectProvenance ||
1294
1251
  this._elementsWithExplicitlyTrackedProvenance.has(sourceElement.id)
@@ -1353,7 +1310,9 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1353
1310
  `;
1354
1311
  if (this.exporter.sourceDbChanges?.element.deleteIds.has(sourceModelId)) {
1355
1312
  const params = new core_common_1.QueryBinder().bindId("targetModelId", targetModelId);
1356
- const reader = this.targetDb.createQueryReader(sql, params);
1313
+ const reader = this.targetDb.createQueryReader(sql, params, {
1314
+ usePrimaryConn: true,
1315
+ });
1357
1316
  const isDefinitionPartition = await reader.step();
1358
1317
  if (isDefinitionPartition) {
1359
1318
  // Skipping model deletion because model's partition will also be deleted.
@@ -1411,12 +1370,12 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1411
1370
  // import DefinitionModels first
1412
1371
  const childDefinitionPartitionSql = `SELECT ECInstanceId FROM ${core_backend_1.DefinitionPartition.classFullName} WHERE Parent.Id=:subjectId`;
1413
1372
  const params = new core_common_1.QueryBinder().bindId("subjectId", sourceSubjectId);
1414
- for await (const row of this.sourceDb.createQueryReader(childDefinitionPartitionSql, params)) {
1373
+ for await (const row of this.sourceDb.createQueryReader(childDefinitionPartitionSql, params, { usePrimaryConn: true })) {
1415
1374
  await this.processModel(row.id);
1416
1375
  }
1417
1376
  // import other partitions next
1418
1377
  const childPartitionSql = `SELECT ECInstanceId FROM ${core_backend_1.InformationPartitionElement.classFullName} WHERE Parent.Id=:subjectId`;
1419
- for await (const row of this.sourceDb.createQueryReader(childPartitionSql, params)) {
1378
+ for await (const row of this.sourceDb.createQueryReader(childPartitionSql, params, { usePrimaryConn: true })) {
1420
1379
  const modelId = row.id;
1421
1380
  const model = this.sourceDb.models.getModel(modelId);
1422
1381
  if (!(model instanceof core_backend_1.DefinitionModel)) {
@@ -1425,7 +1384,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1425
1384
  }
1426
1385
  // recurse into child Subjects
1427
1386
  const childSubjectSql = `SELECT ECInstanceId FROM ${core_backend_1.Subject.classFullName} WHERE Parent.Id=:subjectId`;
1428
- for await (const row of this.sourceDb.createQueryReader(childSubjectSql, params)) {
1387
+ for await (const row of this.sourceDb.createQueryReader(childSubjectSql, params, { usePrimaryConn: true })) {
1429
1388
  await this.processSubjectSubModels(row.id);
1430
1389
  }
1431
1390
  }
@@ -1532,7 +1491,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1532
1491
  core_bentley_1.Logger.logTrace(loggerCategory, `new pendingReverseSyncChanges: ${jsonProps.pendingReverseSyncChangesetIndices}`);
1533
1492
  core_bentley_1.Logger.logTrace(loggerCategory, `new pendingSyncChanges: ${jsonProps.pendingSyncChangesetIndices}`);
1534
1493
  }
1535
- (await this.provenanceDb()).elements.updateAspect({
1494
+ (await this.getProvenanceDb()).elements.updateAspect({
1536
1495
  ...this._targetScopeProvenanceProps,
1537
1496
  jsonProperties: JSON.stringify(this._targetScopeProvenanceProps.jsonProperties),
1538
1497
  });
@@ -1579,7 +1538,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1579
1538
  const targetFedGuid = this.sourceDb.elements.getFederationGuidFromId(sourceRelationship.targetId);
1580
1539
  const targetRelationshipProps = this.onTransformRelationship(sourceRelationship);
1581
1540
  const targetRelationshipInstanceId = this.importer.importRelationship(targetRelationshipProps);
1582
- const provenanceDb = await this.provenanceDb();
1541
+ const provenanceDb = await this.getProvenanceDb();
1583
1542
  if (!this._options.noProvenance &&
1584
1543
  core_bentley_1.Id64.isValid(targetRelationshipInstanceId)) {
1585
1544
  let provenance = !this._options.forceExternalSourceAspectProvenance
@@ -1621,7 +1580,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1621
1580
  }
1622
1581
  if (deletedRelData.provenanceAspectId) {
1623
1582
  try {
1624
- (await this.provenanceDb()).elements.deleteAspect(deletedRelData.provenanceAspectId);
1583
+ (await this.getProvenanceDb()).elements.deleteAspect(deletedRelData.provenanceAspectId);
1625
1584
  }
1626
1585
  catch (error) {
1627
1586
  // This aspect may no longer exist if it was deleted at some other point during the transformation. This is fine.
@@ -1632,58 +1591,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1632
1591
  }
1633
1592
  }
1634
1593
  _yieldManager = new core_bentley_1.YieldManager();
1635
- /** Detect Relationship deletes using ExternalSourceAspects in the target iModel and a *brute force* comparison against relationships in the source iModel.
1636
- * @deprecated in 1.x. Don't use this anymore
1637
- * @see [[process]] with [[IModelTransformOptions.argsForProcessChanges]] provided.
1638
- * @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.
1639
- * @throws [[IModelError]] If the required provenance information is not available to detect deletes.
1640
- */
1641
- // public async detectRelationshipDeletes(): Promise<void> {
1642
- // if (this.isReverseSynchronization) {
1643
- // throw new IModelError(
1644
- // IModelStatus.BadRequest,
1645
- // "Cannot detect deletes when isReverseSynchronization=true"
1646
- // );
1647
- // }
1648
- // const aspectDeleteIds: Id64String[] = [];
1649
- // const sql = `
1650
- // SELECT ECInstanceId, Identifier, JsonProperties
1651
- // FROM ${ExternalSourceAspect.classFullName} aspect
1652
- // WHERE aspect.Scope.Id=:scopeId
1653
- // AND aspect.Kind=:kind
1654
- // `;
1655
- // const params = new QueryBinder().bindId(
1656
- // "scopeId",
1657
- // this.targetScopeElementId
1658
- // );
1659
- // params.bindString("kind", ExternalSourceAspect.Kind.Relationship);
1660
- // for await (const row of this.targetDb.createQueryReader(sql, params)) {
1661
- // const sourceRelInstanceId: Id64String = Id64.fromJSON(row[1]);
1662
- // if (
1663
- // undefined ===
1664
- // this.sourceDb.relationships.tryGetInstanceProps(
1665
- // ElementRefersToElements.classFullName,
1666
- // sourceRelInstanceId
1667
- // )
1668
- // ) {
1669
- // // this function exists only to support some in-imodel transformations, which must
1670
- // // use the old (external source aspect) provenance method anyway so we don't need to support
1671
- // // new provenance
1672
- // const json: any = JSON.parse(row[2]);
1673
- // const targetRelInstanceId =
1674
- // json.targetRelInstanceId ?? json.provenanceRelInstanceId;
1675
- // if (targetRelInstanceId) {
1676
- // this.importer.deleteRelationship({
1677
- // id: targetRelInstanceId,
1678
- // classFullName: ElementRefersToElements.classFullName,
1679
- // });
1680
- // }
1681
- // aspectDeleteIds.push(row.id);
1682
- // }
1683
- // await this._yieldManager.allowYield();
1684
- // }
1685
- // this.targetDb.elements.deleteAspect(aspectDeleteIds);
1686
- // }
1687
1594
  /** Transform the specified sourceRelationship into RelationshipProps for the target iModel.
1688
1595
  * @param sourceRelationship The Relationship from the source iModel to be transformed.
1689
1596
  * @returns RelationshipProps for the target iModel.
@@ -1923,11 +1830,11 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1923
1830
  this._sourceChangeDataState = "has-changes";
1924
1831
  }
1925
1832
  const relationshipECClassIdsToSkip = new Set();
1926
- for await (const row of this.sourceDb.createQueryReader("SELECT ECInstanceId FROM ECDbMeta.ECClassDef where ECInstanceId IS (BisCore.ElementDrivesElement)")) {
1833
+ for await (const row of this.sourceDb.createQueryReader("SELECT ECInstanceId FROM ECDbMeta.ECClassDef where ECInstanceId IS (BisCore.ElementDrivesElement)", undefined, { usePrimaryConn: true })) {
1927
1834
  relationshipECClassIdsToSkip.add(row.ECInstanceId);
1928
1835
  }
1929
1836
  const relationshipECClassIds = new Set();
1930
- for await (const row of this.sourceDb.createQueryReader("SELECT ECInstanceId FROM ECDbMeta.ECClassDef where ECInstanceId IS (BisCore.ElementRefersToElements)")) {
1837
+ for await (const row of this.sourceDb.createQueryReader("SELECT ECInstanceId FROM ECDbMeta.ECClassDef where ECInstanceId IS (BisCore.ElementRefersToElements)", undefined, { usePrimaryConn: true })) {
1931
1838
  relationshipECClassIds.add(row.ECInstanceId);
1932
1839
  }
1933
1840
  // For later use when processing deletes.
@@ -2009,7 +1916,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2009
1916
  async processDeletedOp(change, mapOfDeletedElemIdToScopeEsas, isRelationship, alreadyImportedElementInserts, alreadyImportedModelInserts) {
2010
1917
  // we need a connected iModel with changes to remap elements with deletions
2011
1918
  const notConnectedModel = this.sourceDb.iTwinId === undefined;
2012
- const noChanges = (await this.synchronizationVersion()).index ===
1919
+ const noChanges = (await this.getSynchronizationVersion()).index ===
2013
1920
  this.sourceDb.changeset.index &&
2014
1921
  (this.exporter.sourceDbChanges === undefined ||
2015
1922
  !this.exporter.sourceDbChanges.hasChanges);
@@ -2019,7 +1926,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2019
1926
  * if our ChangedECInstance is in the provenanceDb, then we can use the ids we find in the ChangedECInstance to query for ESAs.
2020
1927
  * This is because the ESAs are stored on an element Id thats present in the provenanceDb.
2021
1928
  */
2022
- const changeDataInProvenanceDb = this.sourceDb === (await this.provenanceDb());
1929
+ const changeDataInProvenanceDb = this.sourceDb === (await this.getProvenanceDb());
2023
1930
  const getTargetIdFromSourceId = async (id) => {
2024
1931
  let identifierValue;
2025
1932
  let element;
@@ -2035,7 +1942,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2035
1942
  this.targetScopeElementId,
2036
1943
  core_backend_1.ExternalSourceAspect.Kind.Element,
2037
1944
  id,
2038
- ]))) {
1945
+ ]), { usePrimaryConn: true })) {
2039
1946
  identifierValue = row.Identifier;
2040
1947
  }
2041
1948
  identifierValue =
@@ -2067,7 +1974,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2067
1974
  targetIdInTarget: targetIdOfRelationshipInTarget,
2068
1975
  });
2069
1976
  }
2070
- else if (this.sourceDb === (await this.provenanceSourceDb())) {
1977
+ else if (this.sourceDb === (await this.getProvenanceSourceDb())) {
2071
1978
  const relProvenance = await this._queryProvenanceForRelationship(changedInstanceId, {
2072
1979
  classFullName: classFullName ?? "",
2073
1980
  sourceId: sourceIdOfRelationshipInSource,
@@ -2084,7 +1991,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2084
1991
  else {
2085
1992
  let targetId = await getTargetIdFromSourceId(changedInstanceId);
2086
1993
  if (targetId === undefined &&
2087
- this.sourceDb === (await this.provenanceSourceDb())) {
1994
+ this.sourceDb === (await this.getProvenanceSourceDb())) {
2088
1995
  targetId = await this._queryProvenanceForElement(changedInstanceId);
2089
1996
  }
2090
1997
  // since we are processing one changeset at a time, we can see local source deletes
@@ -2093,7 +2000,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2093
2000
  if (deletionNotInTarget)
2094
2001
  return;
2095
2002
  if (targetId === undefined) {
2096
- throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadElement, "targetId should aquired from source id or element provenance");
2003
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadElement, "targetId should be acquired from source id or element provenance");
2097
2004
  }
2098
2005
  this.context.remapElement(changedInstanceId, targetId);
2099
2006
  // If an entity insert and an entity delete both point to the same entity in target iModel, that means that entity was recreated.
@@ -2113,7 +2020,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2113
2020
  this._sourceChangeDataState = "unconnected";
2114
2021
  return;
2115
2022
  }
2116
- const syncVersion = await this.synchronizationVersion();
2023
+ const syncVersion = await this.getSynchronizationVersion();
2117
2024
  const noChanges = syncVersion.index === this.sourceDb.changeset.index;
2118
2025
  if (noChanges) {
2119
2026
  this._sourceChangeDataState = "no-changes";
@@ -2220,8 +2127,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2220
2127
  if (this._options.forceExternalSourceAspectProvenance &&
2221
2128
  this.shouldDetectDeletes()) {
2222
2129
  core_bentley_1.Logger.logWarning(loggerCategory, "This workflows was deprecated in v1 and is no longer supported");
2223
- // await this.detectElementDeletes();
2224
- // await this.detectRelationshipDeletes();
2225
2130
  }
2226
2131
  if (this._options.optimizeGeometry)
2227
2132
  this.importer.optimizeGeometry(this._options.optimizeGeometry);
@@ -2283,7 +2188,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
2283
2188
  ? { startChangeset }
2284
2189
  : {
2285
2190
  startChangeset: {
2286
- index: (await this.synchronizationVersion()).index + 1,
2191
+ index: (await this.getSynchronizationVersion()).index + 1,
2287
2192
  },
2288
2193
  }),
2289
2194
  };
@@ -2402,17 +2307,4 @@ class TemplateModelCloner extends IModelTransformer {
2402
2307
  }
2403
2308
  }
2404
2309
  exports.TemplateModelCloner = TemplateModelCloner;
2405
- //Deprecate in preference of imodeldb.elements.getFederationGuidFromId()?
2406
- async function queryElemFedGuid(db, elemId) {
2407
- const sql = `
2408
- SELECT FederationGuid
2409
- FROM bis.Element
2410
- WHERE ECInstanceId=?
2411
- `;
2412
- const params = new core_common_1.QueryBinder().bindId(1, elemId);
2413
- const reader = db.createQueryReader(sql, params);
2414
- (0, core_bentley_1.assert)(await reader.step(), "element not found");
2415
- const result = reader.current.federationGuid;
2416
- return result;
2417
- }
2418
2310
  //# sourceMappingURL=IModelTransformer.js.map