@itwin/ecschema-editing 4.2.0-dev.23 → 4.2.0-dev.25

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 (45) hide show
  1. package/lib/cjs/Merging/CAClassMerger.d.ts +7 -0
  2. package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -0
  3. package/lib/cjs/Merging/CAClassMerger.js +28 -0
  4. package/lib/cjs/Merging/CAClassMerger.js.map +1 -0
  5. package/lib/cjs/Merging/ClassMerger.d.ts +7 -0
  6. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -0
  7. package/lib/cjs/Merging/ClassMerger.js +59 -0
  8. package/lib/cjs/Merging/ClassMerger.js.map +1 -0
  9. package/lib/cjs/Merging/EnumerationMerger.d.ts +7 -0
  10. package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -0
  11. package/lib/cjs/Merging/EnumerationMerger.js +40 -0
  12. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -0
  13. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts +7 -0
  14. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -0
  15. package/lib/cjs/Merging/PropertyCategoryMerger.js +16 -0
  16. package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -0
  17. package/lib/cjs/Merging/SchemaItemFactory.d.ts +8 -0
  18. package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +1 -0
  19. package/lib/cjs/Merging/SchemaItemFactory.js +32 -0
  20. package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -0
  21. package/lib/cjs/Merging/SchemaItemMerger.d.ts +24 -0
  22. package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -0
  23. package/lib/cjs/Merging/SchemaItemMerger.js +77 -0
  24. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -0
  25. package/lib/cjs/Merging/SchemaMerger.d.ts +36 -0
  26. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -0
  27. package/lib/cjs/Merging/SchemaMerger.js +86 -0
  28. package/lib/cjs/Merging/SchemaMerger.js.map +1 -0
  29. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts +10 -0
  30. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts.map +1 -0
  31. package/lib/cjs/Merging/SchemaReferenceMerger.js +55 -0
  32. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -0
  33. package/lib/cjs/Validation/SchemaCompareVisitor.d.ts +4 -2
  34. package/lib/cjs/Validation/SchemaCompareVisitor.d.ts.map +1 -1
  35. package/lib/cjs/Validation/SchemaCompareVisitor.js +23 -19
  36. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  37. package/lib/cjs/Validation/SchemaComparer.d.ts +9 -1
  38. package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
  39. package/lib/cjs/Validation/SchemaComparer.js +4 -3
  40. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  41. package/lib/cjs/ecschema-editing.d.ts +5 -0
  42. package/lib/cjs/ecschema-editing.d.ts.map +1 -1
  43. package/lib/cjs/ecschema-editing.js +7 -1
  44. package/lib/cjs/ecschema-editing.js.map +1 -1
  45. package/package.json +9 -9
