@itwin/imodel-transformer 2.0.0-dev.42 → 2.0.0-dev.44

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 (34) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/IModelExporter.d.ts +5 -0
  3. package/lib/cjs/IModelExporter.d.ts.map +1 -1
  4. package/lib/cjs/IModelExporter.js +20 -17
  5. package/lib/cjs/IModelExporter.js.map +1 -1
  6. package/lib/cjs/IModelTransformer.d.ts +9 -11
  7. package/lib/cjs/IModelTransformer.d.ts.map +1 -1
  8. package/lib/cjs/IModelTransformer.js +19 -64
  9. package/lib/cjs/IModelTransformer.js.map +1 -1
  10. package/lib/cjs/IModelTransformerError.d.ts +4 -0
  11. package/lib/cjs/IModelTransformerError.d.ts.map +1 -1
  12. package/lib/cjs/IModelTransformerError.js +4 -0
  13. package/lib/cjs/IModelTransformerError.js.map +1 -1
  14. package/lib/cjs/imodel-transformer.d.ts +1 -0
  15. package/lib/cjs/imodel-transformer.d.ts.map +1 -1
  16. package/lib/cjs/imodel-transformer.js +1 -0
  17. package/lib/cjs/imodel-transformer.js.map +1 -1
  18. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts +29 -0
  19. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +1 -0
  20. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js +212 -0
  21. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js.map +1 -0
  22. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts +25 -0
  23. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts.map +1 -0
  24. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js +163 -0
  25. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js.map +1 -0
  26. package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts +59 -0
  27. package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts.map +1 -0
  28. package/lib/cjs/schema-processing/SchemaProcessingStrategy.js +28 -0
  29. package/lib/cjs/schema-processing/SchemaProcessingStrategy.js.map +1 -0
  30. package/lib/cjs/schema-processing.d.ts +7 -0
  31. package/lib/cjs/schema-processing.d.ts.map +1 -0
  32. package/lib/cjs/schema-processing.js +27 -0
  33. package/lib/cjs/schema-processing.js.map +1 -0
  34. package/package.json +37 -4
