@itwin/ecschema-editing 4.4.0-dev.26 → 4.4.0-dev.28

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.
@@ -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
- // // TODO: Add relationshipConstraint, multiplicity arguments.
23
- // // Note: This method is not done yet, there's a lot of arguments.
24
- // public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, sourceMultiplicity: RelationshipMultiplicity, targetMultiplicity: RelationshipMultiplicity, baseClass?: SchemaItemKey) {
25
- // const schema = await this._schemaEditor.getSchema(schemaKey);
26
- // if (schema === undefined) return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
27
- // const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;
28
- // if (newClass === undefined) {
29
- // return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
30
- // }
31
- // if (baseClass !== undefined) {
32
- // const baseClassItem = await schema.lookupItem(baseClass) as RelationshipClass;
33
- // newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClass, async () => baseClassItem);
34
- // }
35
- // newClass.setStrength(strength);
36
- // newClass.setStrengthDirection(direction);
37
- // return { itemKey: newClass.key };
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
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Relationship Class ${relationshipKey.fullName} not found in schema context.`);
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
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Expected ${relationshipKey.fullName} to be of type Relationship Class.`);
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":["/*---------------------------------------------------------------------------------------------\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 ECObjectsError, ECObjectsStatus, RelationshipClass, RelationshipClassProps, SchemaItemKey, SchemaItemType,\r\n SchemaKey, StrengthDirection,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableRelationshipClass } from \"./Mutable/MutableRelationshipClass\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\r\n * Can only create RelationshipClass objects using RelationshipClassProps for now.\r\n */\r\nexport class RelationshipClasses extends ECClasses {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n // // TODO: Add relationshipConstraint, multiplicity arguments.\r\n // // Note: This method is not done yet, there's a lot of arguments.\r\n // public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, sourceMultiplicity: RelationshipMultiplicity, targetMultiplicity: RelationshipMultiplicity, baseClass?: SchemaItemKey) {\r\n // const schema = await this._schemaEditor.getSchema(schemaKey);\r\n // if (schema === undefined) return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n // const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\r\n // if (newClass === undefined) {\r\n // return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n // }\r\n\r\n // if (baseClass !== undefined) {\r\n // const baseClassItem = await schema.lookupItem(baseClass) as RelationshipClass;\r\n // newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClass, async () => baseClassItem);\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 * 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 if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${relationshipProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\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 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 throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Relationship Class ${relationshipKey.fullName} not found in schema context.`);\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `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"]}
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,QA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,EAAE,CAAC;QACzB,IAAI,KAAK,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":["/*---------------------------------------------------------------------------------------------\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 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\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(_schemaEditor);\r\n }\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 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 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 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"]}
@@ -47,7 +47,7 @@ export declare const DiagnosticCodes: {
47
47
  IncompatibleUnitPropertyOverride: string;
48
48
  AbstractConstraintMustNarrowBaseConstraints: string;
49
49
  DerivedConstraintsMustNarrowBaseConstraints: string;
50
- ConstraintClassesDeriveFromAbstractContraint: string;
50
+ ConstraintClassesDeriveFromAbstractConstraint: string;
51
51
  AtLeastOneConstraintClassDefined: string;
52
52
  AbstractConstraintMustExistWithMultipleConstraints: string;
53
53
  };
@@ -317,7 +317,7 @@ export declare const Diagnostics: {
317
317
  diagnosticType: import("./Diagnostic").DiagnosticType;
318
318
  };
319
319
  /** EC-1502: Required message parameters: constraint class name, relationship end (source/target), relationship name, abstract constraint class name */
320
- ConstraintClassesDeriveFromAbstractContraint: {
320
+ ConstraintClassesDeriveFromAbstractConstraint: {
321
321
  new (ecDefinition: import("@itwin/ecschema-metadata").SchemaItem, messageArgs: [string, string, string, string], category?: import("./Diagnostic").DiagnosticCategory): {
322
322
  readonly code: string;
323
323
  readonly messageText: string;
@@ -401,6 +401,11 @@ export declare function incompatibleUnitPropertyOverride(property: AnyProperty):
401
401
  * @internal
402
402
  */
403
403
  export declare function validateNavigationProperty(property: AnyProperty): AsyncIterable<PropertyDiagnostic<any[]>>;
404
+ /**
405
+ * Validates a Relationship class and yields EC-1500, EC-1501, and EC-1502 rule violations.
406
+ * @internal
407
+ */
408
+ export declare function validateRelationship(ecClass: RelationshipClass): AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>>;
404
409
  /**
405
410
  * EC Rule: When overriding a RelationshipClass, the derived abstract constraint must narrow the base constraint classes.
406
411
  * @internal
@@ -415,7 +420,12 @@ export declare function derivedConstraintsMustNarrowBaseConstraints(ecClass: Rel
415
420
  * EC Rule: All constraint classes must have a common base class specified in the abstract constraint.
416
421
  * @internal
417
422
  */
418
- export declare function constraintClassesDeriveFromAbstractContraint(ecClass: RelationshipClass): AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>>;
423
+ export declare function constraintClassesDeriveFromAbstractConstraint(ecClass: RelationshipClass): AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>>;
424
+ /**
425
+ * Validates a RelationshipConstraint and yields EC-1600 and EC-1601 rule violations.
426
+ * @internal
427
+ */
428
+ export declare function validateRelationshipConstraint(constraint: RelationshipConstraint): AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;
419
429
  /**
420
430
  * EC Rule: At least on concrete constraint class must be defined in the list of constraint classes.
421
431
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"ECRules.d.ts","sourceRoot":"","sources":["../../../src/Validation/ECRules.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,6BAA6B,EAClD,WAAW,EAAE,WAAW,EACjC,iBAAiB,EAAE,sBAAsB,EAA4B,MAAM,EAEtF,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EAC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AAuB,gCAAgC,CAAC,UAAU,EAAE,sBAAsB,GAAG,aAAa,CAAC,gCAAgC,CAAC,GAAG,EAAE,CAAC,CAAC,CAKlJ;AAED;;;GAGG;AACH,wBAAuB,kDAAkD,CAAC,UAAU,EAAE,sBAAsB,GAAG,aAAa,CAAC,gCAAgC,CAAC,GAAG,EAAE,CAAC,CAAC,CAWpK;AAaD;;;GAGG;AACH,wBAAuB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,CAMnI;AAED;;;GAGG;AACH,wBAAuB,2CAA2C,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC,oBAAoB,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,CAWpJ;AAED;;;GAGG;AACH,wBAAuB,+BAA+B,CAAC,SAAS,EAAE,6BAA6B,EAAE,eAAe,EAAE,eAAe,GAAG,aAAa,CAAC,kCAAkC,CAAC,GAAG,EAAE,CAAC,CAAC,CAI3L"}
@@ -7,7 +7,7 @@
7
7
  * @module Validation
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.validateCustomAttributeInstance = exports.mixinAppliedToClassMustDeriveFromConstraint = exports.enumerationTypeUnsupported = exports.abstractConstraintMustExistWithMultipleConstraints = exports.atLeastOneConstraintClassDefined = exports.constraintClassesDeriveFromAbstractContraint = exports.derivedConstraintsMustNarrowBaseConstraints = exports.abstractConstraintMustNarrowBaseConstraints = exports.validateNavigationProperty = exports.incompatibleUnitPropertyOverride = exports.incompatibleTypePropertyOverride = exports.incompatibleValueTypePropertyOverride = exports.baseClassIsOfDifferentType = exports.baseClassIsSealed = exports.validateSchemaReferencesSync = exports.validateSchemaReferences = exports.ECRuleSet = exports.Diagnostics = exports.DiagnosticCodes = void 0;
10
+ exports.validateCustomAttributeInstance = exports.mixinAppliedToClassMustDeriveFromConstraint = exports.enumerationTypeUnsupported = exports.abstractConstraintMustExistWithMultipleConstraints = exports.atLeastOneConstraintClassDefined = exports.validateRelationshipConstraint = exports.constraintClassesDeriveFromAbstractConstraint = exports.derivedConstraintsMustNarrowBaseConstraints = exports.abstractConstraintMustNarrowBaseConstraints = exports.validateRelationship = exports.validateNavigationProperty = exports.incompatibleUnitPropertyOverride = exports.incompatibleTypePropertyOverride = exports.incompatibleValueTypePropertyOverride = exports.baseClassIsOfDifferentType = exports.baseClassIsSealed = exports.validateSchemaReferencesSync = exports.validateSchemaReferences = exports.ECRuleSet = exports.Diagnostics = exports.DiagnosticCodes = void 0;
11
11
  const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
12
  const Diagnostic_1 = require("./Diagnostic");
13
13
  const ruleSetName = "ECObjects";
@@ -65,7 +65,7 @@ exports.DiagnosticCodes = {
65
65
  // Relationship Rule Codes (1500-1599)
66
66
  AbstractConstraintMustNarrowBaseConstraints: getCode(1500),
67
67
  DerivedConstraintsMustNarrowBaseConstraints: getCode(1501),
68
- ConstraintClassesDeriveFromAbstractContraint: getCode(1502),
68
+ ConstraintClassesDeriveFromAbstractConstraint: getCode(1502),
69
69
  // Relationship Constraint Rule Codes (1600-1699)
70
70
  AtLeastOneConstraintClassDefined: getCode(1600),
71
71
  AbstractConstraintMustExistWithMultipleConstraints: getCode(1601),
@@ -116,7 +116,7 @@ exports.Diagnostics = {
116
116
  /** EC-1501: Required message parameters: constraint class name, relationship end (source/target), relationship name, base relationship name */
117
117
  DerivedConstraintsMustNarrowBaseConstraints: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.DerivedConstraintsMustNarrowBaseConstraints, "The constraint class '{0}' on the {1}-Constraint of '{2}' is not supported by the base class constraint in '{3}'."),
118
118
  /** EC-1502: Required message parameters: constraint class name, relationship end (source/target), relationship name, abstract constraint class name */
119
- ConstraintClassesDeriveFromAbstractContraint: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.ConstraintClassesDeriveFromAbstractContraint, "The constraint class '{0}' on the {1}-Constraint of '{2}' is not derived from the abstract constraint class '{3}'."),
119
+ ConstraintClassesDeriveFromAbstractConstraint: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.ConstraintClassesDeriveFromAbstractConstraint, "The constraint class '{0}' on the {1}-Constraint of '{2}' is not derived from the abstract constraint class '{3}'."),
120
120
  /** EC-1600: Required message parameters: relationship end (source/target), relationship name */
121
121
  AtLeastOneConstraintClassDefined: (0, Diagnostic_1.createRelationshipConstraintDiagnosticClass)(exports.DiagnosticCodes.AtLeastOneConstraintClassDefined, "The {0}-Constraint of '{1}' does not contain any constraint classes."),
122
122
  /** EC-1601: Required message parameters: relationship end (source/target), relationship name */
@@ -143,7 +143,7 @@ exports.ECRuleSet = {
143
143
  ],
144
144
  relationshipRules: [
145
145
  abstractConstraintMustNarrowBaseConstraints,
146
- constraintClassesDeriveFromAbstractContraint,
146
+ constraintClassesDeriveFromAbstractConstraint,
147
147
  derivedConstraintsMustNarrowBaseConstraints,
148
148
  ],
149
149
  relationshipConstraintRules: [
@@ -380,6 +380,16 @@ async function* validateNavigationProperty(property) {
380
380
  return;
381
381
  }
382
382
  exports.validateNavigationProperty = validateNavigationProperty;
383
+ /**
384
+ * Validates a Relationship class and yields EC-1500, EC-1501, and EC-1502 rule violations.
385
+ * @internal
386
+ */
387
+ async function* validateRelationship(ecClass) {
388
+ yield* abstractConstraintMustNarrowBaseConstraints(ecClass);
389
+ yield* derivedConstraintsMustNarrowBaseConstraints(ecClass);
390
+ yield* constraintClassesDeriveFromAbstractConstraint(ecClass);
391
+ }
392
+ exports.validateRelationship = validateRelationship;
383
393
  /**
384
394
  * EC Rule: When overriding a RelationshipClass, the derived abstract constraint must narrow the base constraint classes.
385
395
  * @internal
@@ -416,15 +426,24 @@ exports.derivedConstraintsMustNarrowBaseConstraints = derivedConstraintsMustNarr
416
426
  * EC Rule: All constraint classes must have a common base class specified in the abstract constraint.
417
427
  * @internal
418
428
  */
419
- async function* constraintClassesDeriveFromAbstractContraint(ecClass) {
420
- const sourceResult = await applyConstraintClassesDeriveFromAbstractContraint(ecClass, ecClass.source);
429
+ async function* constraintClassesDeriveFromAbstractConstraint(ecClass) {
430
+ const sourceResult = await applyConstraintClassesDeriveFromAbstractConstraint(ecClass, ecClass.source);
421
431
  if (sourceResult)
422
432
  yield sourceResult;
423
- const targetResult = await applyConstraintClassesDeriveFromAbstractContraint(ecClass, ecClass.target);
433
+ const targetResult = await applyConstraintClassesDeriveFromAbstractConstraint(ecClass, ecClass.target);
424
434
  if (targetResult)
425
435
  yield targetResult;
426
436
  }
427
- exports.constraintClassesDeriveFromAbstractContraint = constraintClassesDeriveFromAbstractContraint;
437
+ exports.constraintClassesDeriveFromAbstractConstraint = constraintClassesDeriveFromAbstractConstraint;
438
+ /**
439
+ * Validates a RelationshipConstraint and yields EC-1600 and EC-1601 rule violations.
440
+ * @internal
441
+ */
442
+ async function* validateRelationshipConstraint(constraint) {
443
+ yield* atLeastOneConstraintClassDefined(constraint);
444
+ yield* abstractConstraintMustExistWithMultipleConstraints(constraint);
445
+ }
446
+ exports.validateRelationshipConstraint = validateRelationshipConstraint;
428
447
  /**
429
448
  * EC Rule: At least on concrete constraint class must be defined in the list of constraint classes.
430
449
  * @internal
@@ -545,7 +564,7 @@ async function applyDerivedConstraintsMustNarrowBaseConstraints(ecClass, constra
545
564
  }
546
565
  return;
547
566
  }
548
- async function applyConstraintClassesDeriveFromAbstractContraint(ecClass, constraint) {
567
+ async function applyConstraintClassesDeriveFromAbstractConstraint(ecClass, constraint) {
549
568
  const abstractConstraint = await getAbstractConstraint(constraint);
550
569
  if (!abstractConstraint)
551
570
  return;
@@ -556,13 +575,13 @@ async function applyConstraintClassesDeriveFromAbstractContraint(ecClass, constr
556
575
  if (constraintClass.schemaItemType === ecschema_metadata_1.SchemaItemType.Mixin && abstractConstraint.schemaItemType === ecschema_metadata_1.SchemaItemType.EntityClass) {
557
576
  if (!await (constraintClass).applicableTo(abstractConstraint)) {
558
577
  const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
559
- return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractContraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
578
+ return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractConstraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
560
579
  }
561
580
  continue;
562
581
  }
563
582
  if (!await constraintClass.is(abstractConstraint)) {
564
583
  const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
565
- return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractContraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
584
+ return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractConstraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
566
585
  }
567
586
  }
568
587
  return;