@itwin/ecschema-editing 3.0.0-dev.72

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.
Files changed (197) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +11 -0
  4. package/lib/Editing/Constants.d.ts +21 -0
  5. package/lib/Editing/Constants.d.ts.map +1 -0
  6. package/lib/Editing/Constants.js +65 -0
  7. package/lib/Editing/Constants.js.map +1 -0
  8. package/lib/Editing/CustomAttributes.d.ts +21 -0
  9. package/lib/Editing/CustomAttributes.d.ts.map +1 -0
  10. package/lib/Editing/CustomAttributes.js +59 -0
  11. package/lib/Editing/CustomAttributes.js.map +1 -0
  12. package/lib/Editing/ECClasses.d.ts +33 -0
  13. package/lib/Editing/ECClasses.d.ts.map +1 -0
  14. package/lib/Editing/ECClasses.js +186 -0
  15. package/lib/Editing/ECClasses.js.map +1 -0
  16. package/lib/Editing/Editor.d.ts +105 -0
  17. package/lib/Editing/Editor.d.ts.map +1 -0
  18. package/lib/Editing/Editor.js +175 -0
  19. package/lib/Editing/Editor.js.map +1 -0
  20. package/lib/Editing/Entities.d.ts +23 -0
  21. package/lib/Editing/Entities.d.ts.map +1 -0
  22. package/lib/Editing/Entities.js +89 -0
  23. package/lib/Editing/Entities.js.map +1 -0
  24. package/lib/Editing/Enumerations.d.ts +22 -0
  25. package/lib/Editing/Enumerations.d.ts.map +1 -0
  26. package/lib/Editing/Enumerations.js +71 -0
  27. package/lib/Editing/Enumerations.js.map +1 -0
  28. package/lib/Editing/Formats.d.ts +21 -0
  29. package/lib/Editing/Formats.d.ts.map +1 -0
  30. package/lib/Editing/Formats.js +61 -0
  31. package/lib/Editing/Formats.js.map +1 -0
  32. package/lib/Editing/InvertedUnits.d.ts +18 -0
  33. package/lib/Editing/InvertedUnits.d.ts.map +1 -0
  34. package/lib/Editing/InvertedUnits.js +86 -0
  35. package/lib/Editing/InvertedUnits.js.map +1 -0
  36. package/lib/Editing/KindOfQuantities.d.ts +29 -0
  37. package/lib/Editing/KindOfQuantities.d.ts.map +1 -0
  38. package/lib/Editing/KindOfQuantities.js +80 -0
  39. package/lib/Editing/KindOfQuantities.js.map +1 -0
  40. package/lib/Editing/Mixins.d.ts +23 -0
  41. package/lib/Editing/Mixins.d.ts.map +1 -0
  42. package/lib/Editing/Mixins.js +89 -0
  43. package/lib/Editing/Mixins.js.map +1 -0
  44. package/lib/Editing/Mutable/MutableCAClass.d.ts +10 -0
  45. package/lib/Editing/Mutable/MutableCAClass.d.ts.map +1 -0
  46. package/lib/Editing/Mutable/MutableCAClass.js +16 -0
  47. package/lib/Editing/Mutable/MutableCAClass.js.map +1 -0
  48. package/lib/Editing/Mutable/MutableClass.d.ts +35 -0
  49. package/lib/Editing/Mutable/MutableClass.d.ts.map +1 -0
  50. package/lib/Editing/Mutable/MutableClass.js +23 -0
  51. package/lib/Editing/Mutable/MutableClass.js.map +1 -0
  52. package/lib/Editing/Mutable/MutableConstant.d.ts +13 -0
  53. package/lib/Editing/Mutable/MutableConstant.d.ts.map +1 -0
  54. package/lib/Editing/Mutable/MutableConstant.js +16 -0
  55. package/lib/Editing/Mutable/MutableConstant.js.map +1 -0
  56. package/lib/Editing/Mutable/MutableEntityClass.d.ts +16 -0
  57. package/lib/Editing/Mutable/MutableEntityClass.d.ts.map +1 -0
  58. package/lib/Editing/Mutable/MutableEntityClass.js +60 -0
  59. package/lib/Editing/Mutable/MutableEntityClass.js.map +1 -0
  60. package/lib/Editing/Mutable/MutableEnumeration.d.ts +10 -0
  61. package/lib/Editing/Mutable/MutableEnumeration.d.ts.map +1 -0
  62. package/lib/Editing/Mutable/MutableEnumeration.js +15 -0
  63. package/lib/Editing/Mutable/MutableEnumeration.js.map +1 -0
  64. package/lib/Editing/Mutable/MutableFormat.d.ts +18 -0
  65. package/lib/Editing/Mutable/MutableFormat.d.ts.map +1 -0
  66. package/lib/Editing/Mutable/MutableFormat.js +16 -0
  67. package/lib/Editing/Mutable/MutableFormat.js.map +1 -0
  68. package/lib/Editing/Mutable/MutableInvertedUnit.d.ts +11 -0
  69. package/lib/Editing/Mutable/MutableInvertedUnit.d.ts.map +1 -0
  70. package/lib/Editing/Mutable/MutableInvertedUnit.js +16 -0
  71. package/lib/Editing/Mutable/MutableInvertedUnit.js.map +1 -0
  72. package/lib/Editing/Mutable/MutableKindOfQuantity.d.ts +11 -0
  73. package/lib/Editing/Mutable/MutableKindOfQuantity.d.ts.map +1 -0
  74. package/lib/Editing/Mutable/MutableKindOfQuantity.js +16 -0
  75. package/lib/Editing/Mutable/MutableKindOfQuantity.js.map +1 -0
  76. package/lib/Editing/Mutable/MutableMixin.d.ts +12 -0
  77. package/lib/Editing/Mutable/MutableMixin.d.ts.map +1 -0
  78. package/lib/Editing/Mutable/MutableMixin.js +16 -0
  79. package/lib/Editing/Mutable/MutableMixin.js.map +1 -0
  80. package/lib/Editing/Mutable/MutablePhenomenon.d.ts +10 -0
  81. package/lib/Editing/Mutable/MutablePhenomenon.d.ts.map +1 -0
  82. package/lib/Editing/Mutable/MutablePhenomenon.js +16 -0
  83. package/lib/Editing/Mutable/MutablePhenomenon.js.map +1 -0
  84. package/lib/Editing/Mutable/MutableProperty.d.ts +9 -0
  85. package/lib/Editing/Mutable/MutableProperty.d.ts.map +1 -0
  86. package/lib/Editing/Mutable/MutableProperty.js +16 -0
  87. package/lib/Editing/Mutable/MutableProperty.js.map +1 -0
  88. package/lib/Editing/Mutable/MutablePropertyCategory.d.ts +10 -0
  89. package/lib/Editing/Mutable/MutablePropertyCategory.d.ts.map +1 -0
  90. package/lib/Editing/Mutable/MutablePropertyCategory.js +16 -0
  91. package/lib/Editing/Mutable/MutablePropertyCategory.js.map +1 -0
  92. package/lib/Editing/Mutable/MutableRelationshipClass.d.ts +22 -0
  93. package/lib/Editing/Mutable/MutableRelationshipClass.d.ts.map +1 -0
  94. package/lib/Editing/Mutable/MutableRelationshipClass.js +25 -0
  95. package/lib/Editing/Mutable/MutableRelationshipClass.js.map +1 -0
  96. package/lib/Editing/Mutable/MutableSchema.d.ts +46 -0
  97. package/lib/Editing/Mutable/MutableSchema.d.ts.map +1 -0
  98. package/lib/Editing/Mutable/MutableSchema.js +18 -0
  99. package/lib/Editing/Mutable/MutableSchema.js.map +1 -0
  100. package/lib/Editing/Mutable/MutableUnit.d.ts +12 -0
  101. package/lib/Editing/Mutable/MutableUnit.d.ts.map +1 -0
  102. package/lib/Editing/Mutable/MutableUnit.js +16 -0
  103. package/lib/Editing/Mutable/MutableUnit.js.map +1 -0
  104. package/lib/Editing/Mutable/MutableUnitSystem.d.ts +9 -0
  105. package/lib/Editing/Mutable/MutableUnitSystem.d.ts.map +1 -0
  106. package/lib/Editing/Mutable/MutableUnitSystem.js +16 -0
  107. package/lib/Editing/Mutable/MutableUnitSystem.js.map +1 -0
  108. package/lib/Editing/Phenomena.d.ts +16 -0
  109. package/lib/Editing/Phenomena.d.ts.map +1 -0
  110. package/lib/Editing/Phenomena.js +48 -0
  111. package/lib/Editing/Phenomena.js.map +1 -0
  112. package/lib/Editing/PropertyCategories.d.ts +17 -0
  113. package/lib/Editing/PropertyCategories.d.ts.map +1 -0
  114. package/lib/Editing/PropertyCategories.js +54 -0
  115. package/lib/Editing/PropertyCategories.js.map +1 -0
  116. package/lib/Editing/RelationshipClasses.d.ts +22 -0
  117. package/lib/Editing/RelationshipClasses.d.ts.map +1 -0
  118. package/lib/Editing/RelationshipClasses.js +70 -0
  119. package/lib/Editing/RelationshipClasses.js.map +1 -0
  120. package/lib/Editing/Structs.d.ts +20 -0
  121. package/lib/Editing/Structs.d.ts.map +1 -0
  122. package/lib/Editing/Structs.js +57 -0
  123. package/lib/Editing/Structs.js.map +1 -0
  124. package/lib/Editing/UnitSystems.d.ts +16 -0
  125. package/lib/Editing/UnitSystems.d.ts.map +1 -0
  126. package/lib/Editing/UnitSystems.js +44 -0
  127. package/lib/Editing/UnitSystems.js.map +1 -0
  128. package/lib/Editing/Units.d.ts +16 -0
  129. package/lib/Editing/Units.d.ts.map +1 -0
  130. package/lib/Editing/Units.js +62 -0
  131. package/lib/Editing/Units.js.map +1 -0
  132. package/lib/Validation/Diagnostic.d.ts +322 -0
  133. package/lib/Validation/Diagnostic.d.ts.map +1 -0
  134. package/lib/Validation/Diagnostic.js +311 -0
  135. package/lib/Validation/Diagnostic.js.map +1 -0
  136. package/lib/Validation/DiagnosticReporter.d.ts +97 -0
  137. package/lib/Validation/DiagnosticReporter.d.ts.map +1 -0
  138. package/lib/Validation/DiagnosticReporter.js +107 -0
  139. package/lib/Validation/DiagnosticReporter.js.map +1 -0
  140. package/lib/Validation/ECRules.d.ts +439 -0
  141. package/lib/Validation/ECRules.d.ts.map +1 -0
  142. package/lib/Validation/ECRules.js +679 -0
  143. package/lib/Validation/ECRules.js.map +1 -0
  144. package/lib/Validation/LoggingDiagnosticReporter.d.ts +14 -0
  145. package/lib/Validation/LoggingDiagnosticReporter.d.ts.map +1 -0
  146. package/lib/Validation/LoggingDiagnosticReporter.js +41 -0
  147. package/lib/Validation/LoggingDiagnosticReporter.js.map +1 -0
  148. package/lib/Validation/RuleSuppressionSet.d.ts +59 -0
  149. package/lib/Validation/RuleSuppressionSet.d.ts.map +1 -0
  150. package/lib/Validation/RuleSuppressionSet.js +10 -0
  151. package/lib/Validation/RuleSuppressionSet.js.map +1 -0
  152. package/lib/Validation/Rules.d.ts +65 -0
  153. package/lib/Validation/Rules.d.ts.map +1 -0
  154. package/lib/Validation/Rules.js +10 -0
  155. package/lib/Validation/Rules.js.map +1 -0
  156. package/lib/Validation/SchemaChanges.d.ts +608 -0
  157. package/lib/Validation/SchemaChanges.d.ts.map +1 -0
  158. package/lib/Validation/SchemaChanges.js +1136 -0
  159. package/lib/Validation/SchemaChanges.js.map +1 -0
  160. package/lib/Validation/SchemaCompareDiagnostics.d.ts +423 -0
  161. package/lib/Validation/SchemaCompareDiagnostics.d.ts.map +1 -0
  162. package/lib/Validation/SchemaCompareDiagnostics.js +112 -0
  163. package/lib/Validation/SchemaCompareDiagnostics.js.map +1 -0
  164. package/lib/Validation/SchemaCompareReporter.d.ts +12 -0
  165. package/lib/Validation/SchemaCompareReporter.d.ts.map +1 -0
  166. package/lib/Validation/SchemaCompareReporter.js +10 -0
  167. package/lib/Validation/SchemaCompareReporter.js.map +1 -0
  168. package/lib/Validation/SchemaCompareResultDelegate.d.ts +237 -0
  169. package/lib/Validation/SchemaCompareResultDelegate.d.ts.map +1 -0
  170. package/lib/Validation/SchemaCompareResultDelegate.js +349 -0
  171. package/lib/Validation/SchemaCompareResultDelegate.js.map +1 -0
  172. package/lib/Validation/SchemaCompareVisitor.d.ts +120 -0
  173. package/lib/Validation/SchemaCompareVisitor.d.ts.map +1 -0
  174. package/lib/Validation/SchemaCompareVisitor.js +207 -0
  175. package/lib/Validation/SchemaCompareVisitor.js.map +1 -0
  176. package/lib/Validation/SchemaComparer.d.ts +172 -0
  177. package/lib/Validation/SchemaComparer.d.ts.map +1 -0
  178. package/lib/Validation/SchemaComparer.js +666 -0
  179. package/lib/Validation/SchemaComparer.js.map +1 -0
  180. package/lib/Validation/SchemaValidater.d.ts +20 -0
  181. package/lib/Validation/SchemaValidater.d.ts.map +1 -0
  182. package/lib/Validation/SchemaValidater.js +62 -0
  183. package/lib/Validation/SchemaValidater.js.map +1 -0
  184. package/lib/Validation/SchemaValidationVisitor.d.ts +171 -0
  185. package/lib/Validation/SchemaValidationVisitor.d.ts.map +1 -0
  186. package/lib/Validation/SchemaValidationVisitor.js +729 -0
  187. package/lib/Validation/SchemaValidationVisitor.js.map +1 -0
  188. package/lib/Validation/SchemaWalker.d.ts +23 -0
  189. package/lib/Validation/SchemaWalker.d.ts.map +1 -0
  190. package/lib/Validation/SchemaWalker.js +52 -0
  191. package/lib/Validation/SchemaWalker.js.map +1 -0
  192. package/lib/ecschema-editing.d.ts +34 -0
  193. package/lib/ecschema-editing.d.ts.map +1 -0
  194. package/lib/ecschema-editing.js +55 -0
  195. package/lib/ecschema-editing.js.map +1 -0
  196. package/package.json +85 -0
  197. package/public/locales/en/ECSchemaEditing.json +27 -0
