@itwin/ecschema-editing 4.2.0-dev.29 → 4.2.0-dev.30
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/lib/cjs/Merging/ConstantMerger.d.ts +12 -0
- package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/ConstantMerger.js +56 -0
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -0
- package/lib/cjs/Merging/EnumerationMerger.d.ts +5 -0
- package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +46 -3
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.d.ts +7 -0
- package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/PhenomenonMerger.js +16 -0
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -0
- package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemFactory.js +6 -0
- package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +9 -2
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +15 -2
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +8 -0
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Constant } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { SchemaItemChanges } from "../Validation/SchemaChanges";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* @param target The constant the differences get merged into
|
|
6
|
+
* @param source The constant to compare
|
|
7
|
+
* @param changes Gets the @see SchemaItemChanges between the two constants.
|
|
8
|
+
* For example, if source constant has an attribute/property that it missing in
|
|
9
|
+
* target one, it would be listed in propertyValueChanges.
|
|
10
|
+
*/
|
|
11
|
+
export default function mergeConstant(target: Constant, source: Constant, changes: SchemaItemChanges): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=ConstantMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConstantMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ConstantMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAA4E,MAAM,0BAA0B,CAAC;AAC9H,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAIhE;;;;;;;GAOG;AACH,wBAA8B,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,iBAuCzG"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
* @param target The constant the differences get merged into
|
|
12
|
+
* @param source The constant to compare
|
|
13
|
+
* @param changes Gets the @see SchemaItemChanges between the two constants.
|
|
14
|
+
* For example, if source constant has an attribute/property that it missing in
|
|
15
|
+
* target one, it would be listed in propertyValueChanges.
|
|
16
|
+
*/
|
|
17
|
+
async function mergeConstant(target, source, changes) {
|
|
18
|
+
const mutableConstant = target;
|
|
19
|
+
// Get referenced higher level phenomenon
|
|
20
|
+
const [refSchema, itemName] = await (0, SchemaItemMerger_1.getItemNameAndSchemaRef)(source, source.phenomenon.fullName);
|
|
21
|
+
await (0, SchemaItemMerger_1.mergeSchemaItemProperties)(mutableConstant, changes.propertyValueChanges, (item, propertyName, propertyValue) => {
|
|
22
|
+
switch (propertyName) {
|
|
23
|
+
case "definition": {
|
|
24
|
+
if (item.definition === "")
|
|
25
|
+
return item.setDefinition(propertyValue);
|
|
26
|
+
throw Error(`Failed to merged, constant definition conflict: ${propertyValue} -> ${item.definition}`);
|
|
27
|
+
}
|
|
28
|
+
case "numerator": {
|
|
29
|
+
if (!item.hasNumerator)
|
|
30
|
+
return item.setNumerator(propertyValue);
|
|
31
|
+
throw Error(`Failed to merged, constant numerator conflict: ${propertyValue} -> ${item.numerator}`);
|
|
32
|
+
}
|
|
33
|
+
case "denominator": {
|
|
34
|
+
if (!item.hasDenominator)
|
|
35
|
+
return item.setDenominator(propertyValue);
|
|
36
|
+
throw Error(`Failed to merged, constant denominator conflict: ${propertyValue} -> ${item.denominator}`);
|
|
37
|
+
}
|
|
38
|
+
case "phenomenon": {
|
|
39
|
+
if (item.phenomenon === undefined) {
|
|
40
|
+
// A lazy loaded phenomenon with the correct reference schema is needed, if reference schema is undefined then item schema.
|
|
41
|
+
const schemaItemKey = new ecschema_metadata_1.SchemaItemKey(itemName, refSchema ? refSchema.schemaKey : target.schema.schemaKey);
|
|
42
|
+
const lazyTargetPhenomenon = new ecschema_metadata_1.DelayedPromiseWithProps(schemaItemKey, async () => {
|
|
43
|
+
const phenomenon = (await target.schema.context.getSchemaItem(schemaItemKey));
|
|
44
|
+
// At this point, higher level phenomenon item should not be undefined
|
|
45
|
+
if (phenomenon === undefined)
|
|
46
|
+
throw Error(`Unable to locate phenomenon item in schema ${schemaItemKey.schemaName}`);
|
|
47
|
+
return phenomenon;
|
|
48
|
+
});
|
|
49
|
+
return item.setPhenomenon(lazyTargetPhenomenon);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.default = mergeConstant;
|
|
56
|
+
//# sourceMappingURL=ConstantMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConstantMerger.js","sourceRoot":"","sources":["../../../src/Merging/ConstantMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAA8H;AAE9H,yDAAwF;AAGxF;;;;;;;GAOG;AACY,KAAK,UAAU,aAAa,CAAC,MAAgB,EAAE,MAAgB,EAAE,OAA0B;IACxG,MAAM,eAAe,GAAG,MAAyB,CAAC;IAElD,yCAAyC;IACzC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,MAAM,IAAA,0CAAuB,EAAC,MAAM,EAAE,MAAM,CAAC,UAAW,CAAC,QAAQ,CAAC,CAAC;IAEjG,MAAM,IAAA,4CAAyB,EAAC,eAAe,EAAE,OAAO,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE;QACnH,QAAQ,YAAY,EAAE;YACpB,KAAK,YAAY,CAAC,CAAC;gBACjB,IAAI,IAAI,CAAC,UAAU,KAAK,EAAE;oBACxB,OAAO,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;gBAC3C,MAAM,KAAK,CAAC,mDAAmD,aAAa,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;aACvG;YACD,KAAK,WAAW,CAAC,CAAC;gBAChB,IAAI,CAAC,IAAI,CAAC,YAAY;oBACpB,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;gBAC1C,MAAM,KAAK,CAAC,kDAAkD,aAAa,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aACrG;YACD,KAAK,aAAa,CAAC,CAAC;gBAClB,IAAI,CAAC,IAAI,CAAC,cAAc;oBACtB,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;gBAC5C,MAAM,KAAK,CAAC,oDAAoD,aAAa,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;aACzG;YACD,KAAK,YAAY,CAAC,CAAC;gBACjB,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE;oBACjC,2HAA2H;oBAC3H,MAAM,aAAa,GAAG,IAAI,iCAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBAC7G,MAAM,oBAAoB,GAAyB,IAAI,2CAAuB,CAA4B,aAAa,EAAE,KAAK,IAAI,EAAE;wBAClI,MAAM,UAAU,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAa,aAAa,CAAC,CAAC,CAAC;wBAC1F,sEAAsE;wBACtE,IAAI,UAAU,KAAK,SAAS;4BAC1B,MAAM,KAAK,CAAC,8CAA8C,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC;wBACxF,OAAO,UAAU,CAAC;oBACpB,CAAC,CAAC,CAAC;oBACH,OAAO,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;iBACjD;aACF;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAvCD,gCAuCC","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 { Constant, DelayedPromiseWithProps, LazyLoadedPhenomenon, Phenomenon, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { getItemNameAndSchemaRef, mergeSchemaItemProperties } from \"./SchemaItemMerger\";\r\nimport { MutableConstant } from \"../Editing/Mutable/MutableConstant\";\r\n\r\n/**\r\n * @internal\r\n * @param target The constant the differences get merged into\r\n * @param source The constant to compare\r\n * @param changes Gets the @see SchemaItemChanges between the two constants.\r\n * For example, if source constant has an attribute/property that it missing in\r\n * target one, it would be listed in propertyValueChanges.\r\n */\r\nexport default async function mergeConstant(target: Constant, source: Constant, changes: SchemaItemChanges) {\r\n const mutableConstant = target as MutableConstant;\r\n\r\n // Get referenced higher level phenomenon\r\n const [refSchema, itemName] = await getItemNameAndSchemaRef(source, source.phenomenon!.fullName);\r\n\r\n await mergeSchemaItemProperties(mutableConstant, changes.propertyValueChanges, (item, propertyName, propertyValue) => {\r\n switch (propertyName) {\r\n case \"definition\": {\r\n if (item.definition === \"\")\r\n return item.setDefinition(propertyValue);\r\n throw Error(`Failed to merged, constant definition conflict: ${propertyValue} -> ${item.definition}`);\r\n }\r\n case \"numerator\": {\r\n if (!item.hasNumerator)\r\n return item.setNumerator(propertyValue);\r\n throw Error(`Failed to merged, constant numerator conflict: ${propertyValue} -> ${item.numerator}`);\r\n }\r\n case \"denominator\": {\r\n if (!item.hasDenominator)\r\n return item.setDenominator(propertyValue);\r\n throw Error(`Failed to merged, constant denominator conflict: ${propertyValue} -> ${item.denominator}`);\r\n }\r\n case \"phenomenon\": {\r\n if (item.phenomenon === undefined) {\r\n // A lazy loaded phenomenon with the correct reference schema is needed, if reference schema is undefined then item schema.\r\n const schemaItemKey = new SchemaItemKey(itemName, refSchema ? refSchema.schemaKey : target.schema.schemaKey);\r\n const lazyTargetPhenomenon: LazyLoadedPhenomenon = new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(schemaItemKey, async () => {\r\n const phenomenon = (await target.schema.context.getSchemaItem<Phenomenon>(schemaItemKey));\r\n // At this point, higher level phenomenon item should not be undefined\r\n if (phenomenon === undefined)\r\n throw Error(`Unable to locate phenomenon item in schema ${schemaItemKey.schemaName}`);\r\n return phenomenon;\r\n });\r\n return item.setPhenomenon(lazyTargetPhenomenon);\r\n }\r\n }\r\n }\r\n });\r\n}\r\n"]}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Enumeration } from "@itwin/ecschema-metadata";
|
|
2
2
|
import { EnumerationChanges } from "../Validation/SchemaChanges";
|
|
3
3
|
/**
|
|
4
|
+
* @param target The Enumeration the differences get merged into
|
|
5
|
+
* @param source The Enumeration to compare
|
|
6
|
+
* @param changes Gets the @see EnumerationChanges between the two Enumerations.
|
|
7
|
+
* For example, if source Enumeration has an attribute that is undefined in
|
|
8
|
+
* target one, it would be listed in propertyValueChanges.
|
|
4
9
|
* @internal
|
|
5
10
|
*/
|
|
6
11
|
export default function mergeEnumeration(target: Enumeration, source: Enumeration, changes: EnumerationChanges): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumerationMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"EnumerationMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,WAAW,EAA6C,MAAM,0BAA0B,CAAC;AACjH,OAAO,EAAc,kBAAkB,EAAmB,MAAM,6BAA6B,CAAC;AAsB9F;;;;;;;GAOG;AACH,wBAA8B,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,iBA8CnH"}
|
|
@@ -8,6 +8,11 @@ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
|
8
8
|
const SchemaChanges_1 = require("../Validation/SchemaChanges");
|
|
9
9
|
const SchemaItemMerger_1 = require("./SchemaItemMerger");
|
|
10
10
|
/**
|
|
11
|
+
* @param target The Enumeration the differences get merged into
|
|
12
|
+
* @param source The Enumeration to compare
|
|
13
|
+
* @param changes Gets the @see EnumerationChanges between the two Enumerations.
|
|
14
|
+
* For example, if source Enumeration has an attribute that is undefined in
|
|
15
|
+
* target one, it would be listed in propertyValueChanges.
|
|
11
16
|
* @internal
|
|
12
17
|
*/
|
|
13
18
|
async function mergeEnumeration(target, source, changes) {
|
|
@@ -24,17 +29,55 @@ async function mergeEnumeration(target, source, changes) {
|
|
|
24
29
|
}
|
|
25
30
|
});
|
|
26
31
|
for (const enumeratorChange of changes.enumeratorChanges.values()) {
|
|
27
|
-
// Handle each case:
|
|
28
|
-
// If missing, add source enumerator to target
|
|
29
32
|
if (enumeratorChange.enumeratorMissing?.changeType === SchemaChanges_1.ChangeType.Missing) {
|
|
30
33
|
const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);
|
|
31
34
|
if (enumerator === undefined) {
|
|
32
|
-
throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in
|
|
35
|
+
throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in Enumeration ${source.fullName}`);
|
|
33
36
|
}
|
|
34
37
|
const result = mutableEnumeration.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description);
|
|
35
38
|
mutableEnumeration.addEnumerator(result);
|
|
36
39
|
}
|
|
40
|
+
else {
|
|
41
|
+
const targetEnumerator = target.getEnumeratorByName(enumeratorChange.ecTypeName);
|
|
42
|
+
if (targetEnumerator === undefined) {
|
|
43
|
+
throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in Enumeration ${target.fullName}`);
|
|
44
|
+
}
|
|
45
|
+
const mutableEnumerator = targetEnumerator;
|
|
46
|
+
await mergeEnumeratorAttributes(mutableEnumerator, enumeratorChange.enumeratorDeltas, (enumerator, attributeName, deltaChange, attributeValue) => {
|
|
47
|
+
switch (attributeName) {
|
|
48
|
+
case "label": {
|
|
49
|
+
enumerator.label = attributeValue;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
case "description": {
|
|
53
|
+
enumerator.description = attributeValue;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
case "value": {
|
|
57
|
+
throw Error(`Failed to merge enumerator attribute, ${deltaChange} in ${enumerator.name}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
37
62
|
}
|
|
38
63
|
}
|
|
39
64
|
exports.default = mergeEnumeration;
|
|
65
|
+
/**
|
|
66
|
+
* Similar logic to mergeSchemaItemProperties but for EnumeratorDelta, which has the differences starting at index 1,
|
|
67
|
+
* hence the .slice(1), this is the main difference between mergeSchemaItemProperties.
|
|
68
|
+
* @param targetEnumerator The enumerator the differences get merged into.
|
|
69
|
+
* @param changes Gets the @see EnumeratorDelta, the Enumerator delta array holds information about changes between two Enumerators.
|
|
70
|
+
* @param handler Defines the information needed to merge the attributes.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
async function mergeEnumeratorAttributes(targetEnumerator, changes, handler) {
|
|
74
|
+
for (let index = 0, stepUp = true; index < changes.length; stepUp && index++, stepUp = true) {
|
|
75
|
+
const deltaChange = changes[index].toString(); // this will be useful for error message.
|
|
76
|
+
const [attributeName, attributeValue] = changes[index].diagnostic.messageArgs.slice(1); // messageArgs[0] seems to be an object, need to get to the next one, slice to start at index 1
|
|
77
|
+
if (handler(targetEnumerator, attributeName, deltaChange, attributeValue) === true) {
|
|
78
|
+
changes.splice(index, 1);
|
|
79
|
+
stepUp = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
40
83
|
//# sourceMappingURL=EnumerationMerger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAiH;AACjH,+DAA8F;AAC9F,yDAA+D;AAqB/D;;;;;;;GAOG;AACY,KAAK,UAAU,gBAAgB,CAAC,MAAmB,EAAE,MAAmB,EAAE,OAA2B;IAClH,MAAM,kBAAkB,GAAG,MA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BAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,CAAC,KAAK,IAAI,EAAE;YAClF,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACzB,MAAM,GAAG,KAAK,CAAC;SAChB;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 { AnyEnumerator, Enumeration, parsePrimitiveType, primitiveTypeToString } from \"@itwin/ecschema-metadata\";\r\nimport { ChangeType, EnumerationChanges, EnumeratorDelta } from \"../Validation/SchemaChanges\";\r\nimport { mergeSchemaItemProperties } from \"./SchemaItemMerger\";\r\nimport { MutableEnumeration } from \"../Editing/Mutable/MutableEnumeration\";\r\n\r\n/**\r\n * @internal\r\n * @param item Type Enumerator, the Enumerator the differences get merged into.\r\n * @param attributeName Name of the Enumerator attribute that changed.\r\n * @param deltaChange Provides information about the changes in Enumerator attributes.\r\n * @param attributeValue The value that gets merged into the Enumerator attribute.\r\n */\r\ntype EnumeratorAttributeChanged<TEnumerator extends AnyEnumerator> = (item: TEnumerator, attributeName: string, deltaChange: string, attributeValue: any) => void | boolean;\r\n\r\n/**\r\n * Simple interface to extend access Enumerator attributes\r\n * and allow editing.\r\n */\r\ninterface MutableEnumerator extends AnyEnumerator {\r\n label?: string;\r\n description?: string;\r\n}\r\n\r\n/**\r\n * @param target The Enumeration the differences get merged into\r\n * @param source The Enumeration to compare\r\n * @param changes Gets the @see EnumerationChanges between the two Enumerations.\r\n * For example, if source Enumeration has an attribute that is undefined in\r\n * target one, it would be listed in propertyValueChanges.\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\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 if (enumeratorChange.enumeratorMissing?.changeType === ChangeType.Missing) {\r\n const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);\r\n if (enumerator === undefined) {\r\n throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in Enumeration ${source.fullName}`);\r\n }\r\n const result = mutableEnumeration.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description);\r\n mutableEnumeration.addEnumerator(result);\r\n } else {\r\n const targetEnumerator = target.getEnumeratorByName(enumeratorChange.ecTypeName);\r\n if (targetEnumerator === undefined) {\r\n throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in Enumeration ${target.fullName}`);\r\n }\r\n const mutableEnumerator = targetEnumerator as MutableEnumerator;\r\n await mergeEnumeratorAttributes(mutableEnumerator, enumeratorChange.enumeratorDeltas, (enumerator, attributeName, deltaChange, attributeValue) => {\r\n switch (attributeName) {\r\n case \"label\": {\r\n enumerator.label = attributeValue;\r\n return;\r\n }\r\n case \"description\": {\r\n enumerator.description = attributeValue;\r\n return;\r\n }\r\n case \"value\": {\r\n throw Error(`Failed to merge enumerator attribute, ${deltaChange} in ${enumerator.name}`);\r\n }\r\n }\r\n });\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Similar logic to mergeSchemaItemProperties but for EnumeratorDelta, which has the differences starting at index 1,\r\n * hence the .slice(1), this is the main difference between mergeSchemaItemProperties.\r\n * @param targetEnumerator The enumerator the differences get merged into.\r\n * @param changes Gets the @see EnumeratorDelta, the Enumerator delta array holds information about changes between two Enumerators.\r\n * @param handler Defines the information needed to merge the attributes.\r\n * @internal\r\n */\r\nasync function mergeEnumeratorAttributes<T extends AnyEnumerator>(targetEnumerator: T, changes: EnumeratorDelta[], handler: EnumeratorAttributeChanged<T>) {\r\n for (let index = 0, stepUp = true; index < changes.length; stepUp && index++, stepUp = true) {\r\n const deltaChange = changes[index].toString(); // this will be useful for error message.\r\n const [attributeName, attributeValue] = changes[index].diagnostic.messageArgs!.slice(1); // messageArgs[0] seems to be an object, need to get to the next one, slice to start at index 1\r\n if (handler(targetEnumerator, attributeName, deltaChange, attributeValue) === true) {\r\n changes.splice(index, 1);\r\n stepUp = false;\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Phenomenon } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { SchemaItemChanges } from "../Validation/SchemaChanges";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export default function mergePhenomenon(target: Phenomenon, source: Phenomenon, _changes?: SchemaItemChanges): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=PhenomenonMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhenomenonMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/PhenomenonMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE;;GAEG;AACH,wBAA8B,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,iBAAiB,iBAQjH"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
async function mergePhenomenon(target, source, _changes) {
|
|
7
|
+
const mutablePhenomenon = target;
|
|
8
|
+
if (mutablePhenomenon.definition === "") {
|
|
9
|
+
await mutablePhenomenon.setDefinition(source.definition);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
throw Error(`Failed to merge schemas, definition attribute conflict: ${source.definition} -> ${target.definition}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = mergePhenomenon;
|
|
16
|
+
//# sourceMappingURL=PhenomenonMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhenomenonMerger.js","sourceRoot":"","sources":["../../../src/Merging/PhenomenonMerger.ts"],"names":[],"mappings":";;AAQA;;GAEG;AACY,KAAK,UAAU,eAAe,CAAC,MAAkB,EAAE,MAAkB,EAAE,QAA4B;IAChH,MAAM,iBAAiB,GAAG,MAA2B,CAAC;IAEtD,IAAG,iBAAiB,CAAC,UAAU,KAAK,EAAE,EAAC;QACrC,MAAM,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KAC1D;SAAI;QACH,MAAM,KAAK,CAAC,2DAA2D,MAAM,CAAC,UAAU,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;KACrH;AACH,CAAC;AARD,kCAQC","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 { Phenomenon } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { MutablePhenomenon } from \"../Editing/Mutable/MutablePhenomenon\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default async function mergePhenomenon(target: Phenomenon, source: Phenomenon, _changes?: SchemaItemChanges) {\r\n const mutablePhenomenon = target as MutablePhenomenon;\r\n\r\n if(mutablePhenomenon.definition === \"\"){\r\n await mutablePhenomenon.setDefinition(source.definition);\r\n }else{\r\n throw Error(`Failed to merge schemas, definition attribute conflict: ${source.definition} -> ${target.definition}`);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemFactory.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"SchemaItemFactory.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":"AAIA,OAAO,EAA0F,MAAM,EAAE,UAAU,EAA2B,MAAM,0BAA0B,CAAC;AAE/K;;GAEG;AACH,yBAAiB,iBAAiB,CAAC;IAEjC,SAAsB,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAoB5F;CAKF"}
|
|
@@ -22,6 +22,12 @@ var SchemaItemFactory;
|
|
|
22
22
|
return new ecschema_metadata_1.CustomAttributeClass(targetSchema, template.name, template.modifier);
|
|
23
23
|
if (is(template, ecschema_metadata_1.PropertyCategory))
|
|
24
24
|
return new ecschema_metadata_1.PropertyCategory(targetSchema, template.name);
|
|
25
|
+
if (is(template, ecschema_metadata_1.Phenomenon))
|
|
26
|
+
return new ecschema_metadata_1.Phenomenon(targetSchema, template.name);
|
|
27
|
+
if (is(template, ecschema_metadata_1.Constant))
|
|
28
|
+
return new ecschema_metadata_1.Constant(targetSchema, template.name);
|
|
29
|
+
if (is(template, ecschema_metadata_1.UnitSystem))
|
|
30
|
+
return new ecschema_metadata_1.UnitSystem(targetSchema, template.name);
|
|
25
31
|
throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);
|
|
26
32
|
}
|
|
27
33
|
SchemaItemFactory.create = create;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/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I,CAAC,CAAC;QACnD,IAAI,EAAE,CAAC,QAAQ,EAAE,8BAAU,CAAC;YAC1B,OAAO,IAAI,8BAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAErD,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAEhF,CAAC;IApBqB,wBAAM,SAoB3B,CAAA;IAED,SAAS,EAAE,CAAuB,IAAgB,EAAE,IAA6B;QAC/E,OAAO,IAAI,YAAY,IAAI,CAAC;IAC9B,CAAC;AACH,CAAC,EA3BgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QA2BjC","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 { Constant, CustomAttributeClass, EntityClass, Enumeration, Phenomenon, PropertyCategory, Schema, SchemaItem, StructClass, UnitSystem } 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 if (is(template, Phenomenon))\r\n return new Phenomenon(targetSchema, template.name);\r\n if (is(template, Constant))\r\n return new Constant(targetSchema, template.name);\r\n if (is(template, UnitSystem))\r\n return new UnitSystem(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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaItem } from "@itwin/ecschema-metadata";
|
|
1
|
+
import { Schema, SchemaItem } from "@itwin/ecschema-metadata";
|
|
2
2
|
import { PropertyValueChange, SchemaItemChanges } from "../Validation/SchemaChanges";
|
|
3
3
|
import { SchemaMergeContext } from "./SchemaMerger";
|
|
4
4
|
type SchemaItemMergeFn<TChange extends SchemaItemChanges, TItem extends SchemaItem> = (target: TItem, source: TItem, change: TChange, context: SchemaMergeContext) => Promise<void>;
|
|
@@ -11,7 +11,7 @@ type PropertyChangedFn<TItem extends SchemaItem> = (item: TItem, propertyName: s
|
|
|
11
11
|
* @param mergeFn Merge function for complex merging.
|
|
12
12
|
* @internal
|
|
13
13
|
*/
|
|
14
|
-
export default function mergeSchemaItems<TChange extends SchemaItemChanges, TItem extends SchemaItem>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>, mergeFn
|
|
14
|
+
export default function mergeSchemaItems<TChange extends SchemaItemChanges, TItem extends SchemaItem>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>, mergeFn?: SchemaItemMergeFn<TChange, TItem>): Promise<void>;
|
|
15
15
|
/**
|
|
16
16
|
* Performs the specified action for each property in the given PropertyValueChange array.
|
|
17
17
|
* @param targetItem The target item
|
|
@@ -20,5 +20,12 @@ export default function mergeSchemaItems<TChange extends SchemaItemChanges, TIte
|
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
22
|
export declare function mergeSchemaItemProperties<T extends SchemaItem>(targetItem: T, changes: PropertyValueChange[], handler: PropertyChangedFn<T>): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* @param source The schema item the reference gets copied from
|
|
25
|
+
* @param itemFullName Parsing through item full name give us the schema reference name and the item name, these values are needed to create a new schema item key.
|
|
26
|
+
* @returns Item referenced schema and item name.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function getItemNameAndSchemaRef(source: SchemaItem, itemFullName: string): Promise<[Schema | undefined, string]>;
|
|
23
30
|
export {};
|
|
24
31
|
//# sourceMappingURL=SchemaItemMerger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"SchemaItemMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC9D,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,CAAC,EAAE,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,iBA6CzN;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;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC,CAI7H"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeSchemaItemProperties = void 0;
|
|
3
|
+
exports.getItemNameAndSchemaRef = exports.mergeSchemaItemProperties = void 0;
|
|
4
4
|
/*---------------------------------------------------------------------------------------------
|
|
5
5
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
6
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -53,7 +53,8 @@ async function mergeSchemaItems(context, schemaItemChanges, mergeFn) {
|
|
|
53
53
|
}
|
|
54
54
|
return;
|
|
55
55
|
});
|
|
56
|
-
|
|
56
|
+
if (mergeFn)
|
|
57
|
+
await mergeFn(targetItem, sourceItem, change, context);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
exports.default = mergeSchemaItems;
|
|
@@ -74,4 +75,16 @@ async function mergeSchemaItemProperties(targetItem, changes, handler) {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
exports.mergeSchemaItemProperties = mergeSchemaItemProperties;
|
|
78
|
+
/**
|
|
79
|
+
* @param source The schema item the reference gets copied from
|
|
80
|
+
* @param itemFullName Parsing through item full name give us the schema reference name and the item name, these values are needed to create a new schema item key.
|
|
81
|
+
* @returns Item referenced schema and item name.
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
async function getItemNameAndSchemaRef(source, itemFullName) {
|
|
85
|
+
const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(itemFullName);
|
|
86
|
+
const refSchema = await source.schema.getReference(schemaName);
|
|
87
|
+
return [refSchema, itemName];
|
|
88
|
+
}
|
|
89
|
+
exports.getItemNameAndSchemaRef = getItemNameAndSchemaRef;
|
|
77
90
|
//# sourceMappingURL=SchemaItemMerger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA8D;AAC9D,+DAAiG;AAEjG,2DAAwD;AAMxD,MAAe,iBAAkB,SAAQ,8BAAU;CAGlD;AAED;;;;;;;GAOG;AACY,KAAK,UAAU,gBAAgB,CAA8D,OAA2B,EAAE,iBAAoC,EAAE,OAA2C;IACxN,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,CA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AAY,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;AAED;;;;;GAKG;AACI,KAAK,UAAU,uBAAuB,CAAC,MAAkB,EAAE,YAAoB;IACpF,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,8BAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAC/D,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAJD,0DAIC","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 { Schema, 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 if (mergeFn)\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\r\n/**\r\n * @param source The schema item the reference gets copied from\r\n * @param itemFullName Parsing through item full name give us the schema reference name and the item name, these values are needed to create a new schema item key.\r\n * @returns Item referenced schema and item name.\r\n * @internal\r\n */\r\nexport async function getItemNameAndSchemaRef(source: SchemaItem, itemFullName: string): Promise<[Schema | undefined, string]> {\r\n const [schemaName, itemName] = SchemaItem.parseFullName(itemFullName);\r\n const refSchema = await source.schema.getReference(schemaName);\r\n return [refSchema, itemName];\r\n}\r\n"]}
|
|
@@ -1 +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;
|
|
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;AAalE;;;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;CAmChF"}
|
|
@@ -16,6 +16,8 @@ const PropertyCategoryMerger_1 = require("./PropertyCategoryMerger");
|
|
|
16
16
|
const SchemaItemMerger_1 = require("./SchemaItemMerger");
|
|
17
17
|
const SchemaReferenceMerger_1 = require("./SchemaReferenceMerger");
|
|
18
18
|
const CAClassMerger_1 = require("./CAClassMerger");
|
|
19
|
+
const PhenomenonMerger_1 = require("./PhenomenonMerger");
|
|
20
|
+
const ConstantMerger_1 = require("./ConstantMerger");
|
|
19
21
|
/**
|
|
20
22
|
* Class to merge two schemas together.
|
|
21
23
|
* @see [[merge]] to merge the schemas.
|
|
@@ -56,6 +58,12 @@ class SchemaMerger {
|
|
|
56
58
|
await (0, SchemaItemMerger_1.default)(mergeContext, schemaChanges.enumerationChanges.values(), EnumerationMerger_1.default);
|
|
57
59
|
const propertyCategoryChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.PropertyCategory);
|
|
58
60
|
await (0, SchemaItemMerger_1.default)(mergeContext, propertyCategoryChanges, PropertyCategoryMerger_1.default);
|
|
61
|
+
const unitSystemChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.UnitSystem);
|
|
62
|
+
await (0, SchemaItemMerger_1.default)(mergeContext, unitSystemChanges);
|
|
63
|
+
const phenomenonChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Phenomenon);
|
|
64
|
+
await (0, SchemaItemMerger_1.default)(mergeContext, phenomenonChanges, PhenomenonMerger_1.default);
|
|
65
|
+
const constantChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Constant);
|
|
66
|
+
await (0, SchemaItemMerger_1.default)(mergeContext, constantChanges, ConstantMerger_1.default);
|
|
59
67
|
// TODO: For now we just do simple copy and merging of properties and classes. For more complex types
|
|
60
68
|
// with bases classes or relationships, this might need to get extended.
|
|
61
69
|
const caClassChanges = filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.CustomAttributeClass);
|
|
@@ -1 +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,uB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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;AA/DD,oCA+DC;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\nimport mergePhenomenon from \"./PhenomenonMerger\";\r\nimport mergeConstant from \"./ConstantMerger\";\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 const unitSystemChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.UnitSystem);\r\n await mergeSchemaItems(mergeContext, unitSystemChanges);\r\n\r\n const phenomenonChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Phenomenon);\r\n await mergeSchemaItems(mergeContext, phenomenonChanges, mergePhenomenon);\r\n\r\n const constantChanges = filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Constant);\r\n await mergeSchemaItems(mergeContext, constantChanges, mergeConstant);\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/ecschema-editing",
|
|
3
|
-
"version": "4.2.0-dev.
|
|
3
|
+
"version": "4.2.0-dev.30",
|
|
4
4
|
"description": "ECSchema editing and validation API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/ecschema-editing.js",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"rimraf": "^3.0.2",
|
|
43
43
|
"sinon": "^15.0.4",
|
|
44
44
|
"typescript": "~5.0.2",
|
|
45
|
-
"@itwin/
|
|
46
|
-
"@itwin/core-
|
|
47
|
-
"@itwin/ecschema-metadata": "4.2.0-dev.
|
|
48
|
-
"@itwin/
|
|
49
|
-
"@itwin/core-
|
|
45
|
+
"@itwin/core-bentley": "4.2.0-dev.30",
|
|
46
|
+
"@itwin/core-common": "4.2.0-dev.30",
|
|
47
|
+
"@itwin/ecschema-metadata": "4.2.0-dev.30",
|
|
48
|
+
"@itwin/build-tools": "4.2.0-dev.30",
|
|
49
|
+
"@itwin/core-quantity": "4.2.0-dev.30"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@itwin/core-bentley": "^4.2.0-dev.
|
|
53
|
-
"@itwin/core-quantity": "^4.2.0-dev.
|
|
54
|
-
"@itwin/ecschema-metadata": "^4.2.0-dev.
|
|
52
|
+
"@itwin/core-bentley": "^4.2.0-dev.30",
|
|
53
|
+
"@itwin/core-quantity": "^4.2.0-dev.30",
|
|
54
|
+
"@itwin/ecschema-metadata": "^4.2.0-dev.30"
|
|
55
55
|
},
|
|
56
56
|
"nyc": {
|
|
57
57
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|