@itwin/ecschema-editing 4.3.0-dev.0 → 4.3.0-dev.10
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 +21 -1
- package/lib/cjs/Editing/Editor.d.ts +3 -0
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +3 -0
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.d.ts +2 -0
- package/lib/cjs/Editing/Enumerations.d.ts.map +1 -1
- package/lib/cjs/Editing/Enumerations.js +22 -0
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.d.ts +15 -0
- package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -0
- package/lib/cjs/Editing/SchemaItems.js +28 -0
- package/lib/cjs/Editing/SchemaItems.js.map +1 -0
- package/lib/cjs/Merging/CAClassMerger.d.ts +8 -2
- package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +12 -20
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +7 -2
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +41 -45
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.d.ts +7 -7
- package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js +37 -46
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.d.ts +8 -7
- package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +38 -67
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemFactory.d.ts +9 -2
- package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemFactory.js +45 -11
- package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +49 -20
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +76 -71
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts +2 -0
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +29 -21
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.js +8 -10
- package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
- package/package.json +9 -9
- package/lib/cjs/Merging/PhenomenonMerger.d.ts +0 -7
- package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/PhenomenonMerger.js +0 -16
- package/lib/cjs/Merging/PhenomenonMerger.js.map +0 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.d.ts +0 -7
- package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.js +0 -16
- package/lib/cjs/Merging/PropertyCategoryMerger.js.map +0 -1
|
@@ -1,56 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
|
-
*--------------------------------------------------------------------------------------------*/
|
|
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
7
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
8
8
|
const SchemaItemMerger_1 = require("./SchemaItemMerger");
|
|
9
9
|
/**
|
|
10
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
11
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
return
|
|
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);
|
|
12
|
+
class ConstantsMerger extends SchemaItemMerger_1.SchemaItemMerger {
|
|
13
|
+
/**
|
|
14
|
+
* Creates the property value resolver for [[Constant]] items.
|
|
15
|
+
*/
|
|
16
|
+
async createPropertyValueResolver() {
|
|
17
|
+
return {
|
|
18
|
+
phenomenon: (phenomenonFullName, targetItemKey) => {
|
|
19
|
+
// There are two options, either the phenomenon was referenced from another
|
|
20
|
+
// schema or it is defined in the same schema as the constant to be merged.
|
|
21
|
+
// In the latter case, the changes would report a different property value that
|
|
22
|
+
// refers to the source schema. So that needs to be changed here.
|
|
23
|
+
const [schemaName, phenomenonName] = ecschema_metadata_1.SchemaItem.parseFullName(phenomenonFullName);
|
|
24
|
+
if (this.context.targetSchema.getReferenceSync(schemaName) === undefined) {
|
|
25
|
+
return `${targetItemKey.schemaName}.${phenomenonName}`;
|
|
50
26
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
27
|
+
return phenomenonFullName;
|
|
28
|
+
},
|
|
29
|
+
numerator: (value, targetItemKey) => {
|
|
30
|
+
const item = this.context.targetSchema.lookupItemSync(targetItemKey);
|
|
31
|
+
if (item !== undefined && item.hasNumerator && item.numerator !== value) {
|
|
32
|
+
throw new Error(`Failed to merged, constant numerator conflict: ${value} -> ${item.numerator}`);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
},
|
|
36
|
+
denominator: (value, targetItemKey) => {
|
|
37
|
+
const item = this.context.targetSchema.lookupItemSync(targetItemKey);
|
|
38
|
+
if (item !== undefined && item.hasDenominator && item.denominator !== value) {
|
|
39
|
+
throw new Error(`Failed to merged, constant denominator conflict: ${value} -> ${item.denominator}`);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
54
45
|
}
|
|
55
|
-
exports.default =
|
|
46
|
+
exports.default = ConstantsMerger;
|
|
56
47
|
//# sourceMappingURL=ConstantMerger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConstantMerger.js","sourceRoot":"","sources":["../../../src/Merging/ConstantMerger.ts"],"names":[],"mappings":";;AAAA
|
|
1
|
+
{"version":3,"file":"ConstantMerger.js","sourceRoot":"","sources":["../../../src/Merging/ConstantMerger.ts"],"names":[],"mappings":";;AAAA,kGAAkG;AAClG,sEAAsE;AACtE,oFAAoF;AACpF,kGAAkG;AAClG,gEAAgE;AAChE,yDAA6E;AAE7E;;GAEG;AACH,MAAqB,eAAgB,SAAQ,mCAA0B;IACrE;;OAEG;IACgB,KAAK,CAAC,2BAA2B;QAClD,OAAO;YACL,UAAU,EAAE,CAAC,kBAAkB,EAAE,aAAa,EAAE,EAAE;gBAChD,2EAA2E;gBAC3E,2EAA2E;gBAC3E,+EAA+E;gBAC/E,iEAAiE;gBACjE,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,8BAAU,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBAClF,IAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE;oBACvE,OAAO,GAAG,aAAa,CAAC,UAAU,IAAI,cAAc,EAAE,CAAC;iBACxD;gBACD,OAAO,kBAAkB,CAAC;YAC5B,CAAC;YACD,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAW,aAAa,CAAC,CAAC;gBAC/E,IAAG,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE;oBACtE,MAAM,IAAI,KAAK,CAAC,kDAAkD,KAAK,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;iBACjG;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,WAAW,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;gBACpC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAW,aAAa,CAAC,CAAC;gBAC/E,IAAG,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,KAAK,KAAK,EAAE;oBAC1E,MAAM,IAAI,KAAK,CAAC,oDAAoD,KAAK,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;iBACrG;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAjCD,kCAiCC","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, SchemaItem } from \"@itwin/ecschema-metadata\";\r\nimport { PropertyValueResolver, SchemaItemMerger } from \"./SchemaItemMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class ConstantsMerger extends SchemaItemMerger<Constant> {\r\n /**\r\n * Creates the property value resolver for [[Constant]] items.\r\n */\r\n protected override async createPropertyValueResolver(): Promise<PropertyValueResolver<Constant>> {\r\n return {\r\n phenomenon: (phenomenonFullName, targetItemKey) => {\r\n // There are two options, either the phenomenon was referenced from another\r\n // schema or it is defined in the same schema as the constant to be merged.\r\n // In the latter case, the changes would report a different property value that\r\n // refers to the source schema. So that needs to be changed here.\r\n const [schemaName, phenomenonName] = SchemaItem.parseFullName(phenomenonFullName);\r\n if(this.context.targetSchema.getReferenceSync(schemaName) === undefined) {\r\n return `${targetItemKey.schemaName}.${phenomenonName}`;\r\n }\r\n return phenomenonFullName;\r\n },\r\n numerator: (value, targetItemKey) => {\r\n const item = this.context.targetSchema.lookupItemSync<Constant>(targetItemKey);\r\n if(item !== undefined && item.hasNumerator && item.numerator !== value) {\r\n throw new Error(`Failed to merged, constant numerator conflict: ${value} -> ${item.numerator}`);\r\n }\r\n return value;\r\n },\r\n denominator: (value, targetItemKey) => {\r\n const item = this.context.targetSchema.lookupItemSync<Constant>(targetItemKey);\r\n if(item !== undefined && item.hasDenominator && item.denominator !== value) {\r\n throw new Error(`Failed to merged, constant denominator conflict: ${value} -> ${item.denominator}`);\r\n }\r\n return value;\r\n },\r\n };\r\n }\r\n}\r\n\r\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Enumeration } from "@itwin/ecschema-metadata";
|
|
1
|
+
import { Enumeration, SchemaItemKey } from "@itwin/ecschema-metadata";
|
|
2
2
|
import { EnumerationChanges } from "../Validation/SchemaChanges";
|
|
3
|
+
import { SchemaItemMerger } from "./SchemaItemMerger";
|
|
3
4
|
/**
|
|
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.
|
|
9
5
|
* @internal
|
|
10
6
|
*/
|
|
11
|
-
export default
|
|
7
|
+
export default class EnumerationMerger extends SchemaItemMerger<Enumeration> {
|
|
8
|
+
/** Shorthand property to the enumerations editor. */
|
|
9
|
+
private get _editor();
|
|
10
|
+
protected merge(itemKey: SchemaItemKey, source: Enumeration, changes: EnumerationChanges): Promise<void>;
|
|
11
|
+
private mergeEnumeratorChanges;
|
|
12
|
+
}
|
|
12
13
|
//# sourceMappingURL=EnumerationMerger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumerationMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,WAAW,
|
|
1
|
+
{"version":3,"file":"EnumerationMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,WAAW,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAc,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,gBAAgB,CAAC,WAAW,CAAC;IAE1E,qDAAqD;IACrD,OAAO,KAAK,OAAO,GAElB;cAEwB,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB;YA6BzF,sBAAsB;CAgBrC"}
|
|
@@ -1,83 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
3
|
const SchemaChanges_1 = require("../Validation/SchemaChanges");
|
|
9
4
|
const SchemaItemMerger_1 = require("./SchemaItemMerger");
|
|
10
5
|
/**
|
|
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.
|
|
16
6
|
* @internal
|
|
17
7
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
class EnumerationMerger extends SchemaItemMerger_1.SchemaItemMerger {
|
|
9
|
+
/** Shorthand property to the enumerations editor. */
|
|
10
|
+
get _editor() {
|
|
11
|
+
return this.context.editor.enumerations;
|
|
12
|
+
}
|
|
13
|
+
async merge(itemKey, source, changes) {
|
|
14
|
+
for (const enumeratorChange of changes.enumeratorChanges.values()) {
|
|
15
|
+
// In case the enumerator entry does not exist in the target enumeration the
|
|
16
|
+
// enumeratorMissing property is set and
|
|
17
|
+
if (enumeratorChange.enumeratorMissing?.changeType === SchemaChanges_1.ChangeType.Missing) {
|
|
18
|
+
const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);
|
|
19
|
+
if (enumerator === undefined) {
|
|
20
|
+
throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in class ${source.fullName}`);
|
|
27
21
|
}
|
|
22
|
+
// Enumerators are plain javascript objects with out any references to other
|
|
23
|
+
// instances or a schema. That allows to simply copy them over.
|
|
24
|
+
await this._editor.addEnumerator(itemKey, enumerator);
|
|
25
|
+
// Since every missing enumerator has delta changes for ech property, the loop
|
|
26
|
+
// must call continue here to avoid having all properties checked and set again.
|
|
27
|
+
continue;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (enumerator === undefined) {
|
|
35
|
-
throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in Enumeration ${source.fullName}`);
|
|
36
|
-
}
|
|
37
|
-
const result = mutableEnumeration.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description);
|
|
38
|
-
mutableEnumeration.addEnumerator(result);
|
|
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}`);
|
|
29
|
+
// For changes where the enumerators differ, the enumeratorDeltas property is
|
|
30
|
+
// filled. This allows to change individual enumerator entries. This is only
|
|
31
|
+
// allowed for labels and descriptions, all other deltas would throw an error.
|
|
32
|
+
for (const enumeratorDelta of enumeratorChange.enumeratorDeltas) {
|
|
33
|
+
await this.mergeEnumeratorChanges(itemKey, enumeratorDelta.diagnostic.messageArgs);
|
|
44
34
|
}
|
|
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
35
|
}
|
|
62
36
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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;
|
|
37
|
+
async mergeEnumeratorChanges(itemKey, [enumerator, propertyName, value]) {
|
|
38
|
+
// In case an enumerator has the same name but different value, the enumerator
|
|
39
|
+
// cannot be merged to keep integrity for the existing schema users.
|
|
40
|
+
if (propertyName === "value") {
|
|
41
|
+
throw new Error(`Failed to merge enumerator attribute, Enumerator "${enumerator.name}" has different values.`);
|
|
42
|
+
}
|
|
43
|
+
// For the other two properties they shall only be merged if the source value is
|
|
44
|
+
// set. In case they'd be undefined, the current enumerators value shall be kept.
|
|
45
|
+
if (propertyName === "label" && value !== undefined) {
|
|
46
|
+
await this._editor.setEnumeratorLabel(itemKey, enumerator.name, value);
|
|
47
|
+
}
|
|
48
|
+
if (propertyName === "description" && value !== undefined) {
|
|
49
|
+
await this._editor.setEnumeratorDescription(itemKey, enumerator.name, value);
|
|
80
50
|
}
|
|
81
51
|
}
|
|
82
52
|
}
|
|
53
|
+
exports.default = EnumerationMerger;
|
|
83
54
|
//# sourceMappingURL=EnumerationMerger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;AAKA,+DAA6E;AAC7E,yDAAsD;AAItD;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,mCAA6B;IAE1E,qDAAqD;IACrD,IAAY,OAAO;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IAC1C,CAAC;IAEkB,KAAK,CAAC,KAAK,CAAC,OAAsB,EAAE,MAAmB,EAAE,OAA2B;QACrG,KAAK,MAAM,gBAAgB,IAAI,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,EAAE;YACjE,4EAA4E;YAC5E,wCAAwC;YACxC,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAEzE,MAAM,UAAU,GAAG,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;gBAC3E,IAAI,UAAU,KAAK,SAAS,EAAE;oBAC5B,MAAM,KAAK,CAAC,eAAe,gBAAgB,CAAC,UAAU,wBAAwB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAClG;gBAED,4EAA4E;gBAC5E,+DAA+D;gBAC/D,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBAEtD,8EAA8E;gBAC9E,gFAAgF;gBAChF,SAAS;aACV;YAED,6EAA6E;YAC7E,4EAA4E;YAC5E,8EAA8E;YAC9E,KAAI,MAAM,eAAe,IAAI,gBAAgB,CAAC,gBAAgB,EAAE;gBAC9D,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,EAAE,eAAe,CAAC,UAAU,CAAC,WAAmC,CAAC,CAAC;aAC5G;SACF;IACH,CAAC;IAEO,KAAK,CAAC,sBAAsB,CAAC,OAAsB,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,CAAsB;QACjH,8EAA8E;QAC9E,oEAAoE;QACpE,IAAG,YAAY,KAAK,OAAO,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,UAAU,CAAC,IAAI,yBAAyB,CAAC,CAAC;SAChH;QAED,gFAAgF;QAChF,iFAAiF;QACjF,IAAG,YAAY,KAAK,OAAO,IAAI,KAAK,KAAK,SAAS,EAAE;YAClD,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SACxE;QACD,IAAG,YAAY,KAAK,aAAa,IAAI,KAAK,KAAK,SAAS,EAAE;YACxD,MAAM,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SAC9E;IACH,CAAC;CACF;AApDD,oCAoDC","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, SchemaItemKey} from \"@itwin/ecschema-metadata\";\r\nimport { ChangeType, EnumerationChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\r\n\r\ntype EnumeratorDeltaArgs = [AnyEnumerator, keyof AnyEnumerator, string | undefined];\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class EnumerationMerger extends SchemaItemMerger<Enumeration> {\r\n\r\n /** Shorthand property to the enumerations editor. */\r\n private get _editor() {\r\n return this.context.editor.enumerations;\r\n }\r\n\r\n protected override async merge(itemKey: SchemaItemKey, source: Enumeration, changes: EnumerationChanges) {\r\n for (const enumeratorChange of changes.enumeratorChanges.values()) {\r\n // In case the enumerator entry does not exist in the target enumeration the\r\n // enumeratorMissing property is set and\r\n if (enumeratorChange.enumeratorMissing?.changeType === ChangeType.Missing) {\r\n\r\n const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);\r\n if (enumerator === undefined) {\r\n throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in class ${source.fullName}`);\r\n }\r\n\r\n // Enumerators are plain javascript objects with out any references to other\r\n // instances or a schema. That allows to simply copy them over.\r\n await this._editor.addEnumerator(itemKey, enumerator);\r\n\r\n // Since every missing enumerator has delta changes for ech property, the loop\r\n // must call continue here to avoid having all properties checked and set again.\r\n continue;\r\n }\r\n\r\n // For changes where the enumerators differ, the enumeratorDeltas property is\r\n // filled. This allows to change individual enumerator entries. This is only\r\n // allowed for labels and descriptions, all other deltas would throw an error.\r\n for(const enumeratorDelta of enumeratorChange.enumeratorDeltas) {\r\n await this.mergeEnumeratorChanges(itemKey, enumeratorDelta.diagnostic.messageArgs! as EnumeratorDeltaArgs);\r\n }\r\n }\r\n }\r\n\r\n private async mergeEnumeratorChanges(itemKey: SchemaItemKey, [enumerator, propertyName, value]: EnumeratorDeltaArgs) {\r\n // In case an enumerator has the same name but different value, the enumerator\r\n // cannot be merged to keep integrity for the existing schema users.\r\n if(propertyName === \"value\") {\r\n throw new Error(`Failed to merge enumerator attribute, Enumerator \"${enumerator.name}\" has different values.`);\r\n }\r\n\r\n // For the other two properties they shall only be merged if the source value is\r\n // set. In case they'd be undefined, the current enumerators value shall be kept.\r\n if(propertyName === \"label\" && value !== undefined) {\r\n await this._editor.setEnumeratorLabel(itemKey, enumerator.name, value);\r\n }\r\n if(propertyName === \"description\" && value !== undefined) {\r\n await this._editor.setEnumeratorDescription(itemKey, enumerator.name, value);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaItem, SchemaItemKey } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { SchemaMergeContext } from "./SchemaMerger";
|
|
2
3
|
/**
|
|
3
4
|
* @internal
|
|
4
5
|
*/
|
|
5
6
|
export declare namespace SchemaItemFactory {
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new Schema Item based on the given template instance.
|
|
9
|
+
* @param context The current merging context.
|
|
10
|
+
* @param template The Schema Items Template
|
|
11
|
+
* @returns The SchemaItemKey of the created item.
|
|
12
|
+
*/
|
|
13
|
+
function create(context: SchemaMergeContext, template: SchemaItem): Promise<SchemaItemKey>;
|
|
7
14
|
}
|
|
8
15
|
//# sourceMappingURL=SchemaItemFactory.d.ts.map
|
|
@@ -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,EAAyG,UAAU,EAAE,aAAa,EAAsC,MAAM,0BAA0B,CAAC;AAEhN,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;CAgDF"}
|
|
@@ -11,26 +11,60 @@ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
|
11
11
|
*/
|
|
12
12
|
var SchemaItemFactory;
|
|
13
13
|
(function (SchemaItemFactory) {
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new Schema Item based on the given template instance.
|
|
16
|
+
* @param context The current merging context.
|
|
17
|
+
* @param template The Schema Items Template
|
|
18
|
+
* @returns The SchemaItemKey of the created item.
|
|
19
|
+
*/
|
|
20
|
+
async function create(context, template) {
|
|
21
|
+
const result = await createItem(context.editor, context.targetSchema.schemaKey, template);
|
|
22
|
+
if (result.errorMessage) {
|
|
23
|
+
throw new Error(result.errorMessage);
|
|
24
|
+
}
|
|
25
|
+
return result.itemKey;
|
|
26
|
+
}
|
|
27
|
+
SchemaItemFactory.create = create;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new Schema Item in the SchemaContextEditor.
|
|
30
|
+
* @param editor The SchemaContextEditor
|
|
31
|
+
* @param targetSchemaKey The key of the target schema the item shall be created in.
|
|
32
|
+
* @param template The Schema Items Template
|
|
33
|
+
* @returns A SchemaItemEditResults with a schema key if the item could be created.
|
|
34
|
+
*/
|
|
35
|
+
async function createItem(editor, targetSchemaKey, template) {
|
|
15
36
|
if (is(template, ecschema_metadata_1.Enumeration))
|
|
16
|
-
return
|
|
37
|
+
return editor.enumerations.create(targetSchemaKey, template.name, template.isInt ? ecschema_metadata_1.PrimitiveType.Integer : ecschema_metadata_1.PrimitiveType.String, template.label, template.isStrict);
|
|
17
38
|
if (is(template, ecschema_metadata_1.EntityClass))
|
|
18
|
-
return
|
|
39
|
+
return editor.entities.create(targetSchemaKey, template.name, template.modifier);
|
|
19
40
|
if (is(template, ecschema_metadata_1.StructClass))
|
|
20
|
-
return
|
|
41
|
+
return editor.structs.create(targetSchemaKey, template.name);
|
|
21
42
|
if (is(template, ecschema_metadata_1.CustomAttributeClass))
|
|
22
|
-
return
|
|
43
|
+
return editor.customAttributes.create(targetSchemaKey, template.name, template.containerType);
|
|
23
44
|
if (is(template, ecschema_metadata_1.PropertyCategory))
|
|
24
|
-
return
|
|
45
|
+
return editor.propertyCategories.create(targetSchemaKey, template.name, template.priority);
|
|
25
46
|
if (is(template, ecschema_metadata_1.Phenomenon))
|
|
26
|
-
return
|
|
27
|
-
if (is(template, ecschema_metadata_1.Constant))
|
|
28
|
-
|
|
47
|
+
return editor.phenomenons.create(targetSchemaKey, template.name, template.definition);
|
|
48
|
+
if (is(template, ecschema_metadata_1.Constant)) {
|
|
49
|
+
if (template.phenomenon === undefined) {
|
|
50
|
+
throw new Error(`Invalid Constant ${template.name} has no phenomenon defined`);
|
|
51
|
+
}
|
|
52
|
+
const phenomenon = await template.phenomenon;
|
|
53
|
+
const itemKey = phenomenon.key.schemaKey.matches(template.key.schemaKey)
|
|
54
|
+
? new ecschema_metadata_1.SchemaItemKey(phenomenon.name, targetSchemaKey)
|
|
55
|
+
: phenomenon.key;
|
|
56
|
+
return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);
|
|
57
|
+
}
|
|
29
58
|
if (is(template, ecschema_metadata_1.UnitSystem))
|
|
30
|
-
return
|
|
59
|
+
return editor.unitSystems.create(targetSchemaKey, template.name);
|
|
31
60
|
throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);
|
|
32
61
|
}
|
|
33
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Type Guard to "cast" a given schema item into an implementation
|
|
64
|
+
* @param item Item to be checked
|
|
65
|
+
* @param type The desired implementation.
|
|
66
|
+
* @returns true if the item could be casted, otherwise false.
|
|
67
|
+
*/
|
|
34
68
|
function is(item, type) {
|
|
35
69
|
return item instanceof type;
|
|
36
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging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AAQ,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,EA9DgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QA8DjC","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, PrimitiveType, PropertyCategory, SchemaItem, SchemaItemKey, SchemaKey, StructClass, UnitSystem } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport namespace SchemaItemFactory {\r\n\r\n /**\r\n * Creates a new Schema Item based on the given template instance.\r\n * @param context The current merging context.\r\n * @param template The Schema Items Template\r\n * @returns The SchemaItemKey of the created item.\r\n */\r\n export async function create(context: SchemaMergeContext, template: SchemaItem): Promise<SchemaItemKey> {\r\n const result = await createItem(context.editor, context.targetSchema.schemaKey, template);\r\n if(result.errorMessage) {\r\n throw new Error(result.errorMessage);\r\n }\r\n return result.itemKey!;\r\n }\r\n\r\n /**\r\n * Creates a new Schema Item in the SchemaContextEditor.\r\n * @param editor The SchemaContextEditor\r\n * @param targetSchemaKey The key of the target schema the item shall be created in.\r\n * @param template The Schema Items Template\r\n * @returns A SchemaItemEditResults with a schema key if the item could be created.\r\n */\r\n async function createItem(editor: SchemaContextEditor, targetSchemaKey: SchemaKey, template: SchemaItem): Promise<SchemaItemEditResults> {\r\n if (is(template, Enumeration))\r\n return editor.enumerations.create(targetSchemaKey, template.name, template.isInt ? PrimitiveType.Integer : PrimitiveType.String, template.label, template.isStrict);\r\n if (is(template, EntityClass))\r\n return editor.entities.create(targetSchemaKey, template.name, template.modifier);\r\n if (is(template, StructClass))\r\n return editor.structs.create(targetSchemaKey, template.name);\r\n if (is(template, CustomAttributeClass))\r\n return editor.customAttributes.create(targetSchemaKey, template.name, template.containerType);\r\n if(is(template, PropertyCategory))\r\n return editor.propertyCategories.create(targetSchemaKey, template.name, template.priority);\r\n if (is(template, Phenomenon))\r\n return editor.phenomenons.create(targetSchemaKey, template.name, template.definition);\r\n if (is(template, Constant)) {\r\n if(template.phenomenon === undefined) {\r\n throw new Error(`Invalid Constant ${template.name} has no phenomenon defined`);\r\n }\r\n const phenomenon = await template.phenomenon;\r\n const itemKey = phenomenon.key.schemaKey.matches(template.key.schemaKey)\r\n ? new SchemaItemKey(phenomenon.name, targetSchemaKey)\r\n : phenomenon.key;\r\n\r\n return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);\r\n }\r\n if (is(template, UnitSystem))\r\n return editor.unitSystems.create(targetSchemaKey, template.name);\r\n\r\n throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);\r\n }\r\n\r\n /**\r\n * Type Guard to \"cast\" a given schema item into an implementation\r\n * @param item Item to be checked\r\n * @param type The desired implementation.\r\n * @returns true if the item could be casted, otherwise false.\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,31 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SchemaItem, SchemaItemKey } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { SchemaItemChanges } from "../Validation/SchemaChanges";
|
|
3
3
|
import { SchemaMergeContext } from "./SchemaMerger";
|
|
4
|
-
type SchemaItemMergeFn<TChange extends SchemaItemChanges, TItem extends SchemaItem> = (target: TItem, source: TItem, change: TChange, context: SchemaMergeContext) => Promise<void>;
|
|
5
|
-
type PropertyChangedFn<TItem extends SchemaItem> = (item: TItem, propertyName: string, propertyValue: any) => void | boolean;
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
* and handles the basic processing such as create-if-not-exists or name collisions or base property setting.
|
|
9
|
-
* @param context The current merge context
|
|
10
|
-
* @param schemaItemChanges The schema items to be merged
|
|
11
|
-
* @param mergeFn Merge function for complex merging.
|
|
5
|
+
* Defines a type-safe interface of Property Value resolver.
|
|
12
6
|
* @internal
|
|
13
7
|
*/
|
|
14
|
-
export
|
|
8
|
+
export type PropertyValueResolver<T extends SchemaItem, TProps = MutableSchemaItemProps<T>> = {
|
|
9
|
+
[P in keyof TProps]?: (value: any, item: SchemaItemKey) => any;
|
|
10
|
+
};
|
|
15
11
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param targetItem The target item
|
|
18
|
-
* @param changes The array with PropertyValueChanges
|
|
19
|
-
* @param handler The callback that gets invoked vor every change.
|
|
20
|
-
* @internal
|
|
12
|
+
* Defines a Mutable Schema Props interface.
|
|
21
13
|
*/
|
|
22
|
-
|
|
14
|
+
type MutableSchemaItemProps<T extends SchemaItem> = {
|
|
15
|
+
-readonly [key in keyof ReturnType<T["toJSON"]>]: ReturnType<T["toJSON"]>[key];
|
|
16
|
+
};
|
|
23
17
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
18
|
+
* The SchemaItemMerger is an base class for several other mergers with the actual logic
|
|
19
|
+
* to perform merging for a certain schema item type. The class provides the shared logics
|
|
20
|
+
* that is shared for all schema item mergers and custom logic can be applied by overriding
|
|
21
|
+
* the protected class members.
|
|
27
22
|
* @internal
|
|
28
23
|
*/
|
|
29
|
-
export declare
|
|
24
|
+
export declare class SchemaItemMerger<TItem extends SchemaItem> {
|
|
25
|
+
protected readonly context: SchemaMergeContext;
|
|
26
|
+
/**
|
|
27
|
+
* Constructor of the SchemaItemMerger class. This should not be overriden or extended
|
|
28
|
+
* by sub-implementations.
|
|
29
|
+
* @param context The current merging context.
|
|
30
|
+
*/
|
|
31
|
+
constructor(context: SchemaMergeContext);
|
|
32
|
+
/**
|
|
33
|
+
* This overridable method allows to create a property value resolver that gets defines
|
|
34
|
+
* a handler function for every possible property change. This allows adding complex handing
|
|
35
|
+
* if a property value requires complicated merging.
|
|
36
|
+
* @returns A resolver map with resolvers for the property.
|
|
37
|
+
*/
|
|
38
|
+
protected createPropertyValueResolver(): Promise<PropertyValueResolver<TItem>>;
|
|
39
|
+
/**
|
|
40
|
+
* This overridable method gets called for more complex merging.
|
|
41
|
+
* @param _itemKey The key of the current schema item.
|
|
42
|
+
* @param _source The source item that shall gets merged into.
|
|
43
|
+
* @param _change The schema item change to be applied.
|
|
44
|
+
*/
|
|
45
|
+
protected merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Merges the given schema item changes in the current context.
|
|
48
|
+
* @param context The merging context
|
|
49
|
+
* @param schemaItemChanges An iterable of item changes.
|
|
50
|
+
*/
|
|
51
|
+
static mergeChanges<TChange extends SchemaItemChanges>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Merges the property values.
|
|
54
|
+
* @param targetItem The current schema item
|
|
55
|
+
* @param changes The property changes.
|
|
56
|
+
*/
|
|
57
|
+
private mergeItemPropertyValues;
|
|
58
|
+
}
|
|
30
59
|
export {};
|
|
31
60
|
//# 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,
|
|
1
|
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