@itwin/ecschema-editing 4.7.0-dev.9 → 4.8.0-dev.1
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/Constants.d.ts +6 -6
- package/lib/cjs/Editing/Constants.d.ts.map +1 -1
- package/lib/cjs/Editing/Constants.js +26 -31
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts +3 -3
- package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js +18 -28
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +24 -23
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +126 -156
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.d.ts +10 -31
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +59 -43
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts +9 -9
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +65 -85
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.d.ts +6 -6
- package/lib/cjs/Editing/Enumerations.d.ts.map +1 -1
- package/lib/cjs/Editing/Enumerations.js +57 -55
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/Exception.d.ts +257 -0
- package/lib/cjs/Editing/Exception.d.ts.map +1 -0
- package/lib/cjs/Editing/Exception.js +426 -0
- package/lib/cjs/Editing/Exception.js.map +1 -0
- package/lib/cjs/Editing/Formats.d.ts +6 -6
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +28 -33
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.d.ts +6 -6
- package/lib/cjs/Editing/InvertedUnits.d.ts.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.js +41 -56
- package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts +6 -6
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +50 -57
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +5 -5
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +43 -58
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts +1 -5
- package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js +1 -45
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
- package/lib/cjs/Editing/Phenomena.d.ts +7 -7
- package/lib/cjs/Editing/Phenomena.d.ts.map +1 -1
- package/lib/cjs/Editing/Phenomena.js +23 -23
- package/lib/cjs/Editing/Phenomena.js.map +1 -1
- package/lib/cjs/Editing/Properties.d.ts +7 -6
- package/lib/cjs/Editing/Properties.d.ts.map +1 -1
- package/lib/cjs/Editing/Properties.js +99 -46
- package/lib/cjs/Editing/Properties.js.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.d.ts +6 -6
- package/lib/cjs/Editing/PropertyCategories.d.ts.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.js +29 -27
- package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +15 -17
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +97 -101
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.d.ts +13 -5
- package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js +58 -6
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Editing/Structs.d.ts +3 -3
- package/lib/cjs/Editing/Structs.d.ts.map +1 -1
- package/lib/cjs/Editing/Structs.js +17 -27
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Editing/UnitSystems.d.ts +7 -7
- package/lib/cjs/Editing/UnitSystems.d.ts.map +1 -1
- package/lib/cjs/Editing/UnitSystems.js +22 -20
- package/lib/cjs/Editing/UnitSystems.js.map +1 -1
- package/lib/cjs/Editing/Units.d.ts +6 -6
- package/lib/cjs/Editing/Units.d.ts.map +1 -1
- package/lib/cjs/Editing/Units.js +26 -35
- package/lib/cjs/Editing/Units.js.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +2 -2
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +1 -2
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +15 -39
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js +2 -3
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts +4 -5
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +8 -18
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.d.ts +1 -2
- package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +3 -10
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +8 -10
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.js +2 -3
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +2 -2
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js +1 -2
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.js +1 -2
- package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.d.ts +2 -3
- package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +21 -42
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts +5 -3
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.js +35 -33
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +3 -4
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +3 -2
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +2 -8
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.js +1 -2
- package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
- package/package.json +9 -9
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
4
|
import { CustomAttribute, ECClassModifier, EntityClass, Mixin, NavigationPropertyProps, RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaKey, StrengthDirection, StrengthType } from "@itwin/ecschema-metadata";
|
|
5
|
-
import {
|
|
5
|
+
import { SchemaContextEditor } from "./Editor";
|
|
6
6
|
import { ECClasses } from "./ECClasses";
|
|
7
7
|
import { NavigationProperties } from "./Properties";
|
|
8
8
|
/**
|
|
@@ -24,47 +24,45 @@ export declare class RelationshipClasses extends ECClasses {
|
|
|
24
24
|
* @param StrengthDirection The relationship StrengthDirection of the class.
|
|
25
25
|
* @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.
|
|
26
26
|
*/
|
|
27
|
-
create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<
|
|
27
|
+
create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemKey>;
|
|
28
28
|
/**
|
|
29
29
|
* Sets the source RelationshipConstraint on the relationship.
|
|
30
30
|
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
31
31
|
* @param source The RelationshipConstraint to add.
|
|
32
|
-
* @returns A promise of type SchemaItemEditResults.
|
|
33
32
|
*/
|
|
34
|
-
setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<
|
|
33
|
+
setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<void>;
|
|
35
34
|
/**
|
|
36
35
|
* Sets the target RelationshipConstraint on the relationship.
|
|
37
36
|
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
38
37
|
* @param target The RelationshipConstraint to add.
|
|
39
|
-
* @returns A promise of type SchemaItemEditResults.
|
|
40
38
|
*/
|
|
41
|
-
setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<
|
|
39
|
+
setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<void>;
|
|
42
40
|
/**
|
|
43
41
|
* Creates a RelationshipClass through a RelationshipClassProps.
|
|
44
42
|
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
45
43
|
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
46
44
|
*/
|
|
47
|
-
createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<
|
|
45
|
+
createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemKey>;
|
|
48
46
|
/**
|
|
49
47
|
* Sets the base class of a RelationshipClass.
|
|
50
48
|
* @param relationshipKey The SchemaItemKey of the RelationshipClass.
|
|
51
49
|
* @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.
|
|
52
50
|
*/
|
|
53
|
-
setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<
|
|
54
|
-
createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<
|
|
51
|
+
setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<void>;
|
|
52
|
+
createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<void>;
|
|
55
53
|
/**
|
|
56
54
|
* Creates a Navigation Property through a NavigationPropertyProps.
|
|
57
55
|
* @param classKey a SchemaItemKey of the Relationship Class that will house the new property.
|
|
58
56
|
* @param navigationProps a json object that will be used to populate the new Navigation Property.
|
|
59
57
|
*/
|
|
60
|
-
createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<
|
|
61
|
-
setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<
|
|
62
|
-
setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<
|
|
63
|
-
setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<
|
|
64
|
-
setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<
|
|
65
|
-
addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<
|
|
66
|
-
removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<
|
|
67
|
-
addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<
|
|
58
|
+
createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<void>;
|
|
59
|
+
setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<void>;
|
|
60
|
+
setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<void>;
|
|
61
|
+
setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<void>;
|
|
62
|
+
setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<void>;
|
|
63
|
+
addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<void>;
|
|
64
|
+
removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<void>;
|
|
65
|
+
addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<void>;
|
|
68
66
|
private validate;
|
|
69
67
|
}
|
|
70
68
|
//# 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,EACL,eAAe,EAA2B,eAAe,EAAE,WAAW,EAAyC,KAAK,EAAE,uBAAuB,EAC7I,iBAAiB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,eAAe,EAAE,wBAAwB,EAAE,aAAa,EAC3H,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAC3C,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"RelationshipClasses.d.ts","sourceRoot":"","sources":["../../../src/Editing/RelationshipClasses.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,eAAe,EAA2B,eAAe,EAAE,WAAW,EAAyC,KAAK,EAAE,uBAAuB,EAC7I,iBAAiB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,eAAe,EAAE,wBAAwB,EAAE,aAAa,EAC3H,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAC3C,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGpD;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;gBAC7B,YAAY,EAAE,mBAAmB;IAIpD;;OAEG;IACH,SAAgB,oBAAoB,uBAAoE;IAExG;;;;;;;;OAQG;IACU,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAa9L;;;;OAIG;IACU,mBAAmB,CAAC,eAAe,EAAE,aAAa,EAAE,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI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W,GAAG,KAAK,GAAG,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1H,8BAA8B,CAAC,UAAU,EAAE,sBAAsB,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;YAkBlH,QAAQ;CAyBvB"}
|
|
@@ -12,6 +12,7 @@ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
|
12
12
|
const ECClasses_1 = require("./ECClasses");
|
|
13
13
|
const Rules = require("../Validation/ECRules");
|
|
14
14
|
const Properties_1 = require("./Properties");
|
|
15
|
+
const Exception_1 = require("./Exception");
|
|
15
16
|
/**
|
|
16
17
|
* @alpha
|
|
17
18
|
* A class extending ECClasses allowing you to create schema items of type RelationshipClass.
|
|
@@ -22,7 +23,7 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
22
23
|
/**
|
|
23
24
|
* Allows access for editing of NavigationProperty attributes.
|
|
24
25
|
*/
|
|
25
|
-
this.navigationProperties = new Properties_1.NavigationProperties(this.schemaItemType, this.
|
|
26
|
+
this.navigationProperties = new Properties_1.NavigationProperties(this.schemaItemType, this.schemaEditor);
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Creates a RelationshipClass.
|
|
@@ -34,52 +35,39 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
34
35
|
* @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.
|
|
35
36
|
*/
|
|
36
37
|
async create(schemaKey, name, modifier, strength, direction, baseClassKey) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };
|
|
46
|
-
}
|
|
47
|
-
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
48
|
-
if (baseClassItem === undefined)
|
|
49
|
-
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
50
|
-
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.RelationshipClass)
|
|
51
|
-
return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };
|
|
52
|
-
newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
38
|
+
try {
|
|
39
|
+
const newClass = await this.createClass(schemaKey, this.schemaItemType, (schema) => schema.createRelationshipClass.bind(schema), name, baseClassKey, modifier);
|
|
40
|
+
newClass.setStrength(strength);
|
|
41
|
+
newClass.setStrengthDirection(direction);
|
|
42
|
+
return newClass.key;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFailed, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
53
46
|
}
|
|
54
|
-
newClass.setStrength(strength);
|
|
55
|
-
newClass.setStrengthDirection(direction);
|
|
56
|
-
return { itemKey: newClass.key };
|
|
57
47
|
}
|
|
58
48
|
/**
|
|
59
49
|
* Sets the source RelationshipConstraint on the relationship.
|
|
60
50
|
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
61
51
|
* @param source The RelationshipConstraint to add.
|
|
62
|
-
* @returns A promise of type SchemaItemEditResults.
|
|
63
52
|
*/
|
|
64
53
|
async setSourceConstraint(relationshipKey, source) {
|
|
65
|
-
const relationship =
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
const relationship = await this.getSchemaItem(relationshipKey)
|
|
55
|
+
.catch((e) => {
|
|
56
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetSourceConstraint, new Exception_1.ClassId(this.schemaItemType, relationshipKey), e);
|
|
57
|
+
});
|
|
68
58
|
relationship.setSourceConstraint(source);
|
|
69
|
-
return { itemKey: relationshipKey };
|
|
70
59
|
}
|
|
71
60
|
/**
|
|
72
61
|
* Sets the target RelationshipConstraint on the relationship.
|
|
73
62
|
* @param relationshipKey The SchemaItemKey for the relationship.
|
|
74
63
|
* @param target The RelationshipConstraint to add.
|
|
75
|
-
* @returns A promise of type SchemaItemEditResults.
|
|
76
64
|
*/
|
|
77
65
|
async setTargetConstraint(relationshipKey, target) {
|
|
78
|
-
const relationship = await this.
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
const relationship = await this.getSchemaItem(relationshipKey)
|
|
67
|
+
.catch((e) => {
|
|
68
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetTargetConstraint, new Exception_1.ClassId(this.schemaItemType, relationshipKey), e);
|
|
69
|
+
});
|
|
81
70
|
relationship.setTargetConstraint(target);
|
|
82
|
-
return { itemKey: relationshipKey };
|
|
83
71
|
}
|
|
84
72
|
/**
|
|
85
73
|
* Creates a RelationshipClass through a RelationshipClassProps.
|
|
@@ -87,16 +75,15 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
87
75
|
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
88
76
|
*/
|
|
89
77
|
async createFromProps(schemaKey, relationshipProps) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return { itemKey: newClass.key };
|
|
78
|
+
try {
|
|
79
|
+
const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createRelationshipClass.bind(schema), relationshipProps);
|
|
80
|
+
await newClass.source.fromJSON(relationshipProps.source);
|
|
81
|
+
await newClass.target.fromJSON(relationshipProps.target);
|
|
82
|
+
return newClass.key;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFromProps, new Exception_1.ClassId(this.schemaItemType, relationshipProps.name, schemaKey), e);
|
|
86
|
+
}
|
|
100
87
|
}
|
|
101
88
|
/**
|
|
102
89
|
* Sets the base class of a RelationshipClass.
|
|
@@ -104,26 +91,25 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
104
91
|
* @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.
|
|
105
92
|
*/
|
|
106
93
|
async setBaseClass(itemKey, baseClassKey) {
|
|
107
|
-
const relClass = await this.
|
|
94
|
+
const relClass = await this.schemaEditor.schemaContext.getSchemaItem(itemKey);
|
|
108
95
|
const baseClass = relClass?.baseClass;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
96
|
+
await super.setBaseClass(itemKey, baseClassKey);
|
|
97
|
+
try {
|
|
98
|
+
await this.validate(relClass);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
relClass.baseClass = baseClass;
|
|
102
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetBaseClass, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.RelationshipClass, itemKey), e);
|
|
116
103
|
}
|
|
117
|
-
return setResult;
|
|
118
104
|
}
|
|
119
105
|
async createNavigationProperty(relationshipKey, name, relationship, direction) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
106
|
+
try {
|
|
107
|
+
const relationshipClass = await this.getSchemaItem(relationshipKey);
|
|
108
|
+
await relationshipClass.createNavigationProperty(name, relationship, direction);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateNavigationProperty, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.RelationshipClass, relationshipKey), e);
|
|
112
|
+
}
|
|
127
113
|
}
|
|
128
114
|
/**
|
|
129
115
|
* Creates a Navigation Property through a NavigationPropertyProps.
|
|
@@ -131,29 +117,26 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
131
117
|
* @param navigationProps a json object that will be used to populate the new Navigation Property.
|
|
132
118
|
*/
|
|
133
119
|
async createNavigationPropertyFromProps(relationshipKey, navigationProps) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
120
|
+
try {
|
|
121
|
+
const relationshipClass = await this.getSchemaItem(relationshipKey);
|
|
122
|
+
const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);
|
|
123
|
+
await property.fromJSON(navigationProps);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateNavigationPropertyFromProps, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.RelationshipClass, relationshipKey), e);
|
|
127
|
+
}
|
|
142
128
|
}
|
|
143
129
|
async setConstraintMultiplicity(constraint, multiplicity) {
|
|
144
130
|
const mutableConstraint = constraint;
|
|
145
131
|
mutableConstraint.multiplicity = multiplicity;
|
|
146
|
-
return { itemKey: constraint.relationshipClass.key };
|
|
147
132
|
}
|
|
148
133
|
async setConstraintPolymorphic(constraint, polymorphic) {
|
|
149
134
|
const mutableConstraint = constraint;
|
|
150
135
|
mutableConstraint.polymorphic = polymorphic;
|
|
151
|
-
return { itemKey: constraint.relationshipClass.key };
|
|
152
136
|
}
|
|
153
137
|
async setConstraintRelationshipEnd(constraint, relationshipEnd) {
|
|
154
138
|
const mutableConstraint = constraint;
|
|
155
139
|
mutableConstraint.relationshipEnd = relationshipEnd;
|
|
156
|
-
return { itemKey: constraint.relationshipClass.key };
|
|
157
140
|
}
|
|
158
141
|
async setAbstractConstraint(constraint, abstractConstraint) {
|
|
159
142
|
const existing = constraint.abstractConstraint;
|
|
@@ -164,73 +147,86 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
|
|
|
164
147
|
else {
|
|
165
148
|
mutableConstraint.abstractConstraint = new ecschema_metadata_1.DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);
|
|
166
149
|
}
|
|
167
|
-
|
|
168
|
-
|
|
150
|
+
try {
|
|
151
|
+
await this.validate(constraint.relationshipClass);
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
169
154
|
mutableConstraint.abstractConstraint = existing;
|
|
170
|
-
|
|
155
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetAbstractConstraint, new Exception_1.RelationshipConstraintId(constraint), e);
|
|
171
156
|
}
|
|
172
|
-
|
|
173
|
-
|
|
157
|
+
try {
|
|
158
|
+
await this.validate(constraint);
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
174
161
|
mutableConstraint.abstractConstraint = existing;
|
|
175
|
-
|
|
162
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetAbstractConstraint, new Exception_1.RelationshipConstraintId(constraint), e);
|
|
176
163
|
}
|
|
177
|
-
return { itemKey: constraint.relationshipClass.key };
|
|
178
164
|
}
|
|
179
165
|
async addConstraintClass(constraint, ecClass) {
|
|
180
166
|
const mutableConstraint = constraint;
|
|
181
167
|
mutableConstraint.addClass(ecClass);
|
|
182
|
-
|
|
183
|
-
|
|
168
|
+
try {
|
|
169
|
+
await this.validate(constraint.relationshipClass);
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
184
172
|
mutableConstraint.removeClass(ecClass);
|
|
185
|
-
|
|
173
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddConstraintClass, new Exception_1.RelationshipConstraintId(constraint), e);
|
|
186
174
|
}
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
try {
|
|
176
|
+
await this.validate(constraint);
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
189
179
|
mutableConstraint.removeClass(ecClass);
|
|
190
|
-
|
|
180
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddConstraintClass, new Exception_1.RelationshipConstraintId(constraint), e);
|
|
191
181
|
}
|
|
192
|
-
return { itemKey: constraint.relationshipClass.key };
|
|
193
182
|
}
|
|
194
183
|
async removeConstraintClass(constraint, ecClass) {
|
|
195
184
|
const mutableConstraint = constraint;
|
|
196
185
|
mutableConstraint.removeClass(ecClass);
|
|
197
|
-
|
|
198
|
-
|
|
186
|
+
try {
|
|
187
|
+
await this.validate(constraint);
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
199
190
|
mutableConstraint.addClass(ecClass);
|
|
200
|
-
|
|
191
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.RemoveConstraintClass, new Exception_1.RelationshipConstraintId(constraint), e);
|
|
201
192
|
}
|
|
202
|
-
return { itemKey: constraint.relationshipClass.key };
|
|
203
193
|
}
|
|
204
194
|
async addCustomAttributeToConstraint(constraint, customAttribute) {
|
|
205
195
|
const mutableConstraint = constraint;
|
|
206
196
|
mutableConstraint.addCustomAttribute(customAttribute);
|
|
207
|
-
const
|
|
208
|
-
const
|
|
209
|
-
for await (const diagnostic of
|
|
210
|
-
|
|
197
|
+
const diagnosticIterable = Rules.validateCustomAttributeInstance(constraint, customAttribute);
|
|
198
|
+
const diagnostics = [];
|
|
199
|
+
for await (const diagnostic of diagnosticIterable) {
|
|
200
|
+
diagnostics.push(diagnostic);
|
|
211
201
|
}
|
|
212
|
-
if (
|
|
202
|
+
if (diagnostics.length > 0) {
|
|
213
203
|
this.removeCustomAttribute(constraint, customAttribute);
|
|
214
|
-
|
|
204
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddCustomAttributeToConstraint, new Exception_1.RelationshipConstraintId(constraint), new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.RuleViolation, new Exception_1.CustomAttributeId(customAttribute.className, constraint), undefined, diagnostics));
|
|
215
205
|
}
|
|
216
|
-
return { itemKey: constraint.relationshipClass.key };
|
|
217
206
|
}
|
|
218
207
|
async validate(relationshipOrConstraint) {
|
|
219
|
-
let
|
|
208
|
+
let diagnosticIterable;
|
|
209
|
+
let relationshipKey;
|
|
220
210
|
if (relationshipOrConstraint instanceof ecschema_metadata_1.RelationshipClass) {
|
|
221
|
-
|
|
211
|
+
diagnosticIterable = Rules.validateRelationship(relationshipOrConstraint);
|
|
212
|
+
relationshipKey = relationshipOrConstraint.key;
|
|
222
213
|
}
|
|
223
214
|
else {
|
|
224
|
-
|
|
215
|
+
diagnosticIterable = Rules.validateRelationshipConstraint(relationshipOrConstraint);
|
|
216
|
+
relationshipKey = relationshipOrConstraint.relationshipClass.key;
|
|
225
217
|
}
|
|
226
|
-
const
|
|
227
|
-
for await (const diagnostic of
|
|
228
|
-
|
|
218
|
+
const diagnostics = [];
|
|
219
|
+
for await (const diagnostic of diagnosticIterable) {
|
|
220
|
+
diagnostics.push(diagnostic);
|
|
229
221
|
}
|
|
230
|
-
if (
|
|
231
|
-
|
|
222
|
+
if (diagnostics.length > 0) {
|
|
223
|
+
if (relationshipOrConstraint instanceof ecschema_metadata_1.RelationshipClass) {
|
|
224
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.RuleViolation, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.RelationshipClass, relationshipKey), undefined, diagnostics);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.RuleViolation, new Exception_1.RelationshipConstraintId(relationshipOrConstraint), undefined, diagnostics);
|
|
228
|
+
}
|
|
232
229
|
}
|
|
233
|
-
return {};
|
|
234
230
|
}
|
|
235
231
|
}
|
|
236
232
|
exports.RelationshipClasses = RelationshipClasses;
|
|
@@ -1 +1 @@
|
|
|
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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GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,MAAM,CAAC;QAC7E,CAAC;QAED,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACxB,IAAI,CAAC,qBAAqB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;YACxD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;IACvD,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,wBAAoE;QACzF,IAAI,WAAmI,CAAC;QAExI,IAAI,wBAAwB,YAAY,qCAAiB,EAAE,CAAC;YAC1D,WAAW,GAAG,KAAK,CAAC,oBAAoB,CAAC,wBAAwB,CAAC,CAAC;QACrE,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,KAAK,CAAC,8BAA8B,CAAC,wBAAwB,CAAC,CAAC;QAC/E,CAAC;QAED,MAAM,aAAa,GAAG,EAAE,CAAC;QACzB,IAAI,KAAK,EAAE,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YAC3C,aAAa,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,OAAO,EAAE,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtD,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA1QD,kDA0QC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttribute, DelayedPromiseWithProps, ECClassModifier, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationPropertyProps,\r\n RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaItemType,\r\n SchemaKey, StrengthDirection, StrengthType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableRelationshipClass, MutableRelationshipConstraint } from \"./Mutable/MutableRelationshipClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { RelationshipConstraintDiagnostic, SchemaItemDiagnostic } from \"../Validation/Diagnostic\";\r\nimport { NavigationProperties } from \"./Properties\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\r\n */\r\nexport class RelationshipClasses extends ECClasses {\r\n public constructor(schemaEditor: SchemaContextEditor) {\r\n super(SchemaItemType.RelationshipClass, schemaEditor);\r\n }\r\n\r\n /**\r\n * Allows access for editing of NavigationProperty attributes.\r\n */\r\n public readonly navigationProperties = new NavigationProperties(this.schemaItemType, this._schemaEditor);\r\n\r\n /**\r\n * Creates a RelationshipClass.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param name The name of the new class.\r\n * @param modifier The ECClassModifier of the new class.\r\n * @param strength The relationship StrengthType of the class.\r\n * @param StrengthDirection The relationship StrengthDirection of the class.\r\n * @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.\r\n */\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<RelationshipClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, RelationshipClass>(baseClassKey, async () => baseClassItem);\r\n }\r\n\r\n newClass.setStrength(strength);\r\n newClass.setStrengthDirection(direction);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the source RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param source The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setSourceConstraint(source);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Sets the target RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param target The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setTargetConstraint(target);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass through a RelationshipClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (relationshipProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createRelationshipClass(relationshipProps.name)) as MutableRelationshipClass;\r\n await newClass.fromJSON(relationshipProps);\r\n await newClass.source.fromJSON(relationshipProps.source);\r\n await newClass.target.fromJSON(relationshipProps.target);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the base class of a RelationshipClass.\r\n * @param relationshipKey The SchemaItemKey of the RelationshipClass.\r\n * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.\r\n */\r\n public override async setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const relClass = await this._schemaEditor.schemaContext.getSchemaItem<RelationshipClass>(itemKey);\r\n const baseClass = relClass?.baseClass;\r\n\r\n const setResult = await super.setBaseClass(itemKey, baseClassKey);\r\n if (setResult.errorMessage === undefined) {\r\n const result = await this.validate(relClass!);\r\n if (result.errorMessage !== undefined) {\r\n relClass!.baseClass = baseClass;\r\n return { itemKey, errorMessage: result.errorMessage };\r\n }\r\n }\r\n return setResult;\r\n }\r\n\r\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n await relationshipClass.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: relationshipKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Relationship Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\r\n const relationshipClass = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await property.fromJSON(navigationProps);\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name };\r\n }\r\n\r\n public async setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.multiplicity = multiplicity;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.polymorphic = polymorphic;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.relationshipEnd = relationshipEnd;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const existing: LazyLoadedRelationshipConstraintClass | undefined = constraint.abstractConstraint;\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n\r\n if (undefined === abstractConstraint) {\r\n mutableConstraint.abstractConstraint = undefined;\r\n } else {\r\n mutableConstraint.abstractConstraint = new DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);\r\n }\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addClass(ecClass);\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.removeClass(ecClass);\r\n\r\n const result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.addClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(constraint, customAttribute);\r\n const result: SchemaItemEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeCustomAttribute(constraint, customAttribute);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n private async validate(relationshipOrConstraint: RelationshipClass | RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n let diagnostics: AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>> | AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;\r\n\r\n if (relationshipOrConstraint instanceof RelationshipClass) {\r\n diagnostics = Rules.validateRelationship(relationshipOrConstraint);\r\n } else {\r\n diagnostics = Rules.validateRelationshipConstraint(relationshipOrConstraint);\r\n }\r\n\r\n const errorMessages = [];\r\n for await (const diagnostic of diagnostics) {\r\n errorMessages.push(`${diagnostic.code}: ${diagnostic.messageText}`);\r\n }\r\n\r\n if (errorMessages.length > 0) {\r\n return { errorMessage: errorMessages.join(\"\\r\\n\") };\r\n }\r\n\r\n return {};\r\n }\r\n}\r\n"]}
|
|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AC;gBACN,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,aAAa,EAAE,IAAI,oCAAwB,CAAC,wBAAwB,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;YAC9I,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA3OD,kDA2OC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttribute, DelayedPromiseWithProps, ECClassModifier, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationPropertyProps,\r\n RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaItemType,\r\n SchemaKey, StrengthDirection, StrengthType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableRelationshipClass, MutableRelationshipConstraint } from \"./Mutable/MutableRelationshipClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { AnyDiagnostic, RelationshipConstraintDiagnostic, SchemaItemDiagnostic } from \"../Validation/Diagnostic\";\r\nimport { NavigationProperties } from \"./Properties\";\r\nimport { ClassId, CustomAttributeId, ECEditingStatus, RelationshipConstraintId, SchemaEditingError } from \"./Exception\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\r\n */\r\nexport class RelationshipClasses extends ECClasses {\r\n public constructor(schemaEditor: SchemaContextEditor) {\r\n super(SchemaItemType.RelationshipClass, schemaEditor);\r\n }\r\n\r\n /**\r\n * Allows access for editing of NavigationProperty attributes.\r\n */\r\n public readonly navigationProperties = new NavigationProperties(this.schemaItemType, this.schemaEditor);\r\n\r\n /**\r\n * Creates a RelationshipClass.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param name The name of the new class.\r\n * @param modifier The ECClassModifier of the new class.\r\n * @param strength The relationship StrengthType of the class.\r\n * @param StrengthDirection The relationship StrengthDirection of the class.\r\n * @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.\r\n */\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemKey> {\r\n try {\r\n const newClass = await this.createClass<RelationshipClass>(schemaKey, this.schemaItemType, (schema) => schema.createRelationshipClass.bind(schema), name, baseClassKey, modifier) as MutableRelationshipClass;\r\n\r\n newClass.setStrength(strength);\r\n newClass.setStrengthDirection(direction);\r\n\r\n return newClass.key;\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFailed, new ClassId(this.schemaItemType, name, schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the source RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param source The RelationshipConstraint to add.\r\n */\r\n public async setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<void> {\r\n const relationship = await this.getSchemaItem<MutableRelationshipClass>(relationshipKey)\r\n .catch((e) => {\r\n throw new SchemaEditingError(ECEditingStatus.SetSourceConstraint, new ClassId(this.schemaItemType, relationshipKey), e);\r\n });\r\n\r\n relationship.setSourceConstraint(source);\r\n }\r\n\r\n /**\r\n * Sets the target RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param target The RelationshipConstraint to add.\r\n */\r\n public async setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<void> {\r\n const relationship = await this.getSchemaItem<MutableRelationshipClass>(relationshipKey)\r\n .catch((e) => {\r\n throw new SchemaEditingError(ECEditingStatus.SetTargetConstraint, new ClassId(this.schemaItemType, relationshipKey), e);\r\n });\r\n\r\n relationship.setTargetConstraint(target);\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass through a RelationshipClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemKey> {\r\n try {\r\n const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createRelationshipClass.bind(schema), relationshipProps);\r\n\r\n await newClass.source.fromJSON(relationshipProps.source);\r\n await newClass.target.fromJSON(relationshipProps.target);\r\n\r\n return newClass.key;\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, relationshipProps.name!, schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the base class of a RelationshipClass.\r\n * @param relationshipKey The SchemaItemKey of the RelationshipClass.\r\n * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.\r\n */\r\n public override async setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<void> {\r\n const relClass = await this.schemaEditor.schemaContext.getSchemaItem<RelationshipClass>(itemKey);\r\n const baseClass = relClass?.baseClass;\r\n\r\n await super.setBaseClass(itemKey, baseClassKey);\r\n\r\n try {\r\n await this.validate(relClass!);\r\n } catch(e: any) {\r\n relClass!.baseClass = baseClass;\r\n throw new SchemaEditingError(ECEditingStatus.SetBaseClass, new ClassId(SchemaItemType.RelationshipClass, itemKey), e);\r\n }\r\n }\r\n\r\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<void> {\r\n try {\r\n const relationshipClass = await this.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n await relationshipClass.createNavigationProperty(name, relationship, direction);\r\n } catch(e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateNavigationProperty, new ClassId(SchemaItemType.RelationshipClass, relationshipKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Relationship Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<void> {\r\n try {\r\n const relationshipClass = await this.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await property.fromJSON(navigationProps);\r\n } catch(e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateNavigationPropertyFromProps, new ClassId(SchemaItemType.RelationshipClass, relationshipKey), e);\r\n }\r\n }\r\n\r\n public async setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<void> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.multiplicity = multiplicity;\r\n }\r\n\r\n public async setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<void> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.polymorphic = polymorphic;\r\n }\r\n\r\n public async setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<void> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.relationshipEnd = relationshipEnd;\r\n }\r\n\r\n public async setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<void> {\r\n const existing: LazyLoadedRelationshipConstraintClass | undefined = constraint.abstractConstraint;\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n\r\n if (undefined === abstractConstraint) {\r\n mutableConstraint.abstractConstraint = undefined;\r\n } else {\r\n mutableConstraint.abstractConstraint = new DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);\r\n }\r\n\r\n try {\r\n await this.validate(constraint.relationshipClass);\r\n } catch(e: any){\r\n mutableConstraint.abstractConstraint = existing;\r\n throw new SchemaEditingError(ECEditingStatus.SetAbstractConstraint, new RelationshipConstraintId(constraint), e);\r\n }\r\n\r\n try {\r\n await this.validate(constraint);\r\n } catch(e: any){\r\n mutableConstraint.abstractConstraint = existing;\r\n throw new SchemaEditingError(ECEditingStatus.SetAbstractConstraint, new RelationshipConstraintId(constraint), e);\r\n }\r\n }\r\n\r\n public async addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<void> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addClass(ecClass);\r\n\r\n try {\r\n await this.validate(constraint.relationshipClass);\r\n } catch(e: any){\r\n mutableConstraint.removeClass(ecClass);\r\n throw new SchemaEditingError(ECEditingStatus.AddConstraintClass, new RelationshipConstraintId(constraint), e);\r\n }\r\n\r\n try {\r\n await this.validate(constraint);\r\n } catch(e: any){\r\n mutableConstraint.removeClass(ecClass);\r\n throw new SchemaEditingError(ECEditingStatus.AddConstraintClass, new RelationshipConstraintId(constraint), e);\r\n }\r\n }\r\n\r\n public async removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<void> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.removeClass(ecClass);\r\n\r\n try{\r\n await this.validate(constraint);\r\n } catch(e: any) {\r\n mutableConstraint.addClass(ecClass);\r\n throw new SchemaEditingError(ECEditingStatus.RemoveConstraintClass, new RelationshipConstraintId(constraint), e);\r\n }\r\n }\r\n\r\n public async addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<void> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addCustomAttribute(customAttribute);\r\n\r\n const diagnosticIterable = Rules.validateCustomAttributeInstance(constraint, customAttribute);\r\n\r\n const diagnostics: AnyDiagnostic[] = [];\r\n for await (const diagnostic of diagnosticIterable) {\r\n diagnostics.push(diagnostic);\r\n }\r\n\r\n if (diagnostics.length > 0) {\r\n this.removeCustomAttribute(constraint, customAttribute);\r\n throw new SchemaEditingError(ECEditingStatus.AddCustomAttributeToConstraint, new RelationshipConstraintId(constraint),\r\n new SchemaEditingError(ECEditingStatus.RuleViolation, new CustomAttributeId(customAttribute.className, constraint), undefined, diagnostics));\r\n }\r\n }\r\n\r\n private async validate(relationshipOrConstraint: RelationshipClass | RelationshipConstraint): Promise<void> {\r\n let diagnosticIterable: AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>> | AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;\r\n let relationshipKey: SchemaItemKey | string;\r\n\r\n if (relationshipOrConstraint instanceof RelationshipClass) {\r\n diagnosticIterable = Rules.validateRelationship(relationshipOrConstraint);\r\n relationshipKey = relationshipOrConstraint.key;\r\n } else {\r\n diagnosticIterable = Rules.validateRelationshipConstraint(relationshipOrConstraint);\r\n relationshipKey = relationshipOrConstraint.relationshipClass.key;\r\n }\r\n\r\n const diagnostics: AnyDiagnostic[] = [];\r\n for await (const diagnostic of diagnosticIterable) {\r\n diagnostics.push(diagnostic);\r\n }\r\n\r\n if (diagnostics.length > 0) {\r\n if (relationshipOrConstraint instanceof RelationshipClass) {\r\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new ClassId(SchemaItemType.RelationshipClass, relationshipKey), undefined, diagnostics);\r\n } else {\r\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new RelationshipConstraintId(relationshipOrConstraint), undefined, diagnostics);\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
|
-
import { SchemaItemKey, SchemaItemProps } from "@itwin/ecschema-metadata";
|
|
4
|
+
import { SchemaItem, SchemaItemKey, SchemaItemProps, SchemaItemType, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { SchemaContextEditor } from "./Editor";
|
|
6
|
+
import { MutableSchema } from "./Mutable/MutableSchema";
|
|
7
|
+
export type CreateSchemaItem<T extends SchemaItem> = (schema: MutableSchema) => (name: string, ...args: any[]) => Promise<T>;
|
|
8
|
+
export type CreateSchemaItemFromProps<T extends SchemaItem> = (props: SchemaItemProps, ...args: any[]) => Promise<T>;
|
|
6
9
|
/**
|
|
7
10
|
* @internal
|
|
8
11
|
* A class allowing you to edit the schema item base class.
|
|
9
12
|
*/
|
|
10
|
-
export declare class SchemaItems {
|
|
11
|
-
protected
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
export declare abstract class SchemaItems {
|
|
14
|
+
protected schemaItemType: SchemaItemType;
|
|
15
|
+
protected schemaEditor: SchemaContextEditor;
|
|
16
|
+
constructor(schemaItemType: SchemaItemType, schemaEditor: SchemaContextEditor);
|
|
17
|
+
protected getSchema(schemaKey: SchemaKey): Promise<MutableSchema>;
|
|
18
|
+
protected getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey, schemaItemType?: SchemaItemType | null): Promise<T>;
|
|
19
|
+
protected lookupSchemaItem<T extends SchemaItem>(schemaOrKey: MutableSchema | SchemaKey, schemaItemKey: SchemaItemKey, schemaItemType?: SchemaItemType | null): Promise<T>;
|
|
20
|
+
protected createSchemaItem<T extends SchemaItem>(schemaKey: SchemaKey, type: SchemaItemType, create: CreateSchemaItem<T>, name: string, ...args: any[]): Promise<T>;
|
|
21
|
+
protected createSchemaItemFromProps<T extends SchemaItem>(schemaKey: SchemaKey, type: SchemaItemType, create: CreateSchemaItem<T>, props: SchemaItemProps): Promise<T>;
|
|
14
22
|
}
|
|
15
23
|
//# sourceMappingURL=SchemaItems.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItems.d.ts","sourceRoot":"","sources":["../../../src/Editing/SchemaItems.ts"],"names":[],"mappings":"AAIA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