@itwin/imodel-transformer 2.0.0-dev.14 → 2.0.0-dev.16

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.
@@ -93,12 +93,18 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
93
93
  _partiallyCommittedElementIds = new Set();
94
94
  _partiallyCommittedAspectIds = new Set();
95
95
  /**
96
- * Tracks target element IDs that were imported (inserted or updated) during the current
96
+ * Tracks target element IDs that were remapped by Code during the current
97
97
  * transformation pass. Used to prevent deletion of target elements that have been remapped
98
98
  * to a new source element in the same pass (e.g., when a source element is deleted and a
99
99
  * new one with the same properties is added, causing a remap to the same target).
100
100
  */
101
- _targetElementsImportedInCurrentTransform = new Set();
101
+ _targetElementIdsRemappedByCode = new Set();
102
+ /**
103
+ * Tracks target model IDs that were imported (inserted or updated) during the current
104
+ * transformation pass. Used to prevent deletion of target models that have been recreated
105
+ * in the same pass (e.g. when a partition element is recreated with a new model).
106
+ */
107
+ _targetModelsImportedInCurrentTransform = new Set();
102
108
  /** the options that were used to initialize this transformer */
103
109
  _options;
104
110
  _changesetRanges = undefined;
@@ -638,6 +644,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
638
644
  // ensure code remapping doesn't change the target class
639
645
  targetElementId = maybeTargetElementId;
640
646
  this.context.remapElement(sourceElement.id, targetElementId); // record that the targetElement was found by Code
647
+ this._targetElementIdsRemappedByCode.add(targetElementId);
641
648
  }
642
649
  else {
643
650
  targetElementProps.code = core_common_1.Code.createEmpty(); // clear out invalid code
@@ -684,7 +691,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
684
691
  if (targetElementProps.id === undefined) {
685
692
  throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadElement, "targetElementProps.id should be assigned by importElement");
686
693
  }
687
- this._targetElementsImportedInCurrentTransform.add(targetElementProps.id);
688
694
  this.context.remapElement(sourceElement.id, targetElementProps.id);
689
695
  // the transformer does not currently 'split' or 'join' any elements, therefore, it does not
690
696
  // insert external source aspects because federation guids are sufficient for this.
@@ -720,9 +726,9 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
720
726
  async onDeleteElement(sourceElementId) {
721
727
  const targetElementId = this.context.findTargetElementId(sourceElementId);
722
728
  if (core_bentley_1.Id64.isValidId64(targetElementId)) {
723
- // Skip deletion if this target element was already imported (inserted/updated) during
729
+ // Skip deletion if new / updated source element was remapped to it by Code during
724
730
  // this transformation pass.
725
- if (!this._targetElementsImportedInCurrentTransform.has(targetElementId)) {
731
+ if (!this._targetElementIdsRemappedByCode.has(targetElementId)) {
726
732
  await this.importer.deleteElement(targetElementId);
727
733
  }
728
734
  }
@@ -742,6 +748,10 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
742
748
  return;
743
749
  const targetModelProps = this.onTransformModel(sourceModel, targetModeledElementId);
744
750
  await this.importer.importModel(targetModelProps);
751
+ if (targetModelProps.id === undefined) {
752
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadModel, "targetModelProps.id should be assigned by now");
753
+ }
754
+ this._targetModelsImportedInCurrentTransform.add(targetModelProps.id);
745
755
  }
746
756
  /** Override of [IModelExportHandler.onDeleteModel]($transformer) that is called when [IModelExporter]($transformer) detects that a [Model]($backend) has been deleted from the source iModel. */
747
757
  async onDeleteModel(sourceModelId) {
@@ -751,6 +761,13 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
751
761
  const targetModelId = this.context.findTargetElementId(sourceModelId);
752
762
  if (!core_bentley_1.Id64.isValidId64(targetModelId))
753
763
  return;
764
+ // This handles cases where model with a partition element was remapped to
765
+ // new element by code value after recreation.
766
+ if (this._targetElementIdsRemappedByCode.has(targetModelId) &&
767
+ this._targetModelsImportedInCurrentTransform.has(targetModelId)) {
768
+ core_bentley_1.Logger.logTrace(loggerCategory, `Skipping delete operation for model (source id: ${sourceModelId}) because the target model (id: ${targetModelId}) was remapped by Code and re-imported during this transformation pass.`);
769
+ return;
770
+ }
754
771
  const sql = `
755
772
  SELECT 1
756
773
  FROM bis.DefinitionPartition
@@ -1480,7 +1497,8 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1480
1497
  * @note [[processSchemas]] is not called automatically since the target iModel may want a different collection of schemas.
1481
1498
  */
1482
1499
  async processAll() {
1483
- this._targetElementsImportedInCurrentTransform.clear();
1500
+ this._targetElementIdsRemappedByCode.clear();
1501
+ this._targetModelsImportedInCurrentTransform.clear();
1484
1502
  // processAll always has changes to process, so mark it as such for version tracking
1485
1503
  this._sourceChangeDataState = "has-changes";
1486
1504
  await this.exporter.exportCodeSpecs();
@@ -1517,7 +1535,8 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
1517
1535
  * @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.
1518
1536
  */
1519
1537
  async processChanges(options) {
1520
- this._targetElementsImportedInCurrentTransform.clear();
1538
+ this._targetElementIdsRemappedByCode.clear();
1539
+ this._targetModelsImportedInCurrentTransform.clear();
1521
1540
  // must wait for initialization of synchronization provenance data
1522
1541
  await this.exporter.exportChanges(await this.getExportInitOpts(options));
1523
1542
  await this.completePartiallyCommittedElements();