@itwin/ecschema-metadata 3.5.0-dev.8 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/CHANGELOG.md +73 -1
  2. package/lib/cjs/Constants.d.ts +23 -23
  3. package/lib/cjs/Constants.js +33 -33
  4. package/lib/cjs/Constants.js.map +1 -1
  5. package/lib/cjs/Context.d.ts +139 -139
  6. package/lib/cjs/Context.js +204 -204
  7. package/lib/cjs/DelayedPromise.d.ts +88 -88
  8. package/lib/cjs/DelayedPromise.js +91 -91
  9. package/lib/cjs/DelayedPromise.js.map +1 -1
  10. package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
  11. package/lib/cjs/Deserialization/AbstractParser.js +11 -11
  12. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  13. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  14. package/lib/cjs/Deserialization/Helper.js +843 -843
  15. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  16. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  17. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  18. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  19. package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
  20. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  21. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  22. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  23. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  24. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  25. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  26. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  27. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  28. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  29. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  30. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  31. package/lib/cjs/ECName.d.ts +30 -30
  32. package/lib/cjs/ECName.js +85 -85
  33. package/lib/cjs/ECName.js.map +1 -1
  34. package/lib/cjs/ECObjects.d.ts +162 -162
  35. package/lib/cjs/ECObjects.js +453 -453
  36. package/lib/cjs/ECObjects.js.map +1 -1
  37. package/lib/cjs/Exception.d.ts +43 -43
  38. package/lib/cjs/Exception.js +86 -86
  39. package/lib/cjs/Exception.js.map +1 -1
  40. package/lib/cjs/Interfaces.d.ts +66 -66
  41. package/lib/cjs/Interfaces.js +9 -9
  42. package/lib/cjs/Interfaces.js.map +1 -1
  43. package/lib/cjs/Metadata/Class.d.ts +243 -243
  44. package/lib/cjs/Metadata/Class.js +558 -558
  45. package/lib/cjs/Metadata/Class.js.map +1 -1
  46. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  47. package/lib/cjs/Metadata/Constant.js +123 -123
  48. package/lib/cjs/Metadata/Constant.js.map +1 -1
  49. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  50. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  51. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  52. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  53. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  54. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  55. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  56. package/lib/cjs/Metadata/EntityClass.js +230 -230
  57. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  58. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  59. package/lib/cjs/Metadata/Enumeration.js +159 -159
  60. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  61. package/lib/cjs/Metadata/Format.d.ts +98 -98
  62. package/lib/cjs/Metadata/Format.js +242 -242
  63. package/lib/cjs/Metadata/Format.js.map +1 -1
  64. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  65. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  66. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  67. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  68. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  69. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  70. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  71. package/lib/cjs/Metadata/Mixin.js +113 -113
  72. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  73. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  74. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  75. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  76. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  77. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  78. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  79. package/lib/cjs/Metadata/Property.d.ts +197 -197
  80. package/lib/cjs/Metadata/Property.js +491 -491
  81. package/lib/cjs/Metadata/Property.js.map +1 -1
  82. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  83. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  84. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  85. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  86. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  87. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  88. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  89. package/lib/cjs/Metadata/Schema.js +520 -520
  90. package/lib/cjs/Metadata/Schema.js.map +1 -1
  91. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  92. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  93. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  94. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  95. package/lib/cjs/Metadata/Unit.js +162 -162
  96. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  97. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  98. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  99. package/lib/cjs/PropertyTypes.d.ts +49 -49
  100. package/lib/cjs/PropertyTypes.js +91 -91
  101. package/lib/cjs/PropertyTypes.js.map +1 -1
  102. package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
  103. package/lib/cjs/SchemaJsonLocater.js +42 -42
  104. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  105. package/lib/cjs/SchemaKey.d.ts +110 -110
  106. package/lib/cjs/SchemaKey.js +219 -219
  107. package/lib/cjs/SchemaKey.js.map +1 -1
  108. package/lib/cjs/SchemaLoader.d.ts +23 -23
  109. package/lib/cjs/SchemaLoader.js +47 -47
  110. package/lib/cjs/SchemaLoader.js.map +1 -1
  111. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  112. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  113. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  114. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  115. package/lib/cjs/UnitConversion/Graph.js +83 -83
  116. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  117. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  118. package/lib/cjs/UnitConversion/Parser.js +42 -42
  119. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  120. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  121. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  122. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  123. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  124. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  125. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  126. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  127. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  128. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  129. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  130. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +236 -236
  131. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  132. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  133. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  134. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  135. package/lib/cjs/ecschema-metadata.d.ts +51 -51
  136. package/lib/cjs/ecschema-metadata.js +96 -96
  137. package/lib/cjs/ecschema-metadata.js.map +1 -1
  138. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  139. package/lib/cjs/utils/SchemaGraph.js +65 -65
  140. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  141. package/package.json +9 -9
