@itwin/ecschema-metadata 3.4.0-dev.9 → 3.5.0-dev.5

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 (153) hide show
  1. package/CHANGELOG.md +25 -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.d.ts.map +1 -1
  27. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  28. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  29. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  30. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  31. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  32. package/lib/cjs/ECName.d.ts +30 -30
  33. package/lib/cjs/ECName.js +85 -85
  34. package/lib/cjs/ECName.js.map +1 -1
  35. package/lib/cjs/ECObjects.d.ts +162 -162
  36. package/lib/cjs/ECObjects.js +453 -453
  37. package/lib/cjs/ECObjects.js.map +1 -1
  38. package/lib/cjs/Exception.d.ts +43 -43
  39. package/lib/cjs/Exception.js +86 -86
  40. package/lib/cjs/Exception.js.map +1 -1
  41. package/lib/cjs/Interfaces.d.ts +66 -66
  42. package/lib/cjs/Interfaces.js +9 -9
  43. package/lib/cjs/Interfaces.js.map +1 -1
  44. package/lib/cjs/Metadata/Class.d.ts +243 -243
  45. package/lib/cjs/Metadata/Class.js +558 -558
  46. package/lib/cjs/Metadata/Class.js.map +1 -1
  47. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  48. package/lib/cjs/Metadata/Constant.js +123 -123
  49. package/lib/cjs/Metadata/Constant.js.map +1 -1
  50. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  51. package/lib/cjs/Metadata/CustomAttribute.d.ts.map +1 -1
  52. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  53. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  54. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  55. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  56. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  57. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  58. package/lib/cjs/Metadata/EntityClass.js +230 -230
  59. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  60. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  61. package/lib/cjs/Metadata/Enumeration.js +159 -159
  62. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  63. package/lib/cjs/Metadata/Format.d.ts +98 -98
  64. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  65. package/lib/cjs/Metadata/Format.js +242 -242
  66. package/lib/cjs/Metadata/Format.js.map +1 -1
  67. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  68. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  69. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  70. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  71. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  72. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  73. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  74. package/lib/cjs/Metadata/Mixin.js +113 -113
  75. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  76. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  77. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  78. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  79. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  80. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  81. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  82. package/lib/cjs/Metadata/Property.d.ts +197 -197
  83. package/lib/cjs/Metadata/Property.js +491 -491
  84. package/lib/cjs/Metadata/Property.js.map +1 -1
  85. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  86. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  87. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  88. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  89. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  90. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  91. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  92. package/lib/cjs/Metadata/Schema.js +520 -520
  93. package/lib/cjs/Metadata/Schema.js.map +1 -1
  94. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  95. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  96. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  97. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  98. package/lib/cjs/Metadata/Unit.js +162 -162
  99. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  100. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  101. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  102. package/lib/cjs/PropertyTypes.d.ts +49 -49
  103. package/lib/cjs/PropertyTypes.d.ts.map +1 -1
  104. package/lib/cjs/PropertyTypes.js +91 -75
  105. package/lib/cjs/PropertyTypes.js.map +1 -1
  106. package/lib/cjs/SchemaJsonLocater.d.ts +35 -0
  107. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -0
  108. package/lib/cjs/SchemaJsonLocater.js +43 -0
  109. package/lib/cjs/SchemaJsonLocater.js.map +1 -0
  110. package/lib/cjs/SchemaKey.d.ts +110 -110
  111. package/lib/cjs/SchemaKey.d.ts.map +1 -1
  112. package/lib/cjs/SchemaKey.js +219 -220
  113. package/lib/cjs/SchemaKey.js.map +1 -1
  114. package/lib/cjs/SchemaLoader.d.ts +24 -0
  115. package/lib/cjs/SchemaLoader.d.ts.map +1 -0
  116. package/lib/cjs/SchemaLoader.js +48 -0
  117. package/lib/cjs/SchemaLoader.js.map +1 -0
  118. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  119. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  120. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  121. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  122. package/lib/cjs/UnitConversion/Graph.js +83 -83
  123. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  124. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  125. package/lib/cjs/UnitConversion/Parser.d.ts.map +1 -1
  126. package/lib/cjs/UnitConversion/Parser.js +42 -41
  127. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  128. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  129. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  130. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  131. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  132. package/lib/cjs/UnitConversion/UnitConverter.d.ts.map +1 -1
  133. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  134. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  135. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  136. package/lib/cjs/UnitConversion/UnitTree.d.ts.map +1 -1
  137. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  138. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  139. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  140. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +236 -236
  141. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  142. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  143. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  144. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  145. package/lib/cjs/ecschema-metadata.d.ts +51 -49
  146. package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
  147. package/lib/cjs/ecschema-metadata.js +96 -94
  148. package/lib/cjs/ecschema-metadata.js.map +1 -1
  149. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  150. package/lib/cjs/utils/SchemaGraph.d.ts.map +1 -1
  151. package/lib/cjs/utils/SchemaGraph.js +65 -65
  152. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  153. package/package.json +8 -8
