@itwin/ecschema-editing 4.0.0-dev.28 → 4.0.0-dev.30

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 (146) hide show
  1. package/lib/cjs/Editing/Constants.d.ts +20 -20
  2. package/lib/cjs/Editing/Constants.js +60 -60
  3. package/lib/cjs/Editing/Constants.js.map +1 -1
  4. package/lib/cjs/Editing/CustomAttributes.d.ts +20 -20
  5. package/lib/cjs/Editing/CustomAttributes.js +59 -59
  6. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  7. package/lib/cjs/Editing/ECClasses.d.ts +54 -54
  8. package/lib/cjs/Editing/ECClasses.js +269 -269
  9. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  10. package/lib/cjs/Editing/Editor.d.ts +112 -112
  11. package/lib/cjs/Editing/Editor.js +166 -166
  12. package/lib/cjs/Editing/Editor.js.map +1 -1
  13. package/lib/cjs/Editing/Entities.d.ts +25 -25
  14. package/lib/cjs/Editing/Entities.js +116 -116
  15. package/lib/cjs/Editing/Entities.js.map +1 -1
  16. package/lib/cjs/Editing/Enumerations.d.ts +21 -21
  17. package/lib/cjs/Editing/Enumerations.js +66 -66
  18. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  19. package/lib/cjs/Editing/Formats.d.ts +21 -21
  20. package/lib/cjs/Editing/Formats.js +61 -61
  21. package/lib/cjs/Editing/Formats.js.map +1 -1
  22. package/lib/cjs/Editing/InvertedUnits.d.ts +17 -17
  23. package/lib/cjs/Editing/InvertedUnits.js +82 -82
  24. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  25. package/lib/cjs/Editing/KindOfQuantities.d.ts +28 -28
  26. package/lib/cjs/Editing/KindOfQuantities.js +78 -78
  27. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  28. package/lib/cjs/Editing/Mixins.d.ts +22 -22
  29. package/lib/cjs/Editing/Mixins.js +84 -84
  30. package/lib/cjs/Editing/Mixins.js.map +1 -1
  31. package/lib/cjs/Editing/Mutable/MutableCAClass.d.ts +9 -9
  32. package/lib/cjs/Editing/Mutable/MutableCAClass.js +15 -15
  33. package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
  34. package/lib/cjs/Editing/Mutable/MutableClass.d.ts +34 -34
  35. package/lib/cjs/Editing/Mutable/MutableClass.js +22 -22
  36. package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
  37. package/lib/cjs/Editing/Mutable/MutableConstant.d.ts +12 -12
  38. package/lib/cjs/Editing/Mutable/MutableConstant.js +15 -15
  39. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  40. package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts +15 -15
  41. package/lib/cjs/Editing/Mutable/MutableEntityClass.js +59 -59
  42. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  43. package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts +9 -9
  44. package/lib/cjs/Editing/Mutable/MutableEnumeration.js +14 -14
  45. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  46. package/lib/cjs/Editing/Mutable/MutableFormat.d.ts +18 -18
  47. package/lib/cjs/Editing/Mutable/MutableFormat.js +15 -15
  48. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  49. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.d.ts +10 -10
  50. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js +15 -15
  51. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  52. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +10 -10
  53. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js +15 -15
  54. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  55. package/lib/cjs/Editing/Mutable/MutableMixin.d.ts +11 -11
  56. package/lib/cjs/Editing/Mutable/MutableMixin.js +15 -15
  57. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  58. package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts +9 -9
  59. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js +15 -15
  60. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  61. package/lib/cjs/Editing/Mutable/MutableProperty.d.ts +8 -8
  62. package/lib/cjs/Editing/Mutable/MutableProperty.js +15 -15
  63. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  64. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts +9 -9
  65. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js +15 -15
  66. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  67. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts +21 -21
  68. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js +24 -24
  69. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  70. package/lib/cjs/Editing/Mutable/MutableSchema.d.ts +45 -45
  71. package/lib/cjs/Editing/Mutable/MutableSchema.js +17 -17
  72. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  73. package/lib/cjs/Editing/Mutable/MutableUnit.d.ts +11 -11
  74. package/lib/cjs/Editing/Mutable/MutableUnit.js +15 -15
  75. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  76. package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts +8 -8
  77. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js +15 -15
  78. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  79. package/lib/cjs/Editing/Phenomena.d.ts +15 -15
  80. package/lib/cjs/Editing/Phenomena.js +44 -44
  81. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  82. package/lib/cjs/Editing/PropertyCategories.d.ts +16 -16
  83. package/lib/cjs/Editing/PropertyCategories.js +51 -51
  84. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  85. package/lib/cjs/Editing/RelationshipClasses.d.ts +21 -21
  86. package/lib/cjs/Editing/RelationshipClasses.js +68 -68
  87. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  88. package/lib/cjs/Editing/Structs.d.ts +19 -19
  89. package/lib/cjs/Editing/Structs.js +57 -57
  90. package/lib/cjs/Editing/Structs.js.map +1 -1
  91. package/lib/cjs/Editing/UnitSystems.d.ts +15 -15
  92. package/lib/cjs/Editing/UnitSystems.js +41 -41
  93. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  94. package/lib/cjs/Editing/Units.d.ts +15 -15
  95. package/lib/cjs/Editing/Units.js +58 -58
  96. package/lib/cjs/Editing/Units.js.map +1 -1
  97. package/lib/cjs/Validation/Diagnostic.d.ts +321 -321
  98. package/lib/cjs/Validation/Diagnostic.js +310 -310
  99. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  100. package/lib/cjs/Validation/DiagnosticReporter.d.ts +96 -96
  101. package/lib/cjs/Validation/DiagnosticReporter.js +106 -106
  102. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  103. package/lib/cjs/Validation/ECRules.d.ts +448 -448
  104. package/lib/cjs/Validation/ECRules.js +593 -593
  105. package/lib/cjs/Validation/ECRules.js.map +1 -1
  106. package/lib/cjs/Validation/LoggingDiagnosticReporter.d.ts +13 -13
  107. package/lib/cjs/Validation/LoggingDiagnosticReporter.js +40 -40
  108. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  109. package/lib/cjs/Validation/RuleSuppressionSet.d.ts +59 -59
  110. package/lib/cjs/Validation/RuleSuppressionSet.js +9 -9
  111. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  112. package/lib/cjs/Validation/Rules.d.ts +64 -64
  113. package/lib/cjs/Validation/Rules.js +9 -9
  114. package/lib/cjs/Validation/Rules.js.map +1 -1
  115. package/lib/cjs/Validation/SchemaChanges.d.ts +607 -607
  116. package/lib/cjs/Validation/SchemaChanges.js +1135 -1135
  117. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  118. package/lib/cjs/Validation/SchemaCompareDiagnostics.d.ts +422 -422
  119. package/lib/cjs/Validation/SchemaCompareDiagnostics.js +111 -111
  120. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  121. package/lib/cjs/Validation/SchemaCompareReporter.d.ts +11 -11
  122. package/lib/cjs/Validation/SchemaCompareReporter.js +9 -9
  123. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  124. package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +236 -236
  125. package/lib/cjs/Validation/SchemaCompareResultDelegate.js +348 -348
  126. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  127. package/lib/cjs/Validation/SchemaCompareVisitor.d.ts +119 -119
  128. package/lib/cjs/Validation/SchemaCompareVisitor.js +206 -206
  129. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  130. package/lib/cjs/Validation/SchemaComparer.d.ts +171 -171
  131. package/lib/cjs/Validation/SchemaComparer.js +666 -666
  132. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  133. package/lib/cjs/Validation/SchemaValidater.d.ts +19 -19
  134. package/lib/cjs/Validation/SchemaValidater.js +61 -61
  135. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  136. package/lib/cjs/Validation/SchemaValidationVisitor.d.ts +170 -170
  137. package/lib/cjs/Validation/SchemaValidationVisitor.js +492 -492
  138. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  139. package/lib/cjs/Validation/SchemaWalker.d.ts +22 -22
  140. package/lib/cjs/Validation/SchemaWalker.js +51 -51
  141. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  142. package/lib/cjs/ecschema-editing.d.ts +33 -33
  143. package/lib/cjs/ecschema-editing.js +54 -54
  144. package/lib/cjs/ecschema-editing.js.map +1 -1
  145. package/package.json +10 -10
  146. package/public/locales/en/ECSchemaEditing.json +26 -26