@@ -1,350 +1,350 @@
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 Metadata
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.MutableRelationshipClass = exports.RelationshipMultiplicity = exports.MutableRelationshipConstraint = exports.RelationshipConstraint = exports.RelationshipClass = void 0;
11
- const DelayedPromise_1 = require("../DelayedPromise");
12
- const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
13
- const ECObjects_1 = require("../ECObjects");
14
- const Exception_1 = require("../Exception");
15
- const Class_1 = require("./Class");
16
- const CustomAttribute_1 = require("./CustomAttribute");
17
- const EntityClass_1 = require("./EntityClass");
18
- const SchemaItem_1 = require("./SchemaItem");
19
- /**
20
- * A Typescript class representation of a ECRelationshipClass.
21
- * @beta
22
- */
23
- class RelationshipClass extends Class_1.ECClass {
24
- constructor(schema, name, modifier) {
25
- super(schema, name, modifier);
26
- this.schemaItemType = ECObjects_1.SchemaItemType.RelationshipClass;
27
- this._strengthDirection = ECObjects_1.StrengthDirection.Forward;
28
- this._strength = ECObjects_1.StrengthType.Referencing;
29
- this._source = new RelationshipConstraint(this, ECObjects_1.RelationshipEnd.Source);
30
- this._target = new RelationshipConstraint(this, ECObjects_1.RelationshipEnd.Target);
31
- }
32
- get strength() { return this._strength; }
33
- get strengthDirection() { return this._strengthDirection; }
34
- get source() { return this._source; }
35
- get target() { return this._target; }
36
- /**
37
- *
38
- * @param name
39
- * @param relationship
40
- * @param direction
41
- */
42
- async createNavigationProperty(name, relationship, direction) {
43
- return this.addProperty(await (0, EntityClass_1.createNavigationProperty)(this, name, relationship, direction));
44
- }
45
- createNavigationPropertySync(name, relationship, direction) {
46
- return this.addProperty((0, EntityClass_1.createNavigationPropertySync)(this, name, relationship, direction));
47
- }
48
- /**
49
- * @alpha Used for schema editing.
50
- */
51
- setStrength(strength) {
52
- this._strength = strength;
53
- }
54
- /**
55
- * @alpha Used for schema editing.
56
- */
57
- setStrengthDirection(direction) {
58
- this._strengthDirection = direction;
59
- }
60
- /**
61
- * Save this RelationshipClass's properties to an object for serializing to JSON.
62
- * @param standalone Serialization includes only this object (as opposed to the full schema).
63
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
64
- */
65
- toJSON(standalone = false, includeSchemaVersion = false) {
66
- const schemaJson = super.toJSON(standalone, includeSchemaVersion);
67
- schemaJson.strength = (0, ECObjects_1.strengthToString)(this.strength);
68
- schemaJson.strengthDirection = (0, ECObjects_1.strengthDirectionToString)(this.strengthDirection);
69
- schemaJson.source = this.source.toJSON();
70
- schemaJson.target = this.target.toJSON();
71
- return schemaJson;
72
- }
73
- /** @internal */
74
- async toXml(schemaXml) {
75
- const itemElement = await super.toXml(schemaXml);
76
- itemElement.setAttribute("strength", (0, ECObjects_1.strengthToString)(this.strength));
77
- itemElement.setAttribute("strengthDirection", (0, ECObjects_1.strengthDirectionToString)(this.strengthDirection));
78
- itemElement.appendChild(await this.source.toXml(schemaXml));
79
- itemElement.appendChild(await this.target.toXml(schemaXml));
80
- return itemElement;
81
- }
82
- fromJSONSync(relationshipClassProps) {
83
- super.fromJSONSync(relationshipClassProps);
84
- const strength = (0, ECObjects_1.parseStrength)(relationshipClassProps.strength);
85
- if (undefined === strength)
86
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrength, `The RelationshipClass ${this.fullName} has an invalid 'strength' attribute. '${relationshipClassProps.strength}' is not a valid StrengthType.`);
87
- const strengthDirection = (0, ECObjects_1.parseStrengthDirection)(relationshipClassProps.strengthDirection);
88
- if (undefined === strengthDirection)
89
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrength, `The RelationshipClass ${this.fullName} has an invalid 'strengthDirection' attribute. '${relationshipClassProps.strengthDirection}' is not a valid StrengthDirection.`);
90
- this._strength = strength;
91
- this._strengthDirection = strengthDirection;
92
- }
93
- async fromJSON(relationshipClassProps) {
94
- this.fromJSONSync(relationshipClassProps);
95
- }
96
- }
97
- exports.RelationshipClass = RelationshipClass;
98
- /**
99
- * A Typescript class representation of a ECRelationshipConstraint.
100
- * @beta
101
- */
102
- class RelationshipConstraint {
103
- constructor(relClass, relEnd, roleLabel, polymorphic) {
104
- this._relationshipEnd = relEnd;
105
- if (polymorphic)
106
- this._polymorphic = polymorphic;
107
- else
108
- this._polymorphic = false;
109
- this._multiplicity = RelationshipMultiplicity.zeroOne;
110
- this._relationshipClass = relClass;
111
- this._roleLabel = roleLabel;
112
- }
113
- get multiplicity() { return this._multiplicity; }
114
- get polymorphic() { return this._polymorphic; }
115
- get roleLabel() { return this._roleLabel; }
116
- get constraintClasses() { return this._constraintClasses; }
117
- get relationshipClass() { return this._relationshipClass; }
118
- get relationshipEnd() { return this._relationshipEnd; }
119
- get customAttributes() { return this._customAttributes; }
120
- /** Returns the constraint name, ie. 'RelationshipName.Source/Target' */
121
- get fullName() { return `${this._relationshipClass.name}:${this.isSource ? "Source" : "Target"}`; }
122
- /** Returns the schema of the RelationshipClass. */
123
- get schema() { return this._relationshipClass.schema; }
124
- get abstractConstraint() {
125
- if (this._abstractConstraint)
126
- return this._abstractConstraint;
127
- if (this.constraintClasses && this.constraintClasses.length === 1)
128
- return this.constraintClasses[0];
129
- return this._abstractConstraint;
130
- }
131
- set abstractConstraint(abstractConstraint) {
132
- this._abstractConstraint = abstractConstraint;
133
- }
134
- /**
135
- * True if this RelationshipConstraint is the Source relationship end.
136
- */
137
- get isSource() { return this.relationshipEnd === ECObjects_1.RelationshipEnd.Source; }
138
- /**
139
- * Adds the provided class as a constraint class to this constraint.
140
- * @param constraint The class to add as a constraint class.
141
- */
142
- addClass(constraint) {
143
- // TODO: Ensure we don't start mixing constraint class types
144
- // TODO: Check that this class is or subclasses abstract constraint?
145
- if (!this._constraintClasses)
146
- this._constraintClasses = [];
147
- // TODO: Handle relationship constraints
148
- this._constraintClasses.push(new DelayedPromise_1.DelayedPromiseWithProps(constraint.key, async () => constraint));
149
- }
150
- /**
151
- * Save this RelationshipConstraint's properties to an object for serializing to JSON.
152
- */
153
- toJSON() {
154
- const schemaJson = {};
155
- schemaJson.multiplicity = this.multiplicity.toString();
156
- schemaJson.roleLabel = this.roleLabel;
157
- schemaJson.polymorphic = this.polymorphic;
158
- if (undefined !== this._abstractConstraint)
159
- schemaJson.abstractConstraint = this._abstractConstraint.fullName;
160
- if (undefined !== this.constraintClasses && this.constraintClasses.length > 0)
161
- schemaJson.constraintClasses = this.constraintClasses.map((constraintClass) => constraintClass.fullName);
162
- const customAttributes = (0, CustomAttribute_1.serializeCustomAttributes)(this.customAttributes);
163
- if (undefined !== customAttributes)
164
- schemaJson.customAttributes = customAttributes;
165
- return schemaJson;
166
- }
167
- /** @internal */
168
- async toXml(schemaXml) {
169
- const elementName = this.isSource ? "Source" : "Target";
170
- const itemElement = schemaXml.createElement(elementName);
171
- if (undefined !== this.polymorphic)
172
- itemElement.setAttribute("polymorphic", this.polymorphic.toString());
173
- if (undefined !== this.roleLabel)
174
- itemElement.setAttribute("roleLabel", this.roleLabel);
175
- if (undefined !== this.multiplicity)
176
- itemElement.setAttribute("multiplicity", this.multiplicity.toString());
177
- const abstractConstraint = await this.abstractConstraint;
178
- if (undefined !== abstractConstraint) {
179
- const abstractConstraintName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, abstractConstraint.schema, abstractConstraint.name);
180
- itemElement.setAttribute("abstractConstraint", abstractConstraintName);
181
- }
182
- if (undefined !== this.constraintClasses) {
183
- for (const item of this.constraintClasses) {
184
- const constraintClass = await item;
185
- const classElement = schemaXml.createElement("Class");
186
- const constraintClassName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, constraintClass.schema, constraintClass.name);
187
- classElement.setAttribute("class", constraintClassName);
188
- itemElement.appendChild(classElement);
189
- }
190
- }
191
- if (this._customAttributes) {
192
- const caContainerElement = schemaXml.createElement("ECCustomAttributes");
193
- for (const [name, attribute] of this._customAttributes) {
194
- const caElement = await XmlSerializationUtils_1.XmlSerializationUtils.writeCustomAttribute(name, attribute, schemaXml, this.schema);
195
- caContainerElement.appendChild(caElement);
196
- }
197
- itemElement.appendChild(caContainerElement);
198
- }
199
- return itemElement;
200
- }
201
- fromJSONSync(relationshipConstraintProps) {
202
- this._roleLabel = relationshipConstraintProps.roleLabel;
203
- this._polymorphic = relationshipConstraintProps.polymorphic;
204
- const parsedMultiplicity = RelationshipMultiplicity.fromString(relationshipConstraintProps.multiplicity);
205
- if (!parsedMultiplicity)
206
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidMultiplicity, ``);
207
- this._multiplicity = parsedMultiplicity;
208
- const relClassSchema = this.relationshipClass.schema;
209
- if (undefined !== relationshipConstraintProps.abstractConstraint) {
210
- const abstractConstraintSchemaItemKey = relClassSchema.getSchemaItemKey(relationshipConstraintProps.abstractConstraint);
211
- if (!abstractConstraintSchemaItemKey)
212
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the abstractConstraint ${relationshipConstraintProps.abstractConstraint}.`);
213
- this.abstractConstraint = new DelayedPromise_1.DelayedPromiseWithProps(abstractConstraintSchemaItemKey, async () => {
214
- const tempAbstractConstraint = await relClassSchema.lookupItem(relationshipConstraintProps.abstractConstraint);
215
- if (undefined === tempAbstractConstraint)
216
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the abstractConstraint ${relationshipConstraintProps.abstractConstraint}.`);
217
- return tempAbstractConstraint;
218
- });
219
- }
220
- const loadEachConstraint = (constraintClassName) => {
221
- const tempConstraintClass = relClassSchema.lookupItemSync(constraintClassName);
222
- if (!tempConstraintClass)
223
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
224
- return tempConstraintClass;
225
- };
226
- for (const constraintClassName of relationshipConstraintProps.constraintClasses) {
227
- const constraintClass = loadEachConstraint(constraintClassName);
228
- this.addClass(constraintClass);
229
- }
230
- }
231
- async fromJSON(relationshipConstraintProps) {
232
- this.fromJSONSync(relationshipConstraintProps);
233
- }
234
- /**
235
- * Indicates if the provided [[ECClass]] is supported by this [[RelationshipConstraint]].
236
- * @param ecClass The class to check.
237
- */
238
- async supportsClass(ecClass) {
239
- if (!this.constraintClasses) {
240
- if (this.relationshipClass.baseClass) {
241
- const baseRelationship = await this.relationshipClass.baseClass;
242
- const baseConstraint = this.isSource ? baseRelationship.source : baseRelationship.target;
243
- return baseConstraint.supportsClass(ecClass);
244
- }
245
- return false;
246
- }
247
- if (ecClass.schemaItemType !== ECObjects_1.SchemaItemType.EntityClass && ecClass.schemaItemType !== ECObjects_1.SchemaItemType.RelationshipClass &&
248
- ecClass.schemaItemType !== ECObjects_1.SchemaItemType.Mixin) {
249
- return false;
250
- }
251
- const abstractConstraint = await this.abstractConstraint;
252
- if (abstractConstraint && await RelationshipConstraint.classCompatibleWithConstraint(abstractConstraint, ecClass, this.polymorphic || false))
253
- return true;
254
- for (const constraint of this.constraintClasses) {
255
- if (await RelationshipConstraint.classCompatibleWithConstraint(await constraint, ecClass, this.polymorphic || false))
256
- return true;
257
- }
258
- return false;
259
- }
260
- /**
261
- * Indicates if an ECClass is of the type or applies to the type (if a mixin) of the ECClass specified by the constraintClass parameter.
262
- * @param constraintClass The ECClass that is a constraint class of a relationship.
263
- * @param testClass The ECClass to check against the constraint class.
264
- * @param isPolymorphic Indicates if the testClass should be checked polymorphically.
265
- */
266
- static async classCompatibleWithConstraint(constraintClass, testClass, isPolymorphic) {
267
- if (SchemaItem_1.SchemaItem.equalByKey(constraintClass, testClass))
268
- return true;
269
- if (isPolymorphic) {
270
- if (testClass.schemaItemType === ECObjects_1.SchemaItemType.EntityClass || testClass.schemaItemType === ECObjects_1.SchemaItemType.RelationshipClass) {
271
- return testClass.is(constraintClass);
272
- }
273
- if (testClass.schemaItemType === ECObjects_1.SchemaItemType.Mixin) {
274
- if (constraintClass.schemaItemType === ECObjects_1.SchemaItemType.EntityClass)
275
- return testClass.applicableTo(constraintClass);
276
- else
277
- return testClass.is(constraintClass);
278
- }
279
- }
280
- return false;
281
- }
282
- /**
283
- * @internal
284
- */
285
- static isRelationshipConstraint(object) {
286
- const relationshipConstrait = object;
287
- return relationshipConstrait !== undefined && relationshipConstrait.polymorphic !== undefined && relationshipConstrait.multiplicity !== undefined
288
- && relationshipConstrait.relationshipEnd !== undefined && relationshipConstrait._relationshipClass !== undefined;
289
- }
290
- addCustomAttribute(customAttribute) {
291
- if (!this._customAttributes)
292
- this._customAttributes = new Map();
293
- this._customAttributes.set(customAttribute.className, customAttribute);
294
- }
295
- }
296
- exports.RelationshipConstraint = RelationshipConstraint;
297
- /**
298
- * Hackish approach that works like a "friend class" so we can access protected members without making them public.
299
- * @internal
300
- */
301
- class MutableRelationshipConstraint extends RelationshipConstraint {
302
- }
303
- exports.MutableRelationshipConstraint = MutableRelationshipConstraint;
304
- const INT32_MAX = 2147483647;
305
- /**
306
- * @beta
307
- */
308
- class RelationshipMultiplicity {
309
- constructor(lowerLimit, upperLimit) {
310
- this.lowerLimit = lowerLimit;
311
- this.upperLimit = upperLimit;
312
- }
313
- static fromString(str) {
314
- const matches = /^\(([0-9]*)\.\.([0-9]*|\*)\)$/.exec(str);
315
- if (matches === null || matches.length !== 3)
316
- return undefined;
317
- const lowerLimit = parseInt(matches[1], 10);
318
- const upperLimit = matches[2] === "*" ? INT32_MAX : parseInt(matches[2], 10);
319
- if (0 === lowerLimit && 1 === upperLimit)
320
- return RelationshipMultiplicity.zeroOne;
321
- else if (0 === lowerLimit && INT32_MAX === upperLimit)
322
- return RelationshipMultiplicity.zeroMany;
323
- else if (1 === lowerLimit && 1 === upperLimit)
324
- return RelationshipMultiplicity.oneOne;
325
- else if (1 === lowerLimit && INT32_MAX === upperLimit)
326
- return RelationshipMultiplicity.oneMany;
327
- return new RelationshipMultiplicity(lowerLimit, upperLimit);
328
- }
329
- equals(rhs) {
330
- return this.lowerLimit === rhs.lowerLimit && this.upperLimit === rhs.upperLimit;
331
- }
332
- toString() {
333
- return `(${this.lowerLimit}..${this.upperLimit === INT32_MAX ? "*" : this.upperLimit})`;
334
- }
335
- }
336
- exports.RelationshipMultiplicity = RelationshipMultiplicity;
337
- RelationshipMultiplicity.zeroOne = new RelationshipMultiplicity(0, 1);
338
- RelationshipMultiplicity.zeroMany = new RelationshipMultiplicity(0, INT32_MAX);
339
- RelationshipMultiplicity.oneOne = new RelationshipMultiplicity(1, 1);
340
- RelationshipMultiplicity.oneMany = new RelationshipMultiplicity(1, INT32_MAX);
341
- /**
342
- * @internal
343
- * An abstract class used for schema editing.
344
- */
345
- class MutableRelationshipClass extends RelationshipClass {
346
- get source() { return this._source; }
347
- get target() { return this._target; }
348
- }
349
- exports.MutableRelationshipClass = MutableRelationshipClass;
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 Metadata
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.MutableRelationshipClass = exports.RelationshipMultiplicity = exports.MutableRelationshipConstraint = exports.RelationshipConstraint = exports.RelationshipClass = void 0;
11
+ const DelayedPromise_1 = require("../DelayedPromise");
12
+ const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
13
+ const ECObjects_1 = require("../ECObjects");
14
+ const Exception_1 = require("../Exception");
15
+ const Class_1 = require("./Class");
16
+ const CustomAttribute_1 = require("./CustomAttribute");
17
+ const EntityClass_1 = require("./EntityClass");
18
+ const SchemaItem_1 = require("./SchemaItem");
19
+ /**
20
+ * A Typescript class representation of a ECRelationshipClass.
21
+ * @beta
22
+ */
23
+ class RelationshipClass extends Class_1.ECClass {
24
+ constructor(schema, name, modifier) {
25
+ super(schema, name, modifier);
26
+ this.schemaItemType = ECObjects_1.SchemaItemType.RelationshipClass;
27
+ this._strengthDirection = ECObjects_1.StrengthDirection.Forward;
28
+ this._strength = ECObjects_1.StrengthType.Referencing;
29
+ this._source = new RelationshipConstraint(this, ECObjects_1.RelationshipEnd.Source);
30
+ this._target = new RelationshipConstraint(this, ECObjects_1.RelationshipEnd.Target);
31
+ }
32
+ get strength() { return this._strength; }
33
+ get strengthDirection() { return this._strengthDirection; }
34
+ get source() { return this._source; }
35
+ get target() { return this._target; }
36
+ /**
37
+ *
38
+ * @param name
39
+ * @param relationship
40
+ * @param direction
41
+ */
42
+ async createNavigationProperty(name, relationship, direction) {
43
+ return this.addProperty(await (0, EntityClass_1.createNavigationProperty)(this, name, relationship, direction));
44
+ }
45
+ createNavigationPropertySync(name, relationship, direction) {
46
+ return this.addProperty((0, EntityClass_1.createNavigationPropertySync)(this, name, relationship, direction));
47
+ }
48
+ /**
49
+ * @alpha Used for schema editing.
50
+ */
51
+ setStrength(strength) {
52
+ this._strength = strength;
53
+ }
54
+ /**
55
+ * @alpha Used for schema editing.
56
+ */
57
+ setStrengthDirection(direction) {
58
+ this._strengthDirection = direction;
59
+ }
60
+ /**
61
+ * Save this RelationshipClass's properties to an object for serializing to JSON.
62
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
63
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
64
+ */
65
+ toJSON(standalone = false, includeSchemaVersion = false) {
66
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
67
+ schemaJson.strength = (0, ECObjects_1.strengthToString)(this.strength);
68
+ schemaJson.strengthDirection = (0, ECObjects_1.strengthDirectionToString)(this.strengthDirection);
69
+ schemaJson.source = this.source.toJSON();
70
+ schemaJson.target = this.target.toJSON();
71
+ return schemaJson;
72
+ }
73
+ /** @internal */
74
+ async toXml(schemaXml) {
75
+ const itemElement = await super.toXml(schemaXml);
76
+ itemElement.setAttribute("strength", (0, ECObjects_1.strengthToString)(this.strength));
77
+ itemElement.setAttribute("strengthDirection", (0, ECObjects_1.strengthDirectionToString)(this.strengthDirection));
78
+ itemElement.appendChild(await this.source.toXml(schemaXml));
79
+ itemElement.appendChild(await this.target.toXml(schemaXml));
80
+ return itemElement;
81
+ }
82
+ fromJSONSync(relationshipClassProps) {
83
+ super.fromJSONSync(relationshipClassProps);
84
+ const strength = (0, ECObjects_1.parseStrength)(relationshipClassProps.strength);
85
+ if (undefined === strength)
86
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrength, `The RelationshipClass ${this.fullName} has an invalid 'strength' attribute. '${relationshipClassProps.strength}' is not a valid StrengthType.`);
87
+ const strengthDirection = (0, ECObjects_1.parseStrengthDirection)(relationshipClassProps.strengthDirection);
88
+ if (undefined === strengthDirection)
89
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrength, `The RelationshipClass ${this.fullName} has an invalid 'strengthDirection' attribute. '${relationshipClassProps.strengthDirection}' is not a valid StrengthDirection.`);
90
+ this._strength = strength;
91
+ this._strengthDirection = strengthDirection;
92
+ }
93
+ async fromJSON(relationshipClassProps) {
94
+ this.fromJSONSync(relationshipClassProps);
95
+ }
96
+ }
97
+ exports.RelationshipClass = RelationshipClass;
98
+ /**
99
+ * A Typescript class representation of a ECRelationshipConstraint.
100
+ * @beta
101
+ */
102
+ class RelationshipConstraint {
103
+ constructor(relClass, relEnd, roleLabel, polymorphic) {
104
+ this._relationshipEnd = relEnd;
105
+ if (polymorphic)
106
+ this._polymorphic = polymorphic;
107
+ else
108
+ this._polymorphic = false;
109
+ this._multiplicity = RelationshipMultiplicity.zeroOne;
110
+ this._relationshipClass = relClass;
111
+ this._roleLabel = roleLabel;
112
+ }
113
+ get multiplicity() { return this._multiplicity; }
114
+ get polymorphic() { return this._polymorphic; }
115
+ get roleLabel() { return this._roleLabel; }
116
+ get constraintClasses() { return this._constraintClasses; }
117
+ get relationshipClass() { return this._relationshipClass; }
118
+ get relationshipEnd() { return this._relationshipEnd; }
119
+ get customAttributes() { return this._customAttributes; }
120
+ /** Returns the constraint name, ie. 'RelationshipName.Source/Target' */
121
+ get fullName() { return `${this._relationshipClass.name}:${this.isSource ? "Source" : "Target"}`; }
122
+ /** Returns the schema of the RelationshipClass. */
123
+ get schema() { return this._relationshipClass.schema; }
124
+ get abstractConstraint() {
125
+ if (this._abstractConstraint)
126
+ return this._abstractConstraint;
127
+ if (this.constraintClasses && this.constraintClasses.length === 1)
128
+ return this.constraintClasses[0];
129
+ return this._abstractConstraint;
130
+ }
131
+ set abstractConstraint(abstractConstraint) {
132
+ this._abstractConstraint = abstractConstraint;
133
+ }
134
+ /**
135
+ * True if this RelationshipConstraint is the Source relationship end.
136
+ */
137
+ get isSource() { return this.relationshipEnd === ECObjects_1.RelationshipEnd.Source; }
138
+ /**
139
+ * Adds the provided class as a constraint class to this constraint.
140
+ * @param constraint The class to add as a constraint class.
141
+ */
142
+ addClass(constraint) {
143
+ // TODO: Ensure we don't start mixing constraint class types
144
+ // TODO: Check that this class is or subclasses abstract constraint?
145
+ if (!this._constraintClasses)
146
+ this._constraintClasses = [];
147
+ // TODO: Handle relationship constraints
148
+ this._constraintClasses.push(new DelayedPromise_1.DelayedPromiseWithProps(constraint.key, async () => constraint));
149
+ }
150
+ /**
151
+ * Save this RelationshipConstraint's properties to an object for serializing to JSON.
152
+ */
153
+ toJSON() {
154
+ const schemaJson = {};
155
+ schemaJson.multiplicity = this.multiplicity.toString();
156
+ schemaJson.roleLabel = this.roleLabel;
157
+ schemaJson.polymorphic = this.polymorphic;
158
+ if (undefined !== this._abstractConstraint)
159
+ schemaJson.abstractConstraint = this._abstractConstraint.fullName;
160
+ if (undefined !== this.constraintClasses && this.constraintClasses.length > 0)
161
+ schemaJson.constraintClasses = this.constraintClasses.map((constraintClass) => constraintClass.fullName);
162
+ const customAttributes = (0, CustomAttribute_1.serializeCustomAttributes)(this.customAttributes);
163
+ if (undefined !== customAttributes)
164
+ schemaJson.customAttributes = customAttributes;
165
+ return schemaJson;
166
+ }
167
+ /** @internal */
168
+ async toXml(schemaXml) {
169
+ const elementName = this.isSource ? "Source" : "Target";
170
+ const itemElement = schemaXml.createElement(elementName);
171
+ if (undefined !== this.polymorphic)
172
+ itemElement.setAttribute("polymorphic", this.polymorphic.toString());
173
+ if (undefined !== this.roleLabel)
174
+ itemElement.setAttribute("roleLabel", this.roleLabel);
175
+ if (undefined !== this.multiplicity)
176
+ itemElement.setAttribute("multiplicity", this.multiplicity.toString());
177
+ const abstractConstraint = await this.abstractConstraint;
178
+ if (undefined !== abstractConstraint) {
179
+ const abstractConstraintName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, abstractConstraint.schema, abstractConstraint.name);
180
+ itemElement.setAttribute("abstractConstraint", abstractConstraintName);
181
+ }
182
+ if (undefined !== this.constraintClasses) {
183
+ for (const item of this.constraintClasses) {
184
+ const constraintClass = await item;
185
+ const classElement = schemaXml.createElement("Class");
186
+ const constraintClassName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, constraintClass.schema, constraintClass.name);
187
+ classElement.setAttribute("class", constraintClassName);
188
+ itemElement.appendChild(classElement);
189
+ }
190
+ }
191
+ if (this._customAttributes) {
192
+ const caContainerElement = schemaXml.createElement("ECCustomAttributes");
193
+ for (const [name, attribute] of this._customAttributes) {
194
+ const caElement = await XmlSerializationUtils_1.XmlSerializationUtils.writeCustomAttribute(name, attribute, schemaXml, this.schema);
195
+ caContainerElement.appendChild(caElement);
196
+ }
197
+ itemElement.appendChild(caContainerElement);
198
+ }
199
+ return itemElement;
200
+ }
201
+ fromJSONSync(relationshipConstraintProps) {
202
+ this._roleLabel = relationshipConstraintProps.roleLabel;
203
+ this._polymorphic = relationshipConstraintProps.polymorphic;
204
+ const parsedMultiplicity = RelationshipMultiplicity.fromString(relationshipConstraintProps.multiplicity);
205
+ if (!parsedMultiplicity)
206
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidMultiplicity, ``);
207
+ this._multiplicity = parsedMultiplicity;
208
+ const relClassSchema = this.relationshipClass.schema;
209
+ if (undefined !== relationshipConstraintProps.abstractConstraint) {
210
+ const abstractConstraintSchemaItemKey = relClassSchema.getSchemaItemKey(relationshipConstraintProps.abstractConstraint);
211
+ if (!abstractConstraintSchemaItemKey)
212
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the abstractConstraint ${relationshipConstraintProps.abstractConstraint}.`);
213
+ this.abstractConstraint = new DelayedPromise_1.DelayedPromiseWithProps(abstractConstraintSchemaItemKey, async () => {
214
+ const tempAbstractConstraint = await relClassSchema.lookupItem(relationshipConstraintProps.abstractConstraint);
215
+ if (undefined === tempAbstractConstraint)
216
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the abstractConstraint ${relationshipConstraintProps.abstractConstraint}.`);
217
+ return tempAbstractConstraint;
218
+ });
219
+ }
220
+ const loadEachConstraint = (constraintClassName) => {
221
+ const tempConstraintClass = relClassSchema.lookupItemSync(constraintClassName);
222
+ if (!tempConstraintClass)
223
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
224
+ return tempConstraintClass;
225
+ };
226
+ for (const constraintClassName of relationshipConstraintProps.constraintClasses) {
227
+ const constraintClass = loadEachConstraint(constraintClassName);
228
+ this.addClass(constraintClass);
229
+ }
230
+ }
231
+ async fromJSON(relationshipConstraintProps) {
232
+ this.fromJSONSync(relationshipConstraintProps);
233
+ }
234
+ /**
235
+ * Indicates if the provided [[ECClass]] is supported by this [[RelationshipConstraint]].
236
+ * @param ecClass The class to check.
237
+ */
238
+ async supportsClass(ecClass) {
239
+ if (!this.constraintClasses) {
240
+ if (this.relationshipClass.baseClass) {
241
+ const baseRelationship = await this.relationshipClass.baseClass;
242
+ const baseConstraint = this.isSource ? baseRelationship.source : baseRelationship.target;
243
+ return baseConstraint.supportsClass(ecClass);
244
+ }
245
+ return false;
246
+ }
247
+ if (ecClass.schemaItemType !== ECObjects_1.SchemaItemType.EntityClass && ecClass.schemaItemType !== ECObjects_1.SchemaItemType.RelationshipClass &&
248
+ ecClass.schemaItemType !== ECObjects_1.SchemaItemType.Mixin) {
249
+ return false;
250
+ }
251
+ const abstractConstraint = await this.abstractConstraint;
252
+ if (abstractConstraint && await RelationshipConstraint.classCompatibleWithConstraint(abstractConstraint, ecClass, this.polymorphic || false))
253
+ return true;
254
+ for (const constraint of this.constraintClasses) {
255
+ if (await RelationshipConstraint.classCompatibleWithConstraint(await constraint, ecClass, this.polymorphic || false))
256
+ return true;
257
+ }
258
+ return false;
259
+ }
260
+ /**
261
+ * Indicates if an ECClass is of the type or applies to the type (if a mixin) of the ECClass specified by the constraintClass parameter.
262
+ * @param constraintClass The ECClass that is a constraint class of a relationship.
263
+ * @param testClass The ECClass to check against the constraint class.
264
+ * @param isPolymorphic Indicates if the testClass should be checked polymorphically.
265
+ */
266
+ static async classCompatibleWithConstraint(constraintClass, testClass, isPolymorphic) {
267
+ if (SchemaItem_1.SchemaItem.equalByKey(constraintClass, testClass))
268
+ return true;
269
+ if (isPolymorphic) {
270
+ if (testClass.schemaItemType === ECObjects_1.SchemaItemType.EntityClass || testClass.schemaItemType === ECObjects_1.SchemaItemType.RelationshipClass) {
271
+ return testClass.is(constraintClass);
272
+ }
273
+ if (testClass.schemaItemType === ECObjects_1.SchemaItemType.Mixin) {
274
+ if (constraintClass.schemaItemType === ECObjects_1.SchemaItemType.EntityClass)
275
+ return testClass.applicableTo(constraintClass);
276
+ else
277
+ return testClass.is(constraintClass);
278
+ }
279
+ }
280
+ return false;
281
+ }
282
+ /**
283
+ * @internal
284
+ */
285
+ static isRelationshipConstraint(object) {
286
+ const relationshipConstrait = object;
287
+ return relationshipConstrait !== undefined && relationshipConstrait.polymorphic !== undefined && relationshipConstrait.multiplicity !== undefined
288
+ && relationshipConstrait.relationshipEnd !== undefined && relationshipConstrait._relationshipClass !== undefined;
289
+ }
290
+ addCustomAttribute(customAttribute) {
291
+ if (!this._customAttributes)
292
+ this._customAttributes = new Map();
293
+ this._customAttributes.set(customAttribute.className, customAttribute);
294
+ }
295
+ }
296
+ exports.RelationshipConstraint = RelationshipConstraint;
297
+ /**
298
+ * Hackish approach that works like a "friend class" so we can access protected members without making them public.
299
+ * @internal
300
+ */
301
+ class MutableRelationshipConstraint extends RelationshipConstraint {
302
+ }
303
+ exports.MutableRelationshipConstraint = MutableRelationshipConstraint;
304
+ const INT32_MAX = 2147483647;
305
+ /**
306
+ * @beta
307
+ */
308
+ class RelationshipMultiplicity {
309
+ constructor(lowerLimit, upperLimit) {
310
+ this.lowerLimit = lowerLimit;
311
+ this.upperLimit = upperLimit;
312
+ }
313
+ static fromString(str) {
314
+ const matches = /^\(([0-9]*)\.\.([0-9]*|\*)\)$/.exec(str);
315
+ if (matches === null || matches.length !== 3)
316
+ return undefined;
317
+ const lowerLimit = parseInt(matches[1], 10);
318
+ const upperLimit = matches[2] === "*" ? INT32_MAX : parseInt(matches[2], 10);
319
+ if (0 === lowerLimit && 1 === upperLimit)
320
+ return RelationshipMultiplicity.zeroOne;
321
+ else if (0 === lowerLimit && INT32_MAX === upperLimit)
322
+ return RelationshipMultiplicity.zeroMany;
323
+ else if (1 === lowerLimit && 1 === upperLimit)
324
+ return RelationshipMultiplicity.oneOne;
325
+ else if (1 === lowerLimit && INT32_MAX === upperLimit)
326
+ return RelationshipMultiplicity.oneMany;
327
+ return new RelationshipMultiplicity(lowerLimit, upperLimit);
328
+ }
329
+ equals(rhs) {
330
+ return this.lowerLimit === rhs.lowerLimit && this.upperLimit === rhs.upperLimit;
331
+ }
332
+ toString() {
333
+ return `(${this.lowerLimit}..${this.upperLimit === INT32_MAX ? "*" : this.upperLimit})`;
334
+ }
335
+ }
336
+ exports.RelationshipMultiplicity = RelationshipMultiplicity;
337
+ RelationshipMultiplicity.zeroOne = new RelationshipMultiplicity(0, 1);
338
+ RelationshipMultiplicity.zeroMany = new RelationshipMultiplicity(0, INT32_MAX);
339
+ RelationshipMultiplicity.oneOne = new RelationshipMultiplicity(1, 1);
340
+ RelationshipMultiplicity.oneMany = new RelationshipMultiplicity(1, INT32_MAX);
341
+ /**
342
+ * @internal
343
+ * An abstract class used for schema editing.
344
+ */
345
+ class MutableRelationshipClass extends RelationshipClass {
346
+ get source() { return this._source; }
347
+ get target() { return this._target; }
348
+ }
349
+ exports.MutableRelationshipClass = MutableRelationshipClass;
350
350
  //# sourceMappingURL=RelationshipClass.js.map