@@ -0,0 +1,679 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Validation
8
+ */
9
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
10
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
11
+ var m = o[Symbol.asyncIterator], i;
12
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
13
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
14
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
15
+ };
16
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
17
+ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
18
+ var i, p;
19
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
20
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
21
+ };
22
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
23
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
24
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
25
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
26
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
28
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
29
+ function fulfill(value) { resume("next", value); }
30
+ function reject(value) { resume("throw", value); }
31
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ 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.abstractClassWithNonAbstractBase = exports.baseClassIsOfDifferentType = exports.baseClassIsSealed = exports.validateSchemaReferencesSync = exports.validateSchemaReferences = exports.ECRuleSet = exports.Diagnostics = exports.DiagnosticCodes = void 0;
35
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
36
+ const Diagnostic_1 = require("./Diagnostic");
37
+ const ruleSetName = "ECObjects";
38
+ function getCode(code) {
39
+ return `${ruleSetName}-${code}`;
40
+ }
41
+ /**
42
+ * The unique diagnostic codes for ECObjects rules.
43
+ *
44
+ * To provide meaning to code values, with anticipation
45
+ * of future rules for all current EC Types, the following
46
+ * value ranges should be used:
47
+ *
48
+ * - Schema: 000-099
49
+ * - Class: 100-199
50
+ * - Constant: 200-299
51
+ * - CustomAttribute 300-399
52
+ * - CustomAttributeClass: 400-499
53
+ * - CustomAttributeContainer: 500-599
54
+ * - EntityClass: 600-699
55
+ * - Enumeration: 700-799
56
+ * - Format: 800-899
57
+ * - InvertedUnit: 900-999
58
+ * - KindOfQuantity: 1000-1099
59
+ * - Mixin: 1100-1199
60
+ * - Phenomenon: 1200-1299
61
+ * - Property: 1300-1399
62
+ * - PropertyCategory: 1400-1499
63
+ * - RelationshipClass: 1500-1599
64
+ * - RelationshipConstraint: 1600-1699
65
+ * - StructClass: 1700-1799
66
+ * - Unit: 1800-1899
67
+ * - UnitSystem: 1900-1999
68
+ * @beta
69
+ */
70
+ /* eslint-disable @typescript-eslint/naming-convention */
71
+ exports.DiagnosticCodes = {
72
+ // Class Rule Codes (100-199)
73
+ BaseClassIsSealed: getCode(100),
74
+ BaseClassOfDifferentType: getCode(101),
75
+ AbstractClassWithNonAbstractBase: getCode(102),
76
+ // CA Container Rule Codes (500-599)
77
+ CustomAttributeNotOfConcreteClass: getCode(500),
78
+ CustomAttributeSchemaMustBeReferenced: getCode(501),
79
+ CustomAttributeClassNotFound: getCode(502),
80
+ // Enumeration Rule Codes (700-799)
81
+ EnumerationTypeUnsupported: getCode(700),
82
+ // Mixin Rule Codes (1100-1199)
83
+ MixinAppliedToClassMustDeriveFromConstraint: getCode(1100),
84
+ // Property Rule Codes (1300-1399)
85
+ IncompatibleValueTypePropertyOverride: getCode(1300),
86
+ IncompatibleTypePropertyOverride: getCode(1301),
87
+ IncompatibleUnitPropertyOverride: getCode(1302),
88
+ // Relationship Rule Codes (1500-1599)
89
+ AbstractConstraintMustNarrowBaseConstraints: getCode(1500),
90
+ DerivedConstraintsMustNarrowBaseConstraints: getCode(1501),
91
+ ConstraintClassesDeriveFromAbstractContraint: getCode(1502),
92
+ // Relationship Constraint Rule Codes (1600-1699)
93
+ AtLeastOneConstraintClassDefined: getCode(1600),
94
+ AbstractConstraintMustExistWithMultipleConstraints: getCode(1601),
95
+ };
96
+ /**
97
+ * The list of [[IDiagnostic]] implementation classes used by the EC rule implementations.
98
+ * @beta
99
+ */
100
+ exports.Diagnostics = {
101
+ /** EC-001: Required message parameters: schema name, referenced schema name */
102
+ SupplementalSchemasCannotBeReferenced: (0, Diagnostic_1.createSchemaDiagnosticClass)(getCode(1), "Referenced schema '{1}' of schema '{0}' is a supplemental schema. Supplemental schemas are not allowed to be referenced."),
103
+ /** EC-002: Required message parameters: schema name, reference schema alias, first schema reference name, second schema reference name. */
104
+ SchemaRefAliasMustBeUnique: (0, Diagnostic_1.createSchemaDiagnosticClass)(getCode(2), "Schema '{0}' has multiple schema references ({2}, {3}) with the same alias '{1}', which is not allowed."),
105
+ /** EC-003: Required message parameters: schema name, cycle text */
106
+ ReferenceCyclesNotAllowed: (0, Diagnostic_1.createSchemaDiagnosticClass)(getCode(3), "Schema '{0}' has reference cycles: {1}"),
107
+ /** EC-100: Required message parameters: childClass.FullName, baseClass.FullName */
108
+ BaseClassIsSealed: (0, Diagnostic_1.createClassDiagnosticClass)(exports.DiagnosticCodes.BaseClassIsSealed, "Class '{0}' cannot derive from sealed base class '{1}'."),
109
+ /** EC-101: Required message parameters: childClass.FullName, baseClass.FullName, baseClass.schemaItemType */
110
+ BaseClassIsOfDifferentType: (0, Diagnostic_1.createClassDiagnosticClass)(exports.DiagnosticCodes.BaseClassOfDifferentType, "Class '{0}' cannot derive from base class '{1}' of type '{2}'."),
111
+ /** EC-102: Required message parameters: childClass.FullName, baseClass.FullName */
112
+ AbstractClassWithNonAbstractBase: (0, Diagnostic_1.createClassDiagnosticClass)(exports.DiagnosticCodes.AbstractClassWithNonAbstractBase, "Abstract Class '{0}' cannot derive from base class '{1}' because it is not an abstract class."),
113
+ /** EC-500: Required message parameters: CustomAttribute container name and CustomAttributeClass name. */
114
+ CustomAttributeNotOfConcreteClass: (0, Diagnostic_1.createCustomAttributeContainerDiagnosticClass)(exports.DiagnosticCodes.CustomAttributeNotOfConcreteClass, "The CustomAttribute container '{0}' has a CustomAttribute with the class '{1}' which is not a concrete class."),
115
+ /** EC-501: Required message parameters: CustomAttribute container name, CustomAttributeClass name, CustomAttributeClass Schema name. */
116
+ CustomAttributeSchemaMustBeReferenced: (0, Diagnostic_1.createCustomAttributeContainerDiagnosticClass)(exports.DiagnosticCodes.CustomAttributeSchemaMustBeReferenced, "The CustomAttribute container '{0}' has a CustomAttribute with the class '{1}' whose schema is not referenced by the container's Schema."),
117
+ /** EC-502: Required message parameters: CustomAttribute container name and CustomAttributeClass name. */
118
+ CustomAttributeClassNotFound: (0, Diagnostic_1.createCustomAttributeContainerDiagnosticClass)(exports.DiagnosticCodes.CustomAttributeClassNotFound, "The CustomAttribute container '{0}' has a CustomAttribute with the class '{1}' which cannot be found."),
119
+ /** EC-700: Required message parameters: Enumeration name */
120
+ EnumerationTypeUnsupported: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.EnumerationTypeUnsupported, "Enumeration '{0}' has invalid primitive type."),
121
+ /** EC-1100: Required message parameters: mixin class fullName, class fullName, applies to constraint class fullName */
122
+ MixinAppliedToClassMustDeriveFromConstraint: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.MixinAppliedToClassMustDeriveFromConstraint, "Mixin '{0}' cannot be applied to the class '{1}' because it does not satisfy the applies to constraint '{2}'."),
123
+ /** EC-1300: Required message parameters: childClass.FullName, property name, baseClass.FullName, base value type, child value type */
124
+ IncompatibleValueTypePropertyOverride: (0, Diagnostic_1.createPropertyDiagnosticClass)(exports.DiagnosticCodes.IncompatibleValueTypePropertyOverride, "The ECProperty '{0}.{1}' has a base property '{2}.{1}' with a value type of {3} which is incompatible with the value type of {4}."),
125
+ /** EC-1301: Required message parameters: childClass.FullName, property name, baseClass.FullName, base property type, child property type */
126
+ IncompatibleTypePropertyOverride: (0, Diagnostic_1.createPropertyDiagnosticClass)(exports.DiagnosticCodes.IncompatibleTypePropertyOverride, "The ECProperty '{0}.{1}' has a base property '{2}.{1}' with a type of {3} which is incompatible with the type of {4}."),
127
+ /** EC-1302: Required message parameters: childClass.Name, property name, baseClass.Name, baseClass Koq name, baseClass Koq persistence unit name, child class Koq persistence unit name, child class Koq name */
128
+ IncompatibleUnitPropertyOverride: (0, Diagnostic_1.createPropertyDiagnosticClass)(exports.DiagnosticCodes.IncompatibleUnitPropertyOverride, "The ECProperty '{0}.{1}' has a base property '{2}.{1}' with KindOfQuantity '{3}' with persistence unit '{4}' which is not the same as the persistence unit '{5}' of the provided KindOfQuantity '{6}'."),
129
+ /** EC-1303: Required message parameters: property.fullName, navigation relationship.fullName */
130
+ NavigationRelationshipMustBeRoot: (0, Diagnostic_1.createPropertyDiagnosticClass)(getCode(1303), "The referenced relationship '{1}', used in NavigationProperty '{0}' is not the root relationship."),
131
+ /** EC-1304: Required message parameters: property.fullName, navigation relationship.fullName */
132
+ NavigationTargetMustHaveSingularMultiplicity: (0, Diagnostic_1.createPropertyDiagnosticClass)(getCode(1304), "NavigationProperty '{0}' uses the relationship '{1}' that cannot be traversed in the '{2}' direction due to a max multiplicity greater than 1."),
133
+ /** EC-1305: Required message parameters: property.fullName, navigation relationship.fullName */
134
+ NavigationRelationshipAbstractConstraintEntityOrMixin: (0, Diagnostic_1.createPropertyDiagnosticClass)(getCode(1305), "The NavigationProperty '{0}', using the relationship '{1}', points to a RelationshipClass, which is not allowed. NavigationProperties must point to an EntityClass or Mixin."),
135
+ /** EC-1306: Required message parameters: class name, property name, navigation relationship.fullName */
136
+ NavigationClassMustBeAConstraintClassOfRelationship: (0, Diagnostic_1.createPropertyDiagnosticClass)(getCode(1306), "The class '{0}' of NavigationProperty '{1}' is not supported by the {3} constraint of the referenced relationship '{2}'."),
137
+ /** EC-1500: Required message parameters: abstract constraint class name, relationship end (source/target), relationship name, base relationship name */
138
+ AbstractConstraintMustNarrowBaseConstraints: (0, Diagnostic_1.createSchemaItemDiagnosticClass)(exports.DiagnosticCodes.AbstractConstraintMustNarrowBaseConstraints, "The abstract constraint class '{0}' on the {1}-Constraint of '{2}' is not supported by the base class constraint in '{3}'."),
139
+ /** EC-1501: Required message parameters: constraint class name, relationship end (source/target), relationship name, base relationship name */
140
+ 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}'."),
141
+ /** EC-1502: Required message parameters: constraint class name, relationship end (source/target), relationship name, abstract constraint class name */
142
+ 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}'."),
143
+ /** EC-1600: Required message parameters: relationship end (source/target), relationship name */
144
+ AtLeastOneConstraintClassDefined: (0, Diagnostic_1.createRelationshipConstraintDiagnosticClass)(exports.DiagnosticCodes.AtLeastOneConstraintClassDefined, "The {0}-Constraint of '{1}' does not contain any constraint classes."),
145
+ /** EC-1601: Required message parameters: relationship end (source/target), relationship name */
146
+ AbstractConstraintMustExistWithMultipleConstraints: (0, Diagnostic_1.createRelationshipConstraintDiagnosticClass)(exports.DiagnosticCodes.AbstractConstraintMustExistWithMultipleConstraints, "The {0}-Constraint of '{1}' has multiple constraint classes which requires an abstract constraint to be defined."),
147
+ };
148
+ /**
149
+ * All schema validation rules that fall under the category of ECObjects.
150
+ * @beta
151
+ */
152
+ exports.ECRuleSet = {
153
+ name: ruleSetName,
154
+ schemaRules: [
155
+ validateSchemaReferences,
156
+ ],
157
+ classRules: [
158
+ baseClassIsSealed,
159
+ baseClassIsOfDifferentType,
160
+ abstractClassWithNonAbstractBase,
161
+ ],
162
+ propertyRules: [
163
+ incompatibleValueTypePropertyOverride,
164
+ incompatibleTypePropertyOverride,
165
+ incompatibleUnitPropertyOverride,
166
+ validateNavigationProperty,
167
+ ],
168
+ relationshipRules: [
169
+ abstractConstraintMustNarrowBaseConstraints,
170
+ constraintClassesDeriveFromAbstractContraint,
171
+ derivedConstraintsMustNarrowBaseConstraints,
172
+ ],
173
+ relationshipConstraintRules: [
174
+ atLeastOneConstraintClassDefined,
175
+ abstractConstraintMustExistWithMultipleConstraints,
176
+ ],
177
+ enumerationRules: [
178
+ enumerationTypeUnsupported,
179
+ ],
180
+ entityClassRules: [
181
+ mixinAppliedToClassMustDeriveFromConstraint,
182
+ ],
183
+ customAttributeInstanceRules: [
184
+ validateCustomAttributeInstance,
185
+ ],
186
+ };
187
+ /* eslint-enable @typescript-eslint/naming-convention */
188
+ /**
189
+ * Validates schema references against multiple EC rules.
190
+ * @param schema The schema to validate.
191
+ */
192
+ function validateSchemaReferences(schema) {
193
+ return __asyncGenerator(this, arguments, function* validateSchemaReferences_1() {
194
+ yield __await(yield* __asyncDelegator(__asyncValues(validateSchemaReferencesSync(schema))));
195
+ });
196
+ }
197
+ exports.validateSchemaReferences = validateSchemaReferences;
198
+ function* validateSchemaReferencesSync(schema) {
199
+ const aliases = new Map();
200
+ for (const schemaRef of schema.references) {
201
+ if (schemaRef.customAttributes && schemaRef.customAttributes.has("CoreCustomAttributes.SupplementalSchema"))
202
+ yield new exports.Diagnostics.SupplementalSchemasCannotBeReferenced(schema, [schema.name, schemaRef.name]);
203
+ if (schema.schemaKey.matches(schemaRef.schemaKey))
204
+ yield new exports.Diagnostics.ReferenceCyclesNotAllowed(schema, [schema.name, `${schema.name} --> ${schemaRef.name}`]);
205
+ if (aliases.has(schemaRef.alias)) {
206
+ const currentRef = aliases.get(schemaRef.alias);
207
+ yield new exports.Diagnostics.SchemaRefAliasMustBeUnique(schema, [schema.name, schemaRef.alias, currentRef.name, schemaRef.name]);
208
+ }
209
+ else {
210
+ aliases.set(schemaRef.alias, schemaRef);
211
+ }
212
+ }
213
+ const graph = new ecschema_metadata_1.SchemaGraph(schema);
214
+ const cycles = graph.detectCycles();
215
+ if (cycles) {
216
+ const result = cycles.map((cycle) => `${cycle.schema.name} --> ${cycle.refSchema.name}`).join(", ");
217
+ yield new exports.Diagnostics.ReferenceCyclesNotAllowed(schema, [schema.name, result]);
218
+ }
219
+ }
220
+ exports.validateSchemaReferencesSync = validateSchemaReferencesSync;
221
+ /**
222
+ * EC Rule: Sealed classes cannot be a base class.
223
+ * @internal
224
+ */
225
+ function baseClassIsSealed(ecClass) {
226
+ return __asyncGenerator(this, arguments, function* baseClassIsSealed_1() {
227
+ if (!ecClass.baseClass)
228
+ return yield __await(void 0);
229
+ const baseClass = yield __await(ecClass.baseClass);
230
+ // return if rule passed
231
+ if (baseClass.modifier !== ecschema_metadata_1.ECClassModifier.Sealed)
232
+ return yield __await(void 0);
233
+ yield yield __await(new exports.Diagnostics.BaseClassIsSealed(ecClass, [ecClass.fullName, baseClass.fullName]));
234
+ });
235
+ }
236
+ exports.baseClassIsSealed = baseClassIsSealed;
237
+ /**
238
+ * EC Rule: Base and child class must be of the same type (i.e. Entity, Mixin, Relationship, etc.)
239
+ * @internal
240
+ */
241
+ function baseClassIsOfDifferentType(ecClass) {
242
+ return __asyncGenerator(this, arguments, function* baseClassIsOfDifferentType_1() {
243
+ if (!ecClass.baseClass)
244
+ return yield __await(void 0);
245
+ const baseClass = yield __await(ecClass.baseClass);
246
+ // return if rule passed
247
+ if (baseClass.schemaItemType === ecClass.schemaItemType)
248
+ return yield __await(void 0);
249
+ const itemType = (0, ecschema_metadata_1.schemaItemTypeToString)(baseClass.schemaItemType);
250
+ yield yield __await(new exports.Diagnostics.BaseClassIsOfDifferentType(ecClass, [ecClass.fullName, baseClass.fullName, itemType]));
251
+ });
252
+ }
253
+ exports.baseClassIsOfDifferentType = baseClassIsOfDifferentType;
254
+ /**
255
+ * EC Rule: Abstract class cannot derive from a non-abstract base class.
256
+ * @internal
257
+ */
258
+ function abstractClassWithNonAbstractBase(ecClass) {
259
+ return __asyncGenerator(this, arguments, function* abstractClassWithNonAbstractBase_1() {
260
+ if (ecClass.modifier !== ecschema_metadata_1.ECClassModifier.Abstract || !ecClass.baseClass)
261
+ return yield __await(void 0);
262
+ const baseClass = yield __await(ecClass.baseClass);
263
+ // return if rule passed
264
+ if (baseClass.modifier === ecschema_metadata_1.ECClassModifier.Abstract)
265
+ return yield __await(void 0);
266
+ yield yield __await(new exports.Diagnostics.AbstractClassWithNonAbstractBase(ecClass, [ecClass.fullName, baseClass.fullName]));
267
+ });
268
+ }
269
+ exports.abstractClassWithNonAbstractBase = abstractClassWithNonAbstractBase;
270
+ /**
271
+ * EC Rule: When overriding a class primitive property, the child and base property must be of the same type (string, number, etc...).
272
+ * @internal
273
+ */
274
+ function incompatibleValueTypePropertyOverride(property) {
275
+ return __asyncGenerator(this, arguments, function* incompatibleValueTypePropertyOverride_1() {
276
+ var e_1, _a;
277
+ if (!property.class.baseClass)
278
+ return yield __await(void 0);
279
+ const primitiveType = getPrimitiveType(property);
280
+ if (!primitiveType)
281
+ return yield __await(void 0);
282
+ async function callback(baseClass) {
283
+ const baseProperty = await baseClass.getProperty(property.name);
284
+ if (!baseProperty)
285
+ return;
286
+ // Other rules will catch this if false, but we need to make sure
287
+ // types match for this rule to be valid.
288
+ if (!propertyTypesMatch(property, baseProperty))
289
+ return;
290
+ const baseType = getPrimitiveType(baseProperty);
291
+ // Return if rule passed
292
+ if (!baseType || primitiveType === baseType)
293
+ return;
294
+ return new exports.Diagnostics.IncompatibleValueTypePropertyOverride(property, [property.class.fullName, property.name, baseClass.fullName, (0, ecschema_metadata_1.primitiveTypeToString)(baseType), (0, ecschema_metadata_1.primitiveTypeToString)(primitiveType)]);
295
+ }
296
+ try {
297
+ for (var _b = __asyncValues(property.class.getAllBaseClasses()), _c; _c = yield __await(_b.next()), !_c.done;) {
298
+ const baseClass = _c.value;
299
+ const result = yield __await(callback(baseClass));
300
+ if (result)
301
+ yield yield __await(result);
302
+ }
303
+ }
304
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
305
+ finally {
306
+ try {
307
+ if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
308
+ }
309
+ finally { if (e_1) throw e_1.error; }
310
+ }
311
+ });
312
+ }
313
+ exports.incompatibleValueTypePropertyOverride = incompatibleValueTypePropertyOverride;
314
+ /**
315
+ * EC Rule: When overriding a class property, the child and base property must be of the same property type (primitive, struct, enumeration, etc...).
316
+ * @internal
317
+ */
318
+ function incompatibleTypePropertyOverride(property) {
319
+ return __asyncGenerator(this, arguments, function* incompatibleTypePropertyOverride_1() {
320
+ var e_2, _a;
321
+ if (!property.class.baseClass)
322
+ return yield __await(void 0);
323
+ async function callback(baseClass) {
324
+ const baseProperty = await baseClass.getProperty(property.name);
325
+ if (!baseProperty)
326
+ return;
327
+ // Return if rule passed
328
+ if (propertyTypesMatch(property, baseProperty))
329
+ return;
330
+ return new exports.Diagnostics.IncompatibleTypePropertyOverride(property, [property.class.fullName, property.name, baseClass.fullName, baseProperty.constructor.name, property.constructor.name]);
331
+ }
332
+ try {
333
+ for (var _b = __asyncValues(property.class.getAllBaseClasses()), _c; _c = yield __await(_b.next()), !_c.done;) {
334
+ const baseClass = _c.value;
335
+ const result = yield __await(callback(baseClass));
336
+ if (result)
337
+ yield yield __await(result);
338
+ }
339
+ }
340
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
341
+ finally {
342
+ try {
343
+ if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
344
+ }
345
+ finally { if (e_2) throw e_2.error; }
346
+ }
347
+ });
348
+ }
349
+ exports.incompatibleTypePropertyOverride = incompatibleTypePropertyOverride;
350
+ /**
351
+ * EC Rule: When overriding a kindOfQuantity property, the child and base property units must be the same.
352
+ * @internal
353
+ */
354
+ function incompatibleUnitPropertyOverride(property) {
355
+ return __asyncGenerator(this, arguments, function* incompatibleUnitPropertyOverride_1() {
356
+ var e_3, _a;
357
+ if (!property.kindOfQuantity || !property.class.baseClass)
358
+ return yield __await(void 0);
359
+ async function callback(baseClass) {
360
+ const baseProperty = await baseClass.getProperty(property.name);
361
+ if (!baseProperty || !baseProperty.kindOfQuantity)
362
+ return;
363
+ // Other rules will catch this if false, but we need to make sure
364
+ // types match for this rule to be valid.
365
+ if (!propertyTypesMatch(property, baseProperty))
366
+ return;
367
+ const koq = await property.kindOfQuantity;
368
+ const baseKoq = await baseProperty.kindOfQuantity;
369
+ if (!koq || !baseKoq)
370
+ return;
371
+ const unit = await koq.persistenceUnit;
372
+ const baseUnit = await baseKoq.persistenceUnit;
373
+ if (!unit || !baseUnit)
374
+ return;
375
+ // return if rule passed
376
+ if (unit.key.matches(baseUnit.key))
377
+ return;
378
+ return new exports.Diagnostics.IncompatibleUnitPropertyOverride(property, [
379
+ property.class.fullName,
380
+ property.name,
381
+ baseClass.fullName,
382
+ baseKoq.fullName,
383
+ baseUnit.fullName,
384
+ unit.fullName,
385
+ koq.fullName,
386
+ ]);
387
+ }
388
+ try {
389
+ for (var _b = __asyncValues(property.class.getAllBaseClasses()), _c; _c = yield __await(_b.next()), !_c.done;) {
390
+ const baseClass = _c.value;
391
+ const result = yield __await(callback(baseClass));
392
+ if (result)
393
+ yield yield __await(result);
394
+ }
395
+ }
396
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
397
+ finally {
398
+ try {
399
+ if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
400
+ }
401
+ finally { if (e_3) throw e_3.error; }
402
+ }
403
+ });
404
+ }
405
+ exports.incompatibleUnitPropertyOverride = incompatibleUnitPropertyOverride;
406
+ /** Validates Navigation Properties. EC Rules: 1303, 1304 */
407
+ function validateNavigationProperty(property) {
408
+ return __asyncGenerator(this, arguments, function* validateNavigationProperty_1() {
409
+ if (!property.isNavigation())
410
+ return yield __await(void 0);
411
+ const navProp = property;
412
+ const relationship = yield __await(navProp.relationshipClass);
413
+ if (relationship.baseClass)
414
+ yield yield __await(new exports.Diagnostics.NavigationRelationshipMustBeRoot(property, [property.fullName, relationship.fullName]));
415
+ let thisConstraint;
416
+ let thatConstraint;
417
+ let navigationClassSide;
418
+ if (navProp.direction === ecschema_metadata_1.StrengthDirection.Forward) {
419
+ thisConstraint = relationship.source;
420
+ thatConstraint = relationship.target;
421
+ navigationClassSide = "source";
422
+ }
423
+ else {
424
+ thisConstraint = relationship.target;
425
+ thatConstraint = relationship.source;
426
+ navigationClassSide = "target";
427
+ }
428
+ const thatAbstractConstraint = yield __await(thatConstraint.abstractConstraint);
429
+ if (thatAbstractConstraint && thatAbstractConstraint.schemaItemType === ecschema_metadata_1.SchemaItemType.RelationshipClass) {
430
+ yield yield __await(new exports.Diagnostics.NavigationRelationshipAbstractConstraintEntityOrMixin(property, [property.fullName, relationship.fullName]));
431
+ }
432
+ const isClassSupported = async (ecClass, propertyName, constraintName) => {
433
+ if (constraintName === ecClass.fullName && undefined !== await ecClass.getProperty(propertyName))
434
+ return true;
435
+ const inheritedProp = await ecClass.getInheritedProperty(propertyName);
436
+ if (inheritedProp && constraintName === inheritedProp.class.fullName)
437
+ return true;
438
+ const baseClass = await ecClass.baseClass;
439
+ if (!baseClass)
440
+ return false;
441
+ return isClassSupported(baseClass, propertyName, constraintName);
442
+ };
443
+ let classSupported = false;
444
+ if (thisConstraint.constraintClasses) {
445
+ for (const constraintClass of thisConstraint.constraintClasses) {
446
+ classSupported = yield __await(isClassSupported(property.class, property.name, constraintClass.fullName));
447
+ if (classSupported)
448
+ break;
449
+ }
450
+ }
451
+ if (!classSupported)
452
+ yield yield __await(new exports.Diagnostics.NavigationClassMustBeAConstraintClassOfRelationship(property, [property.class.name, property.name, relationship.fullName, navigationClassSide]));
453
+ if (thatConstraint.multiplicity === ecschema_metadata_1.RelationshipMultiplicity.oneMany || thatConstraint.multiplicity === ecschema_metadata_1.RelationshipMultiplicity.zeroMany) {
454
+ const direction = (0, ecschema_metadata_1.strengthDirectionToString)(navProp.direction);
455
+ yield yield __await(new exports.Diagnostics.NavigationTargetMustHaveSingularMultiplicity(property, [property.fullName, relationship.fullName, direction]));
456
+ }
457
+ return yield __await(void 0);
458
+ });
459
+ }
460
+ exports.validateNavigationProperty = validateNavigationProperty;
461
+ /**
462
+ * EC Rule: When overriding a RelationshipClass, the derived abstract constraint must narrow the base constraint classes.
463
+ * @internal
464
+ */
465
+ function abstractConstraintMustNarrowBaseConstraints(ecClass) {
466
+ return __asyncGenerator(this, arguments, function* abstractConstraintMustNarrowBaseConstraints_1() {
467
+ if (!ecClass.baseClass)
468
+ return yield __await(void 0);
469
+ const baseRelationship = yield __await(ecClass.baseClass);
470
+ const sourceResult = yield __await(applyAbstractConstraintMustNarrowBaseConstraints(ecClass, ecClass.source, baseRelationship));
471
+ if (sourceResult)
472
+ yield yield __await(sourceResult);
473
+ const targetResult = yield __await(applyAbstractConstraintMustNarrowBaseConstraints(ecClass, ecClass.target, baseRelationship));
474
+ if (targetResult)
475
+ yield yield __await(targetResult);
476
+ });
477
+ }
478
+ exports.abstractConstraintMustNarrowBaseConstraints = abstractConstraintMustNarrowBaseConstraints;
479
+ /**
480
+ * EC Rule: When overriding a RelationshipClass, derived constraint classes must narrow base constraint classes.
481
+ * @internal
482
+ */
483
+ function derivedConstraintsMustNarrowBaseConstraints(ecClass) {
484
+ return __asyncGenerator(this, arguments, function* derivedConstraintsMustNarrowBaseConstraints_1() {
485
+ if (!ecClass.baseClass)
486
+ return yield __await(void 0);
487
+ const baseRelationship = yield __await(ecClass.baseClass);
488
+ const sourceResult = yield __await(applyDerivedConstraintsMustNarrowBaseConstraints(ecClass, ecClass.source, baseRelationship));
489
+ if (sourceResult)
490
+ yield yield __await(sourceResult);
491
+ const targetResult = yield __await(applyDerivedConstraintsMustNarrowBaseConstraints(ecClass, ecClass.target, baseRelationship));
492
+ if (targetResult)
493
+ yield yield __await(targetResult);
494
+ });
495
+ }
496
+ exports.derivedConstraintsMustNarrowBaseConstraints = derivedConstraintsMustNarrowBaseConstraints;
497
+ /**
498
+ * EC Rule: All constraint classes must have a common base class specified in the abstract constraint.
499
+ * @internal
500
+ */
501
+ function constraintClassesDeriveFromAbstractContraint(ecClass) {
502
+ return __asyncGenerator(this, arguments, function* constraintClassesDeriveFromAbstractContraint_1() {
503
+ const sourceResult = yield __await(applyConstraintClassesDeriveFromAbstractContraint(ecClass, ecClass.source));
504
+ if (sourceResult)
505
+ yield yield __await(sourceResult);
506
+ const targetResult = yield __await(applyConstraintClassesDeriveFromAbstractContraint(ecClass, ecClass.target));
507
+ if (targetResult)
508
+ yield yield __await(targetResult);
509
+ });
510
+ }
511
+ exports.constraintClassesDeriveFromAbstractContraint = constraintClassesDeriveFromAbstractContraint;
512
+ /**
513
+ * EC Rule: At least on concrete constraint class must be defined in the list of constraint classes.
514
+ * @internal
515
+ */
516
+ function atLeastOneConstraintClassDefined(constraint) {
517
+ return __asyncGenerator(this, arguments, function* atLeastOneConstraintClassDefined_1() {
518
+ if (!constraint.constraintClasses || constraint.constraintClasses.length === 0) {
519
+ const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
520
+ yield yield __await(new exports.Diagnostics.AtLeastOneConstraintClassDefined(constraint, [constraintType, constraint.relationshipClass.fullName]));
521
+ }
522
+ });
523
+ }
524
+ exports.atLeastOneConstraintClassDefined = atLeastOneConstraintClassDefined;
525
+ /**
526
+ * EC Rule: If multiple constraints exist, an abstract constraint must be defined.
527
+ * @internal
528
+ */
529
+ function abstractConstraintMustExistWithMultipleConstraints(constraint) {
530
+ return __asyncGenerator(this, arguments, function* abstractConstraintMustExistWithMultipleConstraints_1() {
531
+ if (!constraint.constraintClasses || constraint.constraintClasses.length <= 1) {
532
+ return yield __await(void 0);
533
+ }
534
+ const abstractConstraint = yield __await(getAbstractConstraint(constraint));
535
+ if (abstractConstraint)
536
+ return yield __await(void 0);
537
+ const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
538
+ yield yield __await(new exports.Diagnostics.AbstractConstraintMustExistWithMultipleConstraints(constraint, [constraintType, constraint.relationshipClass.fullName]));
539
+ });
540
+ }
541
+ exports.abstractConstraintMustExistWithMultipleConstraints = abstractConstraintMustExistWithMultipleConstraints;
542
+ function propertyTypesMatch(propertyA, propertyB) {
543
+ return propertyA.constructor.name === propertyB.constructor.name;
544
+ }
545
+ function getPrimitiveType(property) {
546
+ if (property.isPrimitive())
547
+ return property.primitiveType;
548
+ return undefined;
549
+ }
550
+ /**
551
+ * EC Rule: Enumeration type must be a string or integer
552
+ * @internal
553
+ */
554
+ function enumerationTypeUnsupported(enumeration) {
555
+ return __asyncGenerator(this, arguments, function* enumerationTypeUnsupported_1() {
556
+ const type = enumeration.type;
557
+ if (type === ecschema_metadata_1.PrimitiveType.Integer || type === ecschema_metadata_1.PrimitiveType.String)
558
+ return yield __await(void 0);
559
+ yield yield __await(new exports.Diagnostics.EnumerationTypeUnsupported(enumeration, [enumeration.fullName]));
560
+ });
561
+ }
562
+ exports.enumerationTypeUnsupported = enumerationTypeUnsupported;
563
+ /**
564
+ * EC Rule: Mixin applied to class must derived from the Mixin appliesTo constraint.
565
+ * @internal
566
+ */
567
+ function mixinAppliedToClassMustDeriveFromConstraint(entityClass) {
568
+ return __asyncGenerator(this, arguments, function* mixinAppliedToClassMustDeriveFromConstraint_1() {
569
+ for (const lazyMixin of entityClass.mixins) {
570
+ const mixin = yield __await(lazyMixin);
571
+ if (!mixin.appliesTo)
572
+ continue;
573
+ if (!(yield __await(entityClass.is(yield __await(mixin.appliesTo)))))
574
+ yield yield __await(new exports.Diagnostics.MixinAppliedToClassMustDeriveFromConstraint(entityClass, [mixin.fullName, entityClass.fullName, mixin.appliesTo.fullName]));
575
+ }
576
+ return yield __await(void 0);
577
+ });
578
+ }
579
+ exports.mixinAppliedToClassMustDeriveFromConstraint = mixinAppliedToClassMustDeriveFromConstraint;
580
+ /**
581
+ * Validates a custom attribute instance and yields EC-500, EC-501, and EC-502 rule violations.
582
+ */
583
+ function validateCustomAttributeInstance(container, customAttribute) {
584
+ return __asyncGenerator(this, arguments, function* validateCustomAttributeInstance_1() {
585
+ yield __await(yield* __asyncDelegator(__asyncValues(customAttributeNotOfConcreteClass(container, customAttribute))));
586
+ yield __await(yield* __asyncDelegator(__asyncValues(customAttributeSchemaMustBeReferenced(container, customAttribute))));
587
+ yield __await(yield* __asyncDelegator(__asyncValues(customAttributeClassMustExist(container, customAttribute))));
588
+ });
589
+ }
590
+ exports.validateCustomAttributeInstance = validateCustomAttributeInstance;
591
+ /** EC Rule: CustomAttribute instance must be of a concrete CustomAttributeClass. */
592
+ function customAttributeNotOfConcreteClass(container, customAttribute) {
593
+ return __asyncGenerator(this, arguments, function* customAttributeNotOfConcreteClass_1() {
594
+ const schema = container.schema;
595
+ const caClass = yield __await(schema.lookupItem(customAttribute.className));
596
+ if (!caClass)
597
+ return yield __await(void 0);
598
+ if (caClass.modifier !== ecschema_metadata_1.ECClassModifier.Abstract)
599
+ return yield __await(void 0);
600
+ yield yield __await(new exports.Diagnostics.CustomAttributeNotOfConcreteClass(container, [container.fullName, caClass.fullName]));
601
+ });
602
+ }
603
+ /** EC Rule: CustomAttribute Schema must be referenced by the container's Schema. */
604
+ function customAttributeSchemaMustBeReferenced(container, customAttribute) {
605
+ return __asyncGenerator(this, arguments, function* customAttributeSchemaMustBeReferenced_1() {
606
+ const schema = container.schema;
607
+ const nameParts = customAttribute.className.split(".");
608
+ if (nameParts.length === 1 || nameParts[0] === schema.name)
609
+ return yield __await(void 0);
610
+ if (schema.references.some((s) => s.name === nameParts[0]))
611
+ return yield __await(void 0);
612
+ yield yield __await(new exports.Diagnostics.CustomAttributeSchemaMustBeReferenced(container, [container.fullName, customAttribute.className]));
613
+ });
614
+ }
615
+ /** EC Rule: CustomAttribute instance class must exist. */
616
+ function customAttributeClassMustExist(container, customAttribute) {
617
+ return __asyncGenerator(this, arguments, function* customAttributeClassMustExist_1() {
618
+ const schema = container.schema;
619
+ const caClass = yield __await(schema.lookupItem(customAttribute.className));
620
+ if (!caClass)
621
+ yield yield __await(new exports.Diagnostics.CustomAttributeClassNotFound(container, [container.fullName, customAttribute.className]));
622
+ });
623
+ }
624
+ async function applyAbstractConstraintMustNarrowBaseConstraints(ecClass, constraint, baseRelationship) {
625
+ const baseConstraint = constraint.isSource ? baseRelationship.source : baseRelationship.target;
626
+ const abstractConstraint = await constraint.abstractConstraint;
627
+ if (!abstractConstraint)
628
+ return;
629
+ if (await baseConstraint.supportsClass(abstractConstraint))
630
+ return;
631
+ const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
632
+ return new exports.Diagnostics.AbstractConstraintMustNarrowBaseConstraints(ecClass, [abstractConstraint.fullName, constraintType, constraint.relationshipClass.fullName, baseRelationship.fullName]);
633
+ }
634
+ async function applyDerivedConstraintsMustNarrowBaseConstraints(ecClass, constraint, baseRelationship) {
635
+ const baseConstraint = constraint.isSource ? baseRelationship.source : baseRelationship.target;
636
+ if (!constraint.constraintClasses)
637
+ return;
638
+ for (const classPromise of constraint.constraintClasses) {
639
+ const constraintClass = await classPromise;
640
+ if (await baseConstraint.supportsClass(constraintClass))
641
+ continue;
642
+ const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
643
+ return new exports.Diagnostics.DerivedConstraintsMustNarrowBaseConstraints(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, baseRelationship.fullName]);
644
+ }
645
+ return;
646
+ }
647
+ async function applyConstraintClassesDeriveFromAbstractContraint(ecClass, constraint) {
648
+ const abstractConstraint = await getAbstractConstraint(constraint);
649
+ if (!abstractConstraint)
650
+ return;
651
+ if (!constraint.constraintClasses)
652
+ return;
653
+ for (const classPromise of constraint.constraintClasses) {
654
+ const constraintClass = await classPromise;
655
+ if (constraintClass.schemaItemType === ecschema_metadata_1.SchemaItemType.Mixin && abstractConstraint.schemaItemType === ecschema_metadata_1.SchemaItemType.EntityClass) {
656
+ if (!await (constraintClass).applicableTo(abstractConstraint)) {
657
+ const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
658
+ return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractContraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
659
+ }
660
+ continue;
661
+ }
662
+ if (!await constraintClass.is(abstractConstraint)) {
663
+ const constraintType = constraint.isSource ? ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_SOURCE : ecschema_metadata_1.ECStringConstants.RELATIONSHIP_END_TARGET;
664
+ return new exports.Diagnostics.ConstraintClassesDeriveFromAbstractContraint(ecClass, [constraintClass.fullName, constraintType, constraint.relationshipClass.fullName, abstractConstraint.fullName]);
665
+ }
666
+ }
667
+ return;
668
+ }
669
+ async function getAbstractConstraint(constraint) {
670
+ const abstractConstraint = await constraint.abstractConstraint;
671
+ if (abstractConstraint)
672
+ return abstractConstraint;
673
+ const baseRelationship = await constraint.relationshipClass.baseClass;
674
+ if (!baseRelationship)
675
+ return;
676
+ const baseConstraint = constraint.isSource ? baseRelationship.source : baseRelationship.target;
677
+ return getAbstractConstraint(baseConstraint);
678
+ }
679
+ //# sourceMappingURL=ECRules.js.map