@@ -60,6 +60,10 @@ export declare enum IModelTransformerError {
60
60
  RelationshipProvenanceNotFound = "relationship-provenance-not-found",
61
61
  /** The root subject cannot be processed directly. */
62
62
  RootSubjectNotProcessable = "root-subject-not-processable",
63
+ /** A schema conflict or incompatible schema version prevented processing. */
64
+ SchemaConflict = "schema-conflict",
65
+ /** The source schema dependency graph contains a cycle. */
66
+ SchemaDependencyCycle = "schema-dependency-cycle",
63
67
  /** A required schema could not be loaded. */
64
68
  SchemaLoadFailed = "schema-load-failed",
65
69
  /** Reverse synchronization requires a source edit transaction. */
@@ -1 +1 @@
1
- {"version":3,"file":"IModelTransformerError.d.ts","sourceRoot":"","sources":["../../src/IModelTransformerError.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,eAAO,MAAM,2BAA2B,8BAA8B,CAAC;AAEvE;;GAEG;AACH,oBAAY,sBAAsB;IAChC,sEAAsE;IACtE,mBAAmB,0BAA0B;IAC7C,qDAAqD;IACrD,8BAA8B,sCAAsC;IACpE,iDAAiD;IACjD,yBAAyB,gCAAgC;IACzD,oFAAoF;IACpF,iBAAiB,uBAAuB;IACxC,mDAAmD;IACnD,wBAAwB,+BAA+B;IACvD,iEAAiE;IACjE,yBAAyB,gCAAgC;IACzD,iDAAiD;IACjD,gBAAgB,wBAAwB;IACxC,+DAA+D;IAC/D,uBAAuB,+BAA+B;IACtD,sDAAsD;IACtD,iBAAiB,wBAAwB;IACzC,qDAAqD;IACrD,8BAA8B,sCAAsC;IACpE,6CAA6C;IAC7C,0BAA0B,kCAAkC;IAC5D,8DAA8D;IAC9D,qCAAqC,6CAA6C;IAClF,wEAAwE;IACxE,kCAAkC,0CAA0C;IAC5E,uFAAuF;IACvF,sBAAsB,4BAA4B;IAClD,sEAAsE;IACtE,sBAAsB,6BAA6B;IACnD,uCAAuC;IACvC,WAAW,iBAAiB;IAC5B,6DAA6D;IAC7D,sBAAsB,6BAA6B;IACnD,gDAAgD;IAChD,cAAc,qBAAqB;IACnC,8CAA8C;IAC9C,kBAAkB,wBAAwB;IAC1C,6DAA6D;IAC7D,YAAY,kBAAkB;IAC9B,gDAAgD;IAChD,mBAAmB,0BAA0B;IAC7C,6DAA6D;IAC7D,uBAAuB,8BAA8B;IACrD,oEAAoE;IACpE,2BAA2B,kCAAkC;IAC7D,+CAA+C;IAC/C,yBAAyB,iCAAiC;IAC1D,2DAA2D;IAC3D,sBAAsB,6BAA6B;IACnD,kDAAkD;IAClD,8BAA8B,sCAAsC;IACpE,qDAAqD;IACrD,yBAAyB,iCAAiC;IAC1D,6CAA6C;IAC7C,gBAAgB,uBAAuB;IACvC,kEAAkE;IAClE,qBAAqB,6BAA6B;IAClD,sDAAsD;IACtD,2BAA2B,kCAAkC;IAC7D,0DAA0D;IAC1D,gCAAgC,wCAAwC;IACxE,uDAAuD;IACvD,6BAA6B,oCAAoC;IACjE,yDAAyD;IACzD,mBAAmB,2BAA2B;CAC/C"}
1
+ {"version":3,"file":"IModelTransformerError.d.ts","sourceRoot":"","sources":["../../src/IModelTransformerError.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,eAAO,MAAM,2BAA2B,8BAA8B,CAAC;AAEvE;;GAEG;AACH,oBAAY,sBAAsB;IAChC,sEAAsE;IACtE,mBAAmB,0BAA0B;IAC7C,qDAAqD;IACrD,8BAA8B,sCAAsC;IACpE,iDAAiD;IACjD,yBAAyB,gCAAgC;IACzD,oFAAoF;IACpF,iBAAiB,uBAAuB;IACxC,mDAAmD;IACnD,wBAAwB,+BAA+B;IACvD,iEAAiE;IACjE,yBAAyB,gCAAgC;IACzD,iDAAiD;IACjD,gBAAgB,wBAAwB;IACxC,+DAA+D;IAC/D,uBAAuB,+BAA+B;IACtD,sDAAsD;IACtD,iBAAiB,wBAAwB;IACzC,qDAAqD;IACrD,8BAA8B,sCAAsC;IACpE,6CAA6C;IAC7C,0BAA0B,kCAAkC;IAC5D,8DAA8D;IAC9D,qCAAqC,6CAA6C;IAClF,wEAAwE;IACxE,kCAAkC,0CAA0C;IAC5E,uFAAuF;IACvF,sBAAsB,4BAA4B;IAClD,sEAAsE;IACtE,sBAAsB,6BAA6B;IACnD,uCAAuC;IACvC,WAAW,iBAAiB;IAC5B,6DAA6D;IAC7D,sBAAsB,6BAA6B;IACnD,gDAAgD;IAChD,cAAc,qBAAqB;IACnC,8CAA8C;IAC9C,kBAAkB,wBAAwB;IAC1C,6DAA6D;IAC7D,YAAY,kBAAkB;IAC9B,gDAAgD;IAChD,mBAAmB,0BAA0B;IAC7C,6DAA6D;IAC7D,uBAAuB,8BAA8B;IACrD,oEAAoE;IACpE,2BAA2B,kCAAkC;IAC7D,+CAA+C;IAC/C,yBAAyB,iCAAiC;IAC1D,2DAA2D;IAC3D,sBAAsB,6BAA6B;IACnD,kDAAkD;IAClD,8BAA8B,sCAAsC;IACpE,qDAAqD;IACrD,yBAAyB,iCAAiC;IAC1D,6EAA6E;IAC7E,cAAc,oBAAoB;IAClC,2DAA2D;IAC3D,qBAAqB,4BAA4B;IACjD,6CAA6C;IAC7C,gBAAgB,uBAAuB;IACvC,kEAAkE;IAClE,qBAAqB,6BAA6B;IAClD,sDAAsD;IACtD,2BAA2B,kCAAkC;IAC7D,0DAA0D;IAC1D,gCAAgC,wCAAwC;IACxE,uDAAuD;IACvD,6BAA6B,oCAAoC;IACjE,yDAAyD;IACzD,mBAAmB,2BAA2B;CAC/C"}
@@ -69,6 +69,10 @@ var IModelTransformerError;
69
69
  IModelTransformerError["RelationshipProvenanceNotFound"] = "relationship-provenance-not-found";
70
70
  /** The root subject cannot be processed directly. */
71
71
  IModelTransformerError["RootSubjectNotProcessable"] = "root-subject-not-processable";
72
+ /** A schema conflict or incompatible schema version prevented processing. */
73
+ IModelTransformerError["SchemaConflict"] = "schema-conflict";
74
+ /** The source schema dependency graph contains a cycle. */
75
+ IModelTransformerError["SchemaDependencyCycle"] = "schema-dependency-cycle";
72
76
  /** A required schema could not be loaded. */
73
77
  IModelTransformerError["SchemaLoadFailed"] = "schema-load-failed";
74
78
  /** Reverse synchronization requires a source edit transaction. */
@@ -1 +1 @@
1
- {"version":3,"file":"IModelTransformerError.js","sourceRoot":"","sources":["../../src/IModelTransformerError.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG;;GAEG;AACH,gEAAgE;AACnD,QAAA,2BAA2B,GAAG,2BAA2B,CAAC;AAEvE;;GAEG;AACH,IAAY,sBAmEX;AAnED,WAAY,sBAAsB;IAChC,sEAAsE;IACtE,uEAA6C,CAAA;IAC7C,qDAAqD;IACrD,8FAAoE,CAAA;IACpE,iDAAiD;IACjD,mFAAyD,CAAA;IACzD,oFAAoF;IACpF,kEAAwC,CAAA;IACxC,mDAAmD;IACnD,iFAAuD,CAAA;IACvD,iEAAiE;IACjE,mFAAyD,CAAA;IACzD,iDAAiD;IACjD,kEAAwC,CAAA;IACxC,+DAA+D;IAC/D,gFAAsD,CAAA;IACtD,sDAAsD;IACtD,mEAAyC,CAAA;IACzC,qDAAqD;IACrD,8FAAoE,CAAA;IACpE,6CAA6C;IAC7C,sFAA4D,CAAA;IAC5D,8DAA8D;IAC9D,4GAAkF,CAAA;IAClF,wEAAwE;IACxE,sGAA4E,CAAA;IAC5E,uFAAuF;IACvF,4EAAkD,CAAA;IAClD,sEAAsE;IACtE,6EAAmD,CAAA;IACnD,uCAAuC;IACvC,sDAA4B,CAAA;IAC5B,6DAA6D;IAC7D,6EAAmD,CAAA;IACnD,gDAAgD;IAChD,6DAAmC,CAAA;IACnC,8CAA8C;IAC9C,oEAA0C,CAAA;IAC1C,6DAA6D;IAC7D,wDAA8B,CAAA;IAC9B,gDAAgD;IAChD,uEAA6C,CAAA;IAC7C,6DAA6D;IAC7D,+EAAqD,CAAA;IACrD,oEAAoE;IACpE,uFAA6D,CAAA;IAC7D,+CAA+C;IAC/C,oFAA0D,CAAA;IAC1D,2DAA2D;IAC3D,6EAAmD,CAAA;IACnD,kDAAkD;IAClD,8FAAoE,CAAA;IACpE,qDAAqD;IACrD,oFAA0D,CAAA;IAC1D,6CAA6C;IAC7C,iEAAuC,CAAA;IACvC,kEAAkE;IAClE,4EAAkD,CAAA;IAClD,sDAAsD;IACtD,uFAA6D,CAAA;IAC7D,0DAA0D;IAC1D,kGAAwE,CAAA;IACxE,uDAAuD;IACvD,2FAAiE,CAAA;IACjE,yDAAyD;IACzD,wEAA8C,CAAA;AAChD,CAAC,EAnEW,sBAAsB,sCAAtB,sBAAsB,QAmEjC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\n/** Scope shared by errors originating from `@itwin/imodel-transformer`.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const IModelTransformerErrorScope = \"@itwin/imodel-transformer\";\n\n/** Errors originating from `@itwin/imodel-transformer`.\n * @beta\n */\nexport enum IModelTransformerError {\n /** An ElementAspect change requires its owning element identifier. */\n AspectOwnerRequired = \"aspect-owner-required\",\n /** Required changed-instance metadata is missing. */\n ChangedInstanceMetadataMissing = \"changed-instance-metadata-missing\",\n /** A required changeset index is unavailable. */\n ChangesetIndexUnavailable = \"changeset-index-unavailable\",\n /** A source entity contains a dangling reference rejected by transformer policy. */\n DanglingReference = \"dangling-reference\",\n /** A required dependency has no target mapping. */\n DependencyMappingMissing = \"dependency-mapping-missing\",\n /** The installed iTwin.js dependency version is incompatible. */\n DependencyVersionMismatch = \"dependency-version-mismatch\",\n /** A required edit transaction is not active. */\n EditTxnNotActive = \"edit-txn-not-active\",\n /** An element identifier cannot be preserved in the target. */\n ElementIdNotPreservable = \"element-id-not-preservable\",\n /** A required element identifier was not provided. */\n ElementIdRequired = \"element-id-required\",\n /** Exporting changes requires a briefcase iModel. */\n ExportChangesRequiresBriefcase = \"export-changes-requires-briefcase\",\n /** No export handler has been registered. */\n ExportHandlerNotRegistered = \"export-handler-not-registered\",\n /** A required geographic coordinate system is unavailable. */\n GeographicCoordinateSystemUnavailable = \"geographic-coordinate-system-unavailable\",\n /** Source and target geographic coordinate systems are incompatible. */\n GeographicCoordinateSystemMismatch = \"geographic-coordinate-system-mismatch\",\n /** Required geolocation data or an invertible geolocation transform is unavailable. */\n GeolocationUnavailable = \"geolocation-unavailable\",\n /** A custom importer option conflicts with the transformer option. */\n ImporterOptionMismatch = \"importer-option-mismatch\",\n /** A code is invalid or incomplete. */\n InvalidCode = \"invalid-code\",\n /** An entity reference has an unsupported representation. */\n InvalidEntityReference = \"invalid-entity-reference\",\n /** A model identifier is invalid or missing. */\n InvalidModelId = \"invalid-model-id\",\n /** A subcategory is invalid or incomplete. */\n InvalidSubCategory = \"invalid-subcategory\",\n /** The source iModel has no changesets or custom changes. */\n NoChangesets = \"no-changesets\",\n /** A required parent model was not provided. */\n ParentModelRequired = \"parent-model-required\",\n /** A provenance scope conflicts with existing provenance. */\n ProvenanceScopeConflict = \"provenance-scope-conflict\",\n /** The BisCore schema does not support required provenance data. */\n ProvenanceSchemaUnsupported = \"provenance-schema-unsupported\",\n /** A required relationship class is absent. */\n RelationshipClassNotFound = \"relationship-class-not-found\",\n /** A required relationship identifier was not provided. */\n RelationshipIdRequired = \"relationship-id-required\",\n /** Expected relationship provenance is absent. */\n RelationshipProvenanceNotFound = \"relationship-provenance-not-found\",\n /** The root subject cannot be processed directly. */\n RootSubjectNotProcessable = \"root-subject-not-processable\",\n /** A required schema could not be loaded. */\n SchemaLoadFailed = \"schema-load-failed\",\n /** Reverse synchronization requires a source edit transaction. */\n SourceEditTxnRequired = \"source-edit-txn-required\",\n /** The requested synchronization range is invalid. */\n SynchronizationRangeInvalid = \"synchronization-range-invalid\",\n /** The synchronization direction cannot be determined. */\n SynchronizationTypeNotDetermined = \"synchronization-type-not-determined\",\n /** The previous synchronization version is missing. */\n SynchronizationVersionMissing = \"synchronization-version-missing\",\n /** A required class is absent from the target iModel. */\n TargetClassNotFound = \"target-class-not-found\",\n}\n"]}
1
+ {"version":3,"file":"IModelTransformerError.js","sourceRoot":"","sources":["../../src/IModelTransformerError.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG;;GAEG;AACH,gEAAgE;AACnD,QAAA,2BAA2B,GAAG,2BAA2B,CAAC;AAEvE;;GAEG;AACH,IAAY,sBAuEX;AAvED,WAAY,sBAAsB;IAChC,sEAAsE;IACtE,uEAA6C,CAAA;IAC7C,qDAAqD;IACrD,8FAAoE,CAAA;IACpE,iDAAiD;IACjD,mFAAyD,CAAA;IACzD,oFAAoF;IACpF,kEAAwC,CAAA;IACxC,mDAAmD;IACnD,iFAAuD,CAAA;IACvD,iEAAiE;IACjE,mFAAyD,CAAA;IACzD,iDAAiD;IACjD,kEAAwC,CAAA;IACxC,+DAA+D;IAC/D,gFAAsD,CAAA;IACtD,sDAAsD;IACtD,mEAAyC,CAAA;IACzC,qDAAqD;IACrD,8FAAoE,CAAA;IACpE,6CAA6C;IAC7C,sFAA4D,CAAA;IAC5D,8DAA8D;IAC9D,4GAAkF,CAAA;IAClF,wEAAwE;IACxE,sGAA4E,CAAA;IAC5E,uFAAuF;IACvF,4EAAkD,CAAA;IAClD,sEAAsE;IACtE,6EAAmD,CAAA;IACnD,uCAAuC;IACvC,sDAA4B,CAAA;IAC5B,6DAA6D;IAC7D,6EAAmD,CAAA;IACnD,gDAAgD;IAChD,6DAAmC,CAAA;IACnC,8CAA8C;IAC9C,oEAA0C,CAAA;IAC1C,6DAA6D;IAC7D,wDAA8B,CAAA;IAC9B,gDAAgD;IAChD,uEAA6C,CAAA;IAC7C,6DAA6D;IAC7D,+EAAqD,CAAA;IACrD,oEAAoE;IACpE,uFAA6D,CAAA;IAC7D,+CAA+C;IAC/C,oFAA0D,CAAA;IAC1D,2DAA2D;IAC3D,6EAAmD,CAAA;IACnD,kDAAkD;IAClD,8FAAoE,CAAA;IACpE,qDAAqD;IACrD,oFAA0D,CAAA;IAC1D,6EAA6E;IAC7E,4DAAkC,CAAA;IAClC,2DAA2D;IAC3D,2EAAiD,CAAA;IACjD,6CAA6C;IAC7C,iEAAuC,CAAA;IACvC,kEAAkE;IAClE,4EAAkD,CAAA;IAClD,sDAAsD;IACtD,uFAA6D,CAAA;IAC7D,0DAA0D;IAC1D,kGAAwE,CAAA;IACxE,uDAAuD;IACvD,2FAAiE,CAAA;IACjE,yDAAyD;IACzD,wEAA8C,CAAA;AAChD,CAAC,EAvEW,sBAAsB,sCAAtB,sBAAsB,QAuEjC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\n/** Scope shared by errors originating from `@itwin/imodel-transformer`.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const IModelTransformerErrorScope = \"@itwin/imodel-transformer\";\n\n/** Errors originating from `@itwin/imodel-transformer`.\n * @beta\n */\nexport enum IModelTransformerError {\n /** An ElementAspect change requires its owning element identifier. */\n AspectOwnerRequired = \"aspect-owner-required\",\n /** Required changed-instance metadata is missing. */\n ChangedInstanceMetadataMissing = \"changed-instance-metadata-missing\",\n /** A required changeset index is unavailable. */\n ChangesetIndexUnavailable = \"changeset-index-unavailable\",\n /** A source entity contains a dangling reference rejected by transformer policy. */\n DanglingReference = \"dangling-reference\",\n /** A required dependency has no target mapping. */\n DependencyMappingMissing = \"dependency-mapping-missing\",\n /** The installed iTwin.js dependency version is incompatible. */\n DependencyVersionMismatch = \"dependency-version-mismatch\",\n /** A required edit transaction is not active. */\n EditTxnNotActive = \"edit-txn-not-active\",\n /** An element identifier cannot be preserved in the target. */\n ElementIdNotPreservable = \"element-id-not-preservable\",\n /** A required element identifier was not provided. */\n ElementIdRequired = \"element-id-required\",\n /** Exporting changes requires a briefcase iModel. */\n ExportChangesRequiresBriefcase = \"export-changes-requires-briefcase\",\n /** No export handler has been registered. */\n ExportHandlerNotRegistered = \"export-handler-not-registered\",\n /** A required geographic coordinate system is unavailable. */\n GeographicCoordinateSystemUnavailable = \"geographic-coordinate-system-unavailable\",\n /** Source and target geographic coordinate systems are incompatible. */\n GeographicCoordinateSystemMismatch = \"geographic-coordinate-system-mismatch\",\n /** Required geolocation data or an invertible geolocation transform is unavailable. */\n GeolocationUnavailable = \"geolocation-unavailable\",\n /** A custom importer option conflicts with the transformer option. */\n ImporterOptionMismatch = \"importer-option-mismatch\",\n /** A code is invalid or incomplete. */\n InvalidCode = \"invalid-code\",\n /** An entity reference has an unsupported representation. */\n InvalidEntityReference = \"invalid-entity-reference\",\n /** A model identifier is invalid or missing. */\n InvalidModelId = \"invalid-model-id\",\n /** A subcategory is invalid or incomplete. */\n InvalidSubCategory = \"invalid-subcategory\",\n /** The source iModel has no changesets or custom changes. */\n NoChangesets = \"no-changesets\",\n /** A required parent model was not provided. */\n ParentModelRequired = \"parent-model-required\",\n /** A provenance scope conflicts with existing provenance. */\n ProvenanceScopeConflict = \"provenance-scope-conflict\",\n /** The BisCore schema does not support required provenance data. */\n ProvenanceSchemaUnsupported = \"provenance-schema-unsupported\",\n /** A required relationship class is absent. */\n RelationshipClassNotFound = \"relationship-class-not-found\",\n /** A required relationship identifier was not provided. */\n RelationshipIdRequired = \"relationship-id-required\",\n /** Expected relationship provenance is absent. */\n RelationshipProvenanceNotFound = \"relationship-provenance-not-found\",\n /** The root subject cannot be processed directly. */\n RootSubjectNotProcessable = \"root-subject-not-processable\",\n /** A schema conflict or incompatible schema version prevented processing. */\n SchemaConflict = \"schema-conflict\",\n /** The source schema dependency graph contains a cycle. */\n SchemaDependencyCycle = \"schema-dependency-cycle\",\n /** A required schema could not be loaded. */\n SchemaLoadFailed = \"schema-load-failed\",\n /** Reverse synchronization requires a source edit transaction. */\n SourceEditTxnRequired = \"source-edit-txn-required\",\n /** The requested synchronization range is invalid. */\n SynchronizationRangeInvalid = \"synchronization-range-invalid\",\n /** The synchronization direction cannot be determined. */\n SynchronizationTypeNotDetermined = \"synchronization-type-not-determined\",\n /** The previous synchronization version is missing. */\n SynchronizationVersionMissing = \"synchronization-version-missing\",\n /** A required class is absent from the target iModel. */\n TargetClassNotFound = \"target-class-not-found\",\n}\n"]}
@@ -3,6 +3,7 @@ export * from "./IModelExporter";
3
3
  export * from "./IModelImporter";
4
4
  export * from "./IModelTransformer";
5
5
  export * from "./IModelTransformContext";
6
+ export * from "./schema-processing/SchemaProcessingStrategy";
6
7
  export * from "./IModelTransformerError";
7
8
  export * from "./BranchProvenanceInitializer";
8
9
  /** @docs-package-description
@@ -1 +1 @@
1
- {"version":3,"file":"imodel-transformer.d.ts","sourceRoot":"","sources":["../../src/imodel-transformer.ts"],"names":[],"mappings":"AAIA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAmD9C;;;;;;GAMG;AACH;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
1
+ {"version":3,"file":"imodel-transformer.d.ts","sourceRoot":"","sources":["../../src/imodel-transformer.ts"],"names":[],"mappings":"AAIA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAmD9C;;;;;;GAMG;AACH;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
@@ -23,6 +23,7 @@ __exportStar(require("./IModelExporter"), exports);
23
23
  __exportStar(require("./IModelImporter"), exports);
24
24
  __exportStar(require("./IModelTransformer"), exports);
25
25
  __exportStar(require("./IModelTransformContext"), exports);
26
+ __exportStar(require("./schema-processing/SchemaProcessingStrategy"), exports);
26
27
  __exportStar(require("./IModelTransformerError"), exports);
27
28
  __exportStar(require("./BranchProvenanceInitializer"), exports);
28
29
  const semver = require("semver");
@@ -1 +1 @@
1
- {"version":3,"file":"imodel-transformer.js","sourceRoot":"","sources":["../../src/imodel-transformer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,8DAA4C;AAC5C,mDAAiC;AACjC,mDAAiC;AACjC,sDAAoC;AACpC,2DAAyC;AACzC,2DAAyC;AACzC,gEAA8C;AAE9C,iCAAiC;AACjC,sDAAiD;AACjD,mEAAsF;AACtF,qEAGkC;AAClC,6EAA0E;AAE1E,MAAM,EACJ,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,OAAO,EACb,gBAAgB,GACjB,GAAG,uDAA0B,CAAC;AAE/B,MAAM,2BAA2B,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;AAE5E,MAAM,sBAAsB,GAAG,iCAAiC,CAAC;AAEjE,4CAA4C;AAC5C,IAAI,MAAM,CAAC,UAAU,CAAC,sBAAuB,CAAC,EAAE,CAAC;IAC/C,sCAAsC;IACtC,OAAO,CAAC,IAAI,CACV,kCAAkC,sBAAuB,KAAK;QAC5D,uFAAuF;QACvF,+FAA+F,CAClG,CAAC;AACJ,CAAC;AAED,IACE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,KAAK,GAAG;IAC3C,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAuB,EAAE,2BAA2B,EAAE;QACtE,iBAAiB,EAAE,IAAI;KACxB,CAAC,EACF,CAAC;IACD,MAAM,SAAS,GACb,GAAG,OAAO,IAAI,UAAU,sCAAsC,2BAA2B,IAAI;QAC7F,0BAA0B,sBAAuB,uDAAuD;QACxG,iFAAiF,sBAAsB,yBAAyB,CAAC;IAEnI,yBAAU,CAAC,UAAU,CAAC;QACpB,YAAY,EAAE;YACZ,KAAK,EAAE,oDAA2B;YAClC,GAAG,EAAE,+CAAsB,CAAC,yBAAyB;SACtD;QACD,OAAO,EAAE,SAAS;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\nexport * from \"./TransformerLoggerCategory\";\nexport * from \"./IModelExporter\";\nexport * from \"./IModelImporter\";\nexport * from \"./IModelTransformer\";\nexport * from \"./IModelTransformContext\";\nexport * from \"./IModelTransformerError\";\nexport * from \"./BranchProvenanceInitializer\";\n\nimport * as semver from \"semver\";\nimport { ITwinError } from \"@itwin/core-bentley\";\nimport { version as iTwinCoreBackendVersion } from \"@itwin/core-backend/package.json\";\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"./IModelTransformerError\";\nimport { transformerPackageMetadata } from \"./TransformerPackageMetadata\";\n\nconst {\n version: ourVersion,\n name: ourName,\n peerDependencies,\n} = transformerPackageMetadata;\n\nconst ourITwinCoreBackendDepRange = peerDependencies[\"@itwin/core-backend\"];\n\nconst noStrictDepCheckEnvVar = \"TRANSFORMER_NO_STRICT_DEP_CHECK\";\n\n// warn if using a prerelease or dev version\nif (semver.prerelease(iTwinCoreBackendVersion)) {\n // eslint-disable-next-line no-console\n console.warn(\n `Warning: dev version detected (${iTwinCoreBackendVersion}). ` +\n \"This version is most likely fine, but it may introduce new behavior that could cause \" +\n \"unexpected issues or changes in the transformer's functionality. Please proceed with caution.\"\n );\n}\n\nif (\n process.env[noStrictDepCheckEnvVar] !== \"1\" &&\n !semver.satisfies(iTwinCoreBackendVersion, ourITwinCoreBackendDepRange, {\n includePrerelease: true,\n })\n) {\n const errHeader =\n `${ourName}@${ourVersion} only supports @itwin/core-backend@${ourITwinCoreBackendDepRange}, ` +\n `but @itwin/core-backend${iTwinCoreBackendVersion} was resolved when looking for the peer dependency.\\n` +\n `If you know exactly what you are doing, you can disable this check by setting ${noStrictDepCheckEnvVar}=1 in the environment\\n`;\n\n ITwinError.throwError({\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.DependencyVersionMismatch,\n },\n message: errHeader,\n });\n}\n\n/** @docs-package-description\n * The @itwin/imodel-transformer package contains classes that [backend code]($docs/learning/backend/index.md) can use to\n * traverse iModels, as well as *transform* an iModel into another existing or empty one, by exporting elements from one during\n * traversal and importing them into another.\n *\n * You can read further in [iModelTransformation and Data Exchange]($docs/learning/transformer/index.md) here.\n */\n/**\n * @docs-group-description iModels\n * Classes for working with [iModels]($docs/learning/iModels.md).\n * See [the learning article]($docs/learning/backend/index.md).\n */\n/**\n * @docs-group-description Utils\n * Miscellaneous utility classes.\n */\n/**\n * @docs-group-description Logging\n * Logger categories used by this package.\n */\n/**\n * @docs-group-description ElementAspectExportCoordinator\n * Internal coordination for scoped, owner-batched ElementAspect export.\n */\n/**\n * @docs-group-description ElementAspectExportProcessor\n * Internal source queries, filtering, and export callbacks for ElementAspects owned by accepted elements.\n */\n/**\n * @docs-group-description IModelTransformerError\n * Stable identifiers for errors originating from this package.\n */\n/**\n * @docs-group-description TransformerPackageMetadata\n * Internal metadata describing this package and its peer dependencies.\n */\n"]}
1
+ {"version":3,"file":"imodel-transformer.js","sourceRoot":"","sources":["../../src/imodel-transformer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,8DAA4C;AAC5C,mDAAiC;AACjC,mDAAiC;AACjC,sDAAoC;AACpC,2DAAyC;AACzC,+EAA6D;AAC7D,2DAAyC;AACzC,gEAA8C;AAE9C,iCAAiC;AACjC,sDAAiD;AACjD,mEAAsF;AACtF,qEAGkC;AAClC,6EAA0E;AAE1E,MAAM,EACJ,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,OAAO,EACb,gBAAgB,GACjB,GAAG,uDAA0B,CAAC;AAE/B,MAAM,2BAA2B,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;AAE5E,MAAM,sBAAsB,GAAG,iCAAiC,CAAC;AAEjE,4CAA4C;AAC5C,IAAI,MAAM,CAAC,UAAU,CAAC,sBAAuB,CAAC,EAAE,CAAC;IAC/C,sCAAsC;IACtC,OAAO,CAAC,IAAI,CACV,kCAAkC,sBAAuB,KAAK;QAC5D,uFAAuF;QACvF,+FAA+F,CAClG,CAAC;AACJ,CAAC;AAED,IACE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,KAAK,GAAG;IAC3C,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAuB,EAAE,2BAA2B,EAAE;QACtE,iBAAiB,EAAE,IAAI;KACxB,CAAC,EACF,CAAC;IACD,MAAM,SAAS,GACb,GAAG,OAAO,IAAI,UAAU,sCAAsC,2BAA2B,IAAI;QAC7F,0BAA0B,sBAAuB,uDAAuD;QACxG,iFAAiF,sBAAsB,yBAAyB,CAAC;IAEnI,yBAAU,CAAC,UAAU,CAAC;QACpB,YAAY,EAAE;YACZ,KAAK,EAAE,oDAA2B;YAClC,GAAG,EAAE,+CAAsB,CAAC,yBAAyB;SACtD;QACD,OAAO,EAAE,SAAS;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\nexport * from \"./TransformerLoggerCategory\";\nexport * from \"./IModelExporter\";\nexport * from \"./IModelImporter\";\nexport * from \"./IModelTransformer\";\nexport * from \"./IModelTransformContext\";\nexport * from \"./schema-processing/SchemaProcessingStrategy\";\nexport * from \"./IModelTransformerError\";\nexport * from \"./BranchProvenanceInitializer\";\n\nimport * as semver from \"semver\";\nimport { ITwinError } from \"@itwin/core-bentley\";\nimport { version as iTwinCoreBackendVersion } from \"@itwin/core-backend/package.json\";\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"./IModelTransformerError\";\nimport { transformerPackageMetadata } from \"./TransformerPackageMetadata\";\n\nconst {\n version: ourVersion,\n name: ourName,\n peerDependencies,\n} = transformerPackageMetadata;\n\nconst ourITwinCoreBackendDepRange = peerDependencies[\"@itwin/core-backend\"];\n\nconst noStrictDepCheckEnvVar = \"TRANSFORMER_NO_STRICT_DEP_CHECK\";\n\n// warn if using a prerelease or dev version\nif (semver.prerelease(iTwinCoreBackendVersion)) {\n // eslint-disable-next-line no-console\n console.warn(\n `Warning: dev version detected (${iTwinCoreBackendVersion}). ` +\n \"This version is most likely fine, but it may introduce new behavior that could cause \" +\n \"unexpected issues or changes in the transformer's functionality. Please proceed with caution.\"\n );\n}\n\nif (\n process.env[noStrictDepCheckEnvVar] !== \"1\" &&\n !semver.satisfies(iTwinCoreBackendVersion, ourITwinCoreBackendDepRange, {\n includePrerelease: true,\n })\n) {\n const errHeader =\n `${ourName}@${ourVersion} only supports @itwin/core-backend@${ourITwinCoreBackendDepRange}, ` +\n `but @itwin/core-backend${iTwinCoreBackendVersion} was resolved when looking for the peer dependency.\\n` +\n `If you know exactly what you are doing, you can disable this check by setting ${noStrictDepCheckEnvVar}=1 in the environment\\n`;\n\n ITwinError.throwError({\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.DependencyVersionMismatch,\n },\n message: errHeader,\n });\n}\n\n/** @docs-package-description\n * The @itwin/imodel-transformer package contains classes that [backend code]($docs/learning/backend/index.md) can use to\n * traverse iModels, as well as *transform* an iModel into another existing or empty one, by exporting elements from one during\n * traversal and importing them into another.\n *\n * You can read further in [iModelTransformation and Data Exchange]($docs/learning/transformer/index.md) here.\n */\n/**\n * @docs-group-description iModels\n * Classes for working with [iModels]($docs/learning/iModels.md).\n * See [the learning article]($docs/learning/backend/index.md).\n */\n/**\n * @docs-group-description Utils\n * Miscellaneous utility classes.\n */\n/**\n * @docs-group-description Logging\n * Logger categories used by this package.\n */\n/**\n * @docs-group-description ElementAspectExportCoordinator\n * Internal coordination for scoped, owner-batched ElementAspect export.\n */\n/**\n * @docs-group-description ElementAspectExportProcessor\n * Internal source queries, filtering, and export callbacks for ElementAspects owned by accepted elements.\n */\n/**\n * @docs-group-description IModelTransformerError\n * Stable identifiers for errors originating from this package.\n */\n/**\n * @docs-group-description TransformerPackageMetadata\n * Internal metadata describing this package and its peer dependencies.\n */\n"]}
@@ -0,0 +1,29 @@
1
+ /** @packageDocumentation
2
+ * @module iModels
3
+ */
4
+ import { SchemaDifferenceResult } from "@itwin/ecschema-editing";
5
+ import { Schema } from "@itwin/ecschema-metadata";
6
+ import { SchemaProcessingContext, SchemaProcessingResult, SchemaProcessingStrategy } from "./SchemaProcessingStrategy";
7
+ /**
8
+ * Processes ordinary schemas with newer-version selection and unions compatible
9
+ * differences for existing dynamic schemas. Dynamic schema root read and write
10
+ * versions must match; only the minor version may differ.
11
+ * @beta
12
+ */
13
+ export declare class DynamicSchemaUnionStrategy implements SchemaProcessingStrategy {
14
+ /**
15
+ * Transform schema differences before conflict validation and merging.
16
+ * A subclass that changes the differencing result is responsible for ensuring
17
+ * that its changes are safe for the source and target schemas.
18
+ * @param sourceSchema The source schema being processed.
19
+ * @param targetSchema The existing target schema.
20
+ * @param differences The complete result from [[getSchemaDifferences]].
21
+ * @returns The differencing result to validate and merge.
22
+ * @beta
23
+ */
24
+ protected onSchemaDifferences(_sourceSchema: Schema, _targetSchema: Schema, differences: SchemaDifferenceResult): Promise<SchemaDifferenceResult>;
25
+ /** Select ordinary schemas and union compatible dynamic schema differences. */
26
+ processSchemas(context: SchemaProcessingContext): Promise<SchemaProcessingResult[]>;
27
+ private createPlan;
28
+ }
29
+ //# sourceMappingURL=DynamicSchemaUnionStrategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicSchemaUnionStrategy.d.ts","sourceRoot":"","sources":["../../../src/schema-processing/DynamicSchemaUnionStrategy.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAKL,sBAAsB,EAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,MAAM,EAGP,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAEL,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAsBpC;;;;;GAKG;AACH,qBAAa,0BAA2B,YAAW,wBAAwB;IACzE;;;;;;;;;OASG;cACa,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,sBAAsB,GAClC,OAAO,CAAC,sBAAsB,CAAC;IAIlC,+EAA+E;IAClE,cAAc,CACzB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,EAAE,CAAC;YA6EtB,UAAU;CAwDzB"}
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module iModels
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DynamicSchemaUnionStrategy = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const ecschema_editing_1 = require("@itwin/ecschema-editing");
13
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
14
+ const IModelTransformerError_1 = require("../IModelTransformerError");
15
+ /**
16
+ * Processes ordinary schemas with newer-version selection and unions compatible
17
+ * differences for existing dynamic schemas. Dynamic schema root read and write
18
+ * versions must match; only the minor version may differ.
19
+ * @beta
20
+ */
21
+ class DynamicSchemaUnionStrategy {
22
+ /**
23
+ * Transform schema differences before conflict validation and merging.
24
+ * A subclass that changes the differencing result is responsible for ensuring
25
+ * that its changes are safe for the source and target schemas.
26
+ * @param sourceSchema The source schema being processed.
27
+ * @param targetSchema The existing target schema.
28
+ * @param differences The complete result from [[getSchemaDifferences]].
29
+ * @returns The differencing result to validate and merge.
30
+ * @beta
31
+ */
32
+ async onSchemaDifferences(_sourceSchema, _targetSchema, differences) {
33
+ return differences;
34
+ }
35
+ /** Select ordinary schemas and union compatible dynamic schema differences. */
36
+ async processSchemas(context) {
37
+ const plans = [];
38
+ const conflicts = [];
39
+ for (const sourceSchema of context.sourceSchemas) {
40
+ try {
41
+ plans.push(await this.createPlan(sourceSchema, context.targetSchemas));
42
+ }
43
+ catch (error) {
44
+ if (core_bentley_1.ITwinError.isError(error, IModelTransformerError_1.IModelTransformerErrorScope, IModelTransformerError_1.IModelTransformerError.SchemaConflict)) {
45
+ conflicts.push(error);
46
+ continue;
47
+ }
48
+ throw error;
49
+ }
50
+ }
51
+ throwSchemaConflicts(conflicts);
52
+ const schemaEditingContext = new ecschema_metadata_1.SchemaContext();
53
+ const schemaCandidates = new Map();
54
+ for (const plan of plans) {
55
+ if (plan.kind === "dynamic-merge") {
56
+ collectSchemaCandidates(plan.target, schemaCandidates, true);
57
+ collectSchemaReferences(plan.source, schemaCandidates);
58
+ }
59
+ else if (plan.kind === "dynamic-noop") {
60
+ collectSchemaCandidates(plan.source, schemaCandidates, false);
61
+ collectSchemaReferences(plan.source, schemaCandidates);
62
+ }
63
+ }
64
+ for (const { schema } of schemaCandidates.values()) {
65
+ await schemaEditingContext.addSchema(schema);
66
+ }
67
+ const schemaMerger = new ecschema_editing_1.SchemaMerger(schemaEditingContext);
68
+ const results = [];
69
+ for (const plan of plans) {
70
+ switch (plan.kind) {
71
+ case "new":
72
+ if (plan.source.isDynamic ||
73
+ (await context.shouldExportSchema(plan.source.schemaKey))) {
74
+ results.push({ kind: "source", schema: plan.source });
75
+ }
76
+ break;
77
+ case "ordinary":
78
+ if (await context.shouldExportSchema(plan.source.schemaKey)) {
79
+ results.push({ kind: "source", schema: plan.source });
80
+ }
81
+ break;
82
+ case "dynamic-noop":
83
+ break;
84
+ case "dynamic-merge": {
85
+ const mergedSchema = await schemaMerger.merge({
86
+ ...plan.differences,
87
+ conflicts: undefined,
88
+ });
89
+ const sourceVersion = plan.source.schemaKey.version;
90
+ mergedSchema.setVersion(sourceVersion.read, sourceVersion.write, incrementMinorVersion(sourceVersion, plan.target.schemaKey.version));
91
+ results.push({ kind: "generated", schema: mergedSchema });
92
+ break;
93
+ }
94
+ }
95
+ }
96
+ appendRequiredNoOpSchemas(results, plans);
97
+ return results;
98
+ }
99
+ async createPlan(source, targetSchemas) {
100
+ const target = await targetSchemas.getSchema(source.name);
101
+ if (target === undefined)
102
+ return { kind: "new", source };
103
+ if (source.isDynamic !== target.isDynamic) {
104
+ throw createSchemaConflictError(source, "Schema DynamicSchema marker changed", new Error("The source and target DynamicSchema markers differ."));
105
+ }
106
+ if (!source.isDynamic)
107
+ return { kind: "ordinary", source, target };
108
+ const sourceVersion = source.schemaKey.version;
109
+ const targetVersion = target.schemaKey.version;
110
+ if (sourceVersion.read !== targetVersion.read ||
111
+ sourceVersion.write !== targetVersion.write) {
112
+ throw createSchemaConflictError(source, "Dynamic schema has incompatible root versions", new Error(`source ${sourceVersion.toString(false)}, target ${targetVersion.toString(false)}`));
113
+ }
114
+ const differences = await this.onSchemaDifferences(source, target, await (0, ecschema_editing_1.getSchemaDifferences)(target, source));
115
+ const unresolvedConflicts = (differences.conflicts ?? []).filter((conflict) => !isCompatibleReferenceVersionConflict(conflict));
116
+ if (unresolvedConflicts.length > 0) {
117
+ throw createSchemaConflictError(source, "Schema conflict", new ecschema_editing_1.SchemaConflictsError(`Schema '${source.name}' has unresolved conflicts`, unresolvedConflicts, source.schemaKey, target.schemaKey));
118
+ }
119
+ return differences.differences.length === 0
120
+ ? { kind: "dynamic-noop", source, target }
121
+ : { kind: "dynamic-merge", source, target, differences };
122
+ }
123
+ }
124
+ exports.DynamicSchemaUnionStrategy = DynamicSchemaUnionStrategy;
125
+ function createSchemaConflictError(schema, operation, cause) {
126
+ return core_bentley_1.ITwinError.create({
127
+ message: `${operation} for '${schema.schemaKey.toString(false)}': ${cause.message}`,
128
+ iTwinErrorId: {
129
+ scope: IModelTransformerError_1.IModelTransformerErrorScope,
130
+ key: IModelTransformerError_1.IModelTransformerError.SchemaConflict,
131
+ },
132
+ cause,
133
+ schemaKey: schema.schemaKey.toString(false),
134
+ });
135
+ }
136
+ function throwSchemaConflicts(conflicts) {
137
+ if (conflicts.length === 1)
138
+ throw conflicts[0];
139
+ if (conflicts.length > 1)
140
+ throw new AggregateError(conflicts, "Schema processing failed");
141
+ }
142
+ function appendRequiredNoOpSchemas(results, plans) {
143
+ const noOpSchemas = new Map(plans
144
+ .filter((plan) => plan.kind === "dynamic-noop")
145
+ .map((plan) => [plan.source.name.toLowerCase(), plan.source]));
146
+ const requiredNoOpSchemas = new Set();
147
+ const schemasToVisit = results.map((result) => result.schema);
148
+ for (const schema of schemasToVisit) {
149
+ for (const reference of schema.references) {
150
+ const schemaName = reference.name.toLowerCase();
151
+ const noOpSchema = noOpSchemas.get(schemaName);
152
+ if (noOpSchema === undefined || requiredNoOpSchemas.has(schemaName))
153
+ continue;
154
+ requiredNoOpSchemas.add(schemaName);
155
+ schemasToVisit.push(noOpSchema);
156
+ }
157
+ }
158
+ for (const schemaName of requiredNoOpSchemas) {
159
+ const schema = noOpSchemas.get(schemaName);
160
+ if (schema !== undefined)
161
+ results.push({ kind: "source", schema });
162
+ }
163
+ }
164
+ function incrementMinorVersion(sourceVersion, targetVersion) {
165
+ const maximumVersion = sourceVersion.compare(targetVersion) >= 0 ? sourceVersion : targetVersion;
166
+ if (maximumVersion.minor >= 9_999_999) {
167
+ throw new Error(`Cannot increment schema version ${maximumVersion.toString(false)}`);
168
+ }
169
+ return maximumVersion.minor + 1;
170
+ }
171
+ function isCompatibleReferenceVersionConflict(conflict) {
172
+ if (conflict.code !== ecschema_editing_1.ConflictCode.ConflictingReferenceVersion)
173
+ return false;
174
+ if (typeof conflict.source !== "string" ||
175
+ typeof conflict.target !== "string")
176
+ return false;
177
+ const sourceVersion = ecschema_metadata_1.SchemaKey.parseString(conflict.source).version;
178
+ const targetVersion = ecschema_metadata_1.SchemaKey.parseString(conflict.target).version;
179
+ return (sourceVersion.read === targetVersion.read &&
180
+ sourceVersion.write === targetVersion.write);
181
+ }
182
+ function collectSchemaCandidates(schema, candidates, isTargetRoot, visited = new Set()) {
183
+ const traversalKey = schema.schemaKey.toString();
184
+ if (visited.has(traversalKey))
185
+ return;
186
+ visited.add(traversalKey);
187
+ const schemaName = schema.name.toLowerCase();
188
+ const existing = candidates.get(schemaName);
189
+ if (existing === undefined) {
190
+ candidates.set(schemaName, { schema, isTargetRoot });
191
+ }
192
+ else if (existing.schema.schemaKey.version.read !== schema.schemaKey.version.read ||
193
+ existing.schema.schemaKey.version.write !== schema.schemaKey.version.write) {
194
+ throw createSchemaConflictError(schema, "Schema reference has incompatible read/write versions", new Error(`${existing.schema.schemaKey.version.read}.${existing.schema.schemaKey.version.write} ` +
195
+ `and ${schema.schemaKey.version.read}.${schema.schemaKey.version.write} differ. ` +
196
+ "Only minor-version reference differences are supported."));
197
+ }
198
+ else if (isTargetRoot ||
199
+ (!existing.isTargetRoot &&
200
+ schema.schemaKey.version.compare(existing.schema.schemaKey.version) > 0)) {
201
+ candidates.set(schemaName, { schema, isTargetRoot });
202
+ }
203
+ for (const reference of schema.references) {
204
+ collectSchemaCandidates(reference, candidates, false, visited);
205
+ }
206
+ }
207
+ function collectSchemaReferences(schema, candidates) {
208
+ for (const reference of schema.references) {
209
+ collectSchemaCandidates(reference, candidates, false);
210
+ }
211
+ }
212
+ //# sourceMappingURL=DynamicSchemaUnionStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicSchemaUnionStrategy.js","sourceRoot":"","sources":["../../../src/schema-processing/DynamicSchemaUnionStrategy.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,sDAAiD;AACjD,8DAOiC;AACjC,gEAKkC;AAClC,sEAGmC;AA4BnC;;;;;GAKG;AACH,MAAa,0BAA0B;IACrC;;;;;;;;;OASG;IACO,KAAK,CAAC,mBAAmB,CACjC,aAAqB,EACrB,aAAqB,EACrB,WAAmC;QAEnC,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,+EAA+E;IACxE,KAAK,CAAC,cAAc,CACzB,OAAgC;QAEhC,MAAM,KAAK,GAAiB,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAY,EAAE,CAAC;QAC9B,KAAK,MAAM,YAAY,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YACjD,IAAI,CAAC;gBACH,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;YACzE,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,IACE,yBAAU,CAAC,OAAO,CAChB,KAAK,EACL,oDAA2B,EAC3B,+CAAsB,CAAC,cAAc,CACtC,EACD,CAAC;oBACD,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACtB,SAAS;gBACX,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAEhC,MAAM,oBAAoB,GAAG,IAAI,iCAAa,EAAE,CAAC;QACjD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA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MAAM,EACN,uDAAuD,EACvD,IAAI,KAAK,CACP,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,GAAG;YACrF,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,WAAW;YACjF,yDAAyD,CAC5D,CACF,CAAC;IACJ,CAAC;SAAM,IACL,YAAY;QACZ,CAAC,CAAC,QAAQ,CAAC,YAAY;YACrB,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAC1E,CAAC;QACD,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,uBAAuB,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED,SAAS,uBAAuB,CAC9B,MAAc,EACd,UAAwC;IAExC,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,uBAAuB,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { ITwinError } from \"@itwin/core-bentley\";\nimport {\n AnySchemaDifferenceConflict,\n ConflictCode,\n getSchemaDifferences,\n SchemaConflictsError,\n SchemaDifferenceResult,\n SchemaMerger,\n} from \"@itwin/ecschema-editing\";\nimport {\n ECVersion,\n Schema,\n SchemaContext,\n SchemaKey,\n} from \"@itwin/ecschema-metadata\";\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"../IModelTransformerError\";\nimport {\n ReadonlySchemaAccessor,\n SchemaProcessingContext,\n SchemaProcessingResult,\n SchemaProcessingStrategy,\n} from \"./SchemaProcessingStrategy\";\n\ntype SchemaPlan =\n | { kind: \"new\"; source: Schema }\n | { kind: \"ordinary\"; source: Schema; target: Schema }\n | { kind: \"dynamic-noop\"; source: Schema; target: Schema }\n | {\n kind: \"dynamic-merge\";\n source: Schema;\n target: Schema;\n differences: SchemaDifferenceResult;\n };\n\ninterface SchemaCandidate {\n schema: Schema;\n isTargetRoot: boolean;\n}\n\ninterface SchemaConflictError extends ITwinError {\n schemaKey: string;\n}\n\n/**\n * Processes ordinary schemas with newer-version selection and unions compatible\n * differences for existing dynamic schemas. Dynamic schema root read and write\n * versions must match; only the minor version may differ.\n * @beta\n */\nexport class DynamicSchemaUnionStrategy implements SchemaProcessingStrategy {\n /**\n * Transform schema differences before conflict validation and merging.\n * A subclass that changes the differencing result is responsible for ensuring\n * that its changes are safe for the source and target schemas.\n * @param sourceSchema The source schema being processed.\n * @param targetSchema The existing target schema.\n * @param differences The complete result from [[getSchemaDifferences]].\n * @returns The differencing result to validate and merge.\n * @beta\n */\n protected async onSchemaDifferences(\n _sourceSchema: Schema,\n _targetSchema: Schema,\n differences: SchemaDifferenceResult\n ): Promise<SchemaDifferenceResult> {\n return differences;\n }\n\n /** Select ordinary schemas and union compatible dynamic schema differences. */\n public async processSchemas(\n context: SchemaProcessingContext\n ): Promise<SchemaProcessingResult[]> {\n const plans: SchemaPlan[] = [];\n const conflicts: Error[] = [];\n for (const sourceSchema of context.sourceSchemas) {\n try {\n plans.push(await this.createPlan(sourceSchema, context.targetSchemas));\n } catch (error: unknown) {\n if (\n ITwinError.isError(\n error,\n IModelTransformerErrorScope,\n IModelTransformerError.SchemaConflict\n )\n ) {\n conflicts.push(error);\n continue;\n }\n throw error;\n }\n }\n throwSchemaConflicts(conflicts);\n\n const schemaEditingContext = new SchemaContext();\n const schemaCandidates = new Map<string, SchemaCandidate>();\n for (const plan of plans) {\n if (plan.kind === \"dynamic-merge\") {\n collectSchemaCandidates(plan.target, schemaCandidates, true);\n collectSchemaReferences(plan.source, schemaCandidates);\n } else if (plan.kind === \"dynamic-noop\") {\n collectSchemaCandidates(plan.source, schemaCandidates, false);\n collectSchemaReferences(plan.source, schemaCandidates);\n }\n }\n for (const { schema } of schemaCandidates.values()) {\n await schemaEditingContext.addSchema(schema);\n }\n\n const schemaMerger = new SchemaMerger(schemaEditingContext);\n const results: SchemaProcessingResult[] = [];\n for (const plan of plans) {\n switch (plan.kind) {\n case \"new\":\n if (\n plan.source.isDynamic ||\n (await context.shouldExportSchema(plan.source.schemaKey))\n ) {\n results.push({ kind: \"source\", schema: plan.source });\n }\n break;\n case \"ordinary\":\n if (await context.shouldExportSchema(plan.source.schemaKey)) {\n results.push({ kind: \"source\", schema: plan.source });\n }\n break;\n case \"dynamic-noop\":\n break;\n case \"dynamic-merge\": {\n const mergedSchema = await schemaMerger.merge({\n ...plan.differences,\n conflicts: undefined,\n });\n const sourceVersion = plan.source.schemaKey.version;\n mergedSchema.setVersion(\n sourceVersion.read,\n sourceVersion.write,\n incrementMinorVersion(sourceVersion, plan.target.schemaKey.version)\n );\n results.push({ kind: \"generated\", schema: mergedSchema });\n break;\n }\n }\n }\n\n appendRequiredNoOpSchemas(results, plans);\n return results;\n }\n\n private async createPlan(\n source: Schema,\n targetSchemas: ReadonlySchemaAccessor\n ): Promise<SchemaPlan> {\n const target = await targetSchemas.getSchema(source.name);\n if (target === undefined) return { kind: \"new\", source };\n\n if (source.isDynamic !== target.isDynamic) {\n throw createSchemaConflictError(\n source,\n \"Schema DynamicSchema marker changed\",\n new Error(\"The source and target DynamicSchema markers differ.\")\n );\n }\n if (!source.isDynamic) return { kind: \"ordinary\", source, target };\n\n const sourceVersion = source.schemaKey.version;\n const targetVersion = target.schemaKey.version;\n if (\n sourceVersion.read !== targetVersion.read ||\n sourceVersion.write !== targetVersion.write\n ) {\n throw createSchemaConflictError(\n source,\n \"Dynamic schema has incompatible root versions\",\n new Error(\n `source ${sourceVersion.toString(false)}, target ${targetVersion.toString(false)}`\n )\n );\n }\n\n const differences = await this.onSchemaDifferences(\n source,\n target,\n await getSchemaDifferences(target, source)\n );\n const unresolvedConflicts = (differences.conflicts ?? []).filter(\n (conflict) => !isCompatibleReferenceVersionConflict(conflict)\n );\n if (unresolvedConflicts.length > 0) {\n throw createSchemaConflictError(\n source,\n \"Schema conflict\",\n new SchemaConflictsError(\n `Schema '${source.name}' has unresolved conflicts`,\n unresolvedConflicts,\n source.schemaKey,\n target.schemaKey\n )\n );\n }\n\n return differences.differences.length === 0\n ? { kind: \"dynamic-noop\", source, target }\n : { kind: \"dynamic-merge\", source, target, differences };\n }\n}\n\nfunction createSchemaConflictError(\n schema: Schema,\n operation: string,\n cause: Error\n): Error {\n return ITwinError.create<SchemaConflictError>({\n message: `${operation} for '${schema.schemaKey.toString(false)}': ${cause.message}`,\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.SchemaConflict,\n },\n cause,\n schemaKey: schema.schemaKey.toString(false),\n });\n}\n\nfunction throwSchemaConflicts(conflicts: Error[]): void {\n if (conflicts.length === 1) throw conflicts[0];\n if (conflicts.length > 1)\n throw new AggregateError(conflicts, \"Schema processing failed\");\n}\n\nfunction appendRequiredNoOpSchemas(\n results: SchemaProcessingResult[],\n plans: SchemaPlan[]\n): void {\n const noOpSchemas = new Map(\n plans\n .filter((plan) => plan.kind === \"dynamic-noop\")\n .map((plan) => [plan.source.name.toLowerCase(), plan.source])\n );\n const requiredNoOpSchemas = new Set<string>();\n const schemasToVisit = results.map((result) => result.schema);\n for (const schema of schemasToVisit) {\n for (const reference of schema.references) {\n const schemaName = reference.name.toLowerCase();\n const noOpSchema = noOpSchemas.get(schemaName);\n if (noOpSchema === undefined || requiredNoOpSchemas.has(schemaName))\n continue;\n\n requiredNoOpSchemas.add(schemaName);\n schemasToVisit.push(noOpSchema);\n }\n }\n for (const schemaName of requiredNoOpSchemas) {\n const schema = noOpSchemas.get(schemaName);\n if (schema !== undefined) results.push({ kind: \"source\", schema });\n }\n}\n\nfunction incrementMinorVersion(\n sourceVersion: ECVersion,\n targetVersion: ECVersion\n): number {\n const maximumVersion =\n sourceVersion.compare(targetVersion) >= 0 ? sourceVersion : targetVersion;\n if (maximumVersion.minor >= 9_999_999) {\n throw new Error(\n `Cannot increment schema version ${maximumVersion.toString(false)}`\n );\n }\n return maximumVersion.minor + 1;\n}\n\nfunction isCompatibleReferenceVersionConflict(\n conflict: AnySchemaDifferenceConflict\n): boolean {\n if (conflict.code !== ConflictCode.ConflictingReferenceVersion) return false;\n if (\n typeof conflict.source !== \"string\" ||\n typeof conflict.target !== \"string\"\n )\n return false;\n\n const sourceVersion = SchemaKey.parseString(conflict.source).version;\n const targetVersion = SchemaKey.parseString(conflict.target).version;\n return (\n sourceVersion.read === targetVersion.read &&\n sourceVersion.write === targetVersion.write\n );\n}\n\nfunction collectSchemaCandidates(\n schema: Schema,\n candidates: Map<string, SchemaCandidate>,\n isTargetRoot: boolean,\n visited: Set<string> = new Set<string>()\n): void {\n const traversalKey = schema.schemaKey.toString();\n if (visited.has(traversalKey)) return;\n visited.add(traversalKey);\n\n const schemaName = schema.name.toLowerCase();\n const existing = candidates.get(schemaName);\n if (existing === undefined) {\n candidates.set(schemaName, { schema, isTargetRoot });\n } else if (\n existing.schema.schemaKey.version.read !== schema.schemaKey.version.read ||\n existing.schema.schemaKey.version.write !== schema.schemaKey.version.write\n ) {\n throw createSchemaConflictError(\n schema,\n \"Schema reference has incompatible read/write versions\",\n new Error(\n `${existing.schema.schemaKey.version.read}.${existing.schema.schemaKey.version.write} ` +\n `and ${schema.schemaKey.version.read}.${schema.schemaKey.version.write} differ. ` +\n \"Only minor-version reference differences are supported.\"\n )\n );\n } else if (\n isTargetRoot ||\n (!existing.isTargetRoot &&\n schema.schemaKey.version.compare(existing.schema.schemaKey.version) > 0)\n ) {\n candidates.set(schemaName, { schema, isTargetRoot });\n }\n\n for (const reference of schema.references) {\n collectSchemaCandidates(reference, candidates, false, visited);\n }\n}\n\nfunction collectSchemaReferences(\n schema: Schema,\n candidates: Map<string, SchemaCandidate>\n): void {\n for (const reference of schema.references) {\n collectSchemaCandidates(reference, candidates, false);\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import { IModelDb } from "@itwin/core-backend";
2
+ import { Schema, SchemaKey } from "@itwin/ecschema-metadata";
3
+ import { ExportSchemaResult, IModelExporter } from "../IModelExporter";
4
+ import { SchemaProcessingStrategy } from "./SchemaProcessingStrategy";
5
+ interface SchemaProcessingCoordinatorArgs {
6
+ exporter: IModelExporter;
7
+ targetDb: IModelDb;
8
+ getSchemaExportDirectory: () => string;
9
+ shouldExportSchema: (schemaKey: SchemaKey) => Promise<boolean>;
10
+ serializeSourceSchema: (schema: Schema) => Promise<void | ExportSchemaResult>;
11
+ }
12
+ /** @internal */
13
+ export declare class SchemaProcessingCoordinator {
14
+ private readonly _args;
15
+ private readonly _longNamedSchemas;
16
+ constructor(_args: SchemaProcessingCoordinatorArgs);
17
+ process(strategy: SchemaProcessingStrategy): Promise<void>;
18
+ serializeSourceSchema(schema: Schema): Promise<ExportSchemaResult>;
19
+ private get _schemaExportDirectory();
20
+ private serializeSchema;
21
+ private getSchemaExportFileName;
22
+ private createLongNameResolvingSchemaContext;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=SchemaProcessingCoordinator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaProcessingCoordinator.d.ts","sourceRoot":"","sources":["../../../src/schema-processing/SchemaProcessingCoordinator.ts"],"names":[],"mappings":"AAOA,OAAO,EAAsB,QAAQ,EAAc,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,SAAS,EAAgB,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKvE,OAAO,EAGL,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAEpC,UAAU,+BAA+B;IACvC,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,wBAAwB,EAAE,MAAM,MAAM,CAAC;IACvC,kBAAkB,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/D,qBAAqB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAC,CAAC;CAC/E;AAED,gBAAgB;AAChB,qBAAa,2BAA2B;IAGnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFzC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6B;gBAE3B,KAAK,EAAE,+BAA+B;IAE7D,OAAO,CAAC,QAAQ,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqE1D,qBAAqB,CAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,kBAAkB,CAAC;IAY9B,OAAO,KAAK,sBAAsB,GAEjC;YAEa,eAAe;IAe7B,OAAO,CAAC,uBAAuB;IAkB/B,OAAO,CAAC,oCAAoC;CAU7C"}
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SchemaProcessingCoordinator = void 0;
8
+ const path = require("node:path");
9
+ const core_bentley_1 = require("@itwin/core-bentley");
10
+ const core_backend_1 = require("@itwin/core-backend");
11
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
+ const IModelTransformerError_1 = require("../IModelTransformerError");
13
+ /** @internal */
14
+ class SchemaProcessingCoordinator {
15
+ _args;
16
+ _longNamedSchemas = new Map();
17
+ constructor(_args) {
18
+ this._args = _args;
19
+ }
20
+ async process(strategy) {
21
+ let processingFailure;
22
+ try {
23
+ core_backend_1.IModelJsFs.mkdirSync(this._schemaExportDirectory);
24
+ this._longNamedSchemas.clear();
25
+ const sourceSchemas = [];
26
+ for await (const schema of this._args.exporter.enumerateSchemas()) {
27
+ sourceSchemas.push(schema);
28
+ }
29
+ const targetSchemaLoader = new ecschema_metadata_1.SchemaLoader((name) => this._args.targetDb.getSchemaProps(name));
30
+ const targetSchemas = {
31
+ getSchema: async (schemaName) => targetSchemaLoader.tryGetSchema(schemaName),
32
+ };
33
+ const processedSchemas = await strategy.processSchemas({
34
+ sourceSchemas: orderSchemasByDependencies(sourceSchemas),
35
+ targetSchemas,
36
+ shouldExportSchema: this._args.shouldExportSchema,
37
+ });
38
+ for (const result of processedSchemas) {
39
+ await this.serializeSchema(result);
40
+ }
41
+ const exportedSchemaFiles = core_backend_1.IModelJsFs.readdirSync(this._schemaExportDirectory);
42
+ if (exportedSchemaFiles.length > 0) {
43
+ await this._args.targetDb.importSchemas(exportedSchemaFiles.map((fileName) => path.join(this._schemaExportDirectory, fileName)), {
44
+ ecSchemaXmlContext: this._longNamedSchemas.size > 0
45
+ ? this.createLongNameResolvingSchemaContext()
46
+ : undefined,
47
+ });
48
+ }
49
+ }
50
+ catch (error) {
51
+ processingFailure = error;
52
+ }
53
+ let cleanupFailure;
54
+ try {
55
+ core_backend_1.IModelJsFs.removeSync(this._schemaExportDirectory);
56
+ }
57
+ catch (error) {
58
+ cleanupFailure = error;
59
+ }
60
+ finally {
61
+ this._longNamedSchemas.clear();
62
+ }
63
+ if (processingFailure !== undefined && cleanupFailure !== undefined) {
64
+ throw new AggregateError([processingFailure, cleanupFailure], "Schema processing and cleanup failed", { cause: processingFailure });
65
+ }
66
+ // Preserve failures from custom strategies and upstream libraries exactly.
67
+ // eslint-disable-next-line @typescript-eslint/only-throw-error
68
+ if (processingFailure !== undefined)
69
+ throw processingFailure;
70
+ // eslint-disable-next-line @typescript-eslint/only-throw-error
71
+ if (cleanupFailure !== undefined)
72
+ throw cleanupFailure;
73
+ }
74
+ async serializeSourceSchema(schema) {
75
+ const schemaFileName = this.getSchemaExportFileName(schema.name);
76
+ this._args.exporter.sourceDb.exportSchema({
77
+ schemaName: schema.name,
78
+ outputDirectory: this._schemaExportDirectory,
79
+ outputFileName: schemaFileName,
80
+ });
81
+ return {
82
+ schemaPath: path.join(this._schemaExportDirectory, schemaFileName),
83
+ };
84
+ }
85
+ get _schemaExportDirectory() {
86
+ return this._args.getSchemaExportDirectory();
87
+ }
88
+ async serializeSchema(result) {
89
+ if (result.kind === "source") {
90
+ await this._args.serializeSourceSchema(result.schema);
91
+ return;
92
+ }
93
+ const schemaLocaters = await Promise.resolve().then(() => require("@itwin/ecschema-locaters"));
94
+ const schemaFileName = this.getSchemaExportFileName(result.schema.name);
95
+ const schemaXml = await schemaLocaters.SchemaXml.writeString(result.schema);
96
+ core_backend_1.IModelJsFs.writeFileSync(path.join(this._schemaExportDirectory, schemaFileName), schemaXml);
97
+ }
98
+ getSchemaExportFileName(schemaName) {
99
+ const extension = ".ecschema.xml";
100
+ let schemaFileName = schemaName + extension;
101
+ const systemMaxPathSegmentSize = 255;
102
+ const windowsMaxPathLimit = 260;
103
+ if (schemaFileName.length > systemMaxPathSegmentSize ||
104
+ path.join(this._schemaExportDirectory, schemaFileName).length >=
105
+ windowsMaxPathLimit) {
106
+ schemaFileName = `${schemaName.slice(0, 100)}${this._longNamedSchemas.size}${extension}`;
107
+ this._longNamedSchemas.set(schemaName, schemaFileName);
108
+ }
109
+ return schemaFileName;
110
+ }
111
+ createLongNameResolvingSchemaContext() {
112
+ const context = new core_backend_1.ECSchemaXmlContext();
113
+ context.setSchemaLocater((key) => {
114
+ const schemaFileName = this._longNamedSchemas.get(key.name);
115
+ return schemaFileName === undefined
116
+ ? undefined
117
+ : path.join(this._schemaExportDirectory, schemaFileName);
118
+ });
119
+ return context;
120
+ }
121
+ }
122
+ exports.SchemaProcessingCoordinator = SchemaProcessingCoordinator;
123
+ function orderSchemasByDependencies(schemas) {
124
+ const schemasByName = new Map(schemas.map((schema) => [schema.name.toLowerCase(), schema]));
125
+ const state = new Map();
126
+ const orderedSchemas = [];
127
+ const stack = [];
128
+ const visit = (schema) => {
129
+ const schemaName = schema.name.toLowerCase();
130
+ const currentState = state.get(schemaName);
131
+ if (currentState === "visited")
132
+ return;
133
+ if (currentState === "visiting") {
134
+ const cycleStart = stack.indexOf(schemaName);
135
+ const schemaNames = stack.slice(cycleStart);
136
+ throw core_bentley_1.ITwinError.create({
137
+ message: `Schema dependency cycle detected: ${[
138
+ ...schemaNames,
139
+ schemaName,
140
+ ].join(" -> ")}`,
141
+ iTwinErrorId: {
142
+ scope: IModelTransformerError_1.IModelTransformerErrorScope,
143
+ key: IModelTransformerError_1.IModelTransformerError.SchemaDependencyCycle,
144
+ },
145
+ schemaNames,
146
+ });
147
+ }
148
+ state.set(schemaName, "visiting");
149
+ stack.push(schemaName);
150
+ for (const reference of schema.references) {
151
+ const referencedSchema = schemasByName.get(reference.name.toLowerCase());
152
+ if (referencedSchema !== undefined)
153
+ visit(referencedSchema);
154
+ }
155
+ stack.pop();
156
+ state.set(schemaName, "visited");
157
+ orderedSchemas.push(schema);
158
+ };
159
+ for (const schema of schemas)
160
+ visit(schema);
161
+ return orderedSchemas;
162
+ }
163
+ //# sourceMappingURL=SchemaProcessingCoordinator.js.map