@@ -1,493 +1,493 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SchemaValidationVisitor = void 0;
11
- const Diagnostic_1 = require("./Diagnostic");
12
- /**
13
- * A SchemaWalkerVisitor interface implementation that is used to validate ECObjects schemas using
14
- * [[IRuleSet]] objects registered with the instance. Also allows for reporting of [[IDiagnostic]]
15
- * objects returned from failing rules using [[IDiagnosticReporter]] implementations registered
16
- * with an instance of this class.
17
- * @beta
18
- */
19
- class SchemaValidationVisitor {
20
- constructor() {
21
- this._reporters = [];
22
- this._ruleSets = {};
23
- }
24
- /** Gets the IRule<AnyClass> objects registered with the visitor. */
25
- get ruleSets() {
26
- return this._ruleSets;
27
- }
28
- get suppressionSet() {
29
- return this._ruleSuppressionSet;
30
- }
31
- /** Gets the IDiagnosticReporter objects registered with the visitor. */
32
- get diagnosticReporters() {
33
- return this._reporters;
34
- }
35
- /**
36
- * Registers a [[IDiagnosticReporter]] allowing the reporter to be
37
- * notified when a [[IDiagnostic]] is created due to a rule violation.
38
- * @param reporter The [[DiagnosticReporter]] to register.
39
- */
40
- registerReporter(...reporters) {
41
- for (const reporter of reporters)
42
- this._reporters.push(reporter);
43
- }
44
- /**
45
- * Registers a [[IRuleSet]] that will applied during schema traversal.
46
- * @param ruleSet The [[IRuleSet]] to register.
47
- */
48
- registerRuleSet(ruleSet) {
49
- if (undefined !== this.ruleSets[ruleSet.name])
50
- throw new Error(`A RuleSet with the name '${ruleSet.name}' has already been registered.`);
51
- this.ruleSets[ruleSet.name] = ruleSet;
52
- }
53
- /**
54
- * Registers a [[IRuleSuppressionSet]] that will be applied during schema traversal.
55
- * @param ruleSet The [[IRuleSuppressionSet]] to register.
56
- * Only supports one Rule Suppression Set, if you call it twice it will overwrite the
57
- * previous suppression set
58
- */
59
- registerRuleSuppressionSet(suppressionSet) {
60
- this._ruleSuppressionSet = suppressionSet;
61
- }
62
- /**
63
- * Called before schema traversal.
64
- * @param schema a Schema object.
65
- */
66
- async visitFullSchema(schema) {
67
- for (const index of Object.keys(this._ruleSets))
68
- await this.applySchemaRules(schema, this._ruleSets[index]);
69
- }
70
- /**
71
- * Called for each [[SchemaItem]] instance found during schema traversal.
72
- * @param schemaItem a SchemaItem object.
73
- */
74
- async visitSchemaItem(schemaItem) {
75
- for (const index of Object.keys(this._ruleSets))
76
- await this.applySchemaItemRules(schemaItem, this._ruleSets[index]);
77
- }
78
- /**
79
- * Called for each [AnyClass]($ecschema-metadata) instance found during schema traversal.
80
- * @param ecClass an ECClass object.
81
- */
82
- async visitClass(ecClass) {
83
- for (const index of Object.keys(this._ruleSets))
84
- await this.applyClassRules(ecClass, this._ruleSets[index]);
85
- }
86
- /**
87
- * Called for each [AnyProperty]($ecschema-metadata) instance of an ECClass.
88
- * @param property an AnyProperty object.
89
- */
90
- async visitProperty(property) {
91
- for (const index of Object.keys(this._ruleSets))
92
- await this.applyPropertyRules(property, this._ruleSets[index]);
93
- }
94
- /**
95
- * Called for each [EntityClass]($ecschema-metadata) instance found during schema traversal.
96
- * @param entityClass an EntityClass object.
97
- */
98
- async visitEntityClass(entity) {
99
- for (const index of Object.keys(this._ruleSets))
100
- await this.applyEntityRules(entity, this._ruleSets[index]);
101
- }
102
- /**
103
- * Called for each [StructClass]($ecschema-metadata) instance found during schema traversal.
104
- * @param structClass a StructClass object.
105
- */
106
- async visitStructClass(struct) {
107
- for (const index of Object.keys(this._ruleSets))
108
- await this.applyStructRules(struct, this._ruleSets[index]);
109
- }
110
- /**
111
- * Called for each [Mixin]($ecschema-metadata) instance found during schema traversal.
112
- * @param mixin a Mixin object.
113
- */
114
- async visitMixin(mixin) {
115
- for (const index of Object.keys(this._ruleSets))
116
- await this.applyMixinRules(mixin, this._ruleSets[index]);
117
- }
118
- /**
119
- * Called for each [RelationshipClass]($ecschema-metadata) instance found during schema traversal.
120
- * @param relationshipClass a RelationshipClass object.
121
- */
122
- async visitRelationshipClass(relationship) {
123
- for (const index of Object.keys(this._ruleSets))
124
- await this.applyRelationshipRules(relationship, this._ruleSets[index]);
125
- }
126
- /**
127
- * Called for each [RelationshipConstraint]($ecschema-metadata) of each RelationshipClass found during schema traversal.
128
- * @param relationshipConstraint a RelationshipConstraint object.
129
- */
130
- async visitRelationshipConstraint(constraint) {
131
- for (const index of Object.keys(this._ruleSets))
132
- await this.applyRelationshipConstraintRules(constraint, this._ruleSets[index]);
133
- }
134
- /**
135
- * Called for each [CustomAttributeClass]($ecschema-metadata) instance found during schema traversal.
136
- * @param customAttributeClass a CustomAttributeClass object.
137
- */
138
- async visitCustomAttributeClass(customAttribute) {
139
- for (const index of Object.keys(this._ruleSets))
140
- await this.applyCustomAttributeRules(customAttribute, this._ruleSets[index]);
141
- }
142
- /**
143
- * Called for each [CustomAttribute]($ecschema-metadata) container in the schema.
144
- * @param customAttributeContainer a [[CustomAttributeContainerProps]] object.
145
- */
146
- async visitCustomAttributeContainer(container) {
147
- for (const index of Object.keys(this._ruleSets))
148
- await this.applyCustomAttributeContainerRules(container, this._ruleSets[index]);
149
- if (undefined === container.customAttributes)
150
- return;
151
- for (const [, customAttribute] of container.customAttributes) {
152
- for (const index of Object.keys(this._ruleSets)) {
153
- await this.applyCustomAttributeInstanceRules(container, customAttribute, this._ruleSets[index]);
154
- }
155
- }
156
- }
157
- /**
158
- * Called for each [Enumeration]($ecschema-metadata) instance found during schema traversal.
159
- * @param enumeration an Enumeration object.
160
- */
161
- async visitEnumeration(enumeration) {
162
- for (const index of Object.keys(this._ruleSets))
163
- await this.applyEnumerationRules(enumeration, this._ruleSets[index]);
164
- }
165
- /**
166
- * Called for each [KindOfQuantity]($ecschema-metadata) instance found during schema traversal.
167
- * @param koq a KindOfQuantity object.
168
- */
169
- async visitKindOfQuantity(koq) {
170
- for (const index of Object.keys(this._ruleSets))
171
- await this.applyKindOfQuantityRules(koq, this._ruleSets[index]);
172
- }
173
- /**
174
- * Called for each [PropertyCategory]($ecschema-metadata) instance found during schema traversal.
175
- * @param category a PropertyCategory object.
176
- */
177
- async visitPropertyCategory(category) {
178
- for (const index of Object.keys(this._ruleSets))
179
- await this.applyPropertyCategoryRules(category, this._ruleSets[index]);
180
- }
181
- /**
182
- * Called for each [Format]($ecschema-metadata) instance found during schema traversal.
183
- * @param format a Format object.
184
- */
185
- async visitFormat(format) {
186
- for (const index of Object.keys(this._ruleSets))
187
- await this.applyFormatRules(format, this._ruleSets[index]);
188
- }
189
- /**
190
- * Called for each [Unit]($ecschema-metadata) instance found during schema traversal.
191
- * @param unit a Unit object.
192
- */
193
- async visitUnit(unit) {
194
- for (const index of Object.keys(this._ruleSets))
195
- await this.applyUnitRules(unit, this._ruleSets[index]);
196
- }
197
- /**
198
- * Called for each [InvertedUnit]($ecschema-metadata) instance found during schema traversal.
199
- * @param invertedUnit an InvertedUnit object.
200
- */
201
- async visitInvertedUnit(invertedUnit) {
202
- for (const index of Object.keys(this._ruleSets))
203
- await this.applyInvertedUnitRules(invertedUnit, this._ruleSets[index]);
204
- }
205
- /**
206
- * Called for each [UnitSystem]($ecschema-metadata) instance found during schema traversal.
207
- * @param unitSystem a UnitSystem object.
208
- */
209
- async visitUnitSystem(unitSystem) {
210
- for (const index of Object.keys(this._ruleSets))
211
- await this.applyUnitSystemRules(unitSystem, this._ruleSets[index]);
212
- }
213
- /**
214
- * Called for each [Phenomenon]($ecschema-metadata) instance found during schema traversal.
215
- * @param phenomena a Phenomenon object.
216
- */
217
- async visitPhenomenon(phenomenon) {
218
- for (const index of Object.keys(this._ruleSets))
219
- await this.applyPhenomenonRules(phenomenon, this._ruleSets[index]);
220
- }
221
- /**
222
- * Called for each [Constant]($ecschema-metadata) instance found during schema traversal.
223
- * @param constant a Constant object.
224
- */
225
- async visitConstant(constant) {
226
- for (const index of Object.keys(this._ruleSets))
227
- await this.applyConstantRules(constant, this._ruleSets[index]);
228
- }
229
- async applySchemaRules(schema, ruleSet) {
230
- if (!ruleSet.schemaRules || this.excludeSchemaFromRuleSet(schema, ruleSet))
231
- return;
232
- for (const rule of ruleSet.schemaRules) {
233
- const result = rule(schema);
234
- for await (const diagnostic of result) {
235
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.schemaRuleSuppressions : undefined;
236
- await this.reportDiagnostics(diagnostic, schema, suppressions);
237
- }
238
- }
239
- }
240
- async applySchemaItemRules(schemaItem, ruleSet) {
241
- if (!ruleSet.schemaItemRules || this.excludeSchemaFromRuleSet(schemaItem.schema, ruleSet))
242
- return;
243
- for (const rule of ruleSet.schemaItemRules) {
244
- const result = rule(schemaItem);
245
- for await (const diagnostic of result) {
246
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.schemaItemRuleSuppressions : undefined;
247
- await this.reportDiagnostics(diagnostic, schemaItem, suppressions);
248
- }
249
- }
250
- }
251
- async applyClassRules(ecClass, ruleSet) {
252
- if (!ruleSet.classRules || this.excludeSchemaFromRuleSet(ecClass.schema, ruleSet))
253
- return;
254
- for (const rule of ruleSet.classRules) {
255
- const result = rule(ecClass);
256
- for await (const diagnostic of result) {
257
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.classRuleSuppressions : undefined;
258
- await this.reportDiagnostics(diagnostic, ecClass, suppressions);
259
- }
260
- }
261
- }
262
- async applyPropertyRules(property, ruleSet) {
263
- if (!ruleSet.propertyRules || this.excludeSchemaFromRuleSet(property.schema, ruleSet))
264
- return;
265
- for (const rule of ruleSet.propertyRules) {
266
- const result = rule(property);
267
- for await (const diagnostic of result) {
268
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.propertyRuleSuppressions : undefined;
269
- await this.reportDiagnostics(diagnostic, property, suppressions);
270
- }
271
- }
272
- }
273
- async applyEntityRules(entityClass, ruleSet) {
274
- if (!ruleSet.entityClassRules || this.excludeSchemaFromRuleSet(entityClass.schema, ruleSet))
275
- return;
276
- for (const rule of ruleSet.entityClassRules) {
277
- const result = rule(entityClass);
278
- for await (const diagnostic of result) {
279
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.entityRuleSuppressions : undefined;
280
- await this.reportDiagnostics(diagnostic, entityClass, suppressions);
281
- }
282
- }
283
- }
284
- async applyStructRules(structClass, ruleSet) {
285
- if (!ruleSet.structClassRules || this.excludeSchemaFromRuleSet(structClass.schema, ruleSet))
286
- return;
287
- for (const rule of ruleSet.structClassRules) {
288
- const result = rule(structClass);
289
- for await (const diagnostic of result) {
290
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.structRuleSuppressions : undefined;
291
- await this.reportDiagnostics(diagnostic, structClass, suppressions);
292
- }
293
- }
294
- }
295
- async applyMixinRules(mixin, ruleSet) {
296
- if (!ruleSet.mixinRules || this.excludeSchemaFromRuleSet(mixin.schema, ruleSet))
297
- return;
298
- for (const rule of ruleSet.mixinRules) {
299
- const result = rule(mixin);
300
- for await (const diagnostic of result) {
301
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.mixinRuleSuppressions : undefined;
302
- await this.reportDiagnostics(diagnostic, mixin, suppressions);
303
- }
304
- }
305
- }
306
- async applyRelationshipRules(relationship, ruleSet) {
307
- if (!ruleSet.relationshipRules || this.excludeSchemaFromRuleSet(relationship.schema, ruleSet))
308
- return;
309
- for (const rule of ruleSet.relationshipRules) {
310
- const result = rule(relationship);
311
- for await (const diagnostic of result) {
312
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.relationshipRuleSuppressions : undefined;
313
- await this.reportDiagnostics(diagnostic, relationship, suppressions);
314
- }
315
- }
316
- }
317
- async applyRelationshipConstraintRules(constraint, ruleSet) {
318
- if (!ruleSet.relationshipConstraintRules || this.excludeSchemaFromRuleSet(constraint.schema, ruleSet))
319
- return;
320
- for (const rule of ruleSet.relationshipConstraintRules) {
321
- const result = rule(constraint);
322
- for await (const diagnostic of result) {
323
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.relationshipConstraintRuleSuppressions : undefined;
324
- await this.reportDiagnostics(diagnostic, constraint, suppressions);
325
- }
326
- }
327
- }
328
- async applyCustomAttributeRules(customAttribute, ruleSet) {
329
- if (!ruleSet.customAttributeClassRules || this.excludeSchemaFromRuleSet(customAttribute.schema, ruleSet))
330
- return;
331
- for (const rule of ruleSet.customAttributeClassRules) {
332
- const result = rule(customAttribute);
333
- for await (const diagnostic of result) {
334
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.customAttributeRuleSuppressions : undefined;
335
- await this.reportDiagnostics(diagnostic, customAttribute, suppressions);
336
- }
337
- }
338
- }
339
- async applyCustomAttributeContainerRules(container, ruleSet) {
340
- if (!ruleSet.customAttributeContainerRules || this.excludeSchemaFromRuleSet(container.schema, ruleSet))
341
- return;
342
- for (const rule of ruleSet.customAttributeContainerRules) {
343
- const result = rule(container);
344
- for await (const diagnostic of result) {
345
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.customAttributeContainerSuppressions : undefined;
346
- await this.reportDiagnostics(diagnostic, container, suppressions);
347
- }
348
- }
349
- }
350
- async applyCustomAttributeInstanceRules(container, customAttribute, ruleSet) {
351
- if (!ruleSet.customAttributeInstanceRules || this.excludeSchemaFromRuleSet(container.schema, ruleSet))
352
- return;
353
- for (const rule of ruleSet.customAttributeInstanceRules) {
354
- const result = rule(container, customAttribute);
355
- for await (const diagnostic of result) {
356
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.customAttributeInstanceSuppressions : undefined;
357
- await this.reportDiagnostics(diagnostic, container, suppressions);
358
- }
359
- }
360
- }
361
- async applyEnumerationRules(enumeration, ruleSet) {
362
- if (!ruleSet.enumerationRules || this.excludeSchemaFromRuleSet(enumeration.schema, ruleSet))
363
- return;
364
- for (const rule of ruleSet.enumerationRules) {
365
- const result = rule(enumeration);
366
- for await (const diagnostic of result) {
367
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.enumerationRuleSuppressions : undefined;
368
- await this.reportDiagnostics(diagnostic, enumeration, suppressions);
369
- }
370
- }
371
- }
372
- async applyKindOfQuantityRules(kindOfQuantity, ruleSet) {
373
- if (!ruleSet.kindOfQuantityRules || this.excludeSchemaFromRuleSet(kindOfQuantity.schema, ruleSet))
374
- return;
375
- for (const rule of ruleSet.kindOfQuantityRules) {
376
- const result = rule(kindOfQuantity);
377
- for await (const diagnostic of result) {
378
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.koqRuleSuppressions : undefined;
379
- await this.reportDiagnostics(diagnostic, kindOfQuantity, suppressions);
380
- }
381
- }
382
- }
383
- async applyPropertyCategoryRules(propertyCategory, ruleSet) {
384
- if (!ruleSet.propertyCategoryRules || this.excludeSchemaFromRuleSet(propertyCategory.schema, ruleSet))
385
- return;
386
- for (const rule of ruleSet.propertyCategoryRules) {
387
- const result = rule(propertyCategory);
388
- for await (const diagnostic of result) {
389
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.propertyCategoryRuleSuppressions : undefined;
390
- await this.reportDiagnostics(diagnostic, propertyCategory, suppressions);
391
- }
392
- }
393
- }
394
- async applyFormatRules(format, ruleSet) {
395
- if (!ruleSet.formatRules || this.excludeSchemaFromRuleSet(format.schema, ruleSet))
396
- return;
397
- for (const rule of ruleSet.formatRules) {
398
- const result = rule(format);
399
- for await (const diagnostic of result) {
400
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.formatRuleSuppressions : undefined;
401
- await this.reportDiagnostics(diagnostic, format, suppressions);
402
- }
403
- }
404
- }
405
- async applyUnitRules(unit, ruleSet) {
406
- if (!ruleSet.unitRules || this.excludeSchemaFromRuleSet(unit.schema, ruleSet))
407
- return;
408
- for (const rule of ruleSet.unitRules) {
409
- const result = rule(unit);
410
- for await (const diagnostic of result) {
411
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.unitRuleSuppressions : undefined;
412
- await this.reportDiagnostics(diagnostic, unit, suppressions);
413
- }
414
- }
415
- }
416
- async applyInvertedUnitRules(invertedUnit, ruleSet) {
417
- if (!ruleSet.invertedUnitRules || this.excludeSchemaFromRuleSet(invertedUnit.schema, ruleSet))
418
- return;
419
- for (const rule of ruleSet.invertedUnitRules) {
420
- const result = rule(invertedUnit);
421
- for await (const diagnostic of result) {
422
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.invertedUnitRuleSuppressions : undefined;
423
- await this.reportDiagnostics(diagnostic, invertedUnit, suppressions);
424
- }
425
- }
426
- }
427
- async applyUnitSystemRules(unitSystem, ruleSet) {
428
- if (!ruleSet.unitSystemRules || this.excludeSchemaFromRuleSet(unitSystem.schema, ruleSet))
429
- return;
430
- for (const rule of ruleSet.unitSystemRules) {
431
- const result = rule(unitSystem);
432
- for await (const diagnostic of result) {
433
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.unitSystemRuleSuppressions : undefined;
434
- await this.reportDiagnostics(diagnostic, unitSystem, suppressions);
435
- }
436
- }
437
- }
438
- async applyPhenomenonRules(phenomenon, ruleSet) {
439
- if (!ruleSet.phenomenonRules || this.excludeSchemaFromRuleSet(phenomenon.schema, ruleSet))
440
- return;
441
- for (const rule of ruleSet.phenomenonRules) {
442
- const result = rule(phenomenon);
443
- for await (const diagnostic of result) {
444
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.phenomenonRuleSuppressions : undefined;
445
- await this.reportDiagnostics(diagnostic, phenomenon, suppressions);
446
- }
447
- }
448
- }
449
- async applyConstantRules(constant, ruleSet) {
450
- if (!ruleSet.constantRules || this.excludeSchemaFromRuleSet(constant.schema, ruleSet))
451
- return;
452
- for (const rule of ruleSet.constantRules) {
453
- const result = rule(constant);
454
- for await (const diagnostic of result) {
455
- const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.constantRuleSuppressions : undefined;
456
- await this.reportDiagnostics(diagnostic, constant, suppressions);
457
- }
458
- }
459
- }
460
- findSuppressionRule(suppressionSet, code) {
461
- if (!suppressionSet)
462
- return;
463
- for (const suppression of suppressionSet) {
464
- if (suppression.ruleCode === code) {
465
- return suppression.rule;
466
- }
467
- }
468
- return;
469
- }
470
- excludeSchemaFromRuleSet(schema, ruleSet) {
471
- if (!ruleSet.schemaExclusionSet)
472
- return false;
473
- return ruleSet.schemaExclusionSet.includes(schema.name);
474
- }
475
- async reportDiagnostics(diagnostic, ecType, suppressionMap) {
476
- if (!diagnostic)
477
- return;
478
- if (suppressionMap) {
479
- const suppressRule = this.findSuppressionRule(suppressionMap, diagnostic.code);
480
- if (suppressRule) {
481
- const ecSuppression = await suppressRule(diagnostic, ecType);
482
- if (ecSuppression) {
483
- diagnostic.category = Diagnostic_1.DiagnosticCategory.Warning;
484
- }
485
- }
486
- }
487
- this._reporters.forEach((reporter) => {
488
- reporter.report(diagnostic);
489
- });
490
- }
491
- }
492
- exports.SchemaValidationVisitor = SchemaValidationVisitor;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SchemaValidationVisitor = void 0;
11
+ const Diagnostic_1 = require("./Diagnostic");
12
+ /**
13
+ * A SchemaWalkerVisitor interface implementation that is used to validate ECObjects schemas using
14
+ * [[IRuleSet]] objects registered with the instance. Also allows for reporting of [[IDiagnostic]]
15
+ * objects returned from failing rules using [[IDiagnosticReporter]] implementations registered
16
+ * with an instance of this class.
17
+ * @beta
18
+ */
19
+ class SchemaValidationVisitor {
20
+ constructor() {
21
+ this._reporters = [];
22
+ this._ruleSets = {};
23
+ }
24
+ /** Gets the IRule<AnyClass> objects registered with the visitor. */
25
+ get ruleSets() {
26
+ return this._ruleSets;
27
+ }
28
+ get suppressionSet() {
29
+ return this._ruleSuppressionSet;
30
+ }
31
+ /** Gets the IDiagnosticReporter objects registered with the visitor. */
32
+ get diagnosticReporters() {
33
+ return this._reporters;
34
+ }
35
+ /**
36
+ * Registers a [[IDiagnosticReporter]] allowing the reporter to be
37
+ * notified when a [[IDiagnostic]] is created due to a rule violation.
38
+ * @param reporter The [[DiagnosticReporter]] to register.
39
+ */
40
+ registerReporter(...reporters) {
41
+ for (const reporter of reporters)
42
+ this._reporters.push(reporter);
43
+ }
44
+ /**
45
+ * Registers a [[IRuleSet]] that will applied during schema traversal.
46
+ * @param ruleSet The [[IRuleSet]] to register.
47
+ */
48
+ registerRuleSet(ruleSet) {
49
+ if (undefined !== this.ruleSets[ruleSet.name])
50
+ throw new Error(`A RuleSet with the name '${ruleSet.name}' has already been registered.`);
51
+ this.ruleSets[ruleSet.name] = ruleSet;
52
+ }
53
+ /**
54
+ * Registers a [[IRuleSuppressionSet]] that will be applied during schema traversal.
55
+ * @param ruleSet The [[IRuleSuppressionSet]] to register.
56
+ * Only supports one Rule Suppression Set, if you call it twice it will overwrite the
57
+ * previous suppression set
58
+ */
59
+ registerRuleSuppressionSet(suppressionSet) {
60
+ this._ruleSuppressionSet = suppressionSet;
61
+ }
62
+ /**
63
+ * Called before schema traversal.
64
+ * @param schema a Schema object.
65
+ */
66
+ async visitFullSchema(schema) {
67
+ for (const index of Object.keys(this._ruleSets))
68
+ await this.applySchemaRules(schema, this._ruleSets[index]);
69
+ }
70
+ /**
71
+ * Called for each [[SchemaItem]] instance found during schema traversal.
72
+ * @param schemaItem a SchemaItem object.
73
+ */
74
+ async visitSchemaItem(schemaItem) {
75
+ for (const index of Object.keys(this._ruleSets))
76
+ await this.applySchemaItemRules(schemaItem, this._ruleSets[index]);
77
+ }
78
+ /**
79
+ * Called for each [AnyClass]($ecschema-metadata) instance found during schema traversal.
80
+ * @param ecClass an ECClass object.
81
+ */
82
+ async visitClass(ecClass) {
83
+ for (const index of Object.keys(this._ruleSets))
84
+ await this.applyClassRules(ecClass, this._ruleSets[index]);
85
+ }
86
+ /**
87
+ * Called for each [AnyProperty]($ecschema-metadata) instance of an ECClass.
88
+ * @param property an AnyProperty object.
89
+ */
90
+ async visitProperty(property) {
91
+ for (const index of Object.keys(this._ruleSets))
92
+ await this.applyPropertyRules(property, this._ruleSets[index]);
93
+ }
94
+ /**
95
+ * Called for each [EntityClass]($ecschema-metadata) instance found during schema traversal.
96
+ * @param entityClass an EntityClass object.
97
+ */
98
+ async visitEntityClass(entity) {
99
+ for (const index of Object.keys(this._ruleSets))
100
+ await this.applyEntityRules(entity, this._ruleSets[index]);
101
+ }
102
+ /**
103
+ * Called for each [StructClass]($ecschema-metadata) instance found during schema traversal.
104
+ * @param structClass a StructClass object.
105
+ */
106
+ async visitStructClass(struct) {
107
+ for (const index of Object.keys(this._ruleSets))
108
+ await this.applyStructRules(struct, this._ruleSets[index]);
109
+ }
110
+ /**
111
+ * Called for each [Mixin]($ecschema-metadata) instance found during schema traversal.
112
+ * @param mixin a Mixin object.
113
+ */
114
+ async visitMixin(mixin) {
115
+ for (const index of Object.keys(this._ruleSets))
116
+ await this.applyMixinRules(mixin, this._ruleSets[index]);
117
+ }
118
+ /**
119
+ * Called for each [RelationshipClass]($ecschema-metadata) instance found during schema traversal.
120
+ * @param relationshipClass a RelationshipClass object.
121
+ */
122
+ async visitRelationshipClass(relationship) {
123
+ for (const index of Object.keys(this._ruleSets))
124
+ await this.applyRelationshipRules(relationship, this._ruleSets[index]);
125
+ }
126
+ /**
127
+ * Called for each [RelationshipConstraint]($ecschema-metadata) of each RelationshipClass found during schema traversal.
128
+ * @param relationshipConstraint a RelationshipConstraint object.
129
+ */
130
+ async visitRelationshipConstraint(constraint) {
131
+ for (const index of Object.keys(this._ruleSets))
132
+ await this.applyRelationshipConstraintRules(constraint, this._ruleSets[index]);
133
+ }
134
+ /**
135
+ * Called for each [CustomAttributeClass]($ecschema-metadata) instance found during schema traversal.
136
+ * @param customAttributeClass a CustomAttributeClass object.
137
+ */
138
+ async visitCustomAttributeClass(customAttribute) {
139
+ for (const index of Object.keys(this._ruleSets))
140
+ await this.applyCustomAttributeRules(customAttribute, this._ruleSets[index]);
141
+ }
142
+ /**
143
+ * Called for each [CustomAttribute]($ecschema-metadata) container in the schema.
144
+ * @param customAttributeContainer a [[CustomAttributeContainerProps]] object.
145
+ */
146
+ async visitCustomAttributeContainer(container) {
147
+ for (const index of Object.keys(this._ruleSets))
148
+ await this.applyCustomAttributeContainerRules(container, this._ruleSets[index]);
149
+ if (undefined === container.customAttributes)
150
+ return;
151
+ for (const [, customAttribute] of container.customAttributes) {
152
+ for (const index of Object.keys(this._ruleSets)) {
153
+ await this.applyCustomAttributeInstanceRules(container, customAttribute, this._ruleSets[index]);
154
+ }
155
+ }
156
+ }
157
+ /**
158
+ * Called for each [Enumeration]($ecschema-metadata) instance found during schema traversal.
159
+ * @param enumeration an Enumeration object.
160
+ */
161
+ async visitEnumeration(enumeration) {
162
+ for (const index of Object.keys(this._ruleSets))
163
+ await this.applyEnumerationRules(enumeration, this._ruleSets[index]);
164
+ }
165
+ /**
166
+ * Called for each [KindOfQuantity]($ecschema-metadata) instance found during schema traversal.
167
+ * @param koq a KindOfQuantity object.
168
+ */
169
+ async visitKindOfQuantity(koq) {
170
+ for (const index of Object.keys(this._ruleSets))
171
+ await this.applyKindOfQuantityRules(koq, this._ruleSets[index]);
172
+ }
173
+ /**
174
+ * Called for each [PropertyCategory]($ecschema-metadata) instance found during schema traversal.
175
+ * @param category a PropertyCategory object.
176
+ */
177
+ async visitPropertyCategory(category) {
178
+ for (const index of Object.keys(this._ruleSets))
179
+ await this.applyPropertyCategoryRules(category, this._ruleSets[index]);
180
+ }
181
+ /**
182
+ * Called for each [Format]($ecschema-metadata) instance found during schema traversal.
183
+ * @param format a Format object.
184
+ */
185
+ async visitFormat(format) {
186
+ for (const index of Object.keys(this._ruleSets))
187
+ await this.applyFormatRules(format, this._ruleSets[index]);
188
+ }
189
+ /**
190
+ * Called for each [Unit]($ecschema-metadata) instance found during schema traversal.
191
+ * @param unit a Unit object.
192
+ */
193
+ async visitUnit(unit) {
194
+ for (const index of Object.keys(this._ruleSets))
195
+ await this.applyUnitRules(unit, this._ruleSets[index]);
196
+ }
197
+ /**
198
+ * Called for each [InvertedUnit]($ecschema-metadata) instance found during schema traversal.
199
+ * @param invertedUnit an InvertedUnit object.
200
+ */
201
+ async visitInvertedUnit(invertedUnit) {
202
+ for (const index of Object.keys(this._ruleSets))
203
+ await this.applyInvertedUnitRules(invertedUnit, this._ruleSets[index]);
204
+ }
205
+ /**
206
+ * Called for each [UnitSystem]($ecschema-metadata) instance found during schema traversal.
207
+ * @param unitSystem a UnitSystem object.
208
+ */
209
+ async visitUnitSystem(unitSystem) {
210
+ for (const index of Object.keys(this._ruleSets))
211
+ await this.applyUnitSystemRules(unitSystem, this._ruleSets[index]);
212
+ }
213
+ /**
214
+ * Called for each [Phenomenon]($ecschema-metadata) instance found during schema traversal.
215
+ * @param phenomena a Phenomenon object.
216
+ */
217
+ async visitPhenomenon(phenomenon) {
218
+ for (const index of Object.keys(this._ruleSets))
219
+ await this.applyPhenomenonRules(phenomenon, this._ruleSets[index]);
220
+ }
221
+ /**
222
+ * Called for each [Constant]($ecschema-metadata) instance found during schema traversal.
223
+ * @param constant a Constant object.
224
+ */
225
+ async visitConstant(constant) {
226
+ for (const index of Object.keys(this._ruleSets))
227
+ await this.applyConstantRules(constant, this._ruleSets[index]);
228
+ }
229
+ async applySchemaRules(schema, ruleSet) {
230
+ if (!ruleSet.schemaRules || this.excludeSchemaFromRuleSet(schema, ruleSet))
231
+ return;
232
+ for (const rule of ruleSet.schemaRules) {
233
+ const result = rule(schema);
234
+ for await (const diagnostic of result) {
235
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.schemaRuleSuppressions : undefined;
236
+ await this.reportDiagnostics(diagnostic, schema, suppressions);
237
+ }
238
+ }
239
+ }
240
+ async applySchemaItemRules(schemaItem, ruleSet) {
241
+ if (!ruleSet.schemaItemRules || this.excludeSchemaFromRuleSet(schemaItem.schema, ruleSet))
242
+ return;
243
+ for (const rule of ruleSet.schemaItemRules) {
244
+ const result = rule(schemaItem);
245
+ for await (const diagnostic of result) {
246
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.schemaItemRuleSuppressions : undefined;
247
+ await this.reportDiagnostics(diagnostic, schemaItem, suppressions);
248
+ }
249
+ }
250
+ }
251
+ async applyClassRules(ecClass, ruleSet) {
252
+ if (!ruleSet.classRules || this.excludeSchemaFromRuleSet(ecClass.schema, ruleSet))
253
+ return;
254
+ for (const rule of ruleSet.classRules) {
255
+ const result = rule(ecClass);
256
+ for await (const diagnostic of result) {
257
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.classRuleSuppressions : undefined;
258
+ await this.reportDiagnostics(diagnostic, ecClass, suppressions);
259
+ }
260
+ }
261
+ }
262
+ async applyPropertyRules(property, ruleSet) {
263
+ if (!ruleSet.propertyRules || this.excludeSchemaFromRuleSet(property.schema, ruleSet))
264
+ return;
265
+ for (const rule of ruleSet.propertyRules) {
266
+ const result = rule(property);
267
+ for await (const diagnostic of result) {
268
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.propertyRuleSuppressions : undefined;
269
+ await this.reportDiagnostics(diagnostic, property, suppressions);
270
+ }
271
+ }
272
+ }
273
+ async applyEntityRules(entityClass, ruleSet) {
274
+ if (!ruleSet.entityClassRules || this.excludeSchemaFromRuleSet(entityClass.schema, ruleSet))
275
+ return;
276
+ for (const rule of ruleSet.entityClassRules) {
277
+ const result = rule(entityClass);
278
+ for await (const diagnostic of result) {
279
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.entityRuleSuppressions : undefined;
280
+ await this.reportDiagnostics(diagnostic, entityClass, suppressions);
281
+ }
282
+ }
283
+ }
284
+ async applyStructRules(structClass, ruleSet) {
285
+ if (!ruleSet.structClassRules || this.excludeSchemaFromRuleSet(structClass.schema, ruleSet))
286
+ return;
287
+ for (const rule of ruleSet.structClassRules) {
288
+ const result = rule(structClass);
289
+ for await (const diagnostic of result) {
290
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.structRuleSuppressions : undefined;
291
+ await this.reportDiagnostics(diagnostic, structClass, suppressions);
292
+ }
293
+ }
294
+ }
295
+ async applyMixinRules(mixin, ruleSet) {
296
+ if (!ruleSet.mixinRules || this.excludeSchemaFromRuleSet(mixin.schema, ruleSet))
297
+ return;
298
+ for (const rule of ruleSet.mixinRules) {
299
+ const result = rule(mixin);
300
+ for await (const diagnostic of result) {
301
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.mixinRuleSuppressions : undefined;
302
+ await this.reportDiagnostics(diagnostic, mixin, suppressions);
303
+ }
304
+ }
305
+ }
306
+ async applyRelationshipRules(relationship, ruleSet) {
307
+ if (!ruleSet.relationshipRules || this.excludeSchemaFromRuleSet(relationship.schema, ruleSet))
308
+ return;
309
+ for (const rule of ruleSet.relationshipRules) {
310
+ const result = rule(relationship);
311
+ for await (const diagnostic of result) {
312
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.relationshipRuleSuppressions : undefined;
313
+ await this.reportDiagnostics(diagnostic, relationship, suppressions);
314
+ }
315
+ }
316
+ }
317
+ async applyRelationshipConstraintRules(constraint, ruleSet) {
318
+ if (!ruleSet.relationshipConstraintRules || this.excludeSchemaFromRuleSet(constraint.schema, ruleSet))
319
+ return;
320
+ for (const rule of ruleSet.relationshipConstraintRules) {
321
+ const result = rule(constraint);
322
+ for await (const diagnostic of result) {
323
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.relationshipConstraintRuleSuppressions : undefined;
324
+ await this.reportDiagnostics(diagnostic, constraint, suppressions);
325
+ }
326
+ }
327
+ }
328
+ async applyCustomAttributeRules(customAttribute, ruleSet) {
329
+ if (!ruleSet.customAttributeClassRules || this.excludeSchemaFromRuleSet(customAttribute.schema, ruleSet))
330
+ return;
331
+ for (const rule of ruleSet.customAttributeClassRules) {
332
+ const result = rule(customAttribute);
333
+ for await (const diagnostic of result) {
334
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.customAttributeRuleSuppressions : undefined;
335
+ await this.reportDiagnostics(diagnostic, customAttribute, suppressions);
336
+ }
337
+ }
338
+ }
339
+ async applyCustomAttributeContainerRules(container, ruleSet) {
340
+ if (!ruleSet.customAttributeContainerRules || this.excludeSchemaFromRuleSet(container.schema, ruleSet))
341
+ return;
342
+ for (const rule of ruleSet.customAttributeContainerRules) {
343
+ const result = rule(container);
344
+ for await (const diagnostic of result) {
345
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.customAttributeContainerSuppressions : undefined;
346
+ await this.reportDiagnostics(diagnostic, container, suppressions);
347
+ }
348
+ }
349
+ }
350
+ async applyCustomAttributeInstanceRules(container, customAttribute, ruleSet) {
351
+ if (!ruleSet.customAttributeInstanceRules || this.excludeSchemaFromRuleSet(container.schema, ruleSet))
352
+ return;
353
+ for (const rule of ruleSet.customAttributeInstanceRules) {
354
+ const result = rule(container, customAttribute);
355
+ for await (const diagnostic of result) {
356
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.customAttributeInstanceSuppressions : undefined;
357
+ await this.reportDiagnostics(diagnostic, container, suppressions);
358
+ }
359
+ }
360
+ }
361
+ async applyEnumerationRules(enumeration, ruleSet) {
362
+ if (!ruleSet.enumerationRules || this.excludeSchemaFromRuleSet(enumeration.schema, ruleSet))
363
+ return;
364
+ for (const rule of ruleSet.enumerationRules) {
365
+ const result = rule(enumeration);
366
+ for await (const diagnostic of result) {
367
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.enumerationRuleSuppressions : undefined;
368
+ await this.reportDiagnostics(diagnostic, enumeration, suppressions);
369
+ }
370
+ }
371
+ }
372
+ async applyKindOfQuantityRules(kindOfQuantity, ruleSet) {
373
+ if (!ruleSet.kindOfQuantityRules || this.excludeSchemaFromRuleSet(kindOfQuantity.schema, ruleSet))
374
+ return;
375
+ for (const rule of ruleSet.kindOfQuantityRules) {
376
+ const result = rule(kindOfQuantity);
377
+ for await (const diagnostic of result) {
378
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.koqRuleSuppressions : undefined;
379
+ await this.reportDiagnostics(diagnostic, kindOfQuantity, suppressions);
380
+ }
381
+ }
382
+ }
383
+ async applyPropertyCategoryRules(propertyCategory, ruleSet) {
384
+ if (!ruleSet.propertyCategoryRules || this.excludeSchemaFromRuleSet(propertyCategory.schema, ruleSet))
385
+ return;
386
+ for (const rule of ruleSet.propertyCategoryRules) {
387
+ const result = rule(propertyCategory);
388
+ for await (const diagnostic of result) {
389
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.propertyCategoryRuleSuppressions : undefined;
390
+ await this.reportDiagnostics(diagnostic, propertyCategory, suppressions);
391
+ }
392
+ }
393
+ }
394
+ async applyFormatRules(format, ruleSet) {
395
+ if (!ruleSet.formatRules || this.excludeSchemaFromRuleSet(format.schema, ruleSet))
396
+ return;
397
+ for (const rule of ruleSet.formatRules) {
398
+ const result = rule(format);
399
+ for await (const diagnostic of result) {
400
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.formatRuleSuppressions : undefined;
401
+ await this.reportDiagnostics(diagnostic, format, suppressions);
402
+ }
403
+ }
404
+ }
405
+ async applyUnitRules(unit, ruleSet) {
406
+ if (!ruleSet.unitRules || this.excludeSchemaFromRuleSet(unit.schema, ruleSet))
407
+ return;
408
+ for (const rule of ruleSet.unitRules) {
409
+ const result = rule(unit);
410
+ for await (const diagnostic of result) {
411
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.unitRuleSuppressions : undefined;
412
+ await this.reportDiagnostics(diagnostic, unit, suppressions);
413
+ }
414
+ }
415
+ }
416
+ async applyInvertedUnitRules(invertedUnit, ruleSet) {
417
+ if (!ruleSet.invertedUnitRules || this.excludeSchemaFromRuleSet(invertedUnit.schema, ruleSet))
418
+ return;
419
+ for (const rule of ruleSet.invertedUnitRules) {
420
+ const result = rule(invertedUnit);
421
+ for await (const diagnostic of result) {
422
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.invertedUnitRuleSuppressions : undefined;
423
+ await this.reportDiagnostics(diagnostic, invertedUnit, suppressions);
424
+ }
425
+ }
426
+ }
427
+ async applyUnitSystemRules(unitSystem, ruleSet) {
428
+ if (!ruleSet.unitSystemRules || this.excludeSchemaFromRuleSet(unitSystem.schema, ruleSet))
429
+ return;
430
+ for (const rule of ruleSet.unitSystemRules) {
431
+ const result = rule(unitSystem);
432
+ for await (const diagnostic of result) {
433
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.unitSystemRuleSuppressions : undefined;
434
+ await this.reportDiagnostics(diagnostic, unitSystem, suppressions);
435
+ }
436
+ }
437
+ }
438
+ async applyPhenomenonRules(phenomenon, ruleSet) {
439
+ if (!ruleSet.phenomenonRules || this.excludeSchemaFromRuleSet(phenomenon.schema, ruleSet))
440
+ return;
441
+ for (const rule of ruleSet.phenomenonRules) {
442
+ const result = rule(phenomenon);
443
+ for await (const diagnostic of result) {
444
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.phenomenonRuleSuppressions : undefined;
445
+ await this.reportDiagnostics(diagnostic, phenomenon, suppressions);
446
+ }
447
+ }
448
+ }
449
+ async applyConstantRules(constant, ruleSet) {
450
+ if (!ruleSet.constantRules || this.excludeSchemaFromRuleSet(constant.schema, ruleSet))
451
+ return;
452
+ for (const rule of ruleSet.constantRules) {
453
+ const result = rule(constant);
454
+ for await (const diagnostic of result) {
455
+ const suppressions = this._ruleSuppressionSet ? this._ruleSuppressionSet.constantRuleSuppressions : undefined;
456
+ await this.reportDiagnostics(diagnostic, constant, suppressions);
457
+ }
458
+ }
459
+ }
460
+ findSuppressionRule(suppressionSet, code) {
461
+ if (!suppressionSet)
462
+ return;
463
+ for (const suppression of suppressionSet) {
464
+ if (suppression.ruleCode === code) {
465
+ return suppression.rule;
466
+ }
467
+ }
468
+ return;
469
+ }
470
+ excludeSchemaFromRuleSet(schema, ruleSet) {
471
+ if (!ruleSet.schemaExclusionSet)
472
+ return false;
473
+ return ruleSet.schemaExclusionSet.includes(schema.name);
474
+ }
475
+ async reportDiagnostics(diagnostic, ecType, suppressionMap) {
476
+ if (!diagnostic)
477
+ return;
478
+ if (suppressionMap) {
479
+ const suppressRule = this.findSuppressionRule(suppressionMap, diagnostic.code);
480
+ if (suppressRule) {
481
+ const ecSuppression = await suppressRule(diagnostic, ecType);
482
+ if (ecSuppression) {
483
+ diagnostic.category = Diagnostic_1.DiagnosticCategory.Warning;
484
+ }
485
+ }
486
+ }
487
+ this._reporters.forEach((reporter) => {
488
+ reporter.report(diagnostic);
489
+ });
490
+ }
491
+ }
492
+ exports.SchemaValidationVisitor = SchemaValidationVisitor;
493
493
  //# sourceMappingURL=SchemaValidationVisitor.js.map