@itwin/ecschema-editing 5.0.0-dev.8 → 5.0.0-dev.83
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.
- package/CHANGELOG.md +46 -1
- package/lib/cjs/Differencing/Errors.js +6 -0
- package/lib/cjs/Differencing/Errors.js.map +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts +3 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.js +2 -0
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts +4 -3
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +57 -11
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.d.ts +33 -4
- package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.js +55 -5
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceValidator.d.ts +2 -1
- package/lib/cjs/Differencing/SchemaDifferenceValidator.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceValidator.js +78 -19
- package/lib/cjs/Differencing/SchemaDifferenceValidator.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceVisitor.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceVisitor.js +5 -0
- package/lib/cjs/Differencing/SchemaDifferenceVisitor.js.map +1 -1
- package/lib/cjs/Editing/Constants.d.ts +2 -1
- package/lib/cjs/Editing/Constants.d.ts.map +1 -1
- package/lib/cjs/Editing/Constants.js +4 -1
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts +2 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js +3 -0
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +6 -0
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +48 -35
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.d.ts +2 -2
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +32 -21
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts +2 -1
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +18 -14
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.d.ts +2 -1
- package/lib/cjs/Editing/Enumerations.d.ts.map +1 -1
- package/lib/cjs/Editing/Enumerations.js +6 -3
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/Exception.js +35 -6
- package/lib/cjs/Editing/Exception.js.map +1 -1
- package/lib/cjs/Editing/Formats.d.ts +2 -1
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +5 -1
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.d.ts +2 -1
- package/lib/cjs/Editing/InvertedUnits.d.ts.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.js +10 -6
- package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts +2 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +11 -7
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +2 -1
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +13 -9
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableClass.d.ts +2 -1
- package/lib/cjs/Editing/Mutable/MutableClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.d.ts +8 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
- package/lib/cjs/Editing/Phenomena.d.ts +2 -1
- package/lib/cjs/Editing/Phenomena.d.ts.map +1 -1
- package/lib/cjs/Editing/Phenomena.js +3 -0
- package/lib/cjs/Editing/Phenomena.js.map +1 -1
- package/lib/cjs/Editing/Properties.d.ts +2 -2
- package/lib/cjs/Editing/Properties.d.ts.map +1 -1
- package/lib/cjs/Editing/Properties.js +6 -4
- package/lib/cjs/Editing/Properties.js.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.d.ts +2 -1
- package/lib/cjs/Editing/PropertyCategories.d.ts.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.js +5 -1
- package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +1 -0
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +17 -10
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.d.ts +2 -2
- package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js +8 -11
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Editing/Structs.d.ts +2 -1
- package/lib/cjs/Editing/Structs.d.ts.map +1 -1
- package/lib/cjs/Editing/Structs.js +3 -0
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Editing/UnitSystems.d.ts +2 -1
- package/lib/cjs/Editing/UnitSystems.d.ts.map +1 -1
- package/lib/cjs/Editing/UnitSystems.js +3 -0
- package/lib/cjs/Editing/UnitSystems.js.map +1 -1
- package/lib/cjs/Editing/Units.d.ts +2 -1
- package/lib/cjs/Editing/Units.d.ts.map +1 -1
- package/lib/cjs/Editing/Units.js +5 -2
- package/lib/cjs/Editing/Units.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js +4 -4
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +7 -6
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/Edits/NameMapping.d.ts +22 -0
- package/lib/cjs/Merging/Edits/NameMapping.d.ts.map +1 -0
- package/lib/cjs/Merging/Edits/NameMapping.js +54 -0
- package/lib/cjs/Merging/Edits/NameMapping.js.map +1 -0
- package/lib/cjs/Merging/Edits/RenameEditHandler.d.ts +1 -1
- package/lib/cjs/Merging/Edits/RenameEditHandler.d.ts.map +1 -1
- package/lib/cjs/Merging/Edits/RenameEditHandler.js +1 -260
- package/lib/cjs/Merging/Edits/RenameEditHandler.js.map +1 -1
- package/lib/cjs/Merging/Edits/SchemaEdits.d.ts +9 -6
- package/lib/cjs/Merging/Edits/SchemaEdits.d.ts.map +1 -1
- package/lib/cjs/Merging/Edits/SchemaEdits.js +19 -14
- package/lib/cjs/Merging/Edits/SchemaEdits.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +1 -2
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumeratorMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumeratorMerger.js +2 -2
- package/lib/cjs/Merging/EnumeratorMerger.js.map +1 -1
- package/lib/cjs/Merging/FormatMerger.d.ts +24 -0
- package/lib/cjs/Merging/FormatMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/FormatMerger.js +143 -0
- package/lib/cjs/Merging/FormatMerger.js.map +1 -0
- package/lib/cjs/Merging/InvertedUnitMerger.d.ts +14 -0
- package/lib/cjs/Merging/InvertedUnitMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/InvertedUnitMerger.js +45 -0
- package/lib/cjs/Merging/InvertedUnitMerger.js.map +1 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.js +4 -5
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +1 -1
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +28 -26
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.js +4 -4
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts +5 -3
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +40 -5
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMergingVisitor.d.ts +14 -8
- package/lib/cjs/Merging/SchemaMergingVisitor.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMergingVisitor.js +42 -17
- package/lib/cjs/Merging/SchemaMergingVisitor.js.map +1 -1
- package/lib/cjs/Merging/SchemaMergingWalker.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMergingWalker.js +2 -0
- package/lib/cjs/Merging/SchemaMergingWalker.js.map +1 -1
- package/lib/cjs/Merging/UnitMerger.d.ts +14 -0
- package/lib/cjs/Merging/UnitMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/UnitMerger.js +62 -0
- package/lib/cjs/Merging/UnitMerger.js.map +1 -0
- package/lib/cjs/Merging/Utils.d.ts +11 -0
- package/lib/cjs/Merging/Utils.d.ts.map +1 -1
- package/lib/cjs/Merging/Utils.js +23 -3
- package/lib/cjs/Merging/Utils.js.map +1 -1
- package/lib/cjs/Validation/Diagnostic.js +18 -16
- package/lib/cjs/Validation/Diagnostic.js.map +1 -1
- package/lib/cjs/Validation/DiagnosticReporter.js +3 -0
- package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
- package/lib/cjs/Validation/ECRules.js +1 -1
- package/lib/cjs/Validation/ECRules.js.map +1 -1
- package/lib/cjs/Validation/SchemaChanges.js +39 -69
- package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareDiagnostics.d.ts +2 -2
- package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js +4 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.js +23 -23
- package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.d.ts +22 -1
- package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.js +30 -5
- package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidater.js +1 -4
- package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidationVisitor.js +3 -4
- package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js +4 -0
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/package.json +16 -16
|
@@ -29,7 +29,7 @@ async function modifyMixinClass(context, change, itemKey) {
|
|
|
29
29
|
const appliesTo = await (0, Utils_1.updateSchemaItemKey)(context, change.difference.appliesTo);
|
|
30
30
|
const currentValue = await mixin.appliesTo;
|
|
31
31
|
if (currentValue !== undefined && !appliesTo.matches(currentValue.key)) {
|
|
32
|
-
throw new Error(`Changing the mixin '${
|
|
32
|
+
throw new Error(`Changing the mixin '${change.itemName}' appliesTo is not supported.`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
return (0, ClassMerger_1.modifyClass)(context, change, itemKey, mixin);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MixinMerger.js","sourceRoot":"","sources":["../../../src/Merging/MixinMerger.ts"],"names":[],"mappings":";;AAeA,sCAUC;AAMD,4CAWC;AAlCD,mCAAwE;AACxE,+CAA4C;AAE5C;;;GAGG;AACI,KAAK,UAAU,aAAa,CAAC,OAA2B,EAAE,MAA4B;IAC3F,IAAI,MAAM,CAAC,UAAU,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,eAAe,EAAE;QACnE,GAAG,MAAM,CAAC,UAAU;QACpB,IAAI,EAAE,MAAM,CAAC,QAAQ;QACrB,cAAc,EAAE,MAAM,CAAC,UAAU;QACjC,SAAS,EAAE,MAAM,IAAA,gCAAwB,EAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;KAChF,CAAC,CAAC;AACL,CAA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AA2B,EAAE,MAA4B,EAAE,OAAsB;IACtH,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAiB,CAAC;IAC7E,IAAG,MAAM,CAAC,UAAU,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,MAAM,IAAA,2BAAmB,EAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAClF,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC;QAC3C,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;YACvE,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,QAAQ,+BAA+B,CAAC,CAAC;QACzF,CAAC;IACH,CAAC;IAED,OAAO,IAAA,yBAAW,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AACtD,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*--------------------------------------------------------------------------------------------*/\nimport type { MixinClassDifference } from \"../Differencing/SchemaDifference\";\nimport type { MutableMixin } from \"../Editing/Mutable/MutableMixin\";\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\nimport type { SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { updateSchemaItemFullName, updateSchemaItemKey } from \"./Utils\";\nimport { modifyClass } from \"./ClassMerger\";\n\n/**\n * Merges a new Mixin into the target schema.\n * @internal\n */\nexport async function addMixinClass(context: SchemaMergeContext, change: MixinClassDifference) {\n if (change.difference.appliesTo === undefined) {\n throw new Error(\"Mixin must define appliesTo\");\n }\n await context.editor.mixins.createFromProps(context.targetSchemaKey, {\n ...change.difference,\n name: change.itemName,\n schemaItemType: change.schemaType,\n appliesTo: await updateSchemaItemFullName(context, change.difference.appliesTo),\n });\n}\n\n/**\n * Merges differences to an existing Mixin in the target schema.\n * @internal\n */\nexport async function modifyMixinClass(context: SchemaMergeContext, change: MixinClassDifference, itemKey: SchemaItemKey) {\n const mixin = await context.targetSchema.lookupItem(itemKey) as MutableMixin;\n if(change.difference.appliesTo !== undefined) {\n const appliesTo = await updateSchemaItemKey(context, change.difference.appliesTo);\n const currentValue = await mixin.appliesTo;\n if (currentValue !== undefined && !appliesTo.matches(currentValue.key)) {\n throw new Error(`Changing the mixin '${change.itemName}' appliesTo is not supported.`);\n }\n }\n\n return modifyClass(context, change, itemKey, mixin);\n}\n"]}
|
|
@@ -33,7 +33,7 @@ async function modifyPhenomenon(context, change, itemKey) {
|
|
|
33
33
|
if (change.difference.definition !== undefined) {
|
|
34
34
|
// It would be better if the validation would be part of phenomenon.setDefinition.
|
|
35
35
|
if (phenomenon.definition !== "" && change.difference.definition.toLowerCase() !== phenomenon.definition.toLowerCase())
|
|
36
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `The Phenomenon ${
|
|
36
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `The Phenomenon ${change.itemName} has an invalid 'definition' attribute.`);
|
|
37
37
|
await phenomenon.setDefinition(change.difference.definition);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhenomenonMerger.js","sourceRoot":"","sources":["../../../src/Merging/PhenomenonMerger.ts"],"names":[],"mappings":";;AAaA,sCAWC;AAMD,4CAgBC;AAvCD,gEAA+F;AAE/F;;;GAGG;AACI,KAAK,UAAU,aAAa,CAAC,OAA2B,EAAE,MAA4B;IAC3F,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IA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YACpH,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,kBAAkB,MAAM,CAAC,QAAQ,yCAAyC,CAAC,CAAC;QAEtI,MAAM,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC/D,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*--------------------------------------------------------------------------------------------*/\nimport type { PhenomenonDifference } from \"../Differencing/SchemaDifference\";\nimport type { MutablePhenomenon } from \"../Editing/Mutable/MutablePhenomenon\";\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\nimport { ECObjectsError, ECObjectsStatus, type SchemaItemKey } from \"@itwin/ecschema-metadata\";\n\n/**\n * Merges a new Phenomenon into the target schema.\n * @internal\n */\nexport async function addPhenomenon(context: SchemaMergeContext, change: PhenomenonDifference) {\n if (change.difference.definition === undefined) {\n throw new Error(\"Phenomenon must define definition\");\n }\n\n await context.editor.phenomenons.createFromProps(context.targetSchemaKey, {\n ...change.difference,\n name: change.itemName,\n schemaItemType: change.schemaType,\n definition: change.difference.definition,\n });\n}\n\n/**\n * Merges differences to an existing Phenomenon in the target schema.\n * @internal\n */\nexport async function modifyPhenomenon(context: SchemaMergeContext, change: PhenomenonDifference, itemKey: SchemaItemKey) {\n const phenomenon = await context.targetSchema.lookupItem(itemKey) as MutablePhenomenon;\n if(change.difference.label !== undefined) {\n await context.editor.phenomenons.setDisplayLabel(itemKey, change.difference.label);\n }\n if(change.difference.description !== undefined) {\n await context.editor.phenomenons.setDescription(itemKey, change.difference.description);\n }\n\n if(change.difference.definition !== undefined) {\n // It would be better if the validation would be part of phenomenon.setDefinition.\n if (phenomenon.definition !== \"\" && change.difference.definition.toLowerCase() !== phenomenon.definition.toLowerCase())\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Phenomenon ${change.itemName} has an invalid 'definition' attribute.`);\n\n await phenomenon.setDefinition(change.difference.definition);\n }\n}\n"]}
|
|
@@ -29,17 +29,18 @@ async function mergeClassProperty(context, change, itemKey, property) {
|
|
|
29
29
|
: modifyClassProperty(context, itemKey, property);
|
|
30
30
|
}
|
|
31
31
|
async function addClassProperty(context, itemKey, property) {
|
|
32
|
+
const ecClass = await context.targetSchema.lookupItem((0, Utils_1.toItemKey)(context, itemKey.name));
|
|
32
33
|
if (property.category !== undefined) {
|
|
33
34
|
property.category = await (0, Utils_1.updateSchemaItemFullName)(context, property.category);
|
|
34
35
|
}
|
|
35
36
|
if (property.kindOfQuantity !== undefined) {
|
|
36
37
|
property.kindOfQuantity = await (0, Utils_1.updateSchemaItemFullName)(context, property.kindOfQuantity);
|
|
37
38
|
}
|
|
38
|
-
await createProperty(context,
|
|
39
|
+
await createProperty(context, ecClass.key, property);
|
|
39
40
|
if (property.customAttributes !== undefined) {
|
|
40
41
|
await (0, CustomAttributeMerger_1.applyCustomAttributes)(context, property.customAttributes, async (ca) => {
|
|
41
|
-
const classEditor = await (0, Utils_1.getClassEditor)(context,
|
|
42
|
-
await classEditor.properties.addCustomAttribute(
|
|
42
|
+
const classEditor = await (0, Utils_1.getClassEditor)(context, ecClass.key);
|
|
43
|
+
await classEditor.properties.addCustomAttribute(ecClass.key, property.name, ca);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -59,48 +60,49 @@ async function createProperty(context, itemKey, property) {
|
|
|
59
60
|
return {};
|
|
60
61
|
}
|
|
61
62
|
async function modifyClassProperty(context, itemKey, propertyProps) {
|
|
62
|
-
const ecClass = await context.
|
|
63
|
-
const
|
|
63
|
+
const ecClass = await context.targetSchema.lookupItem((0, Utils_1.toItemKey)(context, itemKey.name));
|
|
64
|
+
const propertyKey = (0, Utils_1.toPropertyKey)(context, itemKey.name, propertyProps.name);
|
|
65
|
+
const property = await ecClass.getProperty(propertyKey.propertyName);
|
|
64
66
|
if (property === undefined) {
|
|
65
|
-
throw new Error(`Couldn't find property ${
|
|
67
|
+
throw new Error(`Couldn't find property ${propertyKey.propertyName} on class ${ecClass.key.name}`);
|
|
66
68
|
}
|
|
67
69
|
if (propertyProps.type !== undefined) {
|
|
68
70
|
throw new Error(`Changing the property '${property.fullName}' type is not supported.`);
|
|
69
71
|
}
|
|
70
72
|
const classEditor = await (0, Utils_1.getClassEditor)(context, ecClass);
|
|
71
73
|
if (propertyProps.description !== undefined) {
|
|
72
|
-
await classEditor.properties.setDescription(
|
|
74
|
+
await classEditor.properties.setDescription(ecClass.key, property.name, propertyProps.description);
|
|
73
75
|
}
|
|
74
76
|
if (propertyProps.label !== undefined) {
|
|
75
|
-
await classEditor.properties.setLabel(
|
|
77
|
+
await classEditor.properties.setLabel(ecClass.key, property.name, propertyProps.label);
|
|
76
78
|
}
|
|
77
79
|
if (propertyProps.isReadOnly !== undefined) {
|
|
78
|
-
await classEditor.properties.setIsReadOnly(
|
|
80
|
+
await classEditor.properties.setIsReadOnly(ecClass.key, property.name, propertyProps.isReadOnly);
|
|
79
81
|
}
|
|
80
82
|
if (propertyProps.priority !== undefined) {
|
|
81
|
-
await classEditor.properties.setPriority(
|
|
83
|
+
await classEditor.properties.setPriority(ecClass.key, property.name, propertyProps.priority);
|
|
82
84
|
}
|
|
83
85
|
if (propertyProps.kindOfQuantity !== undefined) {
|
|
84
|
-
await classEditor.properties.setKindOfQuantity(
|
|
86
|
+
await classEditor.properties.setKindOfQuantity(ecClass.key, property.name, await (0, Utils_1.updateSchemaItemKey)(context, propertyProps.kindOfQuantity));
|
|
85
87
|
}
|
|
86
88
|
if (property.isArray()) {
|
|
87
|
-
await arrayProperty.merge(context,
|
|
89
|
+
await arrayProperty.merge(context, ecClass.key, property.name, propertyProps);
|
|
88
90
|
}
|
|
89
91
|
if (propertyProps.category !== undefined) {
|
|
90
92
|
const categoryKey = await (0, Utils_1.updateSchemaItemKey)(context, propertyProps.category);
|
|
91
|
-
await classEditor.properties.setCategory(
|
|
93
|
+
await classEditor.properties.setCategory(ecClass.key, property.name, categoryKey);
|
|
92
94
|
}
|
|
93
95
|
if (property.isEnumeration()) {
|
|
94
|
-
return enumerationProperty.merge(context,
|
|
96
|
+
return enumerationProperty.merge(context, ecClass.key, property, propertyProps);
|
|
95
97
|
}
|
|
96
98
|
if (property.isNavigation()) {
|
|
97
|
-
return navigationProperty.merge(context,
|
|
99
|
+
return navigationProperty.merge(context, ecClass.key, property, propertyProps);
|
|
98
100
|
}
|
|
99
101
|
if (property.isPrimitive()) {
|
|
100
|
-
return primitiveProperty.merge(context,
|
|
102
|
+
return primitiveProperty.merge(context, ecClass.key, property, propertyProps);
|
|
101
103
|
}
|
|
102
104
|
if (property.isStruct()) {
|
|
103
|
-
return structProperty.merge(context,
|
|
105
|
+
return structProperty.merge(context, ecClass.key, property, propertyProps);
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
const arrayProperty = {
|
|
@@ -123,11 +125,11 @@ const enumerationProperty = {
|
|
|
123
125
|
},
|
|
124
126
|
async add(context, itemKey, property) {
|
|
125
127
|
const enumerationKey = await (0, Utils_1.updateSchemaItemKey)(context, property.typeName);
|
|
126
|
-
const enumerationType = await context.editor.schemaContext.getSchemaItem(enumerationKey);
|
|
128
|
+
const enumerationType = await context.editor.schemaContext.getSchemaItem(enumerationKey, ecschema_metadata_1.Enumeration);
|
|
127
129
|
if (enumerationType === undefined) {
|
|
128
130
|
throw new Error(`Unable to locate the enumeration class ${enumerationKey.name} in the context schema.`);
|
|
129
131
|
}
|
|
130
|
-
property.typeName =
|
|
132
|
+
property.typeName = enumerationType.fullName;
|
|
131
133
|
const classEditor = await (0, Utils_1.getClassEditor)(context, itemKey);
|
|
132
134
|
arrayProperty.is(property)
|
|
133
135
|
? await classEditor.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)
|
|
@@ -146,18 +148,18 @@ const navigationProperty = {
|
|
|
146
148
|
},
|
|
147
149
|
async add(context, itemKey, property) {
|
|
148
150
|
const relationshipKey = await (0, Utils_1.updateSchemaItemKey)(context, property.relationshipName);
|
|
149
|
-
const relationshipType = await context.editor.schemaContext.getSchemaItem(relationshipKey);
|
|
151
|
+
const relationshipType = await context.editor.schemaContext.getSchemaItem(relationshipKey, ecschema_metadata_1.RelationshipClass);
|
|
150
152
|
if (relationshipType === undefined) {
|
|
151
153
|
throw new Error(`Unable to locate the relationship class ${relationshipKey.name} in the context schema.`);
|
|
152
154
|
}
|
|
153
|
-
property.relationshipName =
|
|
155
|
+
property.relationshipName = relationshipType.fullName;
|
|
154
156
|
const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey);
|
|
155
157
|
if (ecClass.schemaItemType === ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
156
|
-
return context.editor.entities.createNavigationPropertyFromProps(
|
|
158
|
+
return context.editor.entities.createNavigationPropertyFromProps(ecClass.key, property);
|
|
157
159
|
if (ecClass.schemaItemType === ecschema_metadata_1.SchemaItemType.Mixin)
|
|
158
|
-
return context.editor.mixins.createNavigationPropertyFromProps(
|
|
160
|
+
return context.editor.mixins.createNavigationPropertyFromProps(ecClass.key, property);
|
|
159
161
|
if (ecClass.schemaItemType === ecschema_metadata_1.SchemaItemType.RelationshipClass)
|
|
160
|
-
return context.editor.relationships.createNavigationPropertyFromProps(
|
|
162
|
+
return context.editor.relationships.createNavigationPropertyFromProps(ecClass.key, property);
|
|
161
163
|
throw new Error(`Navigation property can't be added to ${ecClass.schemaItemType}.`);
|
|
162
164
|
},
|
|
163
165
|
async merge(_context, _itemKey, property, props) {
|
|
@@ -211,11 +213,11 @@ const structProperty = {
|
|
|
211
213
|
},
|
|
212
214
|
async add(context, itemKey, property) {
|
|
213
215
|
const structKey = await (0, Utils_1.updateSchemaItemKey)(context, property.typeName);
|
|
214
|
-
const structType = await context.editor.schemaContext.getSchemaItem(structKey);
|
|
216
|
+
const structType = await context.editor.schemaContext.getSchemaItem(structKey, ecschema_metadata_1.StructClass);
|
|
215
217
|
if (structType === undefined) {
|
|
216
218
|
throw new Error(`Unable to locate the struct ${structKey.name} in the context schema.`);
|
|
217
219
|
}
|
|
218
|
-
property.typeName =
|
|
220
|
+
property.typeName = structType.fullName;
|
|
219
221
|
const classEditor = await (0, Utils_1.getClassEditor)(context, itemKey);
|
|
220
222
|
return arrayProperty.is(property)
|
|
221
223
|
? classEditor.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":";;AAwBA,0DAMC;AAKD,oDAIC;AAjCD,gEAAuT;AACvT,mCAAwF;AAExF,mEAAgE;AAYhE;;GAEG;AACI,KAAK,UAAU,uBAAuB,CAAC,OAA2B,EAAE,MAA+B;IACxG,MAAM,QAAQ,GAAG,IAAI,iCAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7E,OAAO,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;QACnD,GAAG,MAAM,CAAC,UAAU;QACpB,IAAI,EAAE,MAAM,CAAC,IAAI;KACE,CAAC,CAAC;AACzB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAA8B,EAAE,OAAsB;IAC5H,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QAC1D,MAAM,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,OAA2B,EAAE,MAAsC,EAAE,OAAsB,EAAE,QAA0B;IACvJ,OAAO,MAAM,CAAC,UAAU,KAAK,KAAK;QAChC,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;QAC9C,CAAC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AK,SAAS,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,CAAC,QAAQ,iCAAiC,CAAC,CAAC;QAChG,CAAC;IACH,CAAC;CACF,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*--------------------------------------------------------------------------------------------*/\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\nimport type { AnyClassItemDifference, ClassPropertyDifference, DifferenceType } from \"../Differencing/SchemaDifference\";\nimport { AnyProperty, AnyPropertyProps, ArrayPropertyProps, CustomAttribute, ECClass, Enumeration, EnumerationPropertyProps, NavigationPropertyProps, parsePrimitiveType, PrimitivePropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, StructClass, StructPropertyProps } from \"@itwin/ecschema-metadata\";\nimport { getClassEditor, updateSchemaItemFullName, updateSchemaItemKey } from \"./Utils\";\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\nimport { applyCustomAttributes } from \"./CustomAttributeMerger\";\n\ntype PartialEditable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\ninterface PropertyMerger<T extends AnyPropertyProps> {\n is(property: AnyPropertyProps): property is T;\n add(context: SchemaMergeContext, itemKey: SchemaItemKey, props: PartialEditable<T>): Promise<void>;\n merge(context: SchemaMergeContext, itemKey: SchemaItemKey, property: AnyProperty, props: T): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport async function mergePropertyDifference(context: SchemaMergeContext, change: ClassPropertyDifference): Promise<void> {\n const classKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\n return mergeClassProperty(context, change, classKey, {\n ...change.difference,\n name: change.path,\n } as AnyPropertyProps);\n}\n\n/**\n * @internal\n */\nexport async function mergeClassProperties(context: SchemaMergeContext, change: AnyClassItemDifference, itemKey: SchemaItemKey): Promise<void> {\n for (const property of change.difference.properties || []) {\n await mergeClassProperty(context, change, itemKey, property);\n }\n}\n\nasync function mergeClassProperty(context: SchemaMergeContext, change: { changeType: DifferenceType }, itemKey: SchemaItemKey, property: AnyPropertyProps) {\n return change.changeType === \"add\"\n ? addClassProperty(context, itemKey, property)\n : modifyClassProperty(context, itemKey, property);\n}\n\nasync function addClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>): Promise<void> {\n if (property.category !== undefined) {\n property.category = await updateSchemaItemFullName(context, property.category);\n }\n\n if (property.kindOfQuantity !== undefined) {\n property.kindOfQuantity = await updateSchemaItemFullName(context, property.kindOfQuantity);\n }\n\n await createProperty(context, itemKey, property);\n\n if (property.customAttributes !== undefined) {\n await applyCustomAttributes(context, property.customAttributes as CustomAttribute[], async (ca) => {\n const classEditor = await getClassEditor(context, itemKey);\n await classEditor.properties.addCustomAttribute(itemKey, property.name, ca);\n });\n }\n}\n\nasync function createProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>) {\n if (enumerationProperty.is(property)) {\n return enumerationProperty.add(context, itemKey, property);\n }\n if (navigationProperty.is(property)) {\n return navigationProperty.add(context, itemKey, property);\n }\n if (primitiveProperty.is(property)) {\n return primitiveProperty.add(context, itemKey, property);\n }\n if (structProperty.is(property)) {\n return structProperty.add(context, itemKey, property);\n }\n return {};\n}\n\nasync function modifyClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyProps: AnyPropertyProps): Promise<void> {\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\n const property = await ecClass.getProperty(propertyProps.name) as MutableProperty;\n if (property === undefined) {\n throw new Error(`Couldn't find property ${propertyProps.name} on class ${itemKey.name}`);\n }\n\n if (propertyProps.type !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' type is not supported.`);\n }\n\n const classEditor = await getClassEditor(context, ecClass);\n\n if (propertyProps.description !== undefined) {\n await classEditor.properties.setDescription(itemKey, propertyProps.name, propertyProps.description);\n }\n if (propertyProps.label !== undefined) {\n await classEditor.properties.setLabel(itemKey, propertyProps.name, propertyProps.label);\n }\n if (propertyProps.isReadOnly !== undefined) {\n await classEditor.properties.setIsReadOnly(itemKey, propertyProps.name, propertyProps.isReadOnly);\n }\n if (propertyProps.priority !== undefined) {\n await classEditor.properties.setPriority(itemKey, propertyProps.name, propertyProps.priority);\n }\n if (propertyProps.kindOfQuantity !== undefined) {\n await classEditor.properties.setKindOfQuantity(itemKey, propertyProps.name, await updateSchemaItemKey(context, propertyProps.kindOfQuantity));\n }\n\n if (property.isArray()) {\n await arrayProperty.merge(context, itemKey, property.name, propertyProps);\n }\n\n if (propertyProps.category !== undefined) {\n const categoryKey = await updateSchemaItemKey(context, propertyProps.category);\n await classEditor.properties.setCategory(itemKey, property.name, categoryKey);\n }\n\n if (property.isEnumeration()) {\n return enumerationProperty.merge(context, itemKey, property, propertyProps as any);\n }\n if (property.isNavigation()) {\n return navigationProperty.merge(context, itemKey, property, propertyProps as any);\n }\n if (property.isPrimitive()) {\n return primitiveProperty.merge(context, itemKey, property, propertyProps as any);\n }\n if (property.isStruct()) {\n return structProperty.merge(context, itemKey, property, propertyProps as any);\n }\n}\n\nconst arrayProperty = {\n is(property: AnyPropertyProps): boolean {\n return \"minOccurs\" in property && \"maxOccurs\" in property;\n },\n async merge(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyName: string, props: ArrayPropertyProps) {\n const classEditor = await getClassEditor(context, itemKey);\n if (props.minOccurs !== undefined) {\n await classEditor.arrayProperties.setMinOccurs(itemKey, propertyName, props.minOccurs);\n }\n if (props.maxOccurs !== undefined) {\n await classEditor.arrayProperties.setMaxOccurs(itemKey, propertyName, props.maxOccurs);\n }\n },\n};\n\nconst enumerationProperty: PropertyMerger<EnumerationPropertyProps> = {\n is(property): property is EnumerationPropertyProps {\n return primitiveProperty.is(property) && property.typeName.includes(\".\");\n },\n async add(context, itemKey, property): Promise<void> {\n const enumerationKey = await updateSchemaItemKey(context, property.typeName);\n const enumerationType = await context.editor.schemaContext.getSchemaItem<Enumeration>(enumerationKey);\n if (enumerationType === undefined) {\n throw new Error(`Unable to locate the enumeration class ${enumerationKey.name} in the context schema.`);\n }\n\n property.typeName = enumerationKey.fullName;\n\n const classEditor = await getClassEditor(context, itemKey);\n\n arrayProperty.is(property)\n ? await classEditor.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)\n : await classEditor.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);\n },\n async merge(context, itemKey, property, props) {\n if (\"enumeration\" in props && props.enumeration !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' enumeration is not supported.`);\n }\n return primitiveProperty.merge(context, itemKey, property, props);\n },\n};\n\nconst navigationProperty: PropertyMerger<NavigationPropertyProps> = {\n is(property): property is NavigationPropertyProps {\n return property.type === \"NavigationProperty\";\n },\n async add(context, itemKey, property): Promise<void> {\n const relationshipKey = await updateSchemaItemKey(context, property.relationshipName);\n const relationshipType = await context.editor.schemaContext.getSchemaItem<RelationshipClass>(relationshipKey);\n if (relationshipType === undefined) {\n throw new Error(`Unable to locate the relationship class ${relationshipKey.name} in the context schema.`);\n }\n\n property.relationshipName = relationshipKey.fullName;\n\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\n if (ecClass.schemaItemType === SchemaItemType.EntityClass)\n return context.editor.entities.createNavigationPropertyFromProps(itemKey, property);\n if (ecClass.schemaItemType === SchemaItemType.Mixin)\n return context.editor.mixins.createNavigationPropertyFromProps(itemKey, property);\n if (ecClass.schemaItemType === SchemaItemType.RelationshipClass)\n return context.editor.relationships.createNavigationPropertyFromProps(itemKey, property);\n throw new Error(`Navigation property can't be added to ${ecClass.schemaItemType}.`);\n },\n async merge(_context, _itemKey, property, props) {\n if (props.direction !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' direction is not supported.`);\n }\n if (\"relationshipClass\" in props && props.relationshipClass !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' relationship class is not supported.`);\n }\n },\n};\n\nconst primitiveProperty: PropertyMerger<PrimitivePropertyProps> = {\n is(property): property is PrimitivePropertyProps {\n return property.type === \"PrimitiveProperty\" || property.type === \"PrimitiveArrayProperty\";\n },\n async add(context, itemKey, property): Promise<void> {\n const propertyType = parsePrimitiveType(property.typeName);\n if (propertyType === undefined) {\n throw new Error(`Invalid property type ${property.typeName} on property ${property.name}`);\n }\n\n const classEditor = await getClassEditor(context, itemKey);\n return arrayProperty.is(property)\n ? classEditor.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)\n : classEditor.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);\n },\n async merge(context, itemKey, property, props) {\n if (props.typeName) {\n throw new Error(`Changing the property '${property.fullName}' primitiveType is not supported.`);\n }\n\n const classEditor = await getClassEditor(context, itemKey);\n if (props.extendedTypeName !== undefined) {\n await classEditor.primitiveProperties.setExtendedTypeName(itemKey, property.name, props.extendedTypeName);\n }\n if (props.minLength !== undefined) {\n await classEditor.primitiveProperties.setMinLength(itemKey, property.name, props.minLength);\n }\n if (props.maxLength !== undefined) {\n await classEditor.primitiveProperties.setMaxLength(itemKey, property.name, props.maxLength);\n }\n if (props.minValue !== undefined) {\n await classEditor.primitiveProperties.setMinValue(itemKey, property.name, props.minValue);\n }\n if (props.maxValue !== undefined) {\n await classEditor.primitiveProperties.setMaxValue(itemKey, property.name, props.maxValue);\n }\n },\n};\n\nconst structProperty: PropertyMerger<StructPropertyProps> = {\n is(property): property is StructPropertyProps {\n return property.type === \"StructProperty\" || property.type === \"StructArrayProperty\";\n },\n async add(context, itemKey, property): Promise<void> {\n const structKey = await updateSchemaItemKey(context, property.typeName);\n const structType = await context.editor.schemaContext.getSchemaItem<StructClass>(structKey);\n if (structType === undefined) {\n throw new Error(`Unable to locate the struct ${structKey.name} in the context schema.`);\n }\n\n property.typeName = structKey.fullName;\n\n const classEditor = await getClassEditor(context, itemKey);\n return arrayProperty.is(property)\n ? classEditor.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)\n : classEditor.createStructPropertyFromProps(itemKey, property.name, structType, property);\n },\n async merge(_context, _itemKey, property, props) {\n if (\"structClass\" in props && props.structClass !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' structClass is not supported.`);\n }\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"PropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":";;AAwBA,0DAMC;AAKD,oDAIC;AAjCD,gEAAuT;AACvT,mCAAkH;AAElH,mEAAgE;AAYhE;;GAEG;AACI,KAAK,UAAU,uBAAuB,CAAC,OAA2B,EAAE,MAA+B;IACxG,MAAM,QAAQ,GAAG,IAAI,iCAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7E,OAAO,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;QACnD,GAAG,MAAM,CAAC,UAAU;QACpB,IAAI,EAAE,MAAM,CAAC,IAAI;KACE,CAAC,CAAC;AACzB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAA8B,EAAE,OAAsB;IAC5H,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QAC1D,MAAM,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,OAA2B,EAAE,MAAsC,EAAE,OAAsB,EAAE,QAA0B;IACvJ,OAAO,MAAM,CAAC,UAAU,KAAK,KAAK;QAChC,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;QAC9C,CAAC,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,OAA2B,EAAE,OA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;QAC3D,OAAO,aAAa,CAAC,EAAE,CAAC,QAAQ,CAAC;YAC/B,CAAC,CAAC,WAAW,CAAC,kCAAkC,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC;YAC9F,CAAC,CAAC,WAAW,CAAC,6BAA6B,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC9F,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK;QAC7C,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,CAAC,QAAQ,iCAAiC,CAAC,CAAC;QAChG,CAAC;IACH,CAAC;CACF,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*--------------------------------------------------------------------------------------------*/\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\nimport type { AnyClassItemDifference, ClassPropertyDifference, DifferenceType } from \"../Differencing/SchemaDifference\";\nimport { AnyProperty, AnyPropertyProps, ArrayPropertyProps, CustomAttribute, ECClass, Enumeration, EnumerationPropertyProps, NavigationPropertyProps, parsePrimitiveType, PrimitivePropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, StructClass, StructPropertyProps } from \"@itwin/ecschema-metadata\";\nimport { getClassEditor, toItemKey, toPropertyKey, updateSchemaItemFullName, updateSchemaItemKey } from \"./Utils\";\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\nimport { applyCustomAttributes } from \"./CustomAttributeMerger\";\n\ntype PartialEditable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\ninterface PropertyMerger<T extends AnyPropertyProps> {\n is(property: AnyPropertyProps): property is T;\n add(context: SchemaMergeContext, itemKey: SchemaItemKey, props: PartialEditable<T>): Promise<void>;\n merge(context: SchemaMergeContext, itemKey: SchemaItemKey, property: AnyProperty, props: T): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport async function mergePropertyDifference(context: SchemaMergeContext, change: ClassPropertyDifference): Promise<void> {\n const classKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\n return mergeClassProperty(context, change, classKey, {\n ...change.difference,\n name: change.path,\n } as AnyPropertyProps);\n}\n\n/**\n * @internal\n */\nexport async function mergeClassProperties(context: SchemaMergeContext, change: AnyClassItemDifference, itemKey: SchemaItemKey): Promise<void> {\n for (const property of change.difference.properties || []) {\n await mergeClassProperty(context, change, itemKey, property);\n }\n}\n\nasync function mergeClassProperty(context: SchemaMergeContext, change: { changeType: DifferenceType }, itemKey: SchemaItemKey, property: AnyPropertyProps) {\n return change.changeType === \"add\"\n ? addClassProperty(context, itemKey, property)\n : modifyClassProperty(context, itemKey, property);\n}\n\nasync function addClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>): Promise<void> {\n const ecClass = await context.targetSchema.lookupItem(toItemKey(context, itemKey.name)) as ECClass;\n\n if (property.category !== undefined) {\n property.category = await updateSchemaItemFullName(context, property.category);\n }\n\n if (property.kindOfQuantity !== undefined) {\n property.kindOfQuantity = await updateSchemaItemFullName(context, property.kindOfQuantity);\n }\n\n await createProperty(context, ecClass.key, property);\n\n if (property.customAttributes !== undefined) {\n await applyCustomAttributes(context, property.customAttributes as CustomAttribute[], async (ca) => {\n const classEditor = await getClassEditor(context, ecClass.key);\n await classEditor.properties.addCustomAttribute(ecClass.key, property.name, ca);\n });\n }\n}\n\nasync function createProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>) {\n if (enumerationProperty.is(property)) {\n return enumerationProperty.add(context, itemKey, property);\n }\n if (navigationProperty.is(property)) {\n return navigationProperty.add(context, itemKey, property);\n }\n if (primitiveProperty.is(property)) {\n return primitiveProperty.add(context, itemKey, property);\n }\n if (structProperty.is(property)) {\n return structProperty.add(context, itemKey, property);\n }\n return {};\n}\n\nasync function modifyClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyProps: AnyPropertyProps): Promise<void> {\n const ecClass = await context.targetSchema.lookupItem(toItemKey(context, itemKey.name)) as ECClass;\n const propertyKey = toPropertyKey(context, itemKey.name, propertyProps.name);\n const property = await ecClass.getProperty(propertyKey.propertyName) as MutableProperty;\n\n if (property === undefined) {\n throw new Error(`Couldn't find property ${propertyKey.propertyName} on class ${ecClass.key.name}`);\n }\n\n if (propertyProps.type !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' type is not supported.`);\n }\n\n const classEditor = await getClassEditor(context, ecClass);\n\n if (propertyProps.description !== undefined) {\n await classEditor.properties.setDescription(ecClass.key, property.name, propertyProps.description);\n }\n if (propertyProps.label !== undefined) {\n await classEditor.properties.setLabel(ecClass.key, property.name, propertyProps.label);\n }\n if (propertyProps.isReadOnly !== undefined) {\n await classEditor.properties.setIsReadOnly(ecClass.key, property.name, propertyProps.isReadOnly);\n }\n if (propertyProps.priority !== undefined) {\n await classEditor.properties.setPriority(ecClass.key, property.name, propertyProps.priority);\n }\n if (propertyProps.kindOfQuantity !== undefined) {\n await classEditor.properties.setKindOfQuantity(ecClass.key, property.name, await updateSchemaItemKey(context, propertyProps.kindOfQuantity));\n }\n\n if (property.isArray()) {\n await arrayProperty.merge(context, ecClass.key, property.name, propertyProps);\n }\n\n if (propertyProps.category !== undefined) {\n const categoryKey = await updateSchemaItemKey(context, propertyProps.category);\n await classEditor.properties.setCategory(ecClass.key, property.name, categoryKey);\n }\n\n if (property.isEnumeration()) {\n return enumerationProperty.merge(context, ecClass.key, property, propertyProps as any);\n }\n if (property.isNavigation()) {\n return navigationProperty.merge(context, ecClass.key, property, propertyProps as any);\n }\n if (property.isPrimitive()) {\n return primitiveProperty.merge(context, ecClass.key, property, propertyProps as any);\n }\n if (property.isStruct()) {\n return structProperty.merge(context, ecClass.key, property, propertyProps as any);\n }\n}\n\nconst arrayProperty = {\n is(property: AnyPropertyProps): boolean {\n return \"minOccurs\" in property && \"maxOccurs\" in property;\n },\n async merge(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyName: string, props: ArrayPropertyProps) {\n const classEditor = await getClassEditor(context, itemKey);\n if (props.minOccurs !== undefined) {\n await classEditor.arrayProperties.setMinOccurs(itemKey, propertyName, props.minOccurs);\n }\n if (props.maxOccurs !== undefined) {\n await classEditor.arrayProperties.setMaxOccurs(itemKey, propertyName, props.maxOccurs);\n }\n },\n};\n\nconst enumerationProperty: PropertyMerger<EnumerationPropertyProps> = {\n is(property): property is EnumerationPropertyProps {\n return primitiveProperty.is(property) && property.typeName.includes(\".\");\n },\n async add(context, itemKey, property): Promise<void> {\n const enumerationKey = await updateSchemaItemKey(context, property.typeName);\n const enumerationType = await context.editor.schemaContext.getSchemaItem(enumerationKey, Enumeration);\n if (enumerationType === undefined) {\n throw new Error(`Unable to locate the enumeration class ${enumerationKey.name} in the context schema.`);\n }\n\n property.typeName = enumerationType.fullName;\n\n const classEditor = await getClassEditor(context, itemKey);\n\n arrayProperty.is(property)\n ? await classEditor.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)\n : await classEditor.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);\n },\n async merge(context, itemKey, property, props) {\n if (\"enumeration\" in props && props.enumeration !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' enumeration is not supported.`);\n }\n return primitiveProperty.merge(context, itemKey, property, props);\n },\n};\n\nconst navigationProperty: PropertyMerger<NavigationPropertyProps> = {\n is(property): property is NavigationPropertyProps {\n return property.type === \"NavigationProperty\";\n },\n async add(context, itemKey, property): Promise<void> {\n const relationshipKey = await updateSchemaItemKey(context, property.relationshipName);\n const relationshipType = await context.editor.schemaContext.getSchemaItem(relationshipKey, RelationshipClass);\n if (relationshipType === undefined) {\n throw new Error(`Unable to locate the relationship class ${relationshipKey.name} in the context schema.`);\n }\n\n property.relationshipName = relationshipType.fullName;\n\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\n if (ecClass.schemaItemType === SchemaItemType.EntityClass)\n return context.editor.entities.createNavigationPropertyFromProps(ecClass.key, property);\n if (ecClass.schemaItemType === SchemaItemType.Mixin)\n return context.editor.mixins.createNavigationPropertyFromProps(ecClass.key, property);\n if (ecClass.schemaItemType === SchemaItemType.RelationshipClass)\n return context.editor.relationships.createNavigationPropertyFromProps(ecClass.key, property);\n throw new Error(`Navigation property can't be added to ${ecClass.schemaItemType}.`);\n },\n async merge(_context, _itemKey, property, props) {\n if (props.direction !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' direction is not supported.`);\n }\n if (\"relationshipClass\" in props && props.relationshipClass !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' relationship class is not supported.`);\n }\n },\n};\n\nconst primitiveProperty: PropertyMerger<PrimitivePropertyProps> = {\n is(property): property is PrimitivePropertyProps {\n return property.type === \"PrimitiveProperty\" || property.type === \"PrimitiveArrayProperty\";\n },\n async add(context, itemKey, property): Promise<void> {\n const propertyType = parsePrimitiveType(property.typeName);\n if (propertyType === undefined) {\n throw new Error(`Invalid property type ${property.typeName} on property ${property.name}`);\n }\n\n const classEditor = await getClassEditor(context, itemKey);\n return arrayProperty.is(property)\n ? classEditor.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)\n : classEditor.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);\n },\n async merge(context, itemKey, property, props) {\n if (props.typeName) {\n throw new Error(`Changing the property '${property.fullName}' primitiveType is not supported.`);\n }\n\n const classEditor = await getClassEditor(context, itemKey);\n if (props.extendedTypeName !== undefined) {\n await classEditor.primitiveProperties.setExtendedTypeName(itemKey, property.name, props.extendedTypeName);\n }\n if (props.minLength !== undefined) {\n await classEditor.primitiveProperties.setMinLength(itemKey, property.name, props.minLength);\n }\n if (props.maxLength !== undefined) {\n await classEditor.primitiveProperties.setMaxLength(itemKey, property.name, props.maxLength);\n }\n if (props.minValue !== undefined) {\n await classEditor.primitiveProperties.setMinValue(itemKey, property.name, props.minValue);\n }\n if (props.maxValue !== undefined) {\n await classEditor.primitiveProperties.setMaxValue(itemKey, property.name, props.maxValue);\n }\n },\n};\n\nconst structProperty: PropertyMerger<StructPropertyProps> = {\n is(property): property is StructPropertyProps {\n return property.type === \"StructProperty\" || property.type === \"StructArrayProperty\";\n },\n async add(context, itemKey, property): Promise<void> {\n const structKey = await updateSchemaItemKey(context, property.typeName);\n const structType = await context.editor.schemaContext.getSchemaItem(structKey, StructClass);\n if (structType === undefined) {\n throw new Error(`Unable to locate the struct ${structKey.name} in the context schema.`);\n }\n\n property.typeName = structType.fullName;\n\n const classEditor = await getClassEditor(context, itemKey);\n return arrayProperty.is(property)\n ? classEditor.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)\n : classEditor.createStructPropertyFromProps(itemKey, property.name, structType, property);\n },\n async merge(_context, _itemKey, property, props) {\n if (\"structClass\" in props && props.structClass !== undefined) {\n throw new Error(`Changing the property '${property.fullName}' structClass is not supported.`);\n }\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,2BAA2B,EAAE,qCAAqC,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AAI7J,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"RelationshipClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,2BAA2B,EAAE,qCAAqC,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AAI7J,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAgJ,aAAa,EAAkB,MAAM,0BAA0B,CAAC;AAEvN;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,2BAA2B,iBAuB1G;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,2BAA2B,EAAE,OAAO,EAAE,aAAa,iBAyBrI;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,gCAAgC;;GAgCtH;AAED;;;GAGG;AACH,wBAAsB,gCAAgC,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,qCAAqC,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhJ"}
|
|
@@ -93,8 +93,8 @@ async function mergeRelationshipConstraint(context, change) {
|
|
|
93
93
|
}
|
|
94
94
|
if (change.difference.abstractConstraint !== undefined) {
|
|
95
95
|
const itemKey = await (0, Utils_1.updateSchemaItemKey)(context, change.difference.abstractConstraint);
|
|
96
|
-
const abstractConstraint = await context.editor.schemaContext.getSchemaItem(itemKey);
|
|
97
|
-
if (abstractConstraint === undefined) {
|
|
96
|
+
const abstractConstraint = await context.editor.schemaContext.getSchemaItem(itemKey, ecschema_metadata_1.ECClass);
|
|
97
|
+
if (abstractConstraint === undefined || (!ecschema_metadata_1.EntityClass.isEntityClass(abstractConstraint) && !ecschema_metadata_1.Mixin.isMixin(abstractConstraint) && !ecschema_metadata_1.RelationshipClass.isRelationshipClass(abstractConstraint))) {
|
|
98
98
|
throw new Error(`Unable to locate the abstract constraint class ${change.difference.abstractConstraint} in the context schema.`);
|
|
99
99
|
}
|
|
100
100
|
return context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);
|
|
@@ -113,8 +113,8 @@ async function mergeRelationshipClassConstraint(context, change) {
|
|
|
113
113
|
const constraint = item[parseConstraint(change.path)];
|
|
114
114
|
for (const constraintName of change.difference) {
|
|
115
115
|
const constraintClassKey = await (0, Utils_1.updateSchemaItemKey)(context, constraintName);
|
|
116
|
-
const constraintClass = await context.editor.schemaContext.getSchemaItem(constraintClassKey);
|
|
117
|
-
if (constraintClass === undefined) {
|
|
116
|
+
const constraintClass = await context.editor.schemaContext.getSchemaItem(constraintClassKey, ecschema_metadata_1.ECClass);
|
|
117
|
+
if (constraintClass === undefined || (!ecschema_metadata_1.EntityClass.isEntityClass(constraintClass) && !ecschema_metadata_1.Mixin.isMixin(constraintClass) && !ecschema_metadata_1.RelationshipClass.isRelationshipClass(constraintClass))) {
|
|
118
118
|
throw new Error(`Could not locate relationship constraint class ${constraintClassKey.name}`);
|
|
119
119
|
}
|
|
120
120
|
await context.editor.relationships.addConstraintClass(constraint, constraintClass);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":";;AAiBA,oDAuBC;AAMD,0DAyBC;AAOD,kEAgCC;AAMD,4EAgBC;AA9HD,mCAA0F;AAC1F,+CAA4C;AAE5C,gEAA8M;AAI9M;;;GAGG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAAmC;IACzG,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAA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AC5G,IAAI,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAAC;IAClD,IAAI,kBAAkB,KAAK,SAAS;QAClC,kBAAkB,GAAG,MAAM,IAAA,gCAAwB,EAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAEnF,MAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC9C,iBAAiB,CAAC,IAAI,CAAC,MAAM,IAAA,gCAAwB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO;QACL,GAAG,KAAK;QACR,kBAAkB;QAClB,iBAAiB;KAClB,CAAC;AACJ,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*--------------------------------------------------------------------------------------------*/\nimport type { RelationshipClassDifference, RelationshipConstraintClassDifference, RelationshipConstraintDifference } from \"../Differencing/SchemaDifference\";\nimport type { MutableRelationshipClass } from \"../Editing/Mutable/MutableRelationshipClass\";\nimport { locateSchemaItem, updateSchemaItemFullName, updateSchemaItemKey } from \"./Utils\";\nimport { modifyClass } from \"./ClassMerger\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { EntityClass, Mixin, parseStrength, parseStrengthDirection, RelationshipClass, RelationshipConstraintProps, RelationshipMultiplicity, SchemaItemKey, SchemaItemType } from \"@itwin/ecschema-metadata\";\n\ntype ConstraintClassTypes = EntityClass | Mixin | RelationshipClass;\n\n/**\n * Merges a new RelationshipClass into the target schema.\n * @internal\n */\nexport async function addRelationshipClass(context: SchemaMergeContext, change: RelationshipClassDifference) {\n if (change.difference.strength === undefined) {\n throw new Error(\"RelationshipClass must define strength\");\n }\n if (change.difference.strengthDirection === undefined) {\n throw new Error(\"RelationshipClass must define strengthDirection\");\n }\n if (change.difference.source === undefined) {\n throw new Error(\"RelationshipClass must define a source constraint\");\n }\n if (change.difference.target === undefined) {\n throw new Error(\"RelationshipClass must define a target constraint\");\n }\n\n await context.editor.relationships.createFromProps(context.targetSchemaKey, {\n ...change.difference,\n name: change.itemName,\n schemaItemType: change.schemaType,\n strength: change.difference.strength,\n strengthDirection: change.difference.strengthDirection,\n source: await updateRelationshipConstraintKey(context, change.difference.source),\n target: await updateRelationshipConstraintKey(context, change.difference.target),\n });\n}\n\n/**\n * Merges differences to an existing RelationshipClass in the target schema.\n * @internal\n */\nexport async function modifyRelationshipClass(context: SchemaMergeContext, change: RelationshipClassDifference, itemKey: SchemaItemKey) {\n const item = await context.targetSchema.lookupItem(itemKey) as MutableRelationshipClass;\n if(change.changeType === \"modify\") {\n if(change.difference.strength !== undefined) {\n if (item.strength === undefined) {\n const strength = parseStrength(change.difference.strength);\n if (strength === undefined) {\n throw new Error(`An invalid relationship class strength value '${change.difference.strength}' has been provided.`);\n }\n item.setStrength(strength);\n }\n throw new Error(`Changing the relationship '${itemKey.name}' strength is not supported.`);\n }\n if(change.difference.strengthDirection !== undefined) {\n if (item.strengthDirection === undefined) {\n const strengthDirection = parseStrengthDirection(change.difference.strengthDirection);\n if (strengthDirection === undefined) {\n throw new Error(`An invalid relationship class strengthDirection value '${change.difference.strengthDirection}' has been provided.`);\n }\n item.setStrengthDirection(strengthDirection);\n }\n throw new Error(`Changing the relationship '${itemKey.name}' strengthDirection is not supported.`);\n }\n }\n await modifyClass(context, change, itemKey, item);\n}\n\n/**\n * Merges differences of a Relationship constraint.\n * This only supports modify as the RelationshipConstraints are always set on the Relationship classes.\n * @internal\n */\nexport async function mergeRelationshipConstraint(context: SchemaMergeContext, change: RelationshipConstraintDifference) {\n if(change.changeType !== \"modify\") {\n throw new Error(\"RelationshipConstraints can only be modified.\");\n }\n\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\n const constraint = item[parseConstraint(change.path)];\n if(change.difference.roleLabel !== undefined) {\n constraint.roleLabel = change.difference.roleLabel;\n }\n if(change.difference.polymorphic !== undefined) {\n await context.editor.relationships.setConstraintPolymorphic(constraint, change.difference.polymorphic);\n }\n if(change.difference.multiplicity !== undefined) {\n if (constraint.multiplicity === undefined) {\n const multiplicity = RelationshipMultiplicity.fromString(change.difference.multiplicity);\n if (multiplicity === undefined) {\n throw new Error(`An invalid relationship constraint multiplicity value '${change.difference.multiplicity}' has been provided.`);\n }\n await context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);\n }\n throw new Error(`Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.`);\n }\n if(change.difference.abstractConstraint !== undefined) {\n const itemKey = await updateSchemaItemKey(context, change.difference.abstractConstraint);\n const abstractConstraint = await context.editor.schemaContext.getSchemaItem<ConstraintClassTypes>(itemKey);\n if (abstractConstraint === undefined) {\n throw new Error(`Unable to locate the abstract constraint class ${change.difference.abstractConstraint} in the context schema.`);\n }\n return context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);\n }\n return { itemKey: constraint.relationshipClass.key };\n}\n\n/**\n * Merges differences of a Relationship constraint classes.\n * @internal\n */\nexport async function mergeRelationshipClassConstraint(context: SchemaMergeContext, change: RelationshipConstraintClassDifference): Promise<void> {\n if(change.changeType !== \"add\") {\n throw new Error(`Change type ${change.changeType} is not supported for Relationship constraint classes.`);\n }\n\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\n const constraint = item[parseConstraint(change.path)];\n for(const constraintName of change.difference) {\n const constraintClassKey = await updateSchemaItemKey(context, constraintName);\n const constraintClass = await context.editor.schemaContext.getSchemaItem<ConstraintClassTypes>(constraintClassKey);\n if(constraintClass === undefined) {\n throw new Error(`Could not locate relationship constraint class ${constraintClassKey.name}`);\n }\n\n await context.editor.relationships.addConstraintClass(constraint, constraintClass);\n }\n}\n\nfunction parseConstraint(path: string): \"source\" | \"target\" {\n return path.startsWith(\"$source\")\n ? \"source\"\n : \"target\";\n}\n\nasync function updateRelationshipConstraintKey(context: SchemaMergeContext, props: RelationshipConstraintProps): Promise<RelationshipConstraintProps> {\n let abstractConstraint = props.abstractConstraint;\n if (abstractConstraint !== undefined)\n abstractConstraint = await updateSchemaItemFullName(context, abstractConstraint);\n\n const constraintClasses: string[] = [];\n for (const ecClass of props.constraintClasses) {\n constraintClasses.push(await updateSchemaItemFullName(context, ecClass));\n }\n\n return {\n ...props,\n abstractConstraint,\n constraintClasses,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RelationshipClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":";;AAeA,oDAuBC;AAMD,0DAyBC;AAOD,kEAgCC;AAMD,4EAgBC;AA5HD,mCAA0F;AAC1F,+CAA4C;AAE5C,gEAAuN;AAEvN;;;GAGG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAAmC;IACzG,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,eAAe,EAAE;QAC1E,GAAG,MAAM,CAAC,UAAU;QACpB,IAAI,EAAE,MAAM,CAAC,QAAQ;QACrB,c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C,SAAS,CAAC;QAC/B,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,QAAQ,CAAC;AACf,CAAC;AAED,KAAK,UAAU,+BAA+B,CAAC,OAA2B,EAAE,KAAkC;IAC5G,IAAI,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAAC;IAClD,IAAI,kBAAkB,KAAK,SAAS;QAClC,kBAAkB,GAAG,MAAM,IAAA,gCAAwB,EAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAEnF,MAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC9C,iBAAiB,CAAC,IAAI,CAAC,MAAM,IAAA,gCAAwB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO;QACL,GAAG,KAAK;QACR,kBAAkB;QAClB,iBAAiB;KAClB,CAAC;AACJ,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*--------------------------------------------------------------------------------------------*/\nimport type { RelationshipClassDifference, RelationshipConstraintClassDifference, RelationshipConstraintDifference } from \"../Differencing/SchemaDifference\";\nimport type { MutableRelationshipClass } from \"../Editing/Mutable/MutableRelationshipClass\";\nimport { locateSchemaItem, updateSchemaItemFullName, updateSchemaItemKey } from \"./Utils\";\nimport { modifyClass } from \"./ClassMerger\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { ECClass, EntityClass, Mixin, parseStrength, parseStrengthDirection, RelationshipClass, RelationshipConstraintProps, RelationshipMultiplicity, SchemaItemKey, SchemaItemType } from \"@itwin/ecschema-metadata\";\n\n/**\n * Merges a new RelationshipClass into the target schema.\n * @internal\n */\nexport async function addRelationshipClass(context: SchemaMergeContext, change: RelationshipClassDifference) {\n if (change.difference.strength === undefined) {\n throw new Error(\"RelationshipClass must define strength\");\n }\n if (change.difference.strengthDirection === undefined) {\n throw new Error(\"RelationshipClass must define strengthDirection\");\n }\n if (change.difference.source === undefined) {\n throw new Error(\"RelationshipClass must define a source constraint\");\n }\n if (change.difference.target === undefined) {\n throw new Error(\"RelationshipClass must define a target constraint\");\n }\n\n await context.editor.relationships.createFromProps(context.targetSchemaKey, {\n ...change.difference,\n name: change.itemName,\n schemaItemType: change.schemaType,\n strength: change.difference.strength,\n strengthDirection: change.difference.strengthDirection,\n source: await updateRelationshipConstraintKey(context, change.difference.source),\n target: await updateRelationshipConstraintKey(context, change.difference.target),\n });\n}\n\n/**\n * Merges differences to an existing RelationshipClass in the target schema.\n * @internal\n */\nexport async function modifyRelationshipClass(context: SchemaMergeContext, change: RelationshipClassDifference, itemKey: SchemaItemKey) {\n const item = await context.targetSchema.lookupItem(itemKey) as MutableRelationshipClass;\n if(change.changeType === \"modify\") {\n if(change.difference.strength !== undefined) {\n if (item.strength === undefined) {\n const strength = parseStrength(change.difference.strength);\n if (strength === undefined) {\n throw new Error(`An invalid relationship class strength value '${change.difference.strength}' has been provided.`);\n }\n item.setStrength(strength);\n }\n throw new Error(`Changing the relationship '${itemKey.name}' strength is not supported.`);\n }\n if(change.difference.strengthDirection !== undefined) {\n if (item.strengthDirection === undefined) {\n const strengthDirection = parseStrengthDirection(change.difference.strengthDirection);\n if (strengthDirection === undefined) {\n throw new Error(`An invalid relationship class strengthDirection value '${change.difference.strengthDirection}' has been provided.`);\n }\n item.setStrengthDirection(strengthDirection);\n }\n throw new Error(`Changing the relationship '${itemKey.name}' strengthDirection is not supported.`);\n }\n }\n await modifyClass(context, change, itemKey, item);\n}\n\n/**\n * Merges differences of a Relationship constraint.\n * This only supports modify as the RelationshipConstraints are always set on the Relationship classes.\n * @internal\n */\nexport async function mergeRelationshipConstraint(context: SchemaMergeContext, change: RelationshipConstraintDifference) {\n if(change.changeType !== \"modify\") {\n throw new Error(\"RelationshipConstraints can only be modified.\");\n }\n\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\n const constraint = item[parseConstraint(change.path)];\n if(change.difference.roleLabel !== undefined) {\n constraint.roleLabel = change.difference.roleLabel;\n }\n if(change.difference.polymorphic !== undefined) {\n await context.editor.relationships.setConstraintPolymorphic(constraint, change.difference.polymorphic);\n }\n if(change.difference.multiplicity !== undefined) {\n if (constraint.multiplicity === undefined) {\n const multiplicity = RelationshipMultiplicity.fromString(change.difference.multiplicity);\n if (multiplicity === undefined) {\n throw new Error(`An invalid relationship constraint multiplicity value '${change.difference.multiplicity}' has been provided.`);\n }\n await context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);\n }\n throw new Error(`Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.`);\n }\n if(change.difference.abstractConstraint !== undefined) {\n const itemKey = await updateSchemaItemKey(context, change.difference.abstractConstraint);\n const abstractConstraint = await context.editor.schemaContext.getSchemaItem(itemKey, ECClass);\n if (abstractConstraint === undefined || (!EntityClass.isEntityClass(abstractConstraint) && !Mixin.isMixin(abstractConstraint) && !RelationshipClass.isRelationshipClass(abstractConstraint))) {\n throw new Error(`Unable to locate the abstract constraint class ${change.difference.abstractConstraint} in the context schema.`);\n }\n return context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);\n }\n return { itemKey: constraint.relationshipClass.key };\n}\n\n/**\n * Merges differences of a Relationship constraint classes.\n * @internal\n */\nexport async function mergeRelationshipClassConstraint(context: SchemaMergeContext, change: RelationshipConstraintClassDifference): Promise<void> {\n if(change.changeType !== \"add\") {\n throw new Error(`Change type ${change.changeType} is not supported for Relationship constraint classes.`);\n }\n\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\n const constraint = item[parseConstraint(change.path)];\n for(const constraintName of change.difference) {\n const constraintClassKey = await updateSchemaItemKey(context, constraintName);\n const constraintClass = await context.editor.schemaContext.getSchemaItem(constraintClassKey, ECClass);\n if(constraintClass === undefined || (!EntityClass.isEntityClass(constraintClass) && !Mixin.isMixin(constraintClass) && !RelationshipClass.isRelationshipClass(constraintClass))) {\n throw new Error(`Could not locate relationship constraint class ${constraintClassKey.name}`);\n }\n\n await context.editor.relationships.addConstraintClass(constraint, constraintClass);\n }\n}\n\nfunction parseConstraint(path: string): \"source\" | \"target\" {\n return path.startsWith(\"$source\")\n ? \"source\"\n : \"target\";\n}\n\nasync function updateRelationshipConstraintKey(context: SchemaMergeContext, props: RelationshipConstraintProps): Promise<RelationshipConstraintProps> {\n let abstractConstraint = props.abstractConstraint;\n if (abstractConstraint !== undefined)\n abstractConstraint = await updateSchemaItemFullName(context, abstractConstraint);\n\n const constraintClasses: string[] = [];\n for (const ecClass of props.constraintClasses) {\n constraintClasses.push(await updateSchemaItemFullName(context, ecClass));\n }\n\n return {\n ...props,\n abstractConstraint,\n constraintClasses,\n };\n}\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Merging
|
|
3
3
|
*/
|
|
4
|
-
import { Schema,
|
|
4
|
+
import { Schema, SchemaContext, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { SchemaContextEditor } from "../Editing/Editor";
|
|
6
6
|
import { type SchemaDifferenceResult } from "../Differencing/SchemaDifference";
|
|
7
|
-
import
|
|
7
|
+
import { SchemaEdits } from "./Edits/SchemaEdits";
|
|
8
|
+
import { NameMapping } from "./Edits/NameMapping";
|
|
8
9
|
/**
|
|
9
10
|
* Defines the context of a Schema merging run.
|
|
10
11
|
* @internal
|
|
@@ -14,6 +15,7 @@ export interface SchemaMergeContext {
|
|
|
14
15
|
readonly targetSchemaKey: SchemaKey;
|
|
15
16
|
readonly sourceSchemaKey: SchemaKey;
|
|
16
17
|
readonly editor: SchemaContextEditor;
|
|
18
|
+
readonly nameMapping: NameMapping;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Class to merge two schemas together.
|
|
@@ -21,7 +23,7 @@ export interface SchemaMergeContext {
|
|
|
21
23
|
* @beta
|
|
22
24
|
*/
|
|
23
25
|
export declare class SchemaMerger {
|
|
24
|
-
private readonly
|
|
26
|
+
private readonly _editingContext;
|
|
25
27
|
/**
|
|
26
28
|
* Constructs a new instance of the SchemaMerger object.
|
|
27
29
|
* @param editingContext The schema contexts that holds the schema to be edited.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAA6B,SAAS,EAAmB,MAAM,0BAA0B,CAAC;AACxH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAwB,KAAK,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAGrG,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED;;;;GAIG;AACH,qBAAa,YAAY;IAEvB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgB;IAEhD;;;OAGG;gBACS,cAAc,EAAE,aAAa;IAIzC;;;;;;;OAOG;IACU,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3G;;;;;OAKG;IACU,KAAK,CAAC,gBAAgB,EAAE,sBAAsB,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CA+CnG"}
|
|
@@ -15,18 +15,20 @@ const SchemaDifference_1 = require("../Differencing/SchemaDifference");
|
|
|
15
15
|
const SchemaMergingVisitor_1 = require("./SchemaMergingVisitor");
|
|
16
16
|
const SchemaMergingWalker_1 = require("./SchemaMergingWalker");
|
|
17
17
|
const Exception_1 = require("../Editing/Exception");
|
|
18
|
+
const NameMapping_1 = require("./Edits/NameMapping");
|
|
18
19
|
/**
|
|
19
20
|
* Class to merge two schemas together.
|
|
20
21
|
* @see [[merge]] or [[mergeSchemas]] to merge two schemas together.
|
|
21
22
|
* @beta
|
|
22
23
|
*/
|
|
23
24
|
class SchemaMerger {
|
|
25
|
+
_editingContext;
|
|
24
26
|
/**
|
|
25
27
|
* Constructs a new instance of the SchemaMerger object.
|
|
26
28
|
* @param editingContext The schema contexts that holds the schema to be edited.
|
|
27
29
|
*/
|
|
28
30
|
constructor(editingContext) {
|
|
29
|
-
this.
|
|
31
|
+
this._editingContext = editingContext;
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* Copy the SchemaItems of the source schemas to the target schema.
|
|
@@ -37,7 +39,7 @@ class SchemaMerger {
|
|
|
37
39
|
* @alpha
|
|
38
40
|
*/
|
|
39
41
|
async mergeSchemas(targetSchema, sourceSchema, edits) {
|
|
40
|
-
return this.merge(await (0, SchemaDifference_1.getSchemaDifferences)(targetSchema, sourceSchema), edits);
|
|
42
|
+
return this.merge(await (0, SchemaDifference_1.getSchemaDifferences)(targetSchema, sourceSchema, edits), edits);
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* Merges the schema differences into the target schema context.
|
|
@@ -48,15 +50,17 @@ class SchemaMerger {
|
|
|
48
50
|
async merge(differenceResult, edits) {
|
|
49
51
|
const targetSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.targetSchemaName);
|
|
50
52
|
const sourceSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.sourceSchemaName);
|
|
53
|
+
const nameMapping = new NameMapping_1.NameMapping();
|
|
54
|
+
const editor = new Editor_1.SchemaContextEditor(new MergingSchemaContext(this._editingContext, nameMapping));
|
|
51
55
|
// If schema changes were provided, they'll get applied and a new SchemaDifferenceResult is returned
|
|
52
56
|
// to prevent altering the differenceResult the caller passed in.
|
|
53
57
|
if (edits) {
|
|
54
|
-
await edits.applyTo(differenceResult = { ...differenceResult });
|
|
58
|
+
await edits.applyTo(differenceResult = { ...differenceResult }, nameMapping);
|
|
55
59
|
}
|
|
56
60
|
if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {
|
|
57
61
|
throw new Errors_1.SchemaConflictsError("Schema's can't be merged if there are unresolved conflicts.", differenceResult.conflicts, sourceSchemaKey, targetSchemaKey);
|
|
58
62
|
}
|
|
59
|
-
const schema = await
|
|
63
|
+
const schema = await editor.getSchema(targetSchemaKey).catch((error) => {
|
|
60
64
|
if (error instanceof Exception_1.SchemaEditingError && error.errorNumber === Exception_1.ECEditingStatus.SchemaNotFound) {
|
|
61
65
|
throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);
|
|
62
66
|
}
|
|
@@ -66,10 +70,11 @@ class SchemaMerger {
|
|
|
66
70
|
throw new Error(`The target schema '${targetSchemaKey.name}' is not dynamic. Only dynamic schemas are supported for merging.`);
|
|
67
71
|
}
|
|
68
72
|
const visitor = new SchemaMergingVisitor_1.SchemaMergingVisitor({
|
|
69
|
-
editor
|
|
73
|
+
editor,
|
|
70
74
|
targetSchema: schema,
|
|
71
75
|
targetSchemaKey,
|
|
72
76
|
sourceSchemaKey,
|
|
77
|
+
nameMapping,
|
|
73
78
|
});
|
|
74
79
|
const walker = new SchemaMergingWalker_1.SchemaMergingWalker(visitor);
|
|
75
80
|
await walker.traverse(differenceResult.differences, "add");
|
|
@@ -78,4 +83,34 @@ class SchemaMerger {
|
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
exports.SchemaMerger = SchemaMerger;
|
|
86
|
+
/**
|
|
87
|
+
* SchemaContext implementation that overrides certain methods to allow to apply name mappings
|
|
88
|
+
* for certain schema elements during the schema merging process.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
class MergingSchemaContext extends ecschema_metadata_1.SchemaContext {
|
|
93
|
+
_internalContext;
|
|
94
|
+
_nameMappings;
|
|
95
|
+
constructor(internalContext, nameMapping) {
|
|
96
|
+
super();
|
|
97
|
+
this._internalContext = internalContext;
|
|
98
|
+
this._nameMappings = nameMapping;
|
|
99
|
+
}
|
|
100
|
+
async getCachedSchema(schemaKey, matchType) {
|
|
101
|
+
return this._internalContext.getCachedSchema(schemaKey, matchType);
|
|
102
|
+
}
|
|
103
|
+
async getSchema(schemaKey, matchType) {
|
|
104
|
+
return this._internalContext.getSchema(schemaKey, matchType);
|
|
105
|
+
}
|
|
106
|
+
async getSchemaItem(schemaItemKey, itemConstructor) {
|
|
107
|
+
const mappedKey = this._nameMappings.resolveItemKey(schemaItemKey);
|
|
108
|
+
if (mappedKey !== undefined) {
|
|
109
|
+
schemaItemKey = mappedKey;
|
|
110
|
+
}
|
|
111
|
+
if (itemConstructor === undefined)
|
|
112
|
+
return this._internalContext.getSchemaItem(schemaItemKey);
|
|
113
|
+
return this._internalContext.getSchemaItem(schemaItemKey, itemConstructor);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
81
116
|
//# sourceMappingURL=SchemaMerger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/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Ae,CAAC;QACxC,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC;IACnC,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,SAAoB,EAAE,SAA2B;QACrF,OAAO,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACrE,CAAC;IAEe,KAAK,CAAC,SAAS,CAAC,SAAoB,EAAE,SAA2B;QAC/E,OAAO,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC/D,CAAC;IAEe,KAAK,CAAC,aAAa,CAA8B,aAA4B,EAAE,eAAmB;QAChH,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACnE,IAAG,SAAS,KAAK,SAAS,EAAE,CAAC;YAC3B,aAAa,GAAG,SAA0B,CAAC;QAC7C,CAAC;QAED,IAAG,eAAe,KAAK,SAAS;YAC9B,OAAO,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;QAE5D,OAAO,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;IAC7E,CAAC;CACF","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 Merging\n */\n\nimport { Schema, SchemaContext, SchemaItem, SchemaItemKey, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaConflictsError } from \"../Differencing/Errors\";\nimport { getSchemaDifferences, type SchemaDifferenceResult } from \"../Differencing/SchemaDifference\";\nimport { SchemaMergingVisitor } from \"./SchemaMergingVisitor\";\nimport { SchemaMergingWalker } from \"./SchemaMergingWalker\";\nimport { SchemaEdits } from \"./Edits/SchemaEdits\";\nimport { ECEditingStatus, SchemaEditingError } from \"../Editing/Exception\";\nimport { NameMapping } from \"./Edits/NameMapping\";\n\n/**\n * Defines the context of a Schema merging run.\n * @internal\n */\nexport interface SchemaMergeContext {\n readonly targetSchema: Schema;\n readonly targetSchemaKey: SchemaKey;\n readonly sourceSchemaKey: SchemaKey;\n readonly editor: SchemaContextEditor;\n readonly nameMapping: NameMapping;\n}\n\n/**\n * Class to merge two schemas together.\n * @see [[merge]] or [[mergeSchemas]] to merge two schemas together.\n * @beta\n */\nexport class SchemaMerger {\n\n private readonly _editingContext: SchemaContext;\n\n /**\n * Constructs a new instance of the SchemaMerger object.\n * @param editingContext The schema contexts that holds the schema to be edited.\n */\n constructor(editingContext: SchemaContext) {\n this._editingContext = editingContext;\n }\n\n /**\n * Copy the SchemaItems of the source schemas to the target schema.\n * @param targetSchema The schema the SchemaItems gets merged to.\n * @param sourceSchema The schema the SchemaItems gets copied from.\n * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\n * @returns The merged target schema.\n * @alpha\n */\n public async mergeSchemas(targetSchema: Schema, sourceSchema: Schema, edits?: SchemaEdits): Promise<Schema> {\n return this.merge(await getSchemaDifferences(targetSchema, sourceSchema, edits), edits);\n }\n\n /**\n * Merges the schema differences into the target schema context.\n * @param differenceResult The differences that shall be applied to the target schema.\n * @param edits An optional instance of schema edits that shall be applied before the schemas get merged.\n * @alpha\n */\n public async merge(differenceResult: SchemaDifferenceResult, edits?: SchemaEdits): Promise<Schema> {\n const targetSchemaKey = SchemaKey.parseString(differenceResult.targetSchemaName);\n const sourceSchemaKey = SchemaKey.parseString(differenceResult.sourceSchemaName);\n\n const nameMapping = new NameMapping();\n const editor = new SchemaContextEditor(new MergingSchemaContext(this._editingContext, nameMapping));\n\n // If schema changes were provided, they'll get applied and a new SchemaDifferenceResult is returned\n // to prevent altering the differenceResult the caller passed in.\n if (edits) {\n await edits.applyTo(differenceResult = { ...differenceResult }, nameMapping);\n }\n\n if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {\n throw new SchemaConflictsError(\n \"Schema's can't be merged if there are unresolved conflicts.\",\n differenceResult.conflicts,\n sourceSchemaKey,\n targetSchemaKey,\n );\n }\n\n const schema = await editor.getSchema(targetSchemaKey).catch((error: Error) => {\n if (error instanceof SchemaEditingError && error.errorNumber === ECEditingStatus.SchemaNotFound) {\n throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);\n }\n throw error;\n });\n\n if (!schema.customAttributes || !schema.customAttributes.has(\"CoreCustomAttributes.DynamicSchema\")) {\n throw new Error(`The target schema '${targetSchemaKey.name}' is not dynamic. Only dynamic schemas are supported for merging.`);\n }\n\n const visitor = new SchemaMergingVisitor({\n editor,\n targetSchema: schema,\n targetSchemaKey,\n sourceSchemaKey,\n nameMapping,\n });\n\n const walker = new SchemaMergingWalker(visitor);\n await walker.traverse(differenceResult.differences, \"add\");\n await walker.traverse(differenceResult.differences, \"modify\");\n\n return schema;\n }\n}\n\n/**\n * SchemaContext implementation that overrides certain methods to allow to apply name mappings\n * for certain schema elements during the schema merging process.\n *\n * @internal\n */\nclass MergingSchemaContext extends SchemaContext {\n private _internalContext: SchemaContext;\n private _nameMappings: NameMapping;\n\n public constructor(internalContext: SchemaContext, nameMapping: NameMapping) {\n super();\n this._internalContext = internalContext;\n this._nameMappings = nameMapping;\n }\n\n public override async getCachedSchema(schemaKey: SchemaKey, matchType?: SchemaMatchType): Promise<Schema | undefined> {\n return this._internalContext.getCachedSchema(schemaKey, matchType);\n }\n\n public override async getSchema(schemaKey: SchemaKey, matchType?: SchemaMatchType): Promise<Schema | undefined> {\n return this._internalContext.getSchema(schemaKey, matchType);\n }\n\n public override async getSchemaItem<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor?: T): Promise<SchemaItem | InstanceType<T> | undefined> {\n const mappedKey = this._nameMappings.resolveItemKey(schemaItemKey);\n if(mappedKey !== undefined) {\n schemaItemKey = mappedKey as SchemaItemKey;\n }\n\n if(itemConstructor === undefined)\n return this._internalContext.getSchemaItem(schemaItemKey);\n\n return this._internalContext.getSchemaItem(schemaItemKey, itemConstructor);\n }\n}\n"]}
|