@@ -1,492 +1,492 @@
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.MutableProperty = exports.StructArrayProperty = exports.EnumerationArrayProperty = exports.PrimitiveArrayProperty = exports.ArrayProperty = exports.NavigationProperty = exports.StructProperty = exports.EnumerationProperty = exports.PrimitiveProperty = exports.PrimitiveOrEnumPropertyBase = exports.Property = 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 PropertyTypes_1 = require("../PropertyTypes");
16
- const ECName_1 = require("../ECName");
17
- const CustomAttribute_1 = require("./CustomAttribute");
18
- /**
19
- * A common abstract class for all ECProperty types.
20
- * @beta
21
- */
22
- class Property {
23
- constructor(ecClass, name, type) {
24
- this._class = ecClass;
25
- this._name = new ECName_1.ECName(name);
26
- this._type = type;
27
- }
28
- isArray() { return PropertyTypes_1.PropertyTypeUtils.isArray(this._type); }
29
- isPrimitive() { return PropertyTypes_1.PropertyTypeUtils.isPrimitive(this._type); }
30
- isStruct() { return PropertyTypes_1.PropertyTypeUtils.isStruct(this._type); }
31
- isEnumeration() { return PropertyTypes_1.PropertyTypeUtils.isEnumeration(this._type); }
32
- isNavigation() { return PropertyTypes_1.PropertyTypeUtils.isNavigation(this._type); }
33
- get name() { return this._name.name; }
34
- get class() { return this._class; }
35
- get label() { return this._label; }
36
- get description() { return this._description; }
37
- get isReadOnly() { return this._isReadOnly || false; }
38
- get priority() { return this._priority || 0; }
39
- get category() { return this._category; }
40
- get kindOfQuantity() { return this._kindOfQuantity; }
41
- get propertyType() { return this._type; }
42
- get customAttributes() { return this._customAttributes; }
43
- /** Returns the name in the format 'ClassName.PropertyName'. */
44
- get fullName() { return `${this._class.name}.${this.name}`; }
45
- /** Returns the schema of the class holding the property. */
46
- get schema() { return this._class.schema; }
47
- getCategorySync() {
48
- if (!this._category)
49
- return undefined;
50
- return this.class.schema.lookupItemSync(this._category);
51
- }
52
- getKindOfQuantitySync() {
53
- if (!this._kindOfQuantity)
54
- return undefined;
55
- return this.class.schema.lookupItemSync(this._kindOfQuantity);
56
- }
57
- /**
58
- * Save this Property's properties to an object for serializing to JSON.
59
- */
60
- toJSON() {
61
- const schemaJson = {};
62
- schemaJson.name = this.name;
63
- schemaJson.type = (0, PropertyTypes_1.propertyTypeToString)(this._type);
64
- if (this.description !== undefined)
65
- schemaJson.description = this.description;
66
- if (this.label !== undefined)
67
- schemaJson.label = this.label;
68
- if (this._isReadOnly !== undefined)
69
- schemaJson.isReadOnly = this._isReadOnly;
70
- if (this.category !== undefined)
71
- schemaJson.category = this.category.fullName; // needs to be fully qualified name
72
- if (this._priority !== undefined)
73
- schemaJson.priority = this._priority;
74
- if (this.kindOfQuantity !== undefined)
75
- schemaJson.kindOfQuantity = this.kindOfQuantity.fullName;
76
- const customAttributes = (0, CustomAttribute_1.serializeCustomAttributes)(this.customAttributes);
77
- if (customAttributes !== undefined)
78
- schemaJson.customAttributes = customAttributes;
79
- return schemaJson;
80
- }
81
- /** @internal */
82
- async toXml(schemaXml) {
83
- const propType = `EC${(0, PropertyTypes_1.propertyTypeToString)(this._type)}`.replace("Primitive", "");
84
- const itemElement = schemaXml.createElement(propType);
85
- itemElement.setAttribute("propertyName", this.name);
86
- if (undefined !== this.description)
87
- itemElement.setAttribute("description", this.description);
88
- if (undefined !== this.label)
89
- itemElement.setAttribute("displayLabel", this.label);
90
- if (undefined !== this.isReadOnly)
91
- itemElement.setAttribute("readOnly", String(this.isReadOnly));
92
- if (undefined !== this.category) {
93
- const category = await this.category;
94
- const categoryName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, category.schema, category.name);
95
- itemElement.setAttribute("category", categoryName);
96
- }
97
- if (undefined !== this.priority)
98
- itemElement.setAttribute("priority", this.priority.toString());
99
- if (undefined !== this.kindOfQuantity) {
100
- const kindOfQuantity = await this.kindOfQuantity;
101
- const kindOfQuantityName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, kindOfQuantity.schema, kindOfQuantity.name);
102
- itemElement.setAttribute("kindOfQuantity", kindOfQuantityName);
103
- }
104
- if (this._customAttributes) {
105
- const caContainerElement = schemaXml.createElement("ECCustomAttributes");
106
- for (const [name, attribute] of this._customAttributes) {
107
- const caElement = await XmlSerializationUtils_1.XmlSerializationUtils.writeCustomAttribute(name, attribute, schemaXml, this.schema);
108
- caContainerElement.appendChild(caElement);
109
- }
110
- itemElement.appendChild(caContainerElement);
111
- }
112
- return itemElement;
113
- }
114
- fromJSONSync(propertyProps) {
115
- if (undefined !== propertyProps.label) {
116
- this._label = propertyProps.label;
117
- }
118
- if (undefined !== propertyProps.description) {
119
- this._description = propertyProps.description;
120
- }
121
- if (undefined !== propertyProps.priority) {
122
- this._priority = propertyProps.priority;
123
- }
124
- if (undefined !== propertyProps.isReadOnly) {
125
- this._isReadOnly = propertyProps.isReadOnly;
126
- }
127
- if (undefined !== propertyProps.category) {
128
- const propertyCategorySchemaItemKey = this.class.schema.getSchemaItemKey(propertyProps.category);
129
- if (!propertyCategorySchemaItemKey)
130
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'category' ("${propertyProps.category}") that cannot be found.`);
131
- this._category = new DelayedPromise_1.DelayedPromiseWithProps(propertyCategorySchemaItemKey, async () => {
132
- const category = await this.class.schema.lookupItem(propertyCategorySchemaItemKey);
133
- if (undefined === category)
134
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'category' ("${propertyProps.category}") that cannot be found.`);
135
- return category;
136
- });
137
- }
138
- if (undefined !== propertyProps.kindOfQuantity) {
139
- const koqSchemaItemKey = this.class.schema.getSchemaItemKey(propertyProps.kindOfQuantity);
140
- if (!koqSchemaItemKey)
141
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'kindOfQuantity' ("${propertyProps.kindOfQuantity}") that cannot be found.`);
142
- this._kindOfQuantity = new DelayedPromise_1.DelayedPromiseWithProps(koqSchemaItemKey, async () => {
143
- const koq = await this.class.schema.lookupItem(koqSchemaItemKey);
144
- if (undefined === koq)
145
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'kindOfQuantity' ("${propertyProps.kindOfQuantity}") that cannot be found.`);
146
- return koq;
147
- });
148
- }
149
- }
150
- async fromJSON(propertyProps) {
151
- this.fromJSONSync(propertyProps);
152
- }
153
- addCustomAttribute(customAttribute) {
154
- if (!this._customAttributes)
155
- this._customAttributes = new Map();
156
- this._customAttributes.set(customAttribute.className, customAttribute);
157
- }
158
- /**
159
- * Retrieve all custom attributes in the current property and its base
160
- * This is the async version of getCustomAttributesSync()
161
- */
162
- async getCustomAttributes() {
163
- return this.getCustomAttributesSync();
164
- }
165
- /**
166
- * Retrieve all custom attributes in the current property and its base.
167
- */
168
- getCustomAttributesSync() {
169
- let customAttributes = this._customAttributes;
170
- if (undefined === customAttributes) {
171
- customAttributes = new Map();
172
- }
173
- const baseProperty = this.class.getInheritedPropertySync(this.name);
174
- let baseCustomAttributes;
175
- if (undefined !== baseProperty)
176
- baseCustomAttributes = baseProperty.getCustomAttributesSync();
177
- if (undefined !== baseCustomAttributes) {
178
- customAttributes = new Map([...baseCustomAttributes, ...customAttributes]);
179
- }
180
- return customAttributes;
181
- }
182
- /**
183
- * @internal
184
- */
185
- static isProperty(object) {
186
- const property = object;
187
- return property !== undefined && property.class !== undefined && property.name !== undefined
188
- && property.propertyType !== undefined;
189
- }
190
- }
191
- exports.Property = Property;
192
- /** @beta */
193
- class PrimitiveOrEnumPropertyBase extends Property {
194
- constructor(ecClass, name, type) {
195
- super(ecClass, name, type);
196
- }
197
- get extendedTypeName() { return this._extendedTypeName; }
198
- get minLength() { return this._minLength; }
199
- get maxLength() { return this._maxLength; }
200
- get minValue() { return this._minValue; }
201
- get maxValue() { return this._maxValue; }
202
- /**
203
- * Save this PrimitiveOrEnumPropertyBase's properties to an object for serializing to JSON.
204
- */
205
- toJSON() {
206
- const schemaJson = super.toJSON();
207
- if (this.extendedTypeName !== undefined)
208
- schemaJson.extendedTypeName = this.extendedTypeName;
209
- if (this._minLength !== undefined)
210
- schemaJson.minLength = this.minLength;
211
- if (this._maxLength !== undefined)
212
- schemaJson.maxLength = this.maxLength;
213
- if (this._minValue !== undefined)
214
- schemaJson.minValue = this.minValue;
215
- if (this._maxValue !== undefined)
216
- schemaJson.maxValue = this.maxValue;
217
- return schemaJson;
218
- }
219
- /** @internal */
220
- async toXml(schemaXml) {
221
- const itemElement = await super.toXml(schemaXml);
222
- if (undefined !== this.extendedTypeName)
223
- itemElement.setAttribute("extendedTypeName", this.extendedTypeName);
224
- if (undefined !== this.minValue)
225
- itemElement.setAttribute("minimumValue", this.minValue.toString());
226
- if (undefined !== this.maxValue)
227
- itemElement.setAttribute("maximumValue", this.maxValue.toString());
228
- if (undefined !== this.minLength)
229
- itemElement.setAttribute("minimumLength", this.minLength.toString());
230
- if (undefined !== this.maxLength)
231
- itemElement.setAttribute("maximumLength", this.maxLength.toString());
232
- return itemElement;
233
- }
234
- fromJSONSync(propertyBaseProps) {
235
- super.fromJSONSync(propertyBaseProps);
236
- if (undefined !== propertyBaseProps.minLength) {
237
- this._minLength = propertyBaseProps.minLength;
238
- }
239
- if (undefined !== propertyBaseProps.maxLength) {
240
- this._maxLength = propertyBaseProps.maxLength;
241
- }
242
- if (undefined !== propertyBaseProps.minValue) {
243
- this._minValue = propertyBaseProps.minValue;
244
- }
245
- if (undefined !== propertyBaseProps.maxValue) {
246
- this._maxValue = propertyBaseProps.maxValue;
247
- }
248
- if (undefined !== propertyBaseProps.extendedTypeName) {
249
- this._extendedTypeName = propertyBaseProps.extendedTypeName;
250
- }
251
- }
252
- async fromJSON(propertyBaseProps) {
253
- this.fromJSONSync(propertyBaseProps);
254
- }
255
- }
256
- exports.PrimitiveOrEnumPropertyBase = PrimitiveOrEnumPropertyBase;
257
- /** @beta */
258
- class PrimitiveProperty extends PrimitiveOrEnumPropertyBase {
259
- get primitiveType() { return PropertyTypes_1.PropertyTypeUtils.getPrimitiveType(this._type); }
260
- constructor(ecClass, name, primitiveType = ECObjects_1.PrimitiveType.Integer) {
261
- super(ecClass, name, PropertyTypes_1.PropertyTypeUtils.fromPrimitiveType(primitiveType));
262
- }
263
- fromJSONSync(primitivePropertyProps) {
264
- super.fromJSONSync(primitivePropertyProps);
265
- if (undefined !== primitivePropertyProps.typeName) {
266
- if (this.primitiveType !== (0, ECObjects_1.parsePrimitiveType)(primitivePropertyProps.typeName))
267
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
268
- }
269
- }
270
- async fromJSON(primitivePropertyProps) {
271
- this.fromJSONSync(primitivePropertyProps);
272
- }
273
- /**
274
- * Save this PrimitiveProperty's properties to an object for serializing to JSON.
275
- */
276
- toJSON() {
277
- const schemaJson = super.toJSON();
278
- schemaJson.typeName = (0, ECObjects_1.primitiveTypeToString)(this.primitiveType);
279
- return schemaJson;
280
- }
281
- /** @internal */
282
- async toXml(schemaXml) {
283
- const itemElement = await super.toXml(schemaXml);
284
- itemElement.setAttribute("typeName", (0, ECObjects_1.primitiveTypeToString)(this.primitiveType));
285
- return itemElement;
286
- }
287
- }
288
- exports.PrimitiveProperty = PrimitiveProperty;
289
- /** @beta */
290
- class EnumerationProperty extends PrimitiveOrEnumPropertyBase {
291
- constructor(ecClass, name, type) {
292
- // TODO: Should we allow specifying the backing type?
293
- super(ecClass, name, PropertyTypes_1.PropertyType.Integer_Enumeration);
294
- this._enumeration = type;
295
- }
296
- get enumeration() { return this._enumeration; }
297
- /**
298
- * Save this EnumerationProperty's properties to an object for serializing to JSON.
299
- */
300
- toJSON() {
301
- const schemaJson = super.toJSON();
302
- schemaJson.typeName = this.enumeration.fullName;
303
- return schemaJson;
304
- }
305
- fromJSONSync(enumerationPropertyProps) {
306
- super.fromJSONSync(enumerationPropertyProps);
307
- if (undefined !== enumerationPropertyProps.typeName) {
308
- if (!(this.enumeration.fullName).match(enumerationPropertyProps.typeName)) // need to match {schema}.{version}.{itemName} on typeName
309
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
310
- const enumSchemaItemKey = this.class.schema.getSchemaItemKey(this.enumeration.fullName);
311
- if (!enumSchemaItemKey)
312
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${enumerationPropertyProps.typeName}.`);
313
- this._enumeration = new DelayedPromise_1.DelayedPromiseWithProps(enumSchemaItemKey, async () => {
314
- const enumeration = await this.class.schema.lookupItem(enumSchemaItemKey);
315
- if (undefined === enumeration)
316
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${enumerationPropertyProps.typeName}.`);
317
- return enumeration;
318
- });
319
- }
320
- }
321
- /** @internal */
322
- async toXml(schemaXml) {
323
- const itemElement = await super.toXml(schemaXml);
324
- const enumeration = await this.enumeration;
325
- const enumerationName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, enumeration.schema, enumeration.name);
326
- itemElement.setAttribute("typeName", enumerationName);
327
- return itemElement;
328
- }
329
- async fromJSON(enumerationPropertyProps) {
330
- this.fromJSONSync(enumerationPropertyProps);
331
- }
332
- }
333
- exports.EnumerationProperty = EnumerationProperty;
334
- /** @beta */
335
- class StructProperty extends Property {
336
- constructor(ecClass, name, type) {
337
- super(ecClass, name, PropertyTypes_1.PropertyType.Struct);
338
- this._structClass = type;
339
- }
340
- get structClass() { return this._structClass; }
341
- /**
342
- * Save this StructProperty's properties to an object for serializing to JSON.
343
- */
344
- toJSON() {
345
- const schemaJson = super.toJSON();
346
- schemaJson.typeName = this.structClass.fullName;
347
- return schemaJson;
348
- }
349
- /** @internal */
350
- async toXml(schemaXml) {
351
- const itemElement = await super.toXml(schemaXml);
352
- const structClassName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, this.structClass.schema, this.structClass.name);
353
- itemElement.setAttribute("typeName", structClassName);
354
- return itemElement;
355
- }
356
- fromJSONSync(structPropertyProps) {
357
- super.fromJSONSync(structPropertyProps);
358
- if (undefined !== structPropertyProps.typeName) {
359
- if (!this.structClass.key.matchesFullName(structPropertyProps.typeName))
360
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
361
- }
362
- }
363
- async fromJSON(structPropertyProps) {
364
- this.fromJSONSync(structPropertyProps);
365
- }
366
- }
367
- exports.StructProperty = StructProperty;
368
- /** @beta */
369
- class NavigationProperty extends Property {
370
- constructor(ecClass, name, relationship, direction) {
371
- super(ecClass, name, PropertyTypes_1.PropertyType.Navigation);
372
- this._relationshipClass = relationship;
373
- this._direction = (direction !== undefined) ? direction : ECObjects_1.StrengthDirection.Forward;
374
- }
375
- get relationshipClass() { return this._relationshipClass; }
376
- getRelationshipClassSync() {
377
- if (!this._relationshipClass) // eslint-disable-line @typescript-eslint/no-misused-promises
378
- return undefined;
379
- return this.class.schema.lookupItemSync(this._relationshipClass);
380
- }
381
- get direction() { return this._direction; }
382
- /**
383
- * Save this NavigationProperty's properties to an object for serializing to JSON.
384
- */
385
- toJSON() {
386
- const schemaJson = super.toJSON();
387
- schemaJson.relationshipName = this.relationshipClass.fullName;
388
- schemaJson.direction = (0, ECObjects_1.strengthDirectionToString)(this.direction);
389
- return schemaJson;
390
- }
391
- /** @internal */
392
- async toXml(schemaXml) {
393
- const itemElement = await super.toXml(schemaXml);
394
- const relationshipClass = await this.relationshipClass;
395
- const relationshipClassName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, relationshipClass.schema, relationshipClass.name);
396
- itemElement.setAttribute("relationshipName", relationshipClassName);
397
- itemElement.setAttribute("direction", (0, ECObjects_1.strengthDirectionToString)(this.direction));
398
- return itemElement;
399
- }
400
- }
401
- exports.NavigationProperty = NavigationProperty;
402
- // TODO: Consolidate all of the INT32_MAX variables.
403
- const INT32_MAX = 2147483647;
404
- /** @beta */
405
- class ArrayProperty extends Property {
406
- constructor() {
407
- super(...arguments);
408
- this._minOccurs = 0;
409
- this._maxOccurs = INT32_MAX;
410
- }
411
- get minOccurs() { return this._minOccurs; }
412
- get maxOccurs() { return this._maxOccurs; }
413
- }
414
- exports.ArrayProperty = ArrayProperty;
415
- // eslint-disable-next-line @typescript-eslint/naming-convention
416
- const ArrayPropertyMixin = (Base) => {
417
- return class extends Base {
418
- constructor(...args) {
419
- super(...args);
420
- this._minOccurs = 0;
421
- this._maxOccurs = INT32_MAX;
422
- this._type = PropertyTypes_1.PropertyTypeUtils.asArray(this._type);
423
- }
424
- get minOccurs() { return this._minOccurs; }
425
- get maxOccurs() { return this._maxOccurs; }
426
- fromJSONSync(arrayPropertyProps) {
427
- super.fromJSONSync(arrayPropertyProps);
428
- if (undefined !== arrayPropertyProps.minOccurs) {
429
- this._minOccurs = arrayPropertyProps.minOccurs;
430
- }
431
- if (undefined !== arrayPropertyProps.maxOccurs) {
432
- this._maxOccurs = arrayPropertyProps.maxOccurs;
433
- }
434
- }
435
- async fromJSON(arrayPropertyProps) {
436
- this.fromJSONSync(arrayPropertyProps);
437
- }
438
- /**
439
- * Save this ArrayProperty's properties to an object for serializing to JSON.
440
- */
441
- toJSON() {
442
- const schemaJson = super.toJSON();
443
- schemaJson.minOccurs = this.minOccurs;
444
- if (this.maxOccurs !== undefined)
445
- schemaJson.maxOccurs = this.maxOccurs;
446
- return schemaJson;
447
- }
448
- /** @internal */
449
- async toXml(schemaXml) {
450
- const itemElement = await super.toXml(schemaXml);
451
- itemElement.setAttribute("minOccurs", this.minOccurs.toString());
452
- if (this.maxOccurs)
453
- itemElement.setAttribute("maxOccurs", this.maxOccurs.toString());
454
- return itemElement;
455
- }
456
- };
457
- };
458
- /** @beta */
459
- class PrimitiveArrayProperty extends ArrayPropertyMixin(PrimitiveProperty) {
460
- constructor(ecClass, name, primitiveType = ECObjects_1.PrimitiveType.Integer) {
461
- super(ecClass, name, primitiveType);
462
- }
463
- /**
464
- * Save this PrimitiveArrayProperty's properties to an object for serializing to JSON.
465
- */
466
- toJSON() {
467
- return super.toJSON();
468
- }
469
- }
470
- exports.PrimitiveArrayProperty = PrimitiveArrayProperty;
471
- /** @beta */
472
- class EnumerationArrayProperty extends ArrayPropertyMixin(EnumerationProperty) {
473
- constructor(ecClass, name, type) {
474
- super(ecClass, name, type);
475
- }
476
- }
477
- exports.EnumerationArrayProperty = EnumerationArrayProperty;
478
- /** @beta */
479
- class StructArrayProperty extends ArrayPropertyMixin(StructProperty) {
480
- constructor(ecClass, name, type) {
481
- super(ecClass, name, type);
482
- }
483
- }
484
- exports.StructArrayProperty = StructArrayProperty;
485
- /**
486
- * Hackish approach that works like a "friend class" so we can access protected members without making them public.
487
- * @internal
488
- */
489
- class MutableProperty extends Property {
490
- }
491
- exports.MutableProperty = MutableProperty;
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.MutableProperty = exports.StructArrayProperty = exports.EnumerationArrayProperty = exports.PrimitiveArrayProperty = exports.ArrayProperty = exports.NavigationProperty = exports.StructProperty = exports.EnumerationProperty = exports.PrimitiveProperty = exports.PrimitiveOrEnumPropertyBase = exports.Property = 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 PropertyTypes_1 = require("../PropertyTypes");
16
+ const ECName_1 = require("../ECName");
17
+ const CustomAttribute_1 = require("./CustomAttribute");
18
+ /**
19
+ * A common abstract class for all ECProperty types.
20
+ * @beta
21
+ */
22
+ class Property {
23
+ constructor(ecClass, name, type) {
24
+ this._class = ecClass;
25
+ this._name = new ECName_1.ECName(name);
26
+ this._type = type;
27
+ }
28
+ isArray() { return PropertyTypes_1.PropertyTypeUtils.isArray(this._type); }
29
+ isPrimitive() { return PropertyTypes_1.PropertyTypeUtils.isPrimitive(this._type); }
30
+ isStruct() { return PropertyTypes_1.PropertyTypeUtils.isStruct(this._type); }
31
+ isEnumeration() { return PropertyTypes_1.PropertyTypeUtils.isEnumeration(this._type); }
32
+ isNavigation() { return PropertyTypes_1.PropertyTypeUtils.isNavigation(this._type); }
33
+ get name() { return this._name.name; }
34
+ get class() { return this._class; }
35
+ get label() { return this._label; }
36
+ get description() { return this._description; }
37
+ get isReadOnly() { return this._isReadOnly || false; }
38
+ get priority() { return this._priority || 0; }
39
+ get category() { return this._category; }
40
+ get kindOfQuantity() { return this._kindOfQuantity; }
41
+ get propertyType() { return this._type; }
42
+ get customAttributes() { return this._customAttributes; }
43
+ /** Returns the name in the format 'ClassName.PropertyName'. */
44
+ get fullName() { return `${this._class.name}.${this.name}`; }
45
+ /** Returns the schema of the class holding the property. */
46
+ get schema() { return this._class.schema; }
47
+ getCategorySync() {
48
+ if (!this._category)
49
+ return undefined;
50
+ return this.class.schema.lookupItemSync(this._category);
51
+ }
52
+ getKindOfQuantitySync() {
53
+ if (!this._kindOfQuantity)
54
+ return undefined;
55
+ return this.class.schema.lookupItemSync(this._kindOfQuantity);
56
+ }
57
+ /**
58
+ * Save this Property's properties to an object for serializing to JSON.
59
+ */
60
+ toJSON() {
61
+ const schemaJson = {};
62
+ schemaJson.name = this.name;
63
+ schemaJson.type = (0, PropertyTypes_1.propertyTypeToString)(this._type);
64
+ if (this.description !== undefined)
65
+ schemaJson.description = this.description;
66
+ if (this.label !== undefined)
67
+ schemaJson.label = this.label;
68
+ if (this._isReadOnly !== undefined)
69
+ schemaJson.isReadOnly = this._isReadOnly;
70
+ if (this.category !== undefined)
71
+ schemaJson.category = this.category.fullName; // needs to be fully qualified name
72
+ if (this._priority !== undefined)
73
+ schemaJson.priority = this._priority;
74
+ if (this.kindOfQuantity !== undefined)
75
+ schemaJson.kindOfQuantity = this.kindOfQuantity.fullName;
76
+ const customAttributes = (0, CustomAttribute_1.serializeCustomAttributes)(this.customAttributes);
77
+ if (customAttributes !== undefined)
78
+ schemaJson.customAttributes = customAttributes;
79
+ return schemaJson;
80
+ }
81
+ /** @internal */
82
+ async toXml(schemaXml) {
83
+ const propType = `EC${(0, PropertyTypes_1.propertyTypeToString)(this._type)}`.replace("Primitive", "");
84
+ const itemElement = schemaXml.createElement(propType);
85
+ itemElement.setAttribute("propertyName", this.name);
86
+ if (undefined !== this.description)
87
+ itemElement.setAttribute("description", this.description);
88
+ if (undefined !== this.label)
89
+ itemElement.setAttribute("displayLabel", this.label);
90
+ if (undefined !== this.isReadOnly)
91
+ itemElement.setAttribute("readOnly", String(this.isReadOnly));
92
+ if (undefined !== this.category) {
93
+ const category = await this.category;
94
+ const categoryName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, category.schema, category.name);
95
+ itemElement.setAttribute("category", categoryName);
96
+ }
97
+ if (undefined !== this.priority)
98
+ itemElement.setAttribute("priority", this.priority.toString());
99
+ if (undefined !== this.kindOfQuantity) {
100
+ const kindOfQuantity = await this.kindOfQuantity;
101
+ const kindOfQuantityName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, kindOfQuantity.schema, kindOfQuantity.name);
102
+ itemElement.setAttribute("kindOfQuantity", kindOfQuantityName);
103
+ }
104
+ if (this._customAttributes) {
105
+ const caContainerElement = schemaXml.createElement("ECCustomAttributes");
106
+ for (const [name, attribute] of this._customAttributes) {
107
+ const caElement = await XmlSerializationUtils_1.XmlSerializationUtils.writeCustomAttribute(name, attribute, schemaXml, this.schema);
108
+ caContainerElement.appendChild(caElement);
109
+ }
110
+ itemElement.appendChild(caContainerElement);
111
+ }
112
+ return itemElement;
113
+ }
114
+ fromJSONSync(propertyProps) {
115
+ if (undefined !== propertyProps.label) {
116
+ this._label = propertyProps.label;
117
+ }
118
+ if (undefined !== propertyProps.description) {
119
+ this._description = propertyProps.description;
120
+ }
121
+ if (undefined !== propertyProps.priority) {
122
+ this._priority = propertyProps.priority;
123
+ }
124
+ if (undefined !== propertyProps.isReadOnly) {
125
+ this._isReadOnly = propertyProps.isReadOnly;
126
+ }
127
+ if (undefined !== propertyProps.category) {
128
+ const propertyCategorySchemaItemKey = this.class.schema.getSchemaItemKey(propertyProps.category);
129
+ if (!propertyCategorySchemaItemKey)
130
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'category' ("${propertyProps.category}") that cannot be found.`);
131
+ this._category = new DelayedPromise_1.DelayedPromiseWithProps(propertyCategorySchemaItemKey, async () => {
132
+ const category = await this.class.schema.lookupItem(propertyCategorySchemaItemKey);
133
+ if (undefined === category)
134
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'category' ("${propertyProps.category}") that cannot be found.`);
135
+ return category;
136
+ });
137
+ }
138
+ if (undefined !== propertyProps.kindOfQuantity) {
139
+ const koqSchemaItemKey = this.class.schema.getSchemaItemKey(propertyProps.kindOfQuantity);
140
+ if (!koqSchemaItemKey)
141
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'kindOfQuantity' ("${propertyProps.kindOfQuantity}") that cannot be found.`);
142
+ this._kindOfQuantity = new DelayedPromise_1.DelayedPromiseWithProps(koqSchemaItemKey, async () => {
143
+ const koq = await this.class.schema.lookupItem(koqSchemaItemKey);
144
+ if (undefined === koq)
145
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Property ${this.name} has a 'kindOfQuantity' ("${propertyProps.kindOfQuantity}") that cannot be found.`);
146
+ return koq;
147
+ });
148
+ }
149
+ }
150
+ async fromJSON(propertyProps) {
151
+ this.fromJSONSync(propertyProps);
152
+ }
153
+ addCustomAttribute(customAttribute) {
154
+ if (!this._customAttributes)
155
+ this._customAttributes = new Map();
156
+ this._customAttributes.set(customAttribute.className, customAttribute);
157
+ }
158
+ /**
159
+ * Retrieve all custom attributes in the current property and its base
160
+ * This is the async version of getCustomAttributesSync()
161
+ */
162
+ async getCustomAttributes() {
163
+ return this.getCustomAttributesSync();
164
+ }
165
+ /**
166
+ * Retrieve all custom attributes in the current property and its base.
167
+ */
168
+ getCustomAttributesSync() {
169
+ let customAttributes = this._customAttributes;
170
+ if (undefined === customAttributes) {
171
+ customAttributes = new Map();
172
+ }
173
+ const baseProperty = this.class.getInheritedPropertySync(this.name);
174
+ let baseCustomAttributes;
175
+ if (undefined !== baseProperty)
176
+ baseCustomAttributes = baseProperty.getCustomAttributesSync();
177
+ if (undefined !== baseCustomAttributes) {
178
+ customAttributes = new Map([...baseCustomAttributes, ...customAttributes]);
179
+ }
180
+ return customAttributes;
181
+ }
182
+ /**
183
+ * @internal
184
+ */
185
+ static isProperty(object) {
186
+ const property = object;
187
+ return property !== undefined && property.class !== undefined && property.name !== undefined
188
+ && property.propertyType !== undefined;
189
+ }
190
+ }
191
+ exports.Property = Property;
192
+ /** @beta */
193
+ class PrimitiveOrEnumPropertyBase extends Property {
194
+ constructor(ecClass, name, type) {
195
+ super(ecClass, name, type);
196
+ }
197
+ get extendedTypeName() { return this._extendedTypeName; }
198
+ get minLength() { return this._minLength; }
199
+ get maxLength() { return this._maxLength; }
200
+ get minValue() { return this._minValue; }
201
+ get maxValue() { return this._maxValue; }
202
+ /**
203
+ * Save this PrimitiveOrEnumPropertyBase's properties to an object for serializing to JSON.
204
+ */
205
+ toJSON() {
206
+ const schemaJson = super.toJSON();
207
+ if (this.extendedTypeName !== undefined)
208
+ schemaJson.extendedTypeName = this.extendedTypeName;
209
+ if (this._minLength !== undefined)
210
+ schemaJson.minLength = this.minLength;
211
+ if (this._maxLength !== undefined)
212
+ schemaJson.maxLength = this.maxLength;
213
+ if (this._minValue !== undefined)
214
+ schemaJson.minValue = this.minValue;
215
+ if (this._maxValue !== undefined)
216
+ schemaJson.maxValue = this.maxValue;
217
+ return schemaJson;
218
+ }
219
+ /** @internal */
220
+ async toXml(schemaXml) {
221
+ const itemElement = await super.toXml(schemaXml);
222
+ if (undefined !== this.extendedTypeName)
223
+ itemElement.setAttribute("extendedTypeName", this.extendedTypeName);
224
+ if (undefined !== this.minValue)
225
+ itemElement.setAttribute("minimumValue", this.minValue.toString());
226
+ if (undefined !== this.maxValue)
227
+ itemElement.setAttribute("maximumValue", this.maxValue.toString());
228
+ if (undefined !== this.minLength)
229
+ itemElement.setAttribute("minimumLength", this.minLength.toString());
230
+ if (undefined !== this.maxLength)
231
+ itemElement.setAttribute("maximumLength", this.maxLength.toString());
232
+ return itemElement;
233
+ }
234
+ fromJSONSync(propertyBaseProps) {
235
+ super.fromJSONSync(propertyBaseProps);
236
+ if (undefined !== propertyBaseProps.minLength) {
237
+ this._minLength = propertyBaseProps.minLength;
238
+ }
239
+ if (undefined !== propertyBaseProps.maxLength) {
240
+ this._maxLength = propertyBaseProps.maxLength;
241
+ }
242
+ if (undefined !== propertyBaseProps.minValue) {
243
+ this._minValue = propertyBaseProps.minValue;
244
+ }
245
+ if (undefined !== propertyBaseProps.maxValue) {
246
+ this._maxValue = propertyBaseProps.maxValue;
247
+ }
248
+ if (undefined !== propertyBaseProps.extendedTypeName) {
249
+ this._extendedTypeName = propertyBaseProps.extendedTypeName;
250
+ }
251
+ }
252
+ async fromJSON(propertyBaseProps) {
253
+ this.fromJSONSync(propertyBaseProps);
254
+ }
255
+ }
256
+ exports.PrimitiveOrEnumPropertyBase = PrimitiveOrEnumPropertyBase;
257
+ /** @beta */
258
+ class PrimitiveProperty extends PrimitiveOrEnumPropertyBase {
259
+ get primitiveType() { return PropertyTypes_1.PropertyTypeUtils.getPrimitiveType(this._type); }
260
+ constructor(ecClass, name, primitiveType = ECObjects_1.PrimitiveType.Integer) {
261
+ super(ecClass, name, PropertyTypes_1.PropertyTypeUtils.fromPrimitiveType(primitiveType));
262
+ }
263
+ fromJSONSync(primitivePropertyProps) {
264
+ super.fromJSONSync(primitivePropertyProps);
265
+ if (undefined !== primitivePropertyProps.typeName) {
266
+ if (this.primitiveType !== (0, ECObjects_1.parsePrimitiveType)(primitivePropertyProps.typeName))
267
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
268
+ }
269
+ }
270
+ async fromJSON(primitivePropertyProps) {
271
+ this.fromJSONSync(primitivePropertyProps);
272
+ }
273
+ /**
274
+ * Save this PrimitiveProperty's properties to an object for serializing to JSON.
275
+ */
276
+ toJSON() {
277
+ const schemaJson = super.toJSON();
278
+ schemaJson.typeName = (0, ECObjects_1.primitiveTypeToString)(this.primitiveType);
279
+ return schemaJson;
280
+ }
281
+ /** @internal */
282
+ async toXml(schemaXml) {
283
+ const itemElement = await super.toXml(schemaXml);
284
+ itemElement.setAttribute("typeName", (0, ECObjects_1.primitiveTypeToString)(this.primitiveType));
285
+ return itemElement;
286
+ }
287
+ }
288
+ exports.PrimitiveProperty = PrimitiveProperty;
289
+ /** @beta */
290
+ class EnumerationProperty extends PrimitiveOrEnumPropertyBase {
291
+ constructor(ecClass, name, type) {
292
+ // TODO: Should we allow specifying the backing type?
293
+ super(ecClass, name, PropertyTypes_1.PropertyType.Integer_Enumeration);
294
+ this._enumeration = type;
295
+ }
296
+ get enumeration() { return this._enumeration; }
297
+ /**
298
+ * Save this EnumerationProperty's properties to an object for serializing to JSON.
299
+ */
300
+ toJSON() {
301
+ const schemaJson = super.toJSON();
302
+ schemaJson.typeName = this.enumeration.fullName;
303
+ return schemaJson;
304
+ }
305
+ fromJSONSync(enumerationPropertyProps) {
306
+ super.fromJSONSync(enumerationPropertyProps);
307
+ if (undefined !== enumerationPropertyProps.typeName) {
308
+ if (!(this.enumeration.fullName).match(enumerationPropertyProps.typeName)) // need to match {schema}.{version}.{itemName} on typeName
309
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
310
+ const enumSchemaItemKey = this.class.schema.getSchemaItemKey(this.enumeration.fullName);
311
+ if (!enumSchemaItemKey)
312
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${enumerationPropertyProps.typeName}.`);
313
+ this._enumeration = new DelayedPromise_1.DelayedPromiseWithProps(enumSchemaItemKey, async () => {
314
+ const enumeration = await this.class.schema.lookupItem(enumSchemaItemKey);
315
+ if (undefined === enumeration)
316
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${enumerationPropertyProps.typeName}.`);
317
+ return enumeration;
318
+ });
319
+ }
320
+ }
321
+ /** @internal */
322
+ async toXml(schemaXml) {
323
+ const itemElement = await super.toXml(schemaXml);
324
+ const enumeration = await this.enumeration;
325
+ const enumerationName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, enumeration.schema, enumeration.name);
326
+ itemElement.setAttribute("typeName", enumerationName);
327
+ return itemElement;
328
+ }
329
+ async fromJSON(enumerationPropertyProps) {
330
+ this.fromJSONSync(enumerationPropertyProps);
331
+ }
332
+ }
333
+ exports.EnumerationProperty = EnumerationProperty;
334
+ /** @beta */
335
+ class StructProperty extends Property {
336
+ constructor(ecClass, name, type) {
337
+ super(ecClass, name, PropertyTypes_1.PropertyType.Struct);
338
+ this._structClass = type;
339
+ }
340
+ get structClass() { return this._structClass; }
341
+ /**
342
+ * Save this StructProperty's properties to an object for serializing to JSON.
343
+ */
344
+ toJSON() {
345
+ const schemaJson = super.toJSON();
346
+ schemaJson.typeName = this.structClass.fullName;
347
+ return schemaJson;
348
+ }
349
+ /** @internal */
350
+ async toXml(schemaXml) {
351
+ const itemElement = await super.toXml(schemaXml);
352
+ const structClassName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, this.structClass.schema, this.structClass.name);
353
+ itemElement.setAttribute("typeName", structClassName);
354
+ return itemElement;
355
+ }
356
+ fromJSONSync(structPropertyProps) {
357
+ super.fromJSONSync(structPropertyProps);
358
+ if (undefined !== structPropertyProps.typeName) {
359
+ if (!this.structClass.key.matchesFullName(structPropertyProps.typeName))
360
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
361
+ }
362
+ }
363
+ async fromJSON(structPropertyProps) {
364
+ this.fromJSONSync(structPropertyProps);
365
+ }
366
+ }
367
+ exports.StructProperty = StructProperty;
368
+ /** @beta */
369
+ class NavigationProperty extends Property {
370
+ constructor(ecClass, name, relationship, direction) {
371
+ super(ecClass, name, PropertyTypes_1.PropertyType.Navigation);
372
+ this._relationshipClass = relationship;
373
+ this._direction = (direction !== undefined) ? direction : ECObjects_1.StrengthDirection.Forward;
374
+ }
375
+ get relationshipClass() { return this._relationshipClass; }
376
+ getRelationshipClassSync() {
377
+ if (!this._relationshipClass) // eslint-disable-line @typescript-eslint/no-misused-promises
378
+ return undefined;
379
+ return this.class.schema.lookupItemSync(this._relationshipClass);
380
+ }
381
+ get direction() { return this._direction; }
382
+ /**
383
+ * Save this NavigationProperty's properties to an object for serializing to JSON.
384
+ */
385
+ toJSON() {
386
+ const schemaJson = super.toJSON();
387
+ schemaJson.relationshipName = this.relationshipClass.fullName;
388
+ schemaJson.direction = (0, ECObjects_1.strengthDirectionToString)(this.direction);
389
+ return schemaJson;
390
+ }
391
+ /** @internal */
392
+ async toXml(schemaXml) {
393
+ const itemElement = await super.toXml(schemaXml);
394
+ const relationshipClass = await this.relationshipClass;
395
+ const relationshipClassName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, relationshipClass.schema, relationshipClass.name);
396
+ itemElement.setAttribute("relationshipName", relationshipClassName);
397
+ itemElement.setAttribute("direction", (0, ECObjects_1.strengthDirectionToString)(this.direction));
398
+ return itemElement;
399
+ }
400
+ }
401
+ exports.NavigationProperty = NavigationProperty;
402
+ // TODO: Consolidate all of the INT32_MAX variables.
403
+ const INT32_MAX = 2147483647;
404
+ /** @beta */
405
+ class ArrayProperty extends Property {
406
+ constructor() {
407
+ super(...arguments);
408
+ this._minOccurs = 0;
409
+ this._maxOccurs = INT32_MAX;
410
+ }
411
+ get minOccurs() { return this._minOccurs; }
412
+ get maxOccurs() { return this._maxOccurs; }
413
+ }
414
+ exports.ArrayProperty = ArrayProperty;
415
+ // eslint-disable-next-line @typescript-eslint/naming-convention
416
+ const ArrayPropertyMixin = (Base) => {
417
+ return class extends Base {
418
+ constructor(...args) {
419
+ super(...args);
420
+ this._minOccurs = 0;
421
+ this._maxOccurs = INT32_MAX;
422
+ this._type = PropertyTypes_1.PropertyTypeUtils.asArray(this._type);
423
+ }
424
+ get minOccurs() { return this._minOccurs; }
425
+ get maxOccurs() { return this._maxOccurs; }
426
+ fromJSONSync(arrayPropertyProps) {
427
+ super.fromJSONSync(arrayPropertyProps);
428
+ if (undefined !== arrayPropertyProps.minOccurs) {
429
+ this._minOccurs = arrayPropertyProps.minOccurs;
430
+ }
431
+ if (undefined !== arrayPropertyProps.maxOccurs) {
432
+ this._maxOccurs = arrayPropertyProps.maxOccurs;
433
+ }
434
+ }
435
+ async fromJSON(arrayPropertyProps) {
436
+ this.fromJSONSync(arrayPropertyProps);
437
+ }
438
+ /**
439
+ * Save this ArrayProperty's properties to an object for serializing to JSON.
440
+ */
441
+ toJSON() {
442
+ const schemaJson = super.toJSON();
443
+ schemaJson.minOccurs = this.minOccurs;
444
+ if (this.maxOccurs !== undefined)
445
+ schemaJson.maxOccurs = this.maxOccurs;
446
+ return schemaJson;
447
+ }
448
+ /** @internal */
449
+ async toXml(schemaXml) {
450
+ const itemElement = await super.toXml(schemaXml);
451
+ itemElement.setAttribute("minOccurs", this.minOccurs.toString());
452
+ if (this.maxOccurs)
453
+ itemElement.setAttribute("maxOccurs", this.maxOccurs.toString());
454
+ return itemElement;
455
+ }
456
+ };
457
+ };
458
+ /** @beta */
459
+ class PrimitiveArrayProperty extends ArrayPropertyMixin(PrimitiveProperty) {
460
+ constructor(ecClass, name, primitiveType = ECObjects_1.PrimitiveType.Integer) {
461
+ super(ecClass, name, primitiveType);
462
+ }
463
+ /**
464
+ * Save this PrimitiveArrayProperty's properties to an object for serializing to JSON.
465
+ */
466
+ toJSON() {
467
+ return super.toJSON();
468
+ }
469
+ }
470
+ exports.PrimitiveArrayProperty = PrimitiveArrayProperty;
471
+ /** @beta */
472
+ class EnumerationArrayProperty extends ArrayPropertyMixin(EnumerationProperty) {
473
+ constructor(ecClass, name, type) {
474
+ super(ecClass, name, type);
475
+ }
476
+ }
477
+ exports.EnumerationArrayProperty = EnumerationArrayProperty;
478
+ /** @beta */
479
+ class StructArrayProperty extends ArrayPropertyMixin(StructProperty) {
480
+ constructor(ecClass, name, type) {
481
+ super(ecClass, name, type);
482
+ }
483
+ }
484
+ exports.StructArrayProperty = StructArrayProperty;
485
+ /**
486
+ * Hackish approach that works like a "friend class" so we can access protected members without making them public.
487
+ * @internal
488
+ */
489
+ class MutableProperty extends Property {
490
+ }
491
+ exports.MutableProperty = MutableProperty;
492
492
  //# sourceMappingURL=Property.js.map