@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
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { CustomAttribute, NavigationProperty, RelationshipClass, RelationshipConstraint, StrengthDirection, StrengthType } from "@itwin/ecschema-metadata";
|
|
1
|
+
import { CustomAttribute, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationProperty, RelationshipClass, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, StrengthDirection, StrengthType } from "@itwin/ecschema-metadata";
|
|
2
2
|
/**
|
|
3
3
|
* Hackish approach that works like a "friend class" so we can access protected members without making them public.
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export declare abstract class MutableRelationshipConstraint extends RelationshipConstraint {
|
|
7
7
|
abstract addCustomAttribute(customAttribute: CustomAttribute): void;
|
|
8
|
+
abstract set multiplicity(multiplicity: RelationshipMultiplicity);
|
|
9
|
+
abstract set polymorphic(polymorphic: boolean);
|
|
10
|
+
abstract set roleLabel(roleLabel: string | undefined);
|
|
11
|
+
abstract set relationshipEnd(relationshipEnd: RelationshipEnd);
|
|
12
|
+
abstract set abstractConstraint(abstractConstraint: LazyLoadedRelationshipConstraintClass | undefined);
|
|
13
|
+
abstract removeClass(constraint: EntityClass | Mixin | RelationshipClass): void;
|
|
8
14
|
}
|
|
9
15
|
/**
|
|
10
16
|
* @internal
|
|
@@ -15,6 +21,8 @@ export declare abstract class MutableRelationshipClass extends RelationshipClass
|
|
|
15
21
|
get target(): MutableRelationshipConstraint;
|
|
16
22
|
abstract setStrength(strength: StrengthType): void;
|
|
17
23
|
abstract setStrengthDirection(direction: StrengthDirection): void;
|
|
24
|
+
abstract setSourceConstraint(source: RelationshipConstraint): void;
|
|
25
|
+
abstract setTargetConstraint(target: RelationshipConstraint): void;
|
|
18
26
|
abstract createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;
|
|
19
27
|
abstract createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;
|
|
20
28
|
abstract setDisplayLabel(displayLabel: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutableRelationshipClass.d.ts","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableRelationshipClass.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"MutableRelationshipClass.d.ts","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableRelationshipClass.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,qCAAqC,EAAE,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,eAAe,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEjQ;;;GAGG;AACH,8BAAsB,6BAA8B,SAAQ,sBAAsB;aACvD,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI;IACnF,aAA6B,YAAY,CAAC,YAAY,EAAE,wBAAwB,EAAE;IAClF,aAA6B,WAAW,CAAC,WAAW,EAAE,OAAO,EAAE;IAC/D,aAA6B,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE;IACtE,aAA6B,eAAe,CAAC,eAAe,EAAE,eAAe,EAAG;IAChF,aAA6B,kBAAkB,CAAC,kBAAkB,EAAE,qCAAqC,GAAG,SAAS,EAAE;aAC9F,WAAW,CAAC,UAAU,EAAE,WAAW,GAAG,KAAK,GAAG,iBAAiB,GAAG,IAAI;CAChG;AAED;;;GAGG;AACH,8BAAsB,wBAAyB,SAAQ,iBAAiB;IACtE,IAAoB,MAAM,kCAA4D;IACtF,IAAoB,MAAM,kCAA4D;aAC7D,WAAW,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;aACzC,oBAAoB,CAAC,SAAS,EAAE,iBAAiB,GAAG,IAAI;aACxD,mBAAmB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;aACzD,mBAAmB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;aACzD,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;aACpJ,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,kBAAkB;aAC/I,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CACrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutableRelationshipClass.js","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableRelationshipClass.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"MutableRelationshipClass.js","sourceRoot":"","sources":["../../../../src/Editing/Mutable/MutableRelationshipClass.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAiQ;AAEjQ;;;GAGG;AACH,MAAsB,6BAA8B,SAAQ,0CAAsB;CAQjF;AARD,sEAQC;AAED;;;GAGG;AACH,MAAsB,wBAAyB,SAAQ,qCAAiB;IACtE,IAAoB,MAAM,KAAK,OAAO,IAAI,CAAC,OAAwC,CAAC,CAAC,CAAC;IACtF,IAAoB,MAAM,KAAK,OAAO,IAAI,CAAC,OAAwC,CAAC,CAAC,CAAC;CAQvF;AAVD,4DAUC","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 { CustomAttribute, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationProperty, RelationshipClass, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, StrengthDirection, StrengthType } from \"@itwin/ecschema-metadata\";\n\n/**\n * Hackish approach that works like a \"friend class\" so we can access protected members without making them public.\n * @internal\n */\nexport abstract class MutableRelationshipConstraint extends RelationshipConstraint {\n public abstract override addCustomAttribute(customAttribute: CustomAttribute): void;\n public abstract override set multiplicity(multiplicity: RelationshipMultiplicity);\n public abstract override set polymorphic(polymorphic: boolean);\n public abstract override set roleLabel(roleLabel: string | undefined);\n public abstract override set relationshipEnd(relationshipEnd: RelationshipEnd) ;\n public abstract override set abstractConstraint(abstractConstraint: LazyLoadedRelationshipConstraintClass | undefined);\n public abstract override removeClass(constraint: EntityClass | Mixin | RelationshipClass): void;\n}\n\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableRelationshipClass extends RelationshipClass {\n public override get source() { return this._source as MutableRelationshipConstraint; }\n public override get target() { return this._target as MutableRelationshipConstraint; }\n public abstract override setStrength(strength: StrengthType): void;\n public abstract override setStrengthDirection(direction: StrengthDirection): void;\n public abstract override setSourceConstraint(source: RelationshipConstraint): void;\n public abstract override setTargetConstraint(target: RelationshipConstraint): void;\n public abstract override createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;\n public abstract override createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
|
-
import { RelationshipClass, RelationshipClassProps, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
|
|
4
|
+
import { ECClassModifier, EntityClass, Mixin, NavigationPropertyProps, RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaKey, StrengthDirection, StrengthType } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
|
|
6
6
|
import { ECClasses } from "./ECClasses";
|
|
7
7
|
/**
|
|
8
8
|
* @alpha
|
|
9
9
|
* A class extending ECClasses allowing you to create schema items of type RelationshipClass.
|
|
10
|
-
* Can only create RelationshipClass objects using RelationshipClassProps for now.
|
|
11
10
|
*/
|
|
12
11
|
export declare class RelationshipClasses extends ECClasses {
|
|
13
12
|
constructor(_schemaEditor: SchemaContextEditor);
|
|
13
|
+
/**
|
|
14
|
+
* Creates a RelationshipClass.
|
|
15
|
+
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
16
|
+
* @param name The name of the new class.
|
|
17
|
+
* @param modifier The ECClassModifier of the new class.
|
|
18
|
+
* @param strength The relationship StrengthType of the class.
|
|
19
|
+
* @param StrengthDirection The relationship StrengthDirection of the class.
|
|
20
|
+
* @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.
|
|
21
|
+
*/
|
|
22
|
+
create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults>;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the source RelationshipConstraint on the relationship.
|
|
25
|
+
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
26
|
+
* @param source The RelationshipConstraint to add.
|
|
27
|
+
* @returns A promise of type SchemaItemEditResults.
|
|
28
|
+
*/
|
|
29
|
+
setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<SchemaItemEditResults>;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the target RelationshipConstraint on the relationship.
|
|
32
|
+
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
33
|
+
* @param target The RelationshipConstraint to add.
|
|
34
|
+
* @returns A promise of type SchemaItemEditResults.
|
|
35
|
+
*/
|
|
36
|
+
setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<SchemaItemEditResults>;
|
|
14
37
|
/**
|
|
15
38
|
* Creates a RelationshipClass through a RelationshipClassProps.
|
|
16
39
|
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
@@ -18,5 +41,13 @@ export declare class RelationshipClasses extends ECClasses {
|
|
|
18
41
|
*/
|
|
19
42
|
createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults>;
|
|
20
43
|
createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults>;
|
|
44
|
+
createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults>;
|
|
45
|
+
setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<SchemaItemEditResults>;
|
|
46
|
+
setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<SchemaItemEditResults>;
|
|
47
|
+
setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<SchemaItemEditResults>;
|
|
48
|
+
setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults>;
|
|
49
|
+
addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults>;
|
|
50
|
+
removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults>;
|
|
51
|
+
private validate;
|
|
21
52
|
}
|
|
22
53
|
//# sourceMappingURL=RelationshipClasses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipClasses.d.ts","sourceRoot":"","sources":["../../../src/Editing/RelationshipClasses.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,
|
|
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AAG,OAAO,CAAC,mBAAmB,CAAC;IAarL,iCAAiC,CAAC,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAczI,yBAAyB,CAAC,UAAU,EAAE,sBAAsB,EAAE,YAAY,EAAE,wBAAwB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAMrI,wBAAwB,CAAC,UAAU,EAAE,sBAAsB,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAMlH,4BAA4B,CAAC,UAAU,EAAE,sBAAsB,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAMlI,qBAAqB,CAAC,UAAU,EAAE,sBAAsB,EAAE,kBAAkB,CAAC,EAAE,WAAW,GAAG,KAAK,GAAG,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAyBvJ,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,WAAW,GAAG,KAAK,GAAG,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAmBxI,qBAAqB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,WAAW,GAAG,KAAK,GAAG,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAa1I,QAAQ;CAoBvB"}
|
|
@@ -10,32 +10,72 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.RelationshipClasses = void 0;
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
12
|
const ECClasses_1 = require("./ECClasses");
|
|
13
|
+
const Rules = require("../Validation/ECRules");
|
|
13
14
|
/**
|
|
14
15
|
* @alpha
|
|
15
16
|
* A class extending ECClasses allowing you to create schema items of type RelationshipClass.
|
|
16
|
-
* Can only create RelationshipClass objects using RelationshipClassProps for now.
|
|
17
17
|
*/
|
|
18
18
|
class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
19
19
|
constructor(_schemaEditor) {
|
|
20
20
|
super(_schemaEditor);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Creates a RelationshipClass.
|
|
24
|
+
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
25
|
+
* @param name The name of the new class.
|
|
26
|
+
* @param modifier The ECClassModifier of the new class.
|
|
27
|
+
* @param strength The relationship StrengthType of the class.
|
|
28
|
+
* @param StrengthDirection The relationship StrengthDirection of the class.
|
|
29
|
+
* @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.
|
|
30
|
+
*/
|
|
31
|
+
async create(schemaKey, name, modifier, strength, direction, baseClassKey) {
|
|
32
|
+
const schema = await this._schemaEditor.getSchema(schemaKey);
|
|
33
|
+
if (schema === undefined) {
|
|
34
|
+
return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
|
|
35
|
+
}
|
|
36
|
+
const newClass = (await schema.createRelationshipClass(name, modifier));
|
|
37
|
+
if (baseClassKey !== undefined) {
|
|
38
|
+
const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;
|
|
39
|
+
if (baseClassSchema === undefined) {
|
|
40
|
+
return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };
|
|
41
|
+
}
|
|
42
|
+
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
43
|
+
if (baseClassItem === undefined)
|
|
44
|
+
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
45
|
+
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.RelationshipClass)
|
|
46
|
+
return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };
|
|
47
|
+
newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
48
|
+
}
|
|
49
|
+
newClass.setStrength(strength);
|
|
50
|
+
newClass.setStrengthDirection(direction);
|
|
51
|
+
return { itemKey: newClass.key };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sets the source RelationshipConstraint on the relationship.
|
|
55
|
+
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
56
|
+
* @param source The RelationshipConstraint to add.
|
|
57
|
+
* @returns A promise of type SchemaItemEditResults.
|
|
58
|
+
*/
|
|
59
|
+
async setSourceConstraint(relationshipKey, source) {
|
|
60
|
+
const relationship = (await this._schemaEditor.schemaContext.getSchemaItem(relationshipKey));
|
|
61
|
+
if (relationship === undefined)
|
|
62
|
+
return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };
|
|
63
|
+
relationship.setSourceConstraint(source);
|
|
64
|
+
return { itemKey: relationshipKey };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Sets the target RelationshipConstraint on the relationship.
|
|
68
|
+
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
69
|
+
* @param target The RelationshipConstraint to add.
|
|
70
|
+
* @returns A promise of type SchemaItemEditResults.
|
|
71
|
+
*/
|
|
72
|
+
async setTargetConstraint(relationshipKey, target) {
|
|
73
|
+
const relationship = (await this._schemaEditor.schemaContext.getSchemaItem(relationshipKey));
|
|
74
|
+
if (relationship === undefined)
|
|
75
|
+
return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };
|
|
76
|
+
relationship.setTargetConstraint(target);
|
|
77
|
+
return { itemKey: relationshipKey };
|
|
78
|
+
}
|
|
39
79
|
/**
|
|
40
80
|
* Creates a RelationshipClass through a RelationshipClassProps.
|
|
41
81
|
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
@@ -48,8 +88,6 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
48
88
|
if (relationshipProps.name === undefined)
|
|
49
89
|
return { errorMessage: `No name was supplied within props.` };
|
|
50
90
|
const newClass = (await schema.createRelationshipClass(relationshipProps.name));
|
|
51
|
-
if (newClass === undefined)
|
|
52
|
-
return { errorMessage: `Failed to create class ${relationshipProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
53
91
|
await newClass.fromJSON(relationshipProps);
|
|
54
92
|
await newClass.source.fromJSON(relationshipProps.source);
|
|
55
93
|
await newClass.target.fromJSON(relationshipProps.target);
|
|
@@ -58,12 +96,100 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
58
96
|
async createNavigationProperty(relationshipKey, name, relationship, direction) {
|
|
59
97
|
const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem(relationshipKey));
|
|
60
98
|
if (relationshipClass === undefined)
|
|
61
|
-
|
|
99
|
+
return { itemKey: relationshipKey, propertyName: name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };
|
|
62
100
|
if (relationshipClass.schemaItemType !== ecschema_metadata_1.SchemaItemType.RelationshipClass)
|
|
63
|
-
|
|
101
|
+
return { itemKey: relationshipKey, propertyName: name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };
|
|
64
102
|
await relationshipClass.createNavigationProperty(name, relationship, direction);
|
|
65
103
|
return { itemKey: relationshipKey, propertyName: name };
|
|
66
104
|
}
|
|
105
|
+
async createNavigationPropertyFromProps(relationshipKey, navigationProps) {
|
|
106
|
+
const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem(relationshipKey));
|
|
107
|
+
if (relationshipClass === undefined)
|
|
108
|
+
return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };
|
|
109
|
+
if (relationshipClass.schemaItemType !== ecschema_metadata_1.SchemaItemType.RelationshipClass)
|
|
110
|
+
return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };
|
|
111
|
+
const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);
|
|
112
|
+
await property.fromJSON(navigationProps);
|
|
113
|
+
return { itemKey: relationshipKey, propertyName: navigationProps.name };
|
|
114
|
+
}
|
|
115
|
+
async setConstraintMultiplicity(constraint, multiplicity) {
|
|
116
|
+
const mutableConstraint = constraint;
|
|
117
|
+
mutableConstraint.multiplicity = multiplicity;
|
|
118
|
+
return { itemKey: constraint.relationshipClass.key };
|
|
119
|
+
}
|
|
120
|
+
async setConstraintPolymorphic(constraint, polymorphic) {
|
|
121
|
+
const mutableConstraint = constraint;
|
|
122
|
+
mutableConstraint.polymorphic = polymorphic;
|
|
123
|
+
return { itemKey: constraint.relationshipClass.key };
|
|
124
|
+
}
|
|
125
|
+
async setConstraintRelationshipEnd(constraint, relationshipEnd) {
|
|
126
|
+
const mutableConstraint = constraint;
|
|
127
|
+
mutableConstraint.relationshipEnd = relationshipEnd;
|
|
128
|
+
return { itemKey: constraint.relationshipClass.key };
|
|
129
|
+
}
|
|
130
|
+
async setAbstractConstraint(constraint, abstractConstraint) {
|
|
131
|
+
const existing = constraint.abstractConstraint;
|
|
132
|
+
const mutableConstraint = constraint;
|
|
133
|
+
if (undefined === abstractConstraint) {
|
|
134
|
+
mutableConstraint.abstractConstraint = undefined;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
mutableConstraint.abstractConstraint = new ecschema_metadata_1.DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);
|
|
138
|
+
}
|
|
139
|
+
let result = await this.validate(constraint.relationshipClass);
|
|
140
|
+
if (result.errorMessage) {
|
|
141
|
+
mutableConstraint.abstractConstraint = existing;
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
result = await this.validate(constraint);
|
|
145
|
+
if (result.errorMessage) {
|
|
146
|
+
mutableConstraint.abstractConstraint = existing;
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
return { itemKey: constraint.relationshipClass.key };
|
|
150
|
+
}
|
|
151
|
+
async addConstraintClass(constraint, ecClass) {
|
|
152
|
+
const mutableConstraint = constraint;
|
|
153
|
+
mutableConstraint.addClass(ecClass);
|
|
154
|
+
let result = await this.validate(constraint.relationshipClass);
|
|
155
|
+
if (result.errorMessage) {
|
|
156
|
+
mutableConstraint.removeClass(ecClass);
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
result = await this.validate(constraint);
|
|
160
|
+
if (result.errorMessage) {
|
|
161
|
+
mutableConstraint.removeClass(ecClass);
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
return { itemKey: constraint.relationshipClass.key };
|
|
165
|
+
}
|
|
166
|
+
async removeConstraintClass(constraint, ecClass) {
|
|
167
|
+
const mutableConstraint = constraint;
|
|
168
|
+
mutableConstraint.removeClass(ecClass);
|
|
169
|
+
const result = await this.validate(constraint);
|
|
170
|
+
if (result.errorMessage) {
|
|
171
|
+
mutableConstraint.addClass(ecClass);
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
return { itemKey: constraint.relationshipClass.key };
|
|
175
|
+
}
|
|
176
|
+
async validate(relationshipOrConstraint) {
|
|
177
|
+
let diagnostics;
|
|
178
|
+
if (relationshipOrConstraint instanceof ecschema_metadata_1.RelationshipClass) {
|
|
179
|
+
diagnostics = Rules.validateRelationship(relationshipOrConstraint);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
diagnostics = Rules.validateRelationshipConstraint(relationshipOrConstraint);
|
|
183
|
+
}
|
|
184
|
+
const errorMessages = [];
|
|
185
|
+
for await (const diagnostic of diagnostics) {
|
|
186
|
+
errorMessages.push(`${diagnostic.code}: ${diagnostic.messageText}`);
|
|
187
|
+
}
|
|
188
|
+
if (errorMessages.length > 0) {
|
|
189
|
+
return { errorMessage: errorMessages.join("\r\n") };
|
|
190
|
+
}
|
|
191
|
+
return {};
|
|
192
|
+
}
|
|
67
193
|
}
|
|
68
194
|
exports.RelationshipClasses = RelationshipClasses;
|
|
69
195
|
//# sourceMappingURL=RelationshipClasses.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipClasses.js","sourceRoot":"","sources":["../../../src/Editing/RelationshipClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAGkC;AAElC,2CAAwC;AAGxC;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,qBAAS;IAChD,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAED,+DAA+D;IAC/D,oEAAoE;IACpE,oQAAoQ;IACpQ,kEAAkE;IAClE,sHAAsH;IAEtH,yGAAyG;IACzG,kCAAkC;IAClC,wGAAwG;IACxG,MAAM;IAEN,mCAAmC;IACnC,qFAAqF;IACrF,sHAAsH;IACtH,MAAM;IACN,oCAAoC;IACpC,8CAA8C;IAE9C,sCAAsC;IACtC,IAAI;IAEJ;;;;OAIG;IACI,KAAK,CAAC,eAAe,CAAC,SAAoB,EAAE,iBAAyC;QAC1F,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,IAAI,iBAAiB,CAAC,IAAI,KAAK,SAAS;YACtC,OAAO,EAAE,YAAY,EAAE,oCAAoC,EAAE,CAAC;QAEhE,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAA6B,CAAC;QAC5G,IAAI,QAAQ,KAAK,SAAS;YACxB,OAAO,EAAE,YAAY,EAAE,0BAA0B,iBAAiB,CAAC,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAErH,MAAM,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC3C,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACzD,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAEzD,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,eAA8B,EAAE,IAAY,EAAE,YAAwC,EAAE,SAAqC;QACjK,MAAM,iBAAiB,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,aAAa,CAA2B,eAAe,CAAC,CAAC,CAAC;QAE5H,IAAI,iBAAiB,KAAK,SAAS;YACjC,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,sBAAsB,eAAe,CAAC,QAAQ,+BAA+B,CAAC,CAAC;QAEzI,IAAI,iBAAiB,CAAC,cAAc,KAAK,kCAAc,CAAC,iBAAiB;YACvE,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,qBAAqB,EAAE,YAAY,eAAe,CAAC,QAAQ,oCAAoC,CAAC,CAAC;QAE5I,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QAChF,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;CACF;AA9DD,kDA8DC","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 Editing\n */\n\nimport {\n ECObjectsError, ECObjectsStatus, RelationshipClass, RelationshipClassProps, SchemaItemKey, SchemaItemType,\n SchemaKey, StrengthDirection,\n} from \"@itwin/ecschema-metadata\";\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\nimport { ECClasses } from \"./ECClasses\";\nimport { MutableRelationshipClass } from \"./Mutable/MutableRelationshipClass\";\n\n/**\n * @alpha\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\n * Can only create RelationshipClass objects using RelationshipClassProps for now.\n */\nexport class RelationshipClasses extends ECClasses {\n public constructor(_schemaEditor: SchemaContextEditor) {\n super(_schemaEditor);\n }\n\n // // TODO: Add relationshipConstraint, multiplicity arguments.\n // // Note: This method is not done yet, there's a lot of arguments.\n // public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, sourceMultiplicity: RelationshipMultiplicity, targetMultiplicity: RelationshipMultiplicity, baseClass?: SchemaItemKey) {\n // const schema = await this._schemaEditor.getSchema(schemaKey);\n // if (schema === undefined) return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n // const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\n // if (newClass === undefined) {\n // return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\n // }\n\n // if (baseClass !== undefined) {\n // const baseClassItem = await schema.lookupItem(baseClass) as RelationshipClass;\n // newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClass, async () => baseClassItem);\n // }\n // newClass.setStrength(strength);\n // newClass.setStrengthDirection(direction);\n\n // return { itemKey: newClass.key };\n // }\n\n /**\n * Creates a RelationshipClass through a RelationshipClassProps.\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\n */\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (relationshipProps.name === undefined)\n return { errorMessage: `No name was supplied within props.` };\n\n const newClass = (await schema.createRelationshipClass(relationshipProps.name)) as MutableRelationshipClass;\n if (newClass === undefined)\n return { errorMessage: `Failed to create class ${relationshipProps.name} in schema ${schemaKey.toString(true)}.` };\n\n await newClass.fromJSON(relationshipProps);\n await newClass.source.fromJSON(relationshipProps.source);\n await newClass.target.fromJSON(relationshipProps.target);\n\n return { itemKey: newClass.key };\n }\n\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\n\n if (relationshipClass === undefined)\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Relationship Class ${relationshipKey.fullName} not found in schema context.`);\n\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${relationshipKey.fullName} to be of type Relationship Class.`);\n\n await relationshipClass.createNavigationProperty(name, relationship, direction);\n return { itemKey: relationshipKey, propertyName: name };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RelationshipClasses.js","sourceRoot":"","sources":["../../../src/Editing/RelationshipClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAIkC;AAElC,2CAAwC;AAExC,+CAA+C;AAG/C;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,qBAAS;IAChD,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,QAAyB,EAAE,QAAsB,EAAE,SAA4B,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EAAE,MAAM,UAAU,IAAI,WAAW,EAAE;YAC1C,aAAa,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;SACrE;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,OAAO,EAAE,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;SACrD;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA1ND,kDA0NC","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 Editing\n */\n\nimport {\n DelayedPromiseWithProps, ECClassModifier, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationPropertyProps,\n RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaItemType,\n SchemaKey, StrengthDirection, StrengthType,\n} from \"@itwin/ecschema-metadata\";\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\nimport { ECClasses } from \"./ECClasses\";\nimport { MutableRelationshipClass, MutableRelationshipConstraint } from \"./Mutable/MutableRelationshipClass\";\nimport * as Rules from \"../Validation/ECRules\";\nimport { RelationshipConstraintDiagnostic, SchemaItemDiagnostic } from \"../Validation/Diagnostic\";\n\n/**\n * @alpha\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\n */\nexport class RelationshipClasses extends ECClasses {\n public constructor(_schemaEditor: SchemaContextEditor) {\n super(_schemaEditor);\n }\n\n /**\n * Creates a RelationshipClass.\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\n * @param name The name of the new class.\n * @param modifier The ECClassModifier of the new class.\n * @param strength The relationship StrengthType of the class.\n * @param StrengthDirection The relationship StrengthDirection of the class.\n * @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.\n */\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined) {\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n }\n\n const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\n if (baseClassKey !== undefined) {\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\n if (baseClassSchema === undefined) {\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\n }\n\n const baseClassItem = await baseClassSchema.lookupItem<RelationshipClass>(baseClassKey);\n if (baseClassItem === undefined)\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\n\n if (baseClassItem.schemaItemType !== SchemaItemType.RelationshipClass)\n return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };\n\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, RelationshipClass>(baseClassKey, async () => baseClassItem);\n }\n\n newClass.setStrength(strength);\n newClass.setStrengthDirection(direction);\n\n return { itemKey: newClass.key };\n }\n\n /**\n * Sets the source RelationshipConstraint on the relationship.\n * @param relationshipKey The SchemaItemKey for the relationship.\n * @param source The RelationshipConstraint to add.\n * @returns A promise of type SchemaItemEditResults.\n */\n public async setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<SchemaItemEditResults> {\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\n\n if (relationship === undefined)\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\n\n relationship.setSourceConstraint(source);\n return { itemKey: relationshipKey };\n }\n\n /**\n * Sets the target RelationshipConstraint on the relationship.\n * @param relationshipKey The SchemaItemKey for the relationship.\n * @param target The RelationshipConstraint to add.\n * @returns A promise of type SchemaItemEditResults.\n */\n public async setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<SchemaItemEditResults> {\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\n\n if (relationship === undefined)\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\n\n relationship.setTargetConstraint(target);\n return { itemKey: relationshipKey };\n }\n\n /**\n * Creates a RelationshipClass through a RelationshipClassProps.\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\n */\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (relationshipProps.name === undefined)\n return { errorMessage: `No name was supplied within props.` };\n\n const newClass = (await schema.createRelationshipClass(relationshipProps.name)) as MutableRelationshipClass;\n await newClass.fromJSON(relationshipProps);\n await newClass.source.fromJSON(relationshipProps.source);\n await newClass.target.fromJSON(relationshipProps.target);\n\n return { itemKey: newClass.key };\n }\n\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\n\n if (relationshipClass === undefined)\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\n\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\n\n await relationshipClass.createNavigationProperty(name, relationship, direction);\n return { itemKey: relationshipKey, propertyName: name };\n }\n\n public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\n\n if (relationshipClass === undefined)\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\n\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\n\n const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\n await property.fromJSON(navigationProps);\n return { itemKey: relationshipKey, propertyName: navigationProps.name };\n }\n\n public async setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<SchemaItemEditResults> {\n const mutableConstraint = constraint as MutableRelationshipConstraint;\n mutableConstraint.multiplicity = multiplicity;\n return { itemKey: constraint.relationshipClass.key };\n }\n\n public async setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<SchemaItemEditResults> {\n const mutableConstraint = constraint as MutableRelationshipConstraint;\n mutableConstraint.polymorphic = polymorphic;\n return { itemKey: constraint.relationshipClass.key };\n }\n\n public async setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<SchemaItemEditResults> {\n const mutableConstraint = constraint as MutableRelationshipConstraint;\n mutableConstraint.relationshipEnd = relationshipEnd;\n return { itemKey: constraint.relationshipClass.key };\n }\n\n public async setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\n const existing: LazyLoadedRelationshipConstraintClass | undefined = constraint.abstractConstraint;\n const mutableConstraint = constraint as MutableRelationshipConstraint;\n\n if (undefined === abstractConstraint) {\n mutableConstraint.abstractConstraint = undefined;\n } else {\n mutableConstraint.abstractConstraint = new DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);\n }\n\n let result = await this.validate(constraint.relationshipClass);\n if (result.errorMessage) {\n mutableConstraint.abstractConstraint = existing;\n return result;\n }\n\n result = await this.validate(constraint);\n if (result.errorMessage) {\n mutableConstraint.abstractConstraint = existing;\n return result;\n }\n\n return { itemKey: constraint.relationshipClass.key };\n }\n\n public async addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\n const mutableConstraint = constraint as MutableRelationshipConstraint;\n mutableConstraint.addClass(ecClass);\n\n let result = await this.validate(constraint.relationshipClass);\n if (result.errorMessage) {\n mutableConstraint.removeClass(ecClass);\n return result;\n }\n\n result = await this.validate(constraint);\n if (result.errorMessage) {\n mutableConstraint.removeClass(ecClass);\n return result;\n }\n\n return { itemKey: constraint.relationshipClass.key };\n }\n\n public async removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\n const mutableConstraint = constraint as MutableRelationshipConstraint;\n mutableConstraint.removeClass(ecClass);\n\n const result = await this.validate(constraint);\n if (result.errorMessage) {\n mutableConstraint.addClass(ecClass);\n return result;\n }\n\n return { itemKey: constraint.relationshipClass.key };\n }\n\n private async validate(relationshipOrConstraint: RelationshipClass | RelationshipConstraint): Promise<SchemaItemEditResults> {\n let diagnostics: AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>> | AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;\n\n if (relationshipOrConstraint instanceof RelationshipClass) {\n diagnostics = Rules.validateRelationship(relationshipOrConstraint);\n } else {\n diagnostics = Rules.validateRelationshipConstraint(relationshipOrConstraint);\n }\n\n const errorMessages = [];\n for await (const diagnostic of diagnostics) {\n errorMessages.push(`${diagnostic.code}: ${diagnostic.messageText}`);\n }\n\n if (errorMessages.length > 0) {\n return { errorMessage: errorMessages.join(\"\\r\\n\") };\n }\n\n return {};\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAmB,KAAK,EAAsB,aAAa,EAA0B,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjJ,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAA8B,YAAY,EAA2C,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAmB,KAAK,EAAsB,aAAa,EAA0B,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjJ,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAA8B,YAAY,EAA2C,MAAM,6BAA6B,CAAC;AAIhI;;GAEG;AACH,qBAAa,WAAW,CAAC,MAAM,SAAS,OAAO;IAC7C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBAEnC,OAAO,EAAE,kBAAkB;cAIvB,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAI9E,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAI9E,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,qBAAqB,GAAG,OAAO,CAAC;IAgCjK,SAAS,CAAC,uBAAuB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,qBAAqB;YAI3D,YAAY;YAwBZ,SAAS;YAkBT,0BAA0B;WAmBpB,YAAY,CAAC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC;CAmDnG"}
|
|
@@ -8,6 +8,7 @@ exports.ClassMerger = void 0;
|
|
|
8
8
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
9
9
|
const SchemaChanges_1 = require("../Validation/SchemaChanges");
|
|
10
10
|
const ClassPropertyMerger_1 = require("./ClassPropertyMerger");
|
|
11
|
+
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
11
12
|
/**
|
|
12
13
|
* @internal
|
|
13
14
|
*/
|
|
@@ -134,7 +135,14 @@ class ClassMerger {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);
|
|
137
|
-
|
|
138
|
+
let mergeResults = await ClassPropertyMerger_1.ClassPropertyMerger.mergeChanges(context, targetItemKey, change.propertyChanges.values());
|
|
139
|
+
if (mergeResults.errorMessage !== undefined) {
|
|
140
|
+
throw new Error(mergeResults.errorMessage);
|
|
141
|
+
}
|
|
142
|
+
// merge custom attributes
|
|
143
|
+
mergeResults = await (0, CustomAttributeMerger_1.mergeCustomAttributes)(merger.context, change.customAttributeChanges.values(), async (ca) => {
|
|
144
|
+
return merger.context.editor.entities.addCustomAttribute(targetItemKey, ca);
|
|
145
|
+
});
|
|
138
146
|
if (mergeResults.errorMessage !== undefined) {
|
|
139
147
|
throw new Error(mergeResults.errorMessage);
|
|
140
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAiJ;AAIjJ,+DAA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C,YAAY,KAAK,SAAS,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvC;gBACD,aAAa,GAAG,OAAO,CAAC,OAAQ,CAAC;aAClC;YAED,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE;gBACvC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;gBAC5F,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvC;aACF;YAED,IAAI,MAAM,CAAC,kBAAkB,CAAC,IAAI,GAAG,CAAC,EAAE;gBACtC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;gBACtG,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvC;aACF;YAED,MAAM,MAAM,CAAC,0BAA0B,CAAC,aAAa,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;YACpF,MAAM,YAAY,GAAI,MAAM,yCAAmB,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;YACtH,IAAI,YAAY,CAAC,YAAY,KAAK,SAAS,EAAE;gBAC3C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;aAC5C;SACF;IACH,CAAC;CACF;AA1JD,kCA0JC","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 { ECClass, ECClassModifier, Mixin, parseClassModifier, SchemaItemKey, schemaItemTypeToString, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\nimport { MutableClass } from \"../Editing/Mutable/MutableClass\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { BaseClassDelta, ChangeType, ClassChanges, EntityMixinChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\nimport { ClassPropertyMerger } from \"./ClassPropertyMerger\";\n\n/**\n * @internal\n */\nexport class ClassMerger<TClass extends ECClass> {\n protected readonly context: SchemaMergeContext;\n\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n protected async create(_schemaKey: SchemaKey, ecClass: TClass): Promise<SchemaItemEditResults> {\n return { errorMessage: `${schemaItemTypeToString(ecClass.schemaItemType)} class type is not implemented.`};\n }\n\n protected async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\n return { errorMessage: `Adding mixin '${mixin.name}' to '${itemKey.name}' class is not implemented.` };\n }\n\n protected async mergeAttributes(ecClass: TClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\n const mutableClass = ecClass as unknown as MutableClass;\n switch(attributeName) {\n case \"schemaItemType\":\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\n return { errorMessage: `Changing the class '${ecClass.name}' type is not supported.` };\n }\n return true;\n\n case \"label\":\n mutableClass.setDisplayLabel(attributeNewValue);\n return true;\n\n case \"description\":\n mutableClass.setDescription(attributeNewValue);\n return true;\n\n case \"modifier\":\n const modifier = parseClassModifier(attributeNewValue);\n if (modifier === undefined) {\n return { errorMessage: \"An invalid class modifier has been provided.\" };\n }\n\n if (attributeOldValue === undefined || modifier === ECClassModifier.None) {\n mutableClass.setModifier(modifier);\n return true;\n }\n return { errorMessage: `Changing the class '${ecClass.name}' modifier is not supported.` };\n }\n return false;\n }\n\n protected isSchemaItemEditResults(obj: any): obj is SchemaItemEditResults {\n return typeof obj === \"object\" && \"errorMessage\" in obj;\n }\n\n private async setBaseClass(itemKey: SchemaItemKey, baseClassDelta: BaseClassDelta, changeType?: ChangeType): Promise<SchemaItemEditResults> {\n const [sourceBaseClass, targetBaseClass] = baseClassDelta.diagnostic.messageArgs! as [ECClass, ECClass];\n if (sourceBaseClass !== undefined) {\n const baseClassKey = new SchemaItemKey(sourceBaseClass.name, sourceBaseClass.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : sourceBaseClass.schema.schemaKey);\n\n if (changeType === ChangeType.Missing && targetBaseClass === undefined) {\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\n }\n\n if (targetBaseClass !== undefined) {\n const baseClass = await this.context.targetSchema.lookupItem<ECClass>(baseClassKey);\n if (baseClass === undefined) {\n return { errorMessage: `'${baseClassKey.name}' class could not be located in the merged schema.`};\n }\n if (await baseClass.is(targetBaseClass)) {\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\n }\n }\n }\n return { errorMessage: `Changing the class '${itemKey.name}' baseClass is not supported.`};\n }\n\n private async addMixins(itemKey: SchemaItemKey, entityMixinChanges: Iterable<EntityMixinChanges>, changeType?: ChangeType): Promise<SchemaItemEditResults> {\n if (changeType === ChangeType.Missing) {\n for (const entityMixinChange of entityMixinChanges) {\n for (const change of entityMixinChange.entityMixinChange) {\n const mixins = change.diagnostic.messageArgs! as unknown as [Mixin];\n for (const mixin of mixins) {\n const result = await this.addMixin(itemKey, mixin);\n if (result.errorMessage !== undefined) {\n return result;\n }\n }\n }\n }\n return {};\n }\n return { errorMessage: `Changing the class '${itemKey.name}' mixins is not supported.`};\n }\n\n private async mergeAttributeValueChanges(itemKey: SchemaItemKey, propertyValueChanges: PropertyValueChange[]) {\n if (propertyValueChanges.length === 0) {\n return;\n }\n\n const targetItem = await this.context.targetSchema.lookupItem<TClass>(itemKey);\n if (targetItem === undefined) {\n throw new Error(`'${itemKey.name}' class could not be located in the merged schema.`);\n }\n\n for (const change of propertyValueChanges) {\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\n const results = await this.mergeAttributes(targetItem, attributeName, attributeNewValue, attributeOldValue);\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n }\n\n public static async mergeChanges(context: SchemaMergeContext, classChanges: Iterable<ClassChanges>) {\n const merger = new this(context);\n\n for (const change of classChanges) {\n const sourceItem = (await change.schema.getItem<ECClass>(change.ecTypeName))!;\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\n const changeType = change.schemaItemMissing?.changeType;\n\n if (changeType === ChangeType.Missing) {\n\n if (await context.targetSchema.lookupItem<ECClass>(targetItemKey) !== undefined) {\n throw new Error(`Merged schema already contains a class '${change.ecTypeName}'.`);\n }\n\n const results = await merger.create(context.targetSchema.schemaKey, sourceItem);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n targetItemKey = results.itemKey!;\n }\n\n if (change.baseClassDelta !== undefined) {\n const results = await merger.setBaseClass(targetItemKey, change.baseClassDelta, changeType);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n\n if (change.entityMixinChanges.size > 0) {\n const results = await merger.addMixins(targetItemKey, change.entityMixinChanges.values(), changeType);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n\n await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);\n const mergeResults = await ClassPropertyMerger.mergeChanges(context, targetItemKey, change.propertyChanges.values());\n if (mergeResults.errorMessage !== undefined) {\n throw new Error(mergeResults.errorMessage);\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAiJ;AAIjJ,+DAAgI;AAChI,+DAA4D;AAC5D,m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M,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;YAEH,IAAI,YAAY,CAAC,YAAY,KAAK,SAAS,EAAE;gBAC3C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;aAC5C;SACF;IACH,CAAC;CACF;AAnKD,kCAmKC","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 { ECClass, ECClassModifier, Mixin, parseClassModifier, SchemaItemKey, schemaItemTypeToString, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\nimport { MutableClass } from \"../Editing/Mutable/MutableClass\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { BaseClassDelta, ChangeType, ClassChanges, EntityMixinChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\nimport { ClassPropertyMerger } from \"./ClassPropertyMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\n\n/**\n * @internal\n */\nexport class ClassMerger<TClass extends ECClass> {\n protected readonly context: SchemaMergeContext;\n\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n protected async create(_schemaKey: SchemaKey, ecClass: TClass): Promise<SchemaItemEditResults> {\n return { errorMessage: `${schemaItemTypeToString(ecClass.schemaItemType)} class type is not implemented.`};\n }\n\n protected async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\n return { errorMessage: `Adding mixin '${mixin.name}' to '${itemKey.name}' class is not implemented.` };\n }\n\n protected async mergeAttributes(ecClass: TClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\n const mutableClass = ecClass as unknown as MutableClass;\n switch(attributeName) {\n case \"schemaItemType\":\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\n return { errorMessage: `Changing the class '${ecClass.name}' type is not supported.` };\n }\n return true;\n\n case \"label\":\n mutableClass.setDisplayLabel(attributeNewValue);\n return true;\n\n case \"description\":\n mutableClass.setDescription(attributeNewValue);\n return true;\n\n case \"modifier\":\n const modifier = parseClassModifier(attributeNewValue);\n if (modifier === undefined) {\n return { errorMessage: \"An invalid class modifier has been provided.\" };\n }\n\n if (attributeOldValue === undefined || modifier === ECClassModifier.None) {\n mutableClass.setModifier(modifier);\n return true;\n }\n return { errorMessage: `Changing the class '${ecClass.name}' modifier is not supported.` };\n }\n return false;\n }\n\n protected isSchemaItemEditResults(obj: any): obj is SchemaItemEditResults {\n return typeof obj === \"object\" && \"errorMessage\" in obj;\n }\n\n private async setBaseClass(itemKey: SchemaItemKey, baseClassDelta: BaseClassDelta, changeType?: ChangeType): Promise<SchemaItemEditResults> {\n const [sourceBaseClass, targetBaseClass] = baseClassDelta.diagnostic.messageArgs! as [ECClass, ECClass];\n if (sourceBaseClass !== undefined) {\n const baseClassKey = new SchemaItemKey(sourceBaseClass.name, sourceBaseClass.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : sourceBaseClass.schema.schemaKey);\n\n if (changeType === ChangeType.Missing && targetBaseClass === undefined) {\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\n }\n\n if (targetBaseClass !== undefined) {\n const baseClass = await this.context.targetSchema.lookupItem<ECClass>(baseClassKey);\n if (baseClass === undefined) {\n return { errorMessage: `'${baseClassKey.name}' class could not be located in the merged schema.`};\n }\n if (await baseClass.is(targetBaseClass)) {\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\n }\n }\n }\n return { errorMessage: `Changing the class '${itemKey.name}' baseClass is not supported.`};\n }\n\n private async addMixins(itemKey: SchemaItemKey, entityMixinChanges: Iterable<EntityMixinChanges>, changeType?: ChangeType): Promise<SchemaItemEditResults> {\n if (changeType === ChangeType.Missing) {\n for (const entityMixinChange of entityMixinChanges) {\n for (const change of entityMixinChange.entityMixinChange) {\n const mixins = change.diagnostic.messageArgs! as unknown as [Mixin];\n for (const mixin of mixins) {\n const result = await this.addMixin(itemKey, mixin);\n if (result.errorMessage !== undefined) {\n return result;\n }\n }\n }\n }\n return {};\n }\n return { errorMessage: `Changing the class '${itemKey.name}' mixins is not supported.`};\n }\n\n private async mergeAttributeValueChanges(itemKey: SchemaItemKey, propertyValueChanges: PropertyValueChange[]) {\n if (propertyValueChanges.length === 0) {\n return;\n }\n\n const targetItem = await this.context.targetSchema.lookupItem<TClass>(itemKey);\n if (targetItem === undefined) {\n throw new Error(`'${itemKey.name}' class could not be located in the merged schema.`);\n }\n\n for (const change of propertyValueChanges) {\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\n const results = await this.mergeAttributes(targetItem, attributeName, attributeNewValue, attributeOldValue);\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n }\n\n public static async mergeChanges(context: SchemaMergeContext, classChanges: Iterable<ClassChanges>) {\n const merger = new this(context);\n\n for (const change of classChanges) {\n const sourceItem = (await change.schema.getItem<ECClass>(change.ecTypeName))!;\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\n const changeType = change.schemaItemMissing?.changeType;\n\n if (changeType === ChangeType.Missing) {\n\n if (await context.targetSchema.lookupItem<ECClass>(targetItemKey) !== undefined) {\n throw new Error(`Merged schema already contains a class '${change.ecTypeName}'.`);\n }\n\n const results = await merger.create(context.targetSchema.schemaKey, sourceItem);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n targetItemKey = results.itemKey!;\n }\n\n if (change.baseClassDelta !== undefined) {\n const results = await merger.setBaseClass(targetItemKey, change.baseClassDelta, changeType);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n\n if (change.entityMixinChanges.size > 0) {\n const results = await merger.addMixins(targetItemKey, change.entityMixinChanges.values(), changeType);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n\n await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);\n let mergeResults = await ClassPropertyMerger.mergeChanges(context, targetItemKey, change.propertyChanges.values());\n if (mergeResults.errorMessage !== undefined) {\n throw new Error(mergeResults.errorMessage);\n }\n\n // merge custom attributes\n mergeResults = await mergeCustomAttributes(merger.context, change.customAttributeChanges.values(), async (ca) => {\n return merger.context.editor.entities.addCustomAttribute(targetItemKey, ca);\n });\n\n if (mergeResults.errorMessage !== undefined) {\n throw new Error(mergeResults.errorMessage);\n }\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2C,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAc,eAAe,EAAuB,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2C,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAc,eAAe,EAAuB,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAOpD;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBAEnC,OAAO,EAAE,kBAAkB;IAIvC,OAAO,CAAC,iBAAiB;IAsBzB,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,mBAAmB;YAIvD,0BAA0B;WAepB,YAAY,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAmCnK"}
|
|
@@ -10,6 +10,7 @@ const SchemaChanges_1 = require("../Validation/SchemaChanges");
|
|
|
10
10
|
const StructPropertyMerger_1 = require("./StructPropertyMerger");
|
|
11
11
|
const ArrayPropertyMerger_1 = require("./ArrayPropertyMerger");
|
|
12
12
|
const PrimitiveOrEnumPropertyMerger_1 = require("./PrimitiveOrEnumPropertyMerger");
|
|
13
|
+
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
13
14
|
/**
|
|
14
15
|
* @internal
|
|
15
16
|
*/
|
|
@@ -75,8 +76,14 @@ class ClassPropertyMerger {
|
|
|
75
76
|
const targetProperty = (await targetItem.getProperty(change.ecTypeName));
|
|
76
77
|
await merger.mergeAttributeValueChanges(targetProperty, change.propertyValueChanges);
|
|
77
78
|
}
|
|
79
|
+
const mergeResults = await (0, CustomAttributeMerger_1.mergeCustomAttributes)(merger.context, change.customAttributeChanges.values(), async (ca) => {
|
|
80
|
+
return merger.context.editor.entities.addCustomAttributeToProperty(classKey, change.ecTypeName, ca);
|
|
81
|
+
});
|
|
82
|
+
if (mergeResults.errorMessage !== undefined) {
|
|
83
|
+
return { errorMessage: mergeResults.errorMessage };
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
|
-
return {};
|
|
86
|
+
return { itemKey: classKey };
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
89
|
exports.ClassPropertyMerger = ClassPropertyMerger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAkG;AAElG,+DAA+F;AAE/F,iEAA8D;AAC9D,+DAA+H;AAE/H,mFAAqG;
|
|
1
|
+
{"version":3,"file":"ClassPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAkG;AAElG,+DAA+F;AAE/F,iEAA8D;AAC9D,+DAA+H;AAE/H,mFAAqG;AACrG,mEAAgE;AAEhE;;GAEG;AACH,MAAa,mBAAmB;IAG9B,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEO,iBAAiB,CAAC,QAAkB;QAC1C,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE;YAC5B,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;gBACtB,OAAO,IAAI,oDAA8B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACzD;YACD,OAAO,IAAI,yDAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACpD;QACD,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE;YAC1B,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;gBACtB,OAAO,IAAI,iDAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACtD;YACD,OAAO,IAAI,uDAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAClD;QACD,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE;YACvB,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;gBACtB,OAAO,IAAI,+CAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACpD;YACD,OAAO,IAAI,2CAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC/C;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAA,wCAAoB,EAAC,QAAQ,CAAC,YAAY,CAAC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AmFC","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 { ECClass, Property, propertyTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { PropertyEditResults, SchemaItemEditResults } from \"../Editing/Editor\";\nimport { ChangeType, PropertyChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { StructPropertyMerger } from \"./StructPropertyMerger\";\nimport { EnumerationArrayPropertyMerger, PrimitiveArraPropertyMerger, StructArrayPropertyMerger } from \"./ArrayPropertyMerger\";\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\nimport { EnumerationPropertyMerger, PrimitivePropertyMerger } from \"./PrimitiveOrEnumPropertyMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\n\n/**\n * @internal\n */\nexport class ClassPropertyMerger {\n protected readonly context: SchemaMergeContext;\n\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n private getPropertyMerger(property: Property): AnyPropertyMerger<Property> {\n if (property.isEnumeration()) {\n if (property.isArray()) {\n return new EnumerationArrayPropertyMerger(this.context);\n }\n return new EnumerationPropertyMerger(this.context);\n }\n if (property.isPrimitive()) {\n if (property.isArray()) {\n return new PrimitiveArraPropertyMerger(this.context);\n }\n return new PrimitivePropertyMerger(this.context);\n }\n if (property.isStruct()) {\n if (property.isArray()) {\n return new StructArrayPropertyMerger(this.context);\n }\n return new StructPropertyMerger(this.context);\n }\n throw new Error(`Unsupported Property Type: ${propertyTypeToString(property.propertyType)}`);\n }\n\n protected isPropertyEditResults(obj: any): obj is PropertyEditResults {\n return typeof obj === \"object\" && \"errorMessage\" in obj;\n }\n\n private async mergeAttributeValueChanges(targetProperty: Property, propertyValueChanges: PropertyValueChange[]) {\n if (propertyValueChanges.length === 0)\n return;\n\n const merger = this.getPropertyMerger(targetProperty);\n\n for (const change of propertyValueChanges) {\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\n const results = await merger.mergeAttributes(targetProperty, attributeName, attributeNewValue, attributeOldValue);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n }\n\n public static async mergeChanges(context: SchemaMergeContext, classKey: SchemaItemKey, propertyChanges: Iterable<PropertyChanges>): Promise<SchemaItemEditResults> {\n const merger = new this(context);\n\n for (const change of propertyChanges) {\n const targetItem = await context.targetSchema.lookupItem<ECClass>(classKey);\n if (targetItem === undefined) {\n return { errorMessage: `'${classKey.name}' class could not be located in the merged schema.`};\n }\n\n if (change.propertyMissing?.changeType === ChangeType.Missing) {\n const sourceProperty = change.propertyMissing.diagnostic.ecDefinition as unknown as Property;\n if (await targetItem.getProperty(change.ecTypeName) !== undefined) {\n return { errorMessage: `Merged schema already contains a class '${classKey.name}' property '${change.ecTypeName}'.`};\n }\n\n const propertyMerger = merger.getPropertyMerger(sourceProperty);\n const results = await propertyMerger.createFromProps(classKey, sourceProperty);\n if (results.errorMessage !== undefined) {\n return { errorMessage: results.errorMessage};\n }\n } else {\n const targetProperty = (await targetItem.getProperty(change.ecTypeName))!;\n await merger.mergeAttributeValueChanges(targetProperty, change.propertyValueChanges);\n }\n\n const mergeResults = await mergeCustomAttributes(merger.context, change.customAttributeChanges.values(), async (ca) => {\n return merger.context.editor.entities.addCustomAttributeToProperty(classKey, change.ecTypeName, ca);\n });\n\n if (mergeResults.errorMessage !== undefined) {\n return { errorMessage: mergeResults.errorMessage};\n }\n }\n return { itemKey: classKey };\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Merging
|
|
3
|
+
*/
|
|
4
|
+
import { CustomAttribute } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { CustomAttributeContainerChanges } from "../Validation/SchemaChanges";
|
|
6
|
+
import { SchemaMergeContext } from "./SchemaMerger";
|
|
7
|
+
interface EditResults {
|
|
8
|
+
errorMessage?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass
|
|
12
|
+
* a scope (Class, Property, Schema) specific handler.
|
|
13
|
+
* @param mergeContext The current schema merging context.
|
|
14
|
+
* @param changes An iterable with custom attribute changes.
|
|
15
|
+
* @param callback The callback to add the custom attribute with a scope specific editor.
|
|
16
|
+
* @returns A EditResults object.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function mergeCustomAttributes(mergeContext: SchemaMergeContext, changes: Iterable<CustomAttributeContainerChanges>, callback: (customAttribute: CustomAttribute) => Promise<EditResults>): Promise<EditResults>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=CustomAttributeMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomAttributeMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAA8D,MAAM,0BAA0B,CAAC;AACvH,OAAO,EAAc,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,UAAU,WAAW;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAE,QAAQ,CAAC,+BAA+B,CAAC,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CA6B5N"}
|