@@ -0,0 +1,7 @@
1
+ import { CustomAttributeClass } from "@itwin/ecschema-metadata";
2
+ import { ClassChanges } from "../Validation/SchemaChanges";
3
+ /**
4
+ * @internal
5
+ */
6
+ export default function mergeCAClasses(target: CustomAttributeClass, source: CustomAttributeClass, changes: ClassChanges): Promise<void>;
7
+ //# sourceMappingURL=CAClassMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CAClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/CAClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAqC,MAAM,0BAA0B,CAAC;AAEnG,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAI3D;;GAEG;AACH,wBAA8B,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,YAAY,iBAc7H"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*---------------------------------------------------------------------------------------------
4
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
+ * See LICENSE.md in the project root for license terms and full copyright notice.
6
+ *--------------------------------------------------------------------------------------------*/
7
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
8
+ const SchemaItemMerger_1 = require("./SchemaItemMerger");
9
+ const ClassMerger_1 = require("./ClassMerger");
10
+ /**
11
+ * @internal
12
+ */
13
+ async function mergeCAClasses(target, source, changes) {
14
+ const mutableCAClass = target;
15
+ await (0, SchemaItemMerger_1.mergeSchemaItemProperties)(mutableCAClass, changes.propertyValueChanges, (item, propertyName, propertyValue) => {
16
+ switch (propertyName) {
17
+ case "appliesTo": {
18
+ const containerType = (0, ecschema_metadata_1.parseCustomAttributeContainerType)(propertyValue);
19
+ if (containerType !== undefined) {
20
+ return item.setContainerType(containerType);
21
+ }
22
+ }
23
+ }
24
+ });
25
+ return (0, ClassMerger_1.default)(target, source, changes);
26
+ }
27
+ exports.default = mergeCAClasses;
28
+ //# sourceMappingURL=CAClassMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CAClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/CAClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAmG;AAGnG,yDAA+D;AAC/D,+CAAyC;AAEzC;;GAEG;AACY,KAAK,UAAU,cAAc,CAAC,MAA4B,EAAE,MAA4B,EAAE,OAAqB;IAC5H,MAAM,cAAc,GAAG,MAAwB,CAAC;IAChD,MAAM,IAAA,4CAAyB,EAAC,cAAc,EAAE,OAAO,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE;QAClH,QAAO,YAAY,EAAE;YACnB,KAAK,WAAW,CAAC,CAAC;gBAChB,MAAM,aAAa,GAAG,IAAA,qDAAiC,EAAC,aAAa,CAAC,CAAC;gBACvE,IAAI,aAAa,KAAK,SAAS,EAAE;oBAC/B,OAAO,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;iBAC7C;aACF;SACF;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAA,qBAAY,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AAdD,iCAcC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { CustomAttributeClass, parseCustomAttributeContainerType } from \"@itwin/ecschema-metadata\";\r\nimport { MutableCAClass } from \"../Editing/Mutable/MutableCAClass\";\r\nimport { ClassChanges } from \"../Validation/SchemaChanges\";\r\nimport { mergeSchemaItemProperties } from \"./SchemaItemMerger\";\r\nimport mergeClasses from \"./ClassMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default async function mergeCAClasses(target: CustomAttributeClass, source: CustomAttributeClass, changes: ClassChanges) {\r\n const mutableCAClass = target as MutableCAClass;\r\n await mergeSchemaItemProperties(mutableCAClass, changes.propertyValueChanges, (item, propertyName, propertyValue) => {\r\n switch(propertyName) {\r\n case \"appliesTo\": {\r\n const containerType = parseCustomAttributeContainerType(propertyValue);\r\n if (containerType !== undefined) {\r\n return item.setContainerType(containerType);\r\n }\r\n }\r\n }\r\n });\r\n\r\n return mergeClasses(target, source, changes);\r\n}\r\n"]}
@@ -0,0 +1,7 @@
1
+ import { ECClass } from "@itwin/ecschema-metadata";
2
+ import { ClassChanges } from "../Validation/SchemaChanges";
3
+ /**
4
+ * @internal
5
+ */
6
+ export default function mergeClasses(target: ECClass, source: ECClass, change: ClassChanges): Promise<void>;
7
+ //# sourceMappingURL=ClassMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2B,OAAO,EAAoC,MAAM,0BAA0B,CAAC;AAE9G,OAAO,EAA8B,YAAY,EAAmB,MAAM,6BAA6B,CAAC;AAExG;;GAEG;AACH,wBAA8B,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,iBAQhG"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*---------------------------------------------------------------------------------------------
4
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
+ * See LICENSE.md in the project root for license terms and full copyright notice.
6
+ *--------------------------------------------------------------------------------------------*/
7
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
8
+ const SchemaChanges_1 = require("../Validation/SchemaChanges");
9
+ /**
10
+ * @internal
11
+ */
12
+ async function mergeClasses(target, source, change) {
13
+ // This applies to all type of classes regardless if they are Entities, Structs, Mixins,...
14
+ // all can have properties that required to get merged.
15
+ await mergeBaseClass(target, source, change.baseClassDelta);
16
+ for (const propertyChange of change.propertyChanges.values()) {
17
+ await mergeClassProperties(target, source, propertyChange);
18
+ }
19
+ }
20
+ exports.default = mergeClasses;
21
+ async function mergeBaseClass(target, source, baseClassChange) {
22
+ if (baseClassChange !== undefined) {
23
+ const sourceBaseClass = baseClassChange.diagnostic.messageArgs[0];
24
+ const targetBaseClass = baseClassChange.diagnostic.messageArgs[1];
25
+ if (targetBaseClass === undefined) {
26
+ const itemKey = sourceBaseClass.schema.schemaKey.matches(source.schema.schemaKey)
27
+ ? new ecschema_metadata_1.SchemaItemKey(sourceBaseClass.name, target.schema.schemaKey)
28
+ : sourceBaseClass.key;
29
+ const baseClassEntity = await target.schema.context.getSchemaItem(itemKey);
30
+ if (baseClassEntity === undefined)
31
+ throw new Error(`Unable to locate base class ${sourceBaseClass.name} in schema ${target.schema.name}`);
32
+ const mutableTargetClass = target;
33
+ mutableTargetClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassEntity.key, async () => baseClassEntity);
34
+ }
35
+ else {
36
+ throw new Error(`Failed to merge base class '${sourceBaseClass.name}': not supported case`);
37
+ }
38
+ }
39
+ }
40
+ async function mergeClassProperties(target, source, propertyChange) {
41
+ const mutableTargetClass = target;
42
+ if (propertyChange.propertyMissing?.changeType === SchemaChanges_1.ChangeType.Missing) {
43
+ const property = await source.getProperty(propertyChange.ecTypeName);
44
+ if (property === undefined) {
45
+ throw Error(`Property '${propertyChange.ecTypeName}' not found in class ${source.name}`);
46
+ }
47
+ if (property.isPrimitive()) {
48
+ const primitiveProps = property.toJSON();
49
+ const result = property.isArray()
50
+ ? await mutableTargetClass.createPrimitiveArrayProperty(propertyChange.ecTypeName, property.primitiveType)
51
+ : await mutableTargetClass.createPrimitiveProperty(propertyChange.ecTypeName, property.primitiveType);
52
+ await result.fromJSON(primitiveProps);
53
+ }
54
+ else {
55
+ throw Error(`Failed to merge '${propertyChange.ecTypeName}' property: not supported type`);
56
+ }
57
+ }
58
+ }
59
+ //# sourceMappingURL=ClassMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAA8G;AAE9G,+DAAwG;AAExG;;GAEG;AACY,KAAK,UAAU,YAAY,CAAC,MAAe,EAAE,MAAe,EAAE,MAAoB;IAC/F,2FAA2F;IAC3F,uDAAuD;IACvD,MAAM,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;IAE5D,KAAI,MAAM,cAAc,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE;QAC3D,MAAM,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;KAC5D;AACH,CAAC;AARD,+BAQC;AAED,KAAK,UAAU,cAAc,CAAC,MAAe,EAAE,MAAe,EAAE,eAAgC;IAC9F,IAAI,eAAe,KAAK,SAAS,EAAE;QACjC,MAAM,eAAe,GAAG,eAAe,CAAC,UAAU,CAAC,WAAY,CAAC,CAAC,CAAY,CAAC;QAC9E,MAAM,eAAe,GAAG,eAAe,CAAC,UAAU,CAAC,WAAY,CAAC,CAAC,CAAY,CAAC;QAE9E,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;gBAC/E,CAAC,CAAC,IAAI,iCAAa,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;gBAClE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC;YAExB,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAU,OAAO,CAAC,CAAC;YACpF,IAAI,eAAe,KAAK,SAAS;gBAC/B,MAAM,IAAI,KAAK,CAAC,+BAA+B,eAAe,CAAC,IAAI,cAAc,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YAEzG,MAAM,kBAAkB,GAAG,MAAsB,CAAC;YAClD,kBAAkB,CAAC,SAAS,GAAG,IAAI,2CAAuB,CAAC,eAAe,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,eAAe,CAAsB,CAAC;SACnI;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,+BAA+B,eAAe,CAAC,IAAI,uBAAuB,CAAC,CAAC;SAC7F;KACF;AACH,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,MAAe,EAAE,MAAe,EAAE,cAA+B;IACnG,MAAM,kBAAkB,GAAG,MAAsB,CAAC;IAClD,IAAI,cAAc,CAAC,eAAe,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;QAErE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACrE,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,MAAM,KAAK,CAAC,aAAa,cAAc,CAAC,UAAU,wBAAwB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;SAC1F;QAED,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE;YAC1B,MAAM,cAAc,GAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE;gBAC/B,CAAC,CAAC,MAAM,kBAAkB,CAAC,4BAA4B,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC;gBAC1G,CAAC,CAAC,MAAM,kBAAkB,CAAC,uBAAuB,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;YAExG,MAAM,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;SAEvC;aAAM;YACL,MAAM,KAAK,CAAC,oBAAoB,cAAc,CAAC,UAAU,gCAAgC,CAAC,CAAC;SAC5F;KACF;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { DelayedPromiseWithProps, ECClass, LazyLoadedECClass, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { MutableClass } from \"../Editing/Mutable/MutableClass\";\r\nimport { BaseClassDelta, ChangeType, ClassChanges, PropertyChanges } from \"../Validation/SchemaChanges\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default async function mergeClasses(target: ECClass, source: ECClass, change: ClassChanges) {\r\n // This applies to all type of classes regardless if they are Entities, Structs, Mixins,...\r\n // all can have properties that required to get merged.\r\n await mergeBaseClass(target, source, change.baseClassDelta);\r\n\r\n for(const propertyChange of change.propertyChanges.values()) {\r\n await mergeClassProperties(target, source, propertyChange);\r\n }\r\n}\r\n\r\nasync function mergeBaseClass(target: ECClass, source: ECClass, baseClassChange?: BaseClassDelta) {\r\n if (baseClassChange !== undefined) {\r\n const sourceBaseClass = baseClassChange.diagnostic.messageArgs![0] as ECClass;\r\n const targetBaseClass = baseClassChange.diagnostic.messageArgs![1] as ECClass;\r\n\r\n if (targetBaseClass === undefined) {\r\n const itemKey = sourceBaseClass.schema.schemaKey.matches(source.schema.schemaKey)\r\n ? new SchemaItemKey(sourceBaseClass.name, target.schema.schemaKey)\r\n : sourceBaseClass.key;\r\n\r\n const baseClassEntity = await target.schema.context.getSchemaItem<ECClass>(itemKey);\r\n if (baseClassEntity === undefined)\r\n throw new Error(`Unable to locate base class ${sourceBaseClass.name} in schema ${target.schema.name}`);\r\n\r\n const mutableTargetClass = target as MutableClass;\r\n mutableTargetClass.baseClass = new DelayedPromiseWithProps(baseClassEntity.key, async () => baseClassEntity) as LazyLoadedECClass;\r\n } else {\r\n throw new Error(`Failed to merge base class '${sourceBaseClass.name}': not supported case`);\r\n }\r\n }\r\n}\r\n\r\nasync function mergeClassProperties(target: ECClass, source: ECClass, propertyChange: PropertyChanges) {\r\n const mutableTargetClass = target as MutableClass;\r\n if (propertyChange.propertyMissing?.changeType === ChangeType.Missing) {\r\n\r\n const property = await source.getProperty(propertyChange.ecTypeName);\r\n if (property === undefined) {\r\n throw Error(`Property '${propertyChange.ecTypeName}' not found in class ${source.name}`);\r\n }\r\n\r\n if (property.isPrimitive()) {\r\n const primitiveProps = property.toJSON();\r\n const result = property.isArray()\r\n ? await mutableTargetClass.createPrimitiveArrayProperty(propertyChange.ecTypeName, property.primitiveType)\r\n : await mutableTargetClass.createPrimitiveProperty(propertyChange.ecTypeName, property.primitiveType);\r\n\r\n await result.fromJSON(primitiveProps);\r\n\r\n } else {\r\n throw Error(`Failed to merge '${propertyChange.ecTypeName}' property: not supported type`);\r\n }\r\n }\r\n}\r\n"]}
@@ -0,0 +1,7 @@
1
+ import { Enumeration } from "@itwin/ecschema-metadata";
2
+ import { EnumerationChanges } from "../Validation/SchemaChanges";
3
+ /**
4
+ * @internal
5
+ */
6
+ export default function mergeEnumeration(target: Enumeration, source: Enumeration, changes: EnumerationChanges): Promise<void>;
7
+ //# sourceMappingURL=EnumerationMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumerationMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAA6C,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAc,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAI7E;;GAEG;AACH,wBAA8B,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,iBA4BnH"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*---------------------------------------------------------------------------------------------
4
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
+ * See LICENSE.md in the project root for license terms and full copyright notice.
6
+ *--------------------------------------------------------------------------------------------*/
7
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
8
+ const SchemaChanges_1 = require("../Validation/SchemaChanges");
9
+ const SchemaItemMerger_1 = require("./SchemaItemMerger");
10
+ /**
11
+ * @internal
12
+ */
13
+ async function mergeEnumeration(target, source, changes) {
14
+ const mutableEnumeration = target;
15
+ await (0, SchemaItemMerger_1.mergeSchemaItemProperties)(mutableEnumeration, changes.propertyValueChanges, (item, propertyName, propertyValue) => {
16
+ switch (propertyName) {
17
+ case "isStrict": return item.setIsStrict(propertyValue);
18
+ case "type": {
19
+ const primitiveType = (0, ecschema_metadata_1.parsePrimitiveType)(propertyValue);
20
+ if (primitiveType && item.type !== primitiveType) {
21
+ throw Error(`Merged enumeration ${item.name} types not equal: ${(0, ecschema_metadata_1.primitiveTypeToString)(item.type)} -> ${propertyValue}`);
22
+ }
23
+ }
24
+ }
25
+ });
26
+ for (const enumeratorChange of changes.enumeratorChanges.values()) {
27
+ // Handle each case:
28
+ // If missing, add source enumerator to target
29
+ if (enumeratorChange.enumeratorMissing?.changeType === SchemaChanges_1.ChangeType.Missing) {
30
+ const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);
31
+ if (enumerator === undefined) {
32
+ throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in class ${source.fullName}`);
33
+ }
34
+ const result = mutableEnumeration.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description);
35
+ mutableEnumeration.addEnumerator(result);
36
+ }
37
+ }
38
+ }
39
+ exports.default = mergeEnumeration;
40
+ //# sourceMappingURL=EnumerationMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAkG;AAClG,+DAA6E;AAC7E,yDAA+D;AAG/D;;GAEG;AACY,KAAK,UAAU,gBAAgB,CAAC,MAAmB,EAAE,MAAmB,EAAE,OAA2B;IAClH,MAAM,kBAAkB,GAAG,MAA4B,CAAC;IACxD,MAAM,IAAA,4CAAyB,EAAC,kBAAkB,EAAE,OAAO,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE;QACtH,QAAQ,YAAY,EAAE;YACpB,KAAK,UAAU,CAAC,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;YACxD,KAAK,MAAM,CAAC,CAAC;gBACX,MAAM,aAAa,GAAG,IAAA,sCAAkB,EAAC,aAAa,CAAC,CAAC;gBACxD,IAAI,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE;oBAChD,MAAM,KAAK,CAAC,sBAAsB,IAAI,CAAC,IAAI,qBAAqB,IAAA,yCAAqB,EAAC,IAAI,CAAC,IAAK,CAAC,OAAO,aAAa,EAAE,CAAC,CAAC;iBAC1H;aACF;SACF;IACH,CAAC,CAAC,CAAC;IAEH,KAAK,MAAM,gBAAgB,IAAI,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,EAAE;QACjE,oBAAoB;QACpB,8CAA8C;QAC9C,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;YAEzE,MAAM,UAAU,GAAG,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;YAC3E,IAAI,UAAU,KAAK,SAAS,EAAE;gBAC5B,MAAM,KAAK,CAAC,eAAe,gBAAgB,CAAC,UAAU,wBAAwB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;aAClG;YAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YAChI,kBAAkB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;SAC1C;KACF;AACH,CAAC;AA5BD,mCA4BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { Enumeration, parsePrimitiveType, primitiveTypeToString } from \"@itwin/ecschema-metadata\";\r\nimport { ChangeType, EnumerationChanges } from \"../Validation/SchemaChanges\";\r\nimport { mergeSchemaItemProperties } from \"./SchemaItemMerger\";\r\nimport { MutableEnumeration } from \"../Editing/Mutable/MutableEnumeration\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default async function mergeEnumeration(target: Enumeration, source: Enumeration, changes: EnumerationChanges) {\r\n const mutableEnumeration = target as MutableEnumeration;\r\n await mergeSchemaItemProperties(mutableEnumeration, changes.propertyValueChanges, (item, propertyName, propertyValue) => {\r\n switch (propertyName) {\r\n case \"isStrict\": return item.setIsStrict(propertyValue);\r\n case \"type\": {\r\n const primitiveType = parsePrimitiveType(propertyValue);\r\n if (primitiveType && item.type !== primitiveType) {\r\n throw Error(`Merged enumeration ${item.name} types not equal: ${primitiveTypeToString(item.type!)} -> ${propertyValue}`);\r\n }\r\n }\r\n }\r\n });\r\n\r\n for (const enumeratorChange of changes.enumeratorChanges.values()) {\r\n // Handle each case:\r\n // If missing, add source enumerator to target\r\n if (enumeratorChange.enumeratorMissing?.changeType === ChangeType.Missing) {\r\n\r\n const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);\r\n if (enumerator === undefined) {\r\n throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in class ${source.fullName}`);\r\n }\r\n\r\n const result = mutableEnumeration.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description);\r\n mutableEnumeration.addEnumerator(result);\r\n }\r\n }\r\n}\r\n"]}
@@ -0,0 +1,7 @@
1
+ import { PropertyCategory } from "@itwin/ecschema-metadata";
2
+ import { SchemaItemChanges } from "../Validation/SchemaChanges";
3
+ /**
4
+ * @internal
5
+ */
6
+ export default function mergePropertyCategory(target: PropertyCategory, _source: PropertyCategory, changes: SchemaItemChanges): Promise<void>;
7
+ //# sourceMappingURL=PropertyCategoryMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyCategoryMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/PropertyCategoryMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE;;GAEG;AACH,wBAA8B,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,iBAAiB,iBAOlI"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const SchemaItemMerger_1 = require("./SchemaItemMerger");
4
+ /**
5
+ * @internal
6
+ */
7
+ async function mergePropertyCategory(target, _source, changes) {
8
+ const mutablePropertyCategory = target;
9
+ await (0, SchemaItemMerger_1.mergeSchemaItemProperties)(mutablePropertyCategory, changes.propertyValueChanges, (item, propertyName, propertyValue) => {
10
+ switch (propertyName) {
11
+ case "priority": return item.setPriority(propertyValue);
12
+ }
13
+ });
14
+ }
15
+ exports.default = mergePropertyCategory;
16
+ //# sourceMappingURL=PropertyCategoryMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyCategoryMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyCategoryMerger.ts"],"names":[],"mappings":";;AAOA,yDAA+D;AAE/D;;GAEG;AACY,KAAK,UAAU,qBAAqB,CAAC,MAAwB,EAAE,OAAyB,EAAE,OAA0B;IACjI,MAAM,uBAAuB,GAAG,MAAiC,CAAC;IAClE,MAAM,IAAA,4CAAyB,EAAC,uBAAuB,EAAE,OAAO,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE;QAC3H,QAAO,YAAY,EAAE;YACnB,KAAK,UAAU,CAAC,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;SACzD;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,wCAOC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { PropertyCategory } from \"@itwin/ecschema-metadata\";\r\nimport { MutablePropertyCategory } from \"../Editing/Mutable/MutablePropertyCategory\";\r\nimport { SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { mergeSchemaItemProperties } from \"./SchemaItemMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default async function mergePropertyCategory(target: PropertyCategory, _source: PropertyCategory, changes: SchemaItemChanges) {\r\n const mutablePropertyCategory = target as MutablePropertyCategory;\r\n await mergeSchemaItemProperties(mutablePropertyCategory, changes.propertyValueChanges, (item, propertyName, propertyValue) => {\r\n switch(propertyName) {\r\n case \"priority\": return item.setPriority(propertyValue);\r\n }\r\n });\r\n}\r\n"]}
@@ -0,0 +1,8 @@
1
+ import { Schema, SchemaItem } from "@itwin/ecschema-metadata";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare namespace SchemaItemFactory {
6
+ function create(targetSchema: Schema, template: SchemaItem): Promise<SchemaItem>;
7
+ }
8
+ //# sourceMappingURL=SchemaItemFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaItemFactory.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoE,MAAM,EAAE,UAAU,EAAe,MAAM,0BAA0B,CAAC;AAE7I;;GAEG;AACH,yBAAiB,iBAAiB,CAAC;IAEjC,SAAsB,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAc5F;CAKF"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaItemFactory = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ /**
10
+ * @internal
11
+ */
12
+ var SchemaItemFactory;
13
+ (function (SchemaItemFactory) {
14
+ async function create(targetSchema, template) {
15
+ if (is(template, ecschema_metadata_1.Enumeration))
16
+ return new ecschema_metadata_1.Enumeration(targetSchema, template.name, template.type);
17
+ if (is(template, ecschema_metadata_1.EntityClass))
18
+ return new ecschema_metadata_1.EntityClass(targetSchema, template.name, template.modifier);
19
+ if (is(template, ecschema_metadata_1.StructClass))
20
+ return new ecschema_metadata_1.StructClass(targetSchema, template.name, template.modifier);
21
+ if (is(template, ecschema_metadata_1.CustomAttributeClass))
22
+ return new ecschema_metadata_1.CustomAttributeClass(targetSchema, template.name, template.modifier);
23
+ if (is(template, ecschema_metadata_1.PropertyCategory))
24
+ return new ecschema_metadata_1.PropertyCategory(targetSchema, template.name);
25
+ throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);
26
+ }
27
+ SchemaItemFactory.create = create;
28
+ function is(item, type) {
29
+ return item instanceof type;
30
+ }
31
+ })(SchemaItemFactory = exports.SchemaItemFactory || (exports.SchemaItemFactory = {}));
32
+ //# sourceMappingURL=SchemaItemFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA6I;AAE7I;;GAEG;AACH,IAAiB,iBAAiB,CAqBjC;AArBD,WAAiB,iBAAiB;IAEzB,KAAK,UAAU,MAAM,CAAC,YAAoB,EAAE,QAAoB;QACrE,IAAI,EAAE,CAAC,QAAQ,EAAE,+BAAW,CAAC;YAC3B,OAAO,IAAI,+BAAW,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QACrE,IAAI,EAAE,CAAC,QAAQ,EAAE,+BAAW,CAAC;YAC3B,OAAO,IAAI,+BAAW,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACzE,IAAI,EAAE,CAAC,QAAQ,EAAE,+BAAW,CAAC;YAC3B,OAAO,IAAI,+BAAW,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACzE,IAAI,EAAE,CAAC,QAAQ,EAAE,wCAAoB,CAAC;YACpC,OAAO,IAAI,wCAAoB,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClF,IAAG,EAAE,CAAC,QAAQ,EAAE,oCAAgB,CAAC;YAC/B,OAAO,IAAI,oCAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE3D,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAEhF,CAAC;IAdqB,wBAAM,SAc3B,CAAA;IAED,SAAS,EAAE,CAAuB,IAAgB,EAAE,IAA6B;QAC/E,OAAO,IAAI,YAAY,IAAI,CAAC;IAC9B,CAAC;AACH,CAAC,EArBgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAqBjC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { CustomAttributeClass, EntityClass, Enumeration, PropertyCategory, Schema, SchemaItem, StructClass } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport namespace SchemaItemFactory {\r\n\r\n export async function create(targetSchema: Schema, template: SchemaItem): Promise<SchemaItem> {\r\n if (is(template, Enumeration))\r\n return new Enumeration(targetSchema, template.name, template.type);\r\n if (is(template, EntityClass))\r\n return new EntityClass(targetSchema, template.name, template.modifier);\r\n if (is(template, StructClass))\r\n return new StructClass(targetSchema, template.name, template.modifier);\r\n if (is(template, CustomAttributeClass))\r\n return new CustomAttributeClass(targetSchema, template.name, template.modifier);\r\n if(is(template, PropertyCategory))\r\n return new PropertyCategory(targetSchema, template.name);\r\n\r\n throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);\r\n\r\n }\r\n\r\n function is<T extends SchemaItem>(item: SchemaItem, type: new (...args: any) => T ): item is T {\r\n return item instanceof type;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,24 @@
1
+ import { SchemaItem } from "@itwin/ecschema-metadata";
2
+ import { PropertyValueChange, SchemaItemChanges } from "../Validation/SchemaChanges";
3
+ import { SchemaMergeContext } from "./SchemaMerger";
4
+ type SchemaItemMergeFn<TChange extends SchemaItemChanges, TItem extends SchemaItem> = (target: TItem, source: TItem, change: TChange, context: SchemaMergeContext) => Promise<void>;
5
+ type PropertyChangedFn<TItem extends SchemaItem> = (item: TItem, propertyName: string, propertyValue: any) => void | boolean;
6
+ /**
7
+ * Merges schema items from the source in the target schema. This method applies for all schema items
8
+ * and handles the basic processing such as create-if-not-exists or name collisions or base property setting.
9
+ * @param context The current merge context
10
+ * @param schemaItemChanges The schema items to be merged
11
+ * @param mergeFn Merge function for complex merging.
12
+ * @internal
13
+ */
14
+ export default function mergeSchemaItems<TChange extends SchemaItemChanges, TItem extends SchemaItem>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>, mergeFn: SchemaItemMergeFn<TChange, TItem>): Promise<void>;
15
+ /**
16
+ * Performs the specified action for each property in the given PropertyValueChange array.
17
+ * @param targetItem The target item
18
+ * @param changes The array with PropertyValueChanges
19
+ * @param handler The callback that gets invoked vor every change.
20
+ * @internal
21
+ */
22
+ export declare function mergeSchemaItemProperties<T extends SchemaItem>(targetItem: T, changes: PropertyValueChange[], handler: PropertyChangedFn<T>): Promise<void>;
23
+ export {};
24
+ //# sourceMappingURL=SchemaItemMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaItemMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAc,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,KAAK,iBAAiB,CAAC,OAAO,SAAS,iBAAiB,EAAE,KAAK,SAAS,UAAU,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AACpL,KAAK,iBAAiB,CAAC,KAAK,SAAS,UAAU,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC;AAO7H;;;;;;;GAOG;AACH,wBAA8B,gBAAgB,CAAC,OAAO,SAAS,iBAAiB,EAAE,KAAK,SAAS,UAAU,EAAE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,iBA4CxN;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,iBAQjJ"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeSchemaItemProperties = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
+ const SchemaChanges_1 = require("../Validation/SchemaChanges");
10
+ const SchemaItemFactory_1 = require("./SchemaItemFactory");
11
+ class MutableSchemaItem extends ecschema_metadata_1.SchemaItem {
12
+ }
13
+ /**
14
+ * Merges schema items from the source in the target schema. This method applies for all schema items
15
+ * and handles the basic processing such as create-if-not-exists or name collisions or base property setting.
16
+ * @param context The current merge context
17
+ * @param schemaItemChanges The schema items to be merged
18
+ * @param mergeFn Merge function for complex merging.
19
+ * @internal
20
+ */
21
+ async function mergeSchemaItems(context, schemaItemChanges, mergeFn) {
22
+ for (const change of schemaItemChanges) {
23
+ // Gets the source and the target item. The target item could be undefined at that point.
24
+ const sourceItem = (await context.sourceSchema.getItem(change.ecTypeName));
25
+ let targetItem = await context.targetSchema.getItem(change.ecTypeName);
26
+ // In case the schema item does not exists in the target schema, an instance for
27
+ // this schema item is created. It's properties get set by the merger then.
28
+ if (change.schemaItemMissing?.changeType === SchemaChanges_1.ChangeType.Missing) {
29
+ // Check for name to make sure there is no collision for items with the same name
30
+ // but different type.
31
+ if (targetItem !== undefined) {
32
+ throw new Error(`Schema ${context.targetSchema.name} already contains a Schema Item ${change.ecTypeName}.`);
33
+ }
34
+ // TODO: Think about renaming the Schema Item. This could be controlled though a flag.
35
+ const createdItem = await SchemaItemFactory_1.SchemaItemFactory.create(context.targetSchema, sourceItem);
36
+ context.targetSchema.addItem(targetItem = createdItem);
37
+ }
38
+ if (targetItem === undefined) {
39
+ throw new Error("Invalid state, targetItem must not be undefined at that point.");
40
+ }
41
+ // Sets the Schema items base properties...
42
+ await mergeSchemaItemProperties(targetItem, change.propertyValueChanges, (item, propertyName, propertyValue) => {
43
+ const mutableSchemaItem = item;
44
+ switch (propertyName) {
45
+ case "label":
46
+ mutableSchemaItem.setDisplayLabel(propertyValue);
47
+ return true;
48
+ case "description":
49
+ mutableSchemaItem.setDescription(propertyValue);
50
+ return true;
51
+ case "schemaItemType":
52
+ return true;
53
+ }
54
+ return;
55
+ });
56
+ await mergeFn(targetItem, sourceItem, change, context);
57
+ }
58
+ }
59
+ exports.default = mergeSchemaItems;
60
+ /**
61
+ * Performs the specified action for each property in the given PropertyValueChange array.
62
+ * @param targetItem The target item
63
+ * @param changes The array with PropertyValueChanges
64
+ * @param handler The callback that gets invoked vor every change.
65
+ * @internal
66
+ */
67
+ async function mergeSchemaItemProperties(targetItem, changes, handler) {
68
+ for (let index = 0, increment = true; index < changes.length; increment && index++, increment = true) {
69
+ const [propertyName, propertyValue] = changes[index].diagnostic.messageArgs;
70
+ if (handler(targetItem, propertyName, propertyValue) === true) {
71
+ changes.splice(index, 1);
72
+ increment = false;
73
+ }
74
+ }
75
+ }
76
+ exports.mergeSchemaItemProperties = mergeSchemaItemProperties;
77
+ //# sourceMappingURL=SchemaItemMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAsD;AACtD,+DAAiG;AAEjG,2DAAwD;AAMxD,MAAe,iBAAkB,SAAQ,8BAAU;CAGlD;AAED;;;;;;;GAOG;AACY,KAAK,UAAU,gBAAgB,CAA8D,OAA2B,EAAE,iBAAoC,EAAE,OAA0C;IACvN,KAAI,MAAM,MAAM,IAAI,iBAAiB,EAAE;QAErC,yFAAyF;QACzF,MAAM,UAAU,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAQ,MAAM,CAAC,UAAU,CAAC,CAAE,CAAC;QACnF,IAAI,UAAU,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAQ,MAAM,CAAC,UAAU,CAAC,CAAC;QAE9E,gFAAgF;QAChF,2EAA2E;QAC3E,IAAG,MAAM,CAAC,iBAAiB,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;YAC9D,iFAAiF;YACjF,sBAAsB;YACtB,IAAG,UAAU,KAAK,SAAS,EAAE;gBAC3B,MAAM,IAAI,KAAK,CAAC,UAAU,OAAO,CAAC,YAAY,CAAC,IAAI,mCAAmC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC;aAC7G;YAED,sFAAsF;YAEtF,MAAM,WAAW,GAAG,MAAM,qCAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAU,CAAC;YAC7F,OAAO,CAAC,YAA8B,CAAC,OAAO,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC;SAC3E;QAED,IAAG,UAAU,KAAK,SAAS,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;QAED,2CAA2C;QAC3C,MAAM,yBAAyB,CAAC,UAAU,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE;YAC7G,MAAM,iBAAiB,GAAG,IAAoC,CAAC;YAC/D,QAAO,YAAY,EAAE;gBACnB,KAAK,OAAO;oBACV,iBAAiB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;oBACjD,OAAO,IAAI,CAAC;gBACd,KAAK,aAAa;oBAChB,iBAAiB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;oBAChD,OAAO,IAAI,CAAC;gBACd,KAAK,gBAAgB;oBACnB,OAAO,IAAI,CAAC;aACf;YACD,OAAO;QACT,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KACxD;AACH,CAAC;AA5CD,mCA4CC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,yBAAyB,CAAuB,UAAa,EAAE,OAA8B,EAAE,OAA6B;IAChJ,KAAI,IAAI,KAAK,GAAG,CAAC,EAAE,SAAS,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,SAAS,IAAI,KAAK,EAAE,EAAE,SAAS,GAAG,IAAI,EAAE;QACnG,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,WAAY,CAAC;QAC7E,IAAG,OAAO,CAAC,UAAU,EAAE,YAAY,EAAE,aAAa,CAAC,KAAK,IAAI,EAAE;YAC5D,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACzB,SAAS,GAAG,KAAK,CAAC;SACnB;KACF;AACH,CAAC;AARD,8DAQC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { SchemaItem } from \"@itwin/ecschema-metadata\";\r\nimport { ChangeType, PropertyValueChange, SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { MutableSchema } from \"../Editing/Mutable/MutableSchema\";\r\nimport { SchemaItemFactory } from \"./SchemaItemFactory\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\n\r\ntype SchemaItemMergeFn<TChange extends SchemaItemChanges, TItem extends SchemaItem> = (target: TItem, source: TItem, change: TChange, context: SchemaMergeContext) => Promise<void>;\r\ntype PropertyChangedFn<TItem extends SchemaItem> = (item: TItem, propertyName: string, propertyValue: any) => void | boolean;\r\n\r\nabstract class MutableSchemaItem extends SchemaItem{\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n public abstract override setDescription(description: string): void;\r\n}\r\n\r\n/**\r\n * Merges schema items from the source in the target schema. This method applies for all schema items\r\n * and handles the basic processing such as create-if-not-exists or name collisions or base property setting.\r\n * @param context The current merge context\r\n * @param schemaItemChanges The schema items to be merged\r\n * @param mergeFn Merge function for complex merging.\r\n * @internal\r\n */\r\nexport default async function mergeSchemaItems<TChange extends SchemaItemChanges, TItem extends SchemaItem>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>, mergeFn: SchemaItemMergeFn<TChange, TItem>) {\r\n for(const change of schemaItemChanges) {\r\n\r\n // Gets the source and the target item. The target item could be undefined at that point.\r\n const sourceItem = (await context.sourceSchema.getItem<TItem>(change.ecTypeName))!;\r\n let targetItem = await context.targetSchema.getItem<TItem>(change.ecTypeName);\r\n\r\n // In case the schema item does not exists in the target schema, an instance for\r\n // this schema item is created. It's properties get set by the merger then.\r\n if(change.schemaItemMissing?.changeType === ChangeType.Missing) {\r\n // Check for name to make sure there is no collision for items with the same name\r\n // but different type.\r\n if(targetItem !== undefined) {\r\n throw new Error(`Schema ${context.targetSchema.name} already contains a Schema Item ${change.ecTypeName}.`);\r\n }\r\n\r\n // TODO: Think about renaming the Schema Item. This could be controlled though a flag.\r\n\r\n const createdItem = await SchemaItemFactory.create(context.targetSchema, sourceItem) as TItem;\r\n (context.targetSchema as MutableSchema).addItem(targetItem = createdItem);\r\n }\r\n\r\n if(targetItem === undefined) {\r\n throw new Error(\"Invalid state, targetItem must not be undefined at that point.\");\r\n }\r\n\r\n // Sets the Schema items base properties...\r\n await mergeSchemaItemProperties(targetItem, change.propertyValueChanges, (item, propertyName, propertyValue) => {\r\n const mutableSchemaItem = item as unknown as MutableSchemaItem;\r\n switch(propertyName) {\r\n case \"label\":\r\n mutableSchemaItem.setDisplayLabel(propertyValue);\r\n return true;\r\n case \"description\":\r\n mutableSchemaItem.setDescription(propertyValue);\r\n return true;\r\n case \"schemaItemType\":\r\n return true;\r\n }\r\n return;\r\n });\r\n\r\n await mergeFn(targetItem, sourceItem, change, context);\r\n }\r\n}\r\n\r\n/**\r\n * Performs the specified action for each property in the given PropertyValueChange array.\r\n * @param targetItem The target item\r\n * @param changes The array with PropertyValueChanges\r\n * @param handler The callback that gets invoked vor every change.\r\n * @internal\r\n */\r\nexport async function mergeSchemaItemProperties<T extends SchemaItem>(targetItem: T, changes: PropertyValueChange[], handler: PropertyChangedFn<T>) {\r\n for(let index = 0, increment = true; index < changes.length; increment && index++, increment = true) {\r\n const [propertyName, propertyValue] = changes[index].diagnostic.messageArgs!;\r\n if(handler(targetItem, propertyName, propertyValue) === true) {\r\n changes.splice(index, 1);\r\n increment = false;\r\n }\r\n }\r\n}\r\n"]}
@@ -0,0 +1,36 @@
1
+ /** @packageDocumentation
2
+ * @module Merging
3
+ */
4
+ import { Schema } from "@itwin/ecschema-metadata";
5
+ /**
6
+ * Defines the context of a Schema merging run.
7
+ * @beta
8
+ */
9
+ export interface SchemaMergeContext {
10
+ readonly targetSchema: Schema;
11
+ readonly sourceSchema: Schema;
12
+ }
13
+ /**
14
+ * Class to merge two schemas together.
15
+ * @see [[merge]] to merge the schemas.
16
+ * @beta
17
+ */
18
+ export declare class SchemaMerger {
19
+ /**
20
+ * Gets the @see SchemaChanges between the two given Schemas from perspective of the source
21
+ * to the target schema. For example if source contains a class which does not exists in the
22
+ * target one, it would be listed as missing.
23
+ * @param targetSchema The schema the differences gets merged into.
24
+ * @param sourceSchema The schema to compare.
25
+ * @returns An instance of @see SchemaChanges between the two schemas.
26
+ */
27
+ private getSchemaChanges;
28
+ /**
29
+ * Copy the SchemaItems of the source schemas to the target schema.
30
+ * @param targetSchema The schema the SchemaItems gets merged to.
31
+ * @param sourceSchema The schema the SchemaItems gets copied from.
32
+ * @returns The merged target schema.
33
+ */
34
+ merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema>;
35
+ }
36
+ //# sourceMappingURL=SchemaMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAkB,MAAM,0BAA0B,CAAC;AAWlE;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB;;;;;;;OAOG;YACW,gBAAgB;IAa9B;;;;;OAKG;IACU,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA0BhF"}
@@ -0,0 +1,86 @@
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 Merging
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SchemaMerger = void 0;
11
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
+ const SchemaComparer_1 = require("../Validation/SchemaComparer");
13
+ const ClassMerger_1 = require("./ClassMerger");
14
+ const EnumerationMerger_1 = require("./EnumerationMerger");
15
+ const PropertyCategoryMerger_1 = require("./PropertyCategoryMerger");
16
+ const SchemaItemMerger_1 = require("./SchemaItemMerger");
17
+ const SchemaReferenceMerger_1 = require("./SchemaReferenceMerger");
18
+ const CAClassMerger_1 = require("./CAClassMerger");
19
+ /**
20
+ * Class to merge two schemas together.
21
+ * @see [[merge]] to merge the schemas.
22
+ * @beta
23
+ */
24
+ class SchemaMerger {
25
+ /**
26
+ * Gets the @see SchemaChanges between the two given Schemas from perspective of the source
27
+ * to the target schema. For example if source contains a class which does not exists in the
28
+ * target one, it would be listed as missing.
29
+ * @param targetSchema The schema the differences gets merged into.
30
+ * @param sourceSchema The schema to compare.
31
+ * @returns An instance of @see SchemaChanges between the two schemas.
32
+ */
33
+ async getSchemaChanges(targetSchema, sourceSchema) {
34
+ const changesList = [];
35
+ const schemaComparer = new SchemaComparer_1.SchemaComparer({ report: changesList.push.bind(changesList) });
36
+ // It is important to compare the schema items by name, not full name as otherwise
37
+ // we'd often see differences when comparing two different schemas.
38
+ await schemaComparer.compareSchemas(sourceSchema, targetSchema, {
39
+ compareItemFullName: false,
40
+ });
41
+ return changesList[0];
42
+ }
43
+ /**
44
+ * Copy the SchemaItems of the source schemas to the target schema.
45
+ * @param targetSchema The schema the SchemaItems gets merged to.
46
+ * @param sourceSchema The schema the SchemaItems gets copied from.
47
+ * @returns The merged target schema.
48
+ */
49
+ async merge(targetSchema, sourceSchema) {
50
+ const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);
51
+ const mergeContext = {
52
+ targetSchema,
53
+ sourceSchema,
54
+ };
55
+ await (0, SchemaReferenceMerger_1.default)(mergeContext, schemaChanges);
56
+ await (0, SchemaItemMerger_1.default)(mergeContext, schemaChanges.enumerationChanges.values(), EnumerationMerger_1.default);
57
+ const propertyCategoryChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.PropertyCategory);
58
+ await (0, SchemaItemMerger_1.default)(mergeContext, propertyCategoryChanges, PropertyCategoryMerger_1.default);
59
+ // TODO: For now we just do simple copy and merging of properties and classes. For more complex types
60
+ // with bases classes or relationships, this might need to get extended.
61
+ const caClassChanges = filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.CustomAttributeClass);
62
+ await (0, SchemaItemMerger_1.default)(mergeContext, caClassChanges, CAClassMerger_1.default);
63
+ const classChanges = filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.EntityClass, ecschema_metadata_1.SchemaItemType.StructClass);
64
+ await (0, SchemaItemMerger_1.default)(mergeContext, classChanges, ClassMerger_1.default);
65
+ // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first
66
+ // merge into a temporary schema and eventually swap that with the given instance.
67
+ return targetSchema;
68
+ }
69
+ }
70
+ exports.SchemaMerger = SchemaMerger;
71
+ /**
72
+ * Filters and returns the changed items by its schema item type.
73
+ * @param changes A map of changed schema items.
74
+ * @param types A list of schema item types to filter.
75
+ * @returns An Iterable with the filtered schema items.
76
+ */
77
+ function filterChangesByItemType(changes, ...types) {
78
+ const result = [];
79
+ for (const change of changes.values()) {
80
+ if (types.includes(change.schemaItemType)) {
81
+ result.push(change);
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+ //# sourceMappingURL=SchemaMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAE9D,+CAAyC;AACzC,2DAAmD;AACnD,qEAA6D;AAC7D,yDAAkD;AAClD,mEAA4D;AAC5D,mDAA6C;AAW7C;;;;GAIG;AACH,MAAa,YAAY;IACvB;;;;;;;OAOG;IACK,KAAK,CAAC,gBAAgB,CAAC,YAAoB,EAAE,YAAoB;QACvE,MAAM,WAAW,GAAoB,EAAE,CAAC;QACxC,MAAM,cAAc,GAAG,IAAI,+BAAc,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAE1F,kFAAkF;QAClF,mEAAmE;QACnE,MAAM,cAAc,CAAC,cAAc,CAAC,YAAY,EAAE,YAAY,EAAE;YAC9D,mBAAmB,EAAE,KAAK;SAC3B,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,KAAK,CAAC,YAAoB,EAAE,YAAoB;QAC3D,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC9E,MAAM,YAAY,GAAuB;YACvC,YAAY;YACZ,YAAY;SACb,CAAC;QAEF,MAAM,IAAA,+BAAqB,EAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAEzD,MAAM,IAAA,0BAAgB,EAAC,YAAY,EAAE,aAAa,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,2BAAgB,CAAC,CAAC;QAElG,MAAM,uBAAuB,GAAG,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,gBAAgB,CAAC,CAAC;QAC1H,MAAM,IAAA,0BAAgB,EAAC,YAAY,EAAE,uBAAuB,EAAE,gCAAqB,CAAC,CAAC;QAErF,qGAAqG;QACrG,8EAA8E;QAC9E,MAAM,cAAc,GAAG,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,oBAAoB,CAAC,CAAC;QAChH,MAAM,IAAA,0BAAgB,EAAC,YAAY,EAAE,cAAc,EAAE,uBAAc,CAAC,CAAC;QAErE,MAAM,YAAY,GAAG,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,WAAW,EAAE,kCAAc,CAAC,WAAW,CAAC,CAAC;QACjI,MAAM,IAAA,0BAAgB,EAAC,YAAY,EAAE,YAAY,EAAE,qBAAY,CAAC,CAAC;QAEjE,sGAAsG;QACtG,wFAAwF;QACxF,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAtDD,oCAsDC;AAED;;;;;GAKG;AACH,SAAS,uBAAuB,CAAoC,OAA6B,EAAE,GAAG,KAAuB;IAC3H,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,KAAI,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YACzC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACrB;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Merging\r\n */\r\n\r\nimport { Schema, SchemaItemType } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaChanges, SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\r\n\r\nimport mergeClasses from \"./ClassMerger\";\r\nimport mergeEnumeration from \"./EnumerationMerger\";\r\nimport mergePropertyCategory from \"./PropertyCategoryMerger\";\r\nimport mergeSchemaItems from \"./SchemaItemMerger\";\r\nimport mergeSchemaReferences from \"./SchemaReferenceMerger\";\r\nimport mergeCAClasses from \"./CAClassMerger\";\r\n\r\n/**\r\n * Defines the context of a Schema merging run.\r\n * @beta\r\n */\r\nexport interface SchemaMergeContext {\r\n readonly targetSchema: Schema;\r\n readonly sourceSchema: Schema;\r\n}\r\n\r\n/**\r\n * Class to merge two schemas together.\r\n * @see [[merge]] to merge the schemas.\r\n * @beta\r\n */\r\nexport class SchemaMerger {\r\n /**\r\n * Gets the @see SchemaChanges between the two given Schemas from perspective of the source\r\n * to the target schema. For example if source contains a class which does not exists in the\r\n * target one, it would be listed as missing.\r\n * @param targetSchema The schema the differences gets merged into.\r\n * @param sourceSchema The schema to compare.\r\n * @returns An instance of @see SchemaChanges between the two schemas.\r\n */\r\n private async getSchemaChanges(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaChanges> {\r\n const changesList: SchemaChanges[] = [];\r\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\r\n\r\n // It is important to compare the schema items by name, not full name as otherwise\r\n // we'd often see differences when comparing two different schemas.\r\n await schemaComparer.compareSchemas(sourceSchema, targetSchema, {\r\n compareItemFullName: false,\r\n });\r\n\r\n return changesList[0];\r\n }\r\n\r\n /**\r\n * Copy the SchemaItems of the source schemas to the target schema.\r\n * @param targetSchema The schema the SchemaItems gets merged to.\r\n * @param sourceSchema The schema the SchemaItems gets copied from.\r\n * @returns The merged target schema.\r\n */\r\n public async merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\r\n const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);\r\n const mergeContext: SchemaMergeContext = {\r\n targetSchema,\r\n sourceSchema,\r\n };\r\n\r\n await mergeSchemaReferences(mergeContext, schemaChanges);\r\n\r\n await mergeSchemaItems(mergeContext, schemaChanges.enumerationChanges.values(), mergeEnumeration);\r\n\r\n const propertyCategoryChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.PropertyCategory);\r\n await mergeSchemaItems(mergeContext, propertyCategoryChanges, mergePropertyCategory);\r\n\r\n // TODO: For now we just do simple copy and merging of properties and classes. For more complex types\r\n // with bases classes or relationships, this might need to get extended.\r\n const caClassChanges = filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.CustomAttributeClass);\r\n await mergeSchemaItems(mergeContext, caClassChanges, mergeCAClasses);\r\n\r\n const classChanges = filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.EntityClass, SchemaItemType.StructClass);\r\n await mergeSchemaItems(mergeContext, classChanges, mergeClasses);\r\n\r\n // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first\r\n // merge into a temporary schema and eventually swap that with the given instance.\r\n return targetSchema;\r\n }\r\n}\r\n\r\n/**\r\n * Filters and returns the changed items by its schema item type.\r\n * @param changes A map of changed schema items.\r\n * @param types A list of schema item types to filter.\r\n * @returns An Iterable with the filtered schema items.\r\n */\r\nfunction filterChangesByItemType<TChange extends SchemaItemChanges>(changes: Map<string, TChange>, ...types: SchemaItemType[]): Iterable<TChange> {\r\n const result: TChange[] = [];\r\n for(const change of changes.values()) {\r\n if (types.includes(change.schemaItemType)) {\r\n result.push(change);\r\n }\r\n }\r\n return result;\r\n}\r\n"]}
@@ -0,0 +1,10 @@
1
+ import { SchemaChanges } from "../Validation/SchemaChanges";
2
+ import { SchemaMergeContext } from "./SchemaMerger";
3
+ /**
4
+ * Merges the schema references of two schemas.
5
+ * @param mergeContext current merge context
6
+ * @param changes schema changes.
7
+ * @internal
8
+ */
9
+ export default function mergeSchemaReferences(mergeContext: SchemaMergeContext, changes: SchemaChanges): Promise<void>;
10
+ //# sourceMappingURL=SchemaReferenceMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaReferenceMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaReferenceMerger.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;GAKG;AACH,wBAA8B,qBAAqB,CAAC,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAE,aAAa,iBA+B3G"}