@itwin/ecschema-editing 4.4.0-dev.8 → 4.5.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +5 -0
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.d.ts +1 -1
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +1 -1
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +8 -6
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +2 -0
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts +1 -0
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +20 -0
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +2 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts +9 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +33 -2
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +148 -22
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +9 -1
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassPropertyMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassPropertyMerger.js +8 -1
- package/lib/cjs/Merging/ClassPropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts +21 -0
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/CustomAttributeMerger.js +51 -0
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +15 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.js +66 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -0
- package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemFactory.js +10 -0
- package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +2 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +11 -4
- 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 +7 -0
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Validation/ECRules.d.ts +13 -3
- package/lib/cjs/Validation/ECRules.d.ts.map +1 -1
- package/lib/cjs/Validation/ECRules.js +30 -11
- package/lib/cjs/Validation/ECRules.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js +2 -4
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,51 @@
|
|
|
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.mergeCustomAttributes = void 0;
|
|
11
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
+
const SchemaChanges_1 = require("../Validation/SchemaChanges");
|
|
13
|
+
/**
|
|
14
|
+
* Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass
|
|
15
|
+
* a scope (Class, Property, Schema) specific handler.
|
|
16
|
+
* @param mergeContext The current schema merging context.
|
|
17
|
+
* @param changes An iterable with custom attribute changes.
|
|
18
|
+
* @param callback The callback to add the custom attribute with a scope specific editor.
|
|
19
|
+
* @returns A EditResults object.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
async function mergeCustomAttributes(mergeContext, changes, callback) {
|
|
23
|
+
for (const customAttributeContainerChange of changes) {
|
|
24
|
+
for (const change of customAttributeContainerChange.customAttributeChanges) {
|
|
25
|
+
if (change.changeType === SchemaChanges_1.ChangeType.Missing) {
|
|
26
|
+
const [sourceCustomAttribute] = change.diagnostic.messageArgs;
|
|
27
|
+
const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(sourceCustomAttribute.className);
|
|
28
|
+
const schemaItemKey = new ecschema_metadata_1.SchemaItemKey(itemName, mergeContext.sourceSchema.schemaKey.compareByName(schemaName)
|
|
29
|
+
? mergeContext.targetSchema.schemaKey
|
|
30
|
+
: new ecschema_metadata_1.SchemaKey(schemaName));
|
|
31
|
+
const targetCustomAttribute = await mergeContext.targetSchema.lookupItem(schemaItemKey);
|
|
32
|
+
if (targetCustomAttribute === undefined) {
|
|
33
|
+
return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.` };
|
|
34
|
+
}
|
|
35
|
+
const results = await callback({
|
|
36
|
+
...sourceCustomAttribute,
|
|
37
|
+
className: targetCustomAttribute.fullName,
|
|
38
|
+
});
|
|
39
|
+
if (results.errorMessage !== undefined) {
|
|
40
|
+
return { errorMessage: results.errorMessage };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return { errorMessage: `Changes of Custom Attribute ${customAttributeContainerChange.ecTypeName} on ${mergeContext.targetSchema.name} merge is not implemented.` };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
exports.mergeCustomAttributes = mergeCustomAttributes;
|
|
51
|
+
//# sourceMappingURL=CustomAttributeMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomAttributeMerger.js","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAuH;AACvH,+DAA0F;AAO1F;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CAAC,YAAgC,EAAE,OAAkD,EAAE,QAAoE;IACpM,KAAK,MAAM,8BAA8B,IAAI,OAAO,EAAE;QACpD,KAAK,MAAM,MAAM,IAAI,8BAA8B,CAAC,sBAAsB,EAAE;YAC1E,IAAI,MAAM,CAAC,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAC5C,MAAM,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAgC,CAAC;gBACnF,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAI,8BAAU,CAAC,aAAa,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;gBAC1F,MAAM,aAAa,GAAG,IAAI,iCAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC;oBAC7G,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS;oBACrC,CAAC,CAAC,IAAI,6BAAS,CAAC,UAAU,CAAC,CAC5B,CAAC;gBACF,MAAM,qBAAqB,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,UAAU,CAAuB,aAAa,CAAC,CAAC;gBAC9G,IAAI,qBAAqB,KAAK,SAAS,EAAE;oBACvC,OAAO,EAAE,YAAY,EAAE,+CAA+C,aAAa,CAAC,IAAI,wBAAwB,EAAC,CAAC;iBACnH;gBAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC;oBAC7B,GAAG,qBAAqB;oBACxB,SAAS,EAAE,qBAAqB,CAAC,QAAQ;iBAC1C,CAAC,CAAC;gBAEH,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,OAAO,EAAG,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;iBAChD;aACF;iBAAM;gBACL,OAAO,EAAE,YAAY,EAAE,+BAA+B,8BAA8B,CAAC,UAAU,OAAO,YAAY,CAAC,YAAY,CAAC,IAAI,4BAA4B,EAAC,CAAC;aACnK;SACF;KACF;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AA7BD,sDA6BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Merging\n */\n\nimport { CustomAttribute, CustomAttributeClass, SchemaItem, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { ChangeType, CustomAttributeContainerChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\ninterface EditResults {\n errorMessage?: string;\n}\n\n/**\n * Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass\n * a scope (Class, Property, Schema) specific handler.\n * @param mergeContext The current schema merging context.\n * @param changes An iterable with custom attribute changes.\n * @param callback The callback to add the custom attribute with a scope specific editor.\n * @returns A EditResults object.\n * @internal\n */\nexport async function mergeCustomAttributes(mergeContext: SchemaMergeContext, changes: Iterable<CustomAttributeContainerChanges>, callback: (customAttribute: CustomAttribute) => Promise<EditResults>): Promise<EditResults> {\n for (const customAttributeContainerChange of changes) {\n for (const change of customAttributeContainerChange.customAttributeChanges) {\n if (change.changeType === ChangeType.Missing) {\n const [sourceCustomAttribute] = change.diagnostic.messageArgs as [CustomAttribute];\n const [schemaName, itemName] = SchemaItem.parseFullName(sourceCustomAttribute.className);\n const schemaItemKey = new SchemaItemKey(itemName, mergeContext.sourceSchema.schemaKey.compareByName(schemaName)\n ? mergeContext.targetSchema.schemaKey\n : new SchemaKey(schemaName),\n );\n const targetCustomAttribute = await mergeContext.targetSchema.lookupItem<CustomAttributeClass>(schemaItemKey);\n if (targetCustomAttribute === undefined) {\n return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.`};\n }\n\n const results = await callback({\n ...sourceCustomAttribute,\n className: targetCustomAttribute.fullName,\n });\n\n if (results.errorMessage !== undefined) {\n return { errorMessage: results.errorMessage };\n }\n } else {\n return { errorMessage: `Changes of Custom Attribute ${customAttributeContainerChange.ecTypeName} on ${mergeContext.targetSchema.name} merge is not implemented.`};\n }\n }\n }\n return {};\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { KindOfQuantity, SchemaItemKey } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { PropertyValueResolver, SchemaItemMerger } from "./SchemaItemMerger";
|
|
3
|
+
import { KindOfQuantityChanges } from "../Validation/SchemaChanges";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export default class KindOfQuantityMerger extends SchemaItemMerger<KindOfQuantity> {
|
|
8
|
+
protected merge(itemKey: SchemaItemKey, source: KindOfQuantity, changes: KindOfQuantityChanges): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* Creates the property value resolver for [[KindOfQuantity]] items.
|
|
12
|
+
*/
|
|
13
|
+
protected createPropertyValueResolver(): Promise<PropertyValueResolver<KindOfQuantity>>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=KindOfQuantityMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KindOfQuantityMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/KindOfQuantityMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAwB,cAAc,EAA8B,aAAa,EAAQ,MAAM,0BAA0B,CAAC;AACjI,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,gBAAgB,CAAC,cAAc,CAAC;cAEvD,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,qBAAqB;IAmC7G;;;OAGG;cACsB,2BAA2B,IAAI,OAAO,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;CAcvG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
*/
|
|
12
|
+
class KindOfQuantityMerger extends SchemaItemMerger_1.SchemaItemMerger {
|
|
13
|
+
async merge(itemKey, source, changes) {
|
|
14
|
+
for (const presentationUnitChange of changes.presentationUnitChanges.values()) {
|
|
15
|
+
for (const change of presentationUnitChange.presentationUnitChange) {
|
|
16
|
+
const format = change.diagnostic.messageArgs[0];
|
|
17
|
+
const isDefault = source.defaultPresentationFormat === format;
|
|
18
|
+
if (ecschema_metadata_1.OverrideFormat.isOverrideFormat(format)) {
|
|
19
|
+
const parentFormat = await this.lookup(format.parent);
|
|
20
|
+
if (parentFormat === undefined) {
|
|
21
|
+
throw new Error(`Unable to locate the format class ${format.parent.name} in the merged schema.`);
|
|
22
|
+
}
|
|
23
|
+
const unitAndLabels = [];
|
|
24
|
+
if (format.units !== undefined) {
|
|
25
|
+
for (const [unit, label] of format.units) {
|
|
26
|
+
const targetUnit = await this.lookup(unit);
|
|
27
|
+
if (targetUnit === undefined) {
|
|
28
|
+
throw new Error(`Unable to locate the unit class ${unit.name} in the merged schema.`);
|
|
29
|
+
}
|
|
30
|
+
unitAndLabels.push([targetUnit, label]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const overrideFormat = await this.context.editor.kindOfQuantities.createFormatOverride(itemKey, parentFormat.key, format.precision, unitAndLabels);
|
|
34
|
+
await this.context.editor.kindOfQuantities.addPresentationOverrideFormat(itemKey, overrideFormat, isDefault);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const targetFormat = await this.lookup(format);
|
|
38
|
+
if (targetFormat === undefined) {
|
|
39
|
+
throw new Error(`Unable to locate the format class ${format.name} in the merged schema.`);
|
|
40
|
+
}
|
|
41
|
+
await this.context.editor.kindOfQuantities.addPresentationFormat(itemKey, targetFormat.key, isDefault);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* Creates the property value resolver for [[KindOfQuantity]] items.
|
|
49
|
+
*/
|
|
50
|
+
async createPropertyValueResolver() {
|
|
51
|
+
return {
|
|
52
|
+
persistenceUnit: (newValue, targetItemKey, oldValue) => {
|
|
53
|
+
if (oldValue !== undefined && oldValue !== newValue) {
|
|
54
|
+
throw new Error(`Changing the kind of quantity '${targetItemKey.name}' persistenceUnit is not supported.`);
|
|
55
|
+
}
|
|
56
|
+
const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(newValue);
|
|
57
|
+
if (this.context.targetSchema.getReferenceSync(schemaName) === undefined) {
|
|
58
|
+
return `${targetItemKey.schemaName}.${itemName}`;
|
|
59
|
+
}
|
|
60
|
+
return newValue;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.default = KindOfQuantityMerger;
|
|
66
|
+
//# sourceMappingURL=KindOfQuantityMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KindOfQuantityMerger.js","sourceRoot":"","sources":["../../../src/Merging/KindOfQuantityMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAiI;AACjI,yDAA6E;AAG7E;;GAEG;AACH,MAAqB,oBAAqB,SAAQ,mCAAgC;IAE7D,KAAK,CAAC,KAAK,CAAC,OAAsB,EAAE,MAAsB,EAAE,OAA8B;QAC3G,KAAK,MAAM,sBAAsB,IAAI,OAAO,CAAC,uBAAuB,CAAC,MAAM,EAAE,EAAE;YAC7E,KAAK,MAAM,MAAM,IAAI,sBAAsB,CAAC,sBAAsB,EAAE;gBAClE,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,WAAY,CAAC,CAAC,CAAC,CAAC;gBACjD,MAAM,SAAS,GAAG,MAAM,CAAC,yBAAyB,KAAK,MAAM,CAAC;gBAE9D,IAAI,kCAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE;oBAC3C,MAAM,YAAY,GAAG,MAAM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O,EAAE,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;iBACxG;aACF;SACF;IACH,CAAC;IAED;;;OAGG;IACgB,KAAK,CAAC,2BAA2B;QAClD,OAAO;YACL,eAAe,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE;gBACrD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,QAAQ,EAAE;oBACnD,MAAM,IAAI,KAAK,CAAC,kCAAkC,aAAa,CAAC,IAAI,qCAAqC,CAAC,CAAC;iBAC5G;gBACD,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,8BAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;gBAClE,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE;oBACxE,OAAO,GAAG,aAAa,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC;iBAClD;gBACD,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAvDD,uCAuDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Format, InvertedUnit, KindOfQuantity, OverrideFormat, SchemaItem, SchemaItemKey, Unit } from \"@itwin/ecschema-metadata\";\nimport { PropertyValueResolver, SchemaItemMerger } from \"./SchemaItemMerger\";\nimport { KindOfQuantityChanges } from \"../Validation/SchemaChanges\";\n\n/**\n * @internal\n */\nexport default class KindOfQuantityMerger extends SchemaItemMerger<KindOfQuantity> {\n\n protected override async merge(itemKey: SchemaItemKey, source: KindOfQuantity, changes: KindOfQuantityChanges) {\n for (const presentationUnitChange of changes.presentationUnitChanges.values()) {\n for (const change of presentationUnitChange.presentationUnitChange) {\n const format = change.diagnostic.messageArgs![0];\n const isDefault = source.defaultPresentationFormat === format;\n\n if (OverrideFormat.isOverrideFormat(format)) {\n const parentFormat = await this.lookup<Format>(format.parent);\n if (parentFormat === undefined) {\n throw new Error(`Unable to locate the format class ${format.parent.name} in the merged schema.`);\n }\n\n const unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined = [];\n if (format.units !== undefined) {\n for (const [unit, label] of format.units) {\n const targetUnit = await this.lookup<Unit | InvertedUnit>(unit);\n if (targetUnit === undefined) {\n throw new Error(`Unable to locate the unit class ${unit.name} in the merged schema.`);\n }\n unitAndLabels.push([targetUnit, label]);\n }\n }\n const overrideFormat = await this.context.editor.kindOfQuantities.createFormatOverride(itemKey, parentFormat.key, format.precision, unitAndLabels);\n await this.context.editor.kindOfQuantities.addPresentationOverrideFormat(itemKey, overrideFormat, isDefault);\n } else {\n const targetFormat = await this.lookup<Format>(format);\n if (targetFormat === undefined) {\n throw new Error(`Unable to locate the format class ${format.name} in the merged schema.`);\n }\n await this.context.editor.kindOfQuantities.addPresentationFormat(itemKey, targetFormat.key, isDefault);\n }\n }\n }\n }\n\n /**\n *\n * Creates the property value resolver for [[KindOfQuantity]] items.\n */\n protected override async createPropertyValueResolver(): Promise<PropertyValueResolver<KindOfQuantity>> {\n return {\n persistenceUnit: (newValue, targetItemKey, oldValue) => {\n if (oldValue !== undefined && oldValue !== newValue) {\n throw new Error(`Changing the kind of quantity '${targetItemKey.name}' persistenceUnit is not supported.`);\n }\n const [schemaName, itemName] = SchemaItem.parseFullName(newValue);\n if (this.context.targetSchema.getReferenceSync(schemaName) === undefined) {\n return `${targetItemKey.schemaName}.${itemName}`;\n }\n return newValue;\n },\n };\n }\n}\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,EAAyH,UAAU,EAAE,aAAa,EAAsC,MAAM,0BAA0B,CAAC;AAEhO,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,yBAAiB,iBAAiB,CAAC;IAEjC;;;;;OAKG;IACH,SAAsB,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAMtG;CA0DF"}
|
|
@@ -55,6 +55,16 @@ var SchemaItemFactory;
|
|
|
55
55
|
: phenomenon.key;
|
|
56
56
|
return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);
|
|
57
57
|
}
|
|
58
|
+
if (is(template, ecschema_metadata_1.KindOfQuantity)) {
|
|
59
|
+
if (template.persistenceUnit === undefined) {
|
|
60
|
+
throw new Error(`Invalid KindOfQuantity ${template.name} has no persistenceUnit defined`);
|
|
61
|
+
}
|
|
62
|
+
const persistenceUnit = await template.persistenceUnit;
|
|
63
|
+
const itemKey = persistenceUnit.key.schemaKey.matches(template.key.schemaKey)
|
|
64
|
+
? new ecschema_metadata_1.SchemaItemKey(persistenceUnit.name, targetSchemaKey)
|
|
65
|
+
: persistenceUnit.key;
|
|
66
|
+
return editor.kindOfQuantities.create(targetSchemaKey, template.name, itemKey);
|
|
67
|
+
}
|
|
58
68
|
if (is(template, ecschema_metadata_1.UnitSystem))
|
|
59
69
|
return editor.unitSystems.create(targetSchemaKey, template.name);
|
|
60
70
|
throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":";;;AAA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AC3F;YACD,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAC;YACvD,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC;gBAC3E,CAAC,CAAC,IAAI,iCAAa,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC;gBAC1D,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC;YACxB,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAChF;QACD,IAAI,EAAE,CAAC,QAAQ,EAAE,8BAAU,CAAC;YAC1B,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEnE,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IAED;;;;;OAKG;IACH,SAAS,EAAE,CAAuB,IAAgB,EAAE,IAA6B;QAC/E,OAAO,IAAI,YAAY,IAAI,CAAC;IAC9B,CAAC;AACH,CAAC,EAxEgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAwEjC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Constant, CustomAttributeClass, EntityClass, Enumeration, KindOfQuantity, Phenomenon, PrimitiveType, PropertyCategory, SchemaItem, SchemaItemKey, SchemaKey, StructClass, UnitSystem } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor, SchemaItemEditResults } from \"../Editing/Editor\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * @internal\n */\nexport namespace SchemaItemFactory {\n\n /**\n * Creates a new Schema Item based on the given template instance.\n * @param context The current merging context.\n * @param template The Schema Items Template\n * @returns The SchemaItemKey of the created item.\n */\n export async function create(context: SchemaMergeContext, template: SchemaItem): Promise<SchemaItemKey> {\n const result = await createItem(context.editor, context.targetSchema.schemaKey, template);\n if(result.errorMessage) {\n throw new Error(result.errorMessage);\n }\n return result.itemKey!;\n }\n\n /**\n * Creates a new Schema Item in the SchemaContextEditor.\n * @param editor The SchemaContextEditor\n * @param targetSchemaKey The key of the target schema the item shall be created in.\n * @param template The Schema Items Template\n * @returns A SchemaItemEditResults with a schema key if the item could be created.\n */\n async function createItem(editor: SchemaContextEditor, targetSchemaKey: SchemaKey, template: SchemaItem): Promise<SchemaItemEditResults> {\n if (is(template, Enumeration))\n return editor.enumerations.create(targetSchemaKey, template.name, template.isInt ? PrimitiveType.Integer : PrimitiveType.String, template.label, template.isStrict);\n if (is(template, EntityClass))\n return editor.entities.create(targetSchemaKey, template.name, template.modifier);\n if (is(template, StructClass))\n return editor.structs.create(targetSchemaKey, template.name);\n if (is(template, CustomAttributeClass))\n return editor.customAttributes.create(targetSchemaKey, template.name, template.containerType);\n if(is(template, PropertyCategory))\n return editor.propertyCategories.create(targetSchemaKey, template.name, template.priority);\n if (is(template, Phenomenon))\n return editor.phenomenons.create(targetSchemaKey, template.name, template.definition);\n if (is(template, Constant)) {\n if(template.phenomenon === undefined) {\n throw new Error(`Invalid Constant ${template.name} has no phenomenon defined`);\n }\n const phenomenon = await template.phenomenon;\n const itemKey = phenomenon.key.schemaKey.matches(template.key.schemaKey)\n ? new SchemaItemKey(phenomenon.name, targetSchemaKey)\n : phenomenon.key;\n\n return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);\n }\n if (is(template, KindOfQuantity)) {\n if(template.persistenceUnit === undefined) {\n throw new Error(`Invalid KindOfQuantity ${template.name} has no persistenceUnit defined`);\n }\n const persistenceUnit = await template.persistenceUnit;\n const itemKey = persistenceUnit.key.schemaKey.matches(template.key.schemaKey)\n ? new SchemaItemKey(persistenceUnit.name, targetSchemaKey)\n : persistenceUnit.key;\n return editor.kindOfQuantities.create(targetSchemaKey, template.name, itemKey);\n }\n if (is(template, UnitSystem))\n return editor.unitSystems.create(targetSchemaKey, template.name);\n\n throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);\n }\n\n /**\n * Type Guard to \"cast\" a given schema item into an implementation\n * @param item Item to be checked\n * @param type The desired implementation.\n * @returns true if the item could be casted, otherwise false.\n */\n function is<T extends SchemaItem>(item: SchemaItem, type: new (...args: any) => T ): item is T {\n return item instanceof type;\n }\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import { SchemaMergeContext } from "./SchemaMerger";
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export type PropertyValueResolver<T extends SchemaItem, TProps = MutableSchemaItemProps<T>> = {
|
|
9
|
-
[P in keyof TProps]?: (
|
|
9
|
+
[P in keyof TProps]?: (newValue: any, item: SchemaItemKey, oldValue?: any) => any;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Defines a Mutable Schema Props interface.
|
|
@@ -43,6 +43,7 @@ export declare class SchemaItemMerger<TItem extends SchemaItem> {
|
|
|
43
43
|
* @param _change The schema item change to be applied.
|
|
44
44
|
*/
|
|
45
45
|
protected merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges): Promise<void>;
|
|
46
|
+
protected lookup<T extends SchemaItem>(schemaItem: T): Promise<T | undefined>;
|
|
46
47
|
/**
|
|
47
48
|
* Merges the given schema item changes in the current context.
|
|
48
49
|
* @param context The merging context
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAmC,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEjG,OAAO,EAAE,kBAAkB,E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CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB;cAIzE,MAAM,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAQnF;;;;OAIG;WACiB,YAAY,CAAC,OAAO,SAAS,iBAAiB,EAAE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,QAAQ,CAAC,OAAO,CAAC;IAyBrI;;;;OAIG;YACW,uBAAuB;CAoBtC"}
|
|
@@ -43,6 +43,12 @@ class SchemaItemMerger {
|
|
|
43
43
|
async merge(_itemKey, _source, _change) {
|
|
44
44
|
// Can be overriden for complex merging
|
|
45
45
|
}
|
|
46
|
+
async lookup(schemaItem) {
|
|
47
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(schemaItem.name, this.context.sourceSchema.schemaKey.matches(schemaItem.schema.schemaKey)
|
|
48
|
+
? this.context.targetSchema.schemaKey
|
|
49
|
+
: schemaItem.schema.schemaKey);
|
|
50
|
+
return this.context.targetSchema.lookupItem(itemKey);
|
|
51
|
+
}
|
|
46
52
|
/**
|
|
47
53
|
* Merges the given schema item changes in the current context.
|
|
48
54
|
* @param context The merging context
|
|
@@ -79,14 +85,15 @@ class SchemaItemMerger {
|
|
|
79
85
|
if (changes.length === 0) {
|
|
80
86
|
return;
|
|
81
87
|
}
|
|
82
|
-
const
|
|
88
|
+
const targetItem = (await this.context.targetSchema.lookupItem(targetItemKey));
|
|
89
|
+
const jsonProps = (targetItem?.toJSON() ?? {});
|
|
83
90
|
const propertyResolver = await this.createPropertyValueResolver();
|
|
84
91
|
for (const change of changes) {
|
|
85
|
-
const [propertyName,
|
|
92
|
+
const [propertyName, propertyNewValue, propertyOldValue] = change.diagnostic.messageArgs;
|
|
86
93
|
const resolver = propertyResolver[propertyName];
|
|
87
94
|
jsonProps[propertyName] = resolver !== undefined
|
|
88
|
-
? resolver(
|
|
89
|
-
:
|
|
95
|
+
? resolver(propertyNewValue, targetItemKey, propertyOldValue)
|
|
96
|
+
: propertyNewValue;
|
|
90
97
|
}
|
|
91
98
|
await this.context.editor.schemaItems.applyProps(targetItemKey, jsonProps);
|
|
92
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAqE;AACrE,+DAAiG;AACjG,2DAAwD;AAkBxD;;;;;;GAMG;AACH,MAAa,gBAAgB;IAI3B;;;;OAIG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,2BAA2B;QACzC,sDAAsD;QACtD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,KAAK,CAAC,QAAuB,EAAE,OAAc,EAAE,OAA0B;QACvF,uCAAuC;IACzC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,YAAY,CAAoC,OAA2B,EAAE,iBAAoC;QACnI,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,KAAI,MAAM,MAAM,IAAI,iBAAiB,EAAE;YAErC,yFAAyF;YACzF,MAAM,UAAU,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAa,MAAM,CAAC,UAAU,CAAC,CAAE,CAAC;YACxF,IAAI,aAAa,GAAG,IAAI,iCAAa,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAEzF,gFAAgF;YAChF,2EAA2E;YAC3E,IAAG,MAAM,CAAC,iBAAiB,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAC9D,iFAAiF;gBACjF,sBAAsB;gBACtB,IAAG,MAAM,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AC,CAAC;YACjF,MAAM,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;SACvD;IACH,CAAC;IACD;;;;OAIG;IACK,KAAK,CAAC,uBAAuB,CAAC,aAA4B,EAAE,OAA8B;QAChG,uDAAuD;QACvD,IAAG,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,OAAO;SACR;QAED,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAa,aAAa,CAAC,CAAC,CAAC;QAC3F,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CAAkC,CAAC;QAChF,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAC;QAElE,KAAI,MAAM,MAAM,IAAI,OAAO,EAAE;YAC3B,MAAM,CAAC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAkD,CAAC;YAChI,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAChD,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,KAAK,SAAS;gBAC9C,CAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,CAAC;gBAC7D,CAAC,CAAC,gBAAgB,CAAC;SACtB;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CACF;AAjGD,4CAiGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { ChangeType, PropertyValueChange, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaItemFactory } from \"./SchemaItemFactory\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * Defines a type-safe interface of Property Value resolver.\n * @internal\n */\nexport type PropertyValueResolver<T extends SchemaItem, TProps=MutableSchemaItemProps<T>> = {\n [P in keyof TProps]?: (newValue: any, item: SchemaItemKey, oldValue?: any) => any;\n};\n\n/**\n * Defines a Mutable Schema Props interface.\n */\ntype MutableSchemaItemProps<T extends SchemaItem> = {\n -readonly [key in keyof ReturnType<T[\"toJSON\"]>]: ReturnType<T[\"toJSON\"]>[key];\n};\n\n/**\n * The SchemaItemMerger is an base class for several other mergers with the actual logic\n * to perform merging for a certain schema item type. The class provides the shared logics\n * that is shared for all schema item mergers and custom logic can be applied by overriding\n * the protected class members.\n * @internal\n */\nexport class SchemaItemMerger<TItem extends SchemaItem> {\n\n protected readonly context: SchemaMergeContext;\n\n /**\n * Constructor of the SchemaItemMerger class. This should not be overriden or extended\n * by sub-implementations.\n * @param context The current merging context.\n */\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n /**\n * This overridable method allows to create a property value resolver that gets defines\n * a handler function for every possible property change. This allows adding complex handing\n * if a property value requires complicated merging.\n * @returns A resolver map with resolvers for the property.\n */\n protected async createPropertyValueResolver(): Promise<PropertyValueResolver<TItem>> {\n // Can be overriden for complex property value merging\n return {};\n }\n\n /**\n * This overridable method gets called for more complex merging.\n * @param _itemKey The key of the current schema item.\n * @param _source The source item that shall gets merged into.\n * @param _change The schema item change to be applied.\n */\n protected async merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges) {\n // Can be overriden for complex merging\n }\n\n protected async lookup<T extends SchemaItem>(schemaItem: T): Promise<T | undefined>{\n const itemKey = new SchemaItemKey(schemaItem.name, this.context.sourceSchema.schemaKey.matches(schemaItem.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : schemaItem.schema.schemaKey,\n );\n return this.context.targetSchema.lookupItem<T>(itemKey);\n }\n\n /**\n * Merges the given schema item changes in the current context.\n * @param context The merging context\n * @param schemaItemChanges An iterable of item changes.\n */\n public static async mergeChanges<TChange extends SchemaItemChanges>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>) {\n const merger = new this(context);\n for(const change of schemaItemChanges) {\n\n // Gets the source and the target item. The target item could be undefined at that point.\n const sourceItem = (await context.sourceSchema.getItem<SchemaItem>(change.ecTypeName))!;\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\n\n // In case the schema item does not exists in the target schema, an instance for\n // this schema item is created. It's properties get set by the merger then.\n if(change.schemaItemMissing?.changeType === ChangeType.Missing) {\n // Check for name to make sure there is no collision for items with the same name\n // but different type.\n if(await context.targetSchema.lookupItem(targetItemKey) !== undefined) {\n throw new Error(`Schema ${context.targetSchema.name} already contains a Schema Item ${change.ecTypeName}.`);\n }\n\n // TODO: Think about renaming the Schema Item. This could be controlled though a flag.\n targetItemKey = await SchemaItemFactory.create(context, sourceItem);\n }\n\n await merger.mergeItemPropertyValues(targetItemKey, change.propertyValueChanges);\n await merger.merge(targetItemKey, sourceItem, change);\n }\n }\n /**\n * Merges the property values.\n * @param targetItem The current schema item\n * @param changes The property changes.\n */\n private async mergeItemPropertyValues(targetItemKey: SchemaItemKey, changes: PropertyValueChange[]) {\n // No need to process anything if no properties differ.\n if(changes.length === 0) {\n return;\n }\n\n const targetItem = (await this.context.targetSchema.lookupItem<SchemaItem>(targetItemKey));\n const jsonProps = (targetItem?.toJSON() ?? {}) as MutableSchemaItemProps<TItem>;\n const propertyResolver = await this.createPropertyValueResolver();\n\n for(const change of changes) {\n const [propertyName, propertyNewValue, propertyOldValue] = change.diagnostic.messageArgs! as [keyof typeof jsonProps, any, any];\n const resolver = propertyResolver[propertyName];\n jsonProps[propertyName] = resolver !== undefined\n ? resolver(propertyNewValue, targetItemKey, propertyOldValue)\n : propertyNewValue;\n }\n\n await this.context.editor.schemaItems.applyProps(targetItemKey, jsonProps);\n }\n}\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;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,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;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAaxD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;CACtC;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB;;;;;;;OAOG;YACW,gBAAgB;IAW9B;;;;;OAKG;IACU,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkChF"}
|
|
@@ -19,6 +19,8 @@ const ConstantMerger_1 = require("./ConstantMerger");
|
|
|
19
19
|
const EntityClassMerger_1 = require("./EntityClassMerger");
|
|
20
20
|
const StructClassMerger_1 = require("./StructClassMerger");
|
|
21
21
|
const MixinMerger_1 = require("./MixinMerger");
|
|
22
|
+
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
23
|
+
const KindOfQuantityMerger_1 = require("./KindOfQuantityMerger");
|
|
22
24
|
/**
|
|
23
25
|
* Class to merge two schemas together.
|
|
24
26
|
* @see [[merge]] to merge the schemas.
|
|
@@ -61,12 +63,16 @@ class SchemaMerger {
|
|
|
61
63
|
await SchemaItemMerger_1.SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);
|
|
62
64
|
await SchemaItemMerger_1.SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);
|
|
63
65
|
await ConstantMerger_1.default.mergeChanges(mergeContext, itemChanges.constants);
|
|
66
|
+
await KindOfQuantityMerger_1.default.mergeChanges(mergeContext, itemChanges.kindOfQuantities);
|
|
64
67
|
// TODO: For now we just do simple copy and merging of properties and classes. For more complex types
|
|
65
68
|
// with bases classes or relationships, this might need to get extended.
|
|
66
69
|
await CAClassMerger_1.default.mergeChanges(mergeContext, itemChanges.customAttributeClasses);
|
|
67
70
|
await StructClassMerger_1.default.mergeChanges(mergeContext, itemChanges.structClasses);
|
|
68
71
|
await EntityClassMerger_1.default.mergeChanges(mergeContext, itemChanges.entityClasses);
|
|
69
72
|
await MixinMerger_1.default.mergeChanges(mergeContext, itemChanges.mixins);
|
|
73
|
+
await (0, CustomAttributeMerger_1.mergeCustomAttributes)(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {
|
|
74
|
+
return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);
|
|
75
|
+
});
|
|
70
76
|
// TODO: For now we directly manipulate the target schema. For error handing purposes, we should first
|
|
71
77
|
// merge into a temporary schema and eventually swap that with the given instance.
|
|
72
78
|
return targetSchema;
|
|
@@ -83,6 +89,7 @@ function getSchemaItemChanges(schemaChanges) {
|
|
|
83
89
|
get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Constant); },
|
|
84
90
|
get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.CustomAttributeClass); },
|
|
85
91
|
get enumeratations() { return schemaChanges.enumerationChanges.values(); },
|
|
92
|
+
get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },
|
|
86
93
|
get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Phenomenon); },
|
|
87
94
|
get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.PropertyCategory); },
|
|
88
95
|
get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.UnitSystem); },
|
|
@@ -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;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D,mDAA4C;AAC5C,2DAAoD;AACpD,qDAA+C;AAC/C,2DAAoD;AACpD,2DAAoD;AACpD,+CAAwC;
|
|
1
|
+
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D,mDAA4C;AAC5C,2DAAoD;AACpD,qDAA+C;AAC/C,2DAAoD;AACpD,2DAAoD;AACpD,+CAAwC;AACxC,mEAAgE;AAChE,iEAA0D;AAY1D;;;;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,CAAC,CAAC;QAEhE,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;IACx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iB,EAAE,kCAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjH,IAAI,aAAa,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/G,IAAI,MAAM,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACnG,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,QAAS,CAAC,CAAC,uBAAuB,CAAoC,OAA6B,EAAE,GAAG,KAAuB;IAC7H,KAAI,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YACzC,MAAM,MAAM,CAAC;SACd;KACF;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Merging\n */\n\nimport { Schema, SchemaItemType } from \"@itwin/ecschema-metadata\";\nimport { SchemaChanges, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\n\nimport mergeSchemaReferences from \"./SchemaReferenceMerger\";\nimport CAClassMerger from \"./CAClassMerger\";\nimport EnumerationMerger from \"./EnumerationMerger\";\nimport ConstantsMerger from \"./ConstantMerger\";\nimport EntityClassMerger from \"./EntityClassMerger\";\nimport StructClassMerger from \"./StructClassMerger\";\nimport MixinMerger from \"./MixinMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\nimport KindOfQuantityMerger from \"./KindOfQuantityMerger\";\n\n/**\n * Defines the context of a Schema merging run.\n * @beta\n */\nexport interface SchemaMergeContext {\n readonly targetSchema: Schema;\n readonly sourceSchema: Schema;\n readonly editor: SchemaContextEditor;\n}\n\n/**\n * Class to merge two schemas together.\n * @see [[merge]] to merge the schemas.\n * @beta\n */\nexport class SchemaMerger {\n /**\n * Gets the @see SchemaChanges between the two given Schemas from perspective of the source\n * to the target schema. For example if source contains a class which does not exists in the\n * target one, it would be listed as missing.\n * @param targetSchema The schema the differences gets merged into.\n * @param sourceSchema The schema to compare.\n * @returns An instance of @see SchemaChanges between the two schemas.\n */\n private async getSchemaChanges(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaChanges> {\n const changesList: SchemaChanges[] = [];\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\n\n // It is important to compare the schema items by name, not full name as otherwise\n // we'd often see differences when comparing two different schemas.\n await schemaComparer.compareSchemas(sourceSchema, targetSchema);\n\n return changesList[0];\n }\n\n /**\n * Copy the SchemaItems of the source schemas to the target schema.\n * @param targetSchema The schema the SchemaItems gets merged to.\n * @param sourceSchema The schema the SchemaItems gets copied from.\n * @returns The merged target schema.\n */\n public async merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\n const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);\n const mergeContext: SchemaMergeContext = {\n editor: new SchemaContextEditor(targetSchema.context),\n targetSchema,\n sourceSchema,\n };\n\n await mergeSchemaReferences(mergeContext, schemaChanges);\n\n const itemChanges = getSchemaItemChanges(schemaChanges);\n await EnumerationMerger.mergeChanges(mergeContext, itemChanges.enumeratations);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.propertyCategories);\n\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);\n await ConstantsMerger.mergeChanges(mergeContext, itemChanges.constants);\n await KindOfQuantityMerger.mergeChanges(mergeContext, itemChanges.kindOfQuantities);\n\n // TODO: For now we just do simple copy and merging of properties and classes. For more complex types\n // with bases classes or relationships, this might need to get extended.\n await CAClassMerger.mergeChanges(mergeContext, itemChanges.customAttributeClasses);\n await StructClassMerger.mergeChanges(mergeContext, itemChanges.structClasses);\n await EntityClassMerger.mergeChanges(mergeContext, itemChanges.entityClasses);\n await MixinMerger.mergeChanges(mergeContext, itemChanges.mixins);\n\n await mergeCustomAttributes(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {\n return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);\n });\n\n // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first\n // merge into a temporary schema and eventually swap that with the given instance.\n return targetSchema;\n }\n}\n\n/**\n * This helper method composes the different schema change objects to a single easier\n * to use object that should improve readability when the methods get called.\n */\nfunction getSchemaItemChanges(schemaChanges: SchemaChanges) {\n return {\n get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.EntityClass); },\n get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Constant); },\n get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.CustomAttributeClass); },\n get enumeratations() { return schemaChanges.enumerationChanges.values(); },\n get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },\n get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Phenomenon); },\n get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.PropertyCategory); },\n get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.UnitSystem); },\n get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.StructClass); },\n get mixins() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.Mixin); },\n };\n}\n\n/**\n * Filters and returns the changed items by its schema item type.\n * @param changes A map of changed schema items.\n * @param types A list of schema item types to filter.\n * @returns An Iterable with the filtered schema items.\n */\nfunction * filterChangesByItemType<TChange extends SchemaItemChanges>(changes: Map<string, TChange>, ...types: SchemaItemType[]): Iterable<TChange> {\n for(const change of changes.values()) {\n if (types.includes(change.schemaItemType)) {\n yield change;\n }\n }\n}\n"]}
|
|
@@ -47,7 +47,7 @@ export declare const DiagnosticCodes: {
|
|
|
47
47
|
IncompatibleUnitPropertyOverride: string;
|
|
48
48
|
AbstractConstraintMustNarrowBaseConstraints: string;
|
|
49
49
|
DerivedConstraintsMustNarrowBaseConstraints: string;
|
|
50
|
-
|
|
50
|
+
ConstraintClassesDeriveFromAbstractConstraint: string;
|
|
51
51
|
AtLeastOneConstraintClassDefined: string;
|
|
52
52
|
AbstractConstraintMustExistWithMultipleConstraints: string;
|
|
53
53
|
};
|
|
@@ -317,7 +317,7 @@ export declare const Diagnostics: {
|
|
|
317
317
|
diagnosticType: import("./Diagnostic").DiagnosticType;
|
|
318
318
|
};
|
|
319
319
|
/** EC-1502: Required message parameters: constraint class name, relationship end (source/target), relationship name, abstract constraint class name */
|
|
320
|
-
|
|
320
|
+
ConstraintClassesDeriveFromAbstractConstraint: {
|
|
321
321
|
new (ecDefinition: import("@itwin/ecschema-metadata").SchemaItem, messageArgs: [string, string, string, string], category?: import("./Diagnostic").DiagnosticCategory): {
|
|
322
322
|
readonly code: string;
|
|
323
323
|
readonly messageText: string;
|
|
@@ -401,6 +401,11 @@ export declare function incompatibleUnitPropertyOverride(property: AnyProperty):
|
|
|
401
401
|
* @internal
|
|
402
402
|
*/
|
|
403
403
|
export declare function validateNavigationProperty(property: AnyProperty): AsyncIterable<PropertyDiagnostic<any[]>>;
|
|
404
|
+
/**
|
|
405
|
+
* Validates a Relationship class and yields EC-1500, EC-1501, and EC-1502 rule violations.
|
|
406
|
+
* @internal
|
|
407
|
+
*/
|
|
408
|
+
export declare function validateRelationship(ecClass: RelationshipClass): AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>>;
|
|
404
409
|
/**
|
|
405
410
|
* EC Rule: When overriding a RelationshipClass, the derived abstract constraint must narrow the base constraint classes.
|
|
406
411
|
* @internal
|
|
@@ -415,7 +420,12 @@ export declare function derivedConstraintsMustNarrowBaseConstraints(ecClass: Rel
|
|
|
415
420
|
* EC Rule: All constraint classes must have a common base class specified in the abstract constraint.
|
|
416
421
|
* @internal
|
|
417
422
|
*/
|
|
418
|
-
export declare function
|
|
423
|
+
export declare function constraintClassesDeriveFromAbstractConstraint(ecClass: RelationshipClass): AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>>;
|
|
424
|
+
/**
|
|
425
|
+
* Validates a RelationshipConstraint and yields EC-1600 and EC-1601 rule violations.
|
|
426
|
+
* @internal
|
|
427
|
+
*/
|
|
428
|
+
export declare function validateRelationshipConstraint(constraint: RelationshipConstraint): AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;
|
|
419
429
|
/**
|
|
420
430
|
* EC Rule: At least on concrete constraint class must be defined in the list of constraint classes.
|
|
421
431
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECRules.d.ts","sourceRoot":"","sources":["../../../src/Validation/ECRules.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,6BAA6B,EAClD,WAAW,EAAE,WAAW,EACjC,iBAAiB,EAAE,sBAAsB,EAA4B,MAAM,EAEtF,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EAC4F,kCAAkC,EAC7I,kBAAkB,EAAE,gCAAgC,EAAE,gBAAgB,EAAE,oBAAoB,EAC7F,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;CA+B3B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW;IACtB,+EAA+E;;;;;;;;;;;;;;IAI/E,2IAA2I;;;;;;;;;;;;;;IAI3I,mEAAmE;;;;;;;;;;;;;;IAIn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,gCAAgC,CAAC,GAAG,EAAE,CAAC,CAAC,CAGhJ;AAED;;;GAGG;AACH,wBAAuB,gCAAgC,CAAC,UAAU,EAAE,sBAAsB,GAAG,aAAa,CAAC,gCAAgC,CAAC,GAAG,EAAE,CAAC,CAAC,CAKlJ;AAED;;;GAGG;AACH,wBAAuB,kDAAkD,CAAC,UAAU,EAAE,sBAAsB,GAAG,aAAa,CAAC,gCAAgC,CAAC,GAAG,EAAE,CAAC,CAAC,CAWpK;AAaD;;;GAGG;AACH,wBAAuB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,CAMnI;AAED;;;GAGG;AACH,wBAAuB,2CAA2C,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,CAWpJ;AAED;;;GAGG;AACH,wBAAuB,+BAA+B,CAAC,SAAS,EAAE,6BAA6B,EAAE,eAAe,EAAE,eAAe,GAAG,aAAa,CAAC,kCAAkC,CAAC,GAAG,EAAE,CAAC,CAAC,CAI3L"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module Validation
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.validateCustomAttributeInstance = exports.mixinAppliedToClassMustDeriveFromConstraint = exports.enumerationTypeUnsupported = exports.abstractConstraintMustExistWithMultipleConstraints = exports.atLeastOneConstraintClassDefined = exports.
|
|
10
|
+
exports.validateCustomAttributeInstance = exports.mixinAppliedToClassMustDeriveFromConstraint = exports.enumerationTypeUnsupported = exports.abstractConstraintMustExistWithMultipleConstraints = exports.atLeastOneConstraintClassDefined = exports.validateRelationshipConstraint = exports.constraintClassesDeriveFromAbstractConstraint = exports.derivedConstraintsMustNarrowBaseConstraints = exports.abstractConstraintMustNarrowBaseConstraints = exports.validateRelationship = exports.validateNavigationProperty = exports.incompatibleUnitPropertyOverride = exports.incompatibleTypePropertyOverride = exports.incompatibleValueTypePropertyOverride = exports.baseClassIsOfDifferentType = exports.baseClassIsSealed = exports.validateSchemaReferencesSync = exports.validateSchemaReferences = exports.ECRuleSet = exports.Diagnostics = exports.DiagnosticCodes = void 0;
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
12
|
const Diagnostic_1 = require("./Diagnostic");
|
|
13
13
|
const ruleSetName = "ECObjects";
|
|
@@ -65,7 +65,7 @@ exports.DiagnosticCodes = {
|
|
|
65
65
|
// Relationship Rule Codes (1500-1599)
|
|
66
66
|
AbstractConstraintMustNarrowBaseConstraints: getCode(1500),
|
|
67
67
|
DerivedConstraintsMustNarrowBaseConstraints: getCode(1501),
|
|
68
|
-
|
|
68
|
+
ConstraintClassesDeriveFromAbstractConstraint: getCode(1502),
|
|
69
69
|
// Relationship Constraint Rule Codes (1600-1699)
|
|
70
70
|
AtLeastOneConstraintClassDefined: getCode(1600),
|
|
71
71
|
AbstractConstraintMustExistWithMultipleConstraints: getCode(1601),
|
|
@@ -116,7 +116,7 @@ exports.Diagnostics = {
|
|
|
116
116
|
/** EC-1501: Required message parameters: constraint class name, relationship end (source/target), relationship name, base relationship name */
|
|
117
117
|
DerivedConstraintsMustNarrowBaseConstraints: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.DerivedConstraintsMustNarrowBaseConstraints, "The constraint class '{0}' on the {1}-Constraint of '{2}' is not supported by the base class constraint in '{3}'."),
|
|
118
118
|
/** EC-1502: Required message parameters: constraint class name, relationship end (source/target), relationship name, abstract constraint class name */
|
|
119
|
-
|
|
119
|
+
ConstraintClassesDeriveFromAbstractConstraint: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.ConstraintClassesDeriveFromAbstractConstraint, "The constraint class '{0}' on the {1}-Constraint of '{2}' is not derived from the abstract constraint class '{3}'."),
|
|
120
120
|
/** EC-1600: Required message parameters: relationship end (source/target), relationship name */
|
|
121
121
|
AtLeastOneConstraintClassDefined: (0, Diagnostic_1.createRelationshipConstraintDiagnosticClass)(exports.DiagnosticCodes.AtLeastOneConstraintClassDefined, "The {0}-Constraint of '{1}' does not contain any constraint classes."),
|
|
122
122
|
/** EC-1601: Required message parameters: relationship end (source/target), relationship name */
|
|
@@ -143,7 +143,7 @@ exports.ECRuleSet = {
|
|
|
143
143
|
],
|
|
144
144
|
relationshipRules: [
|
|
145
145
|
abstractConstraintMustNarrowBaseConstraints,
|
|
146
|
-
|
|
146
|
+
constraintClassesDeriveFromAbstractConstraint,
|
|
147
147
|
derivedConstraintsMustNarrowBaseConstraints,
|
|
148
148
|
],
|
|
149
149
|
relationshipConstraintRules: [
|
|
@@ -380,6 +380,16 @@ async function* validateNavigationProperty(property) {
|
|
|
380
380
|
return;
|
|
381
381
|
}
|
|
382
382
|
exports.validateNavigationProperty = validateNavigationProperty;
|
|
383
|
+
/**
|
|
384
|
+
* Validates a Relationship class and yields EC-1500, EC-1501, and EC-1502 rule violations.
|
|
385
|
+
* @internal
|
|
386
|
+
*/
|
|
387
|
+
async function* validateRelationship(ecClass) {
|
|
388
|
+
yield* abstractConstraintMustNarrowBaseConstraints(ecClass);
|
|
389
|
+
yield* derivedConstraintsMustNarrowBaseConstraints(ecClass);
|
|
390
|
+
yield* constraintClassesDeriveFromAbstractConstraint(ecClass);
|
|
391
|
+
}
|
|
392
|
+
exports.validateRelationship = validateRelationship;
|
|
383
393
|
/**
|
|
384
394
|
* EC Rule: When overriding a RelationshipClass, the derived abstract constraint must narrow the base constraint classes.
|
|
385
395
|
* @internal
|
|
@@ -416,15 +426,24 @@ exports.derivedConstraintsMustNarrowBaseConstraints = derivedConstraintsMustNarr
|
|
|
416
426
|
* EC Rule: All constraint classes must have a common base class specified in the abstract constraint.
|
|
417
427
|
* @internal
|
|
418
428
|
*/
|
|
419
|
-
async function*
|
|
420
|
-
const sourceResult = await
|
|
429
|
+
async function* constraintClassesDeriveFromAbstractConstraint(ecClass) {
|
|
430
|
+
const sourceResult = await applyConstraintClassesDeriveFromAbstractConstraint(ecClass, ecClass.source);
|
|
421
431
|
if (sourceResult)
|
|
422
432
|
yield sourceResult;
|
|
423
|
-
const targetResult = await
|
|
433
|
+
const targetResult = await applyConstraintClassesDeriveFromAbstractConstraint(ecClass, ecClass.target);
|
|
424
434
|
if (targetResult)
|
|
425
435
|
yield targetResult;
|
|
426
436
|
}
|
|
427
|
-
exports.
|
|
437
|
+
exports.constraintClassesDeriveFromAbstractConstraint = constraintClassesDeriveFromAbstractConstraint;
|
|
438
|
+
/**
|
|
439
|
+
* Validates a RelationshipConstraint and yields EC-1600 and EC-1601 rule violations.
|
|
440
|
+
* @internal
|
|
441
|
+
*/
|
|
442
|
+
async function* validateRelationshipConstraint(constraint) {
|
|
443
|
+
yield* atLeastOneConstraintClassDefined(constraint);
|
|
444
|
+
yield* abstractConstraintMustExistWithMultipleConstraints(constraint);
|
|
445
|
+
}
|
|
446
|
+
exports.validateRelationshipConstraint = validateRelationshipConstraint;
|
|
428
447
|
/**
|
|
429
448
|
* EC Rule: At least on concrete constraint class must be defined in the list of constraint classes.
|
|
430
449
|
* @internal
|
|
@@ -545,7 +564,7 @@ async function applyDerivedConstraintsMustNarrowBaseConstraints(ecClass, constra
|
|
|
545
564
|
}
|
|
546
565
|
return;
|
|
547
566
|
}
|
|
548
|
-
async function
|
|
567
|
+
async function applyConstraintClassesDeriveFromAbstractConstraint(ecClass, constraint) {
|
|
549
568
|
const abstractConstraint = await getAbstractConstraint(constraint);
|
|
550
569
|
if (!abstractConstraint)
|
|
551
570
|
return;
|
|
@@ -556,13 +575,13 @@ async function applyConstraintClassesDeriveFromAbstractContraint(ecClass, constr
|
|
|
556
575
|
if (constraintClass.schemaItemType === ecschema_metadata_1.SchemaItemType.Mixin && abstractConstraint.schemaItemType === ecschema_metadata_1.SchemaItemType.EntityClass) {
|
|
557
576
|
if (!await (constraintClass).applicableTo(abstractConstraint)) {
|
|
558
577
|
const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
|
|
559
|
-
return new exports.Diagnostics.
|
|
578
|
+
return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractConstraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
|
|
560
579
|
}
|
|
561
580
|
continue;
|
|
562
581
|
}
|
|
563
582
|
if (!await constraintClass.is(abstractConstraint)) {
|
|
564
583
|
const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
|
|
565
|
-
return new exports.Diagnostics.
|
|
584
|
+
return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractConstraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
|
|
566
585
|
}
|
|
567
586
|
}
|
|
568
587
|
return;
|