@itwin/ecschema-metadata 3.6.0-dev.35 → 3.6.0-dev.36

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/LICENSE.md +1 -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 +7 -7
@@ -1,226 +1,226 @@
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.MutableKindOfQuantity = exports.KindOfQuantity = 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 core_quantity_1 = require("@itwin/core-quantity");
16
- const OverrideFormat_1 = require("./OverrideFormat");
17
- const SchemaItem_1 = require("./SchemaItem");
18
- /** A Typescript class representation of a KindOfQuantity.
19
- * @beta
20
- */
21
- class KindOfQuantity extends SchemaItem_1.SchemaItem {
22
- constructor(schema, name) {
23
- super(schema, name);
24
- this._relativeError = 1.0;
25
- this._presentationFormats = new Array();
26
- this.schemaItemType = ECObjects_1.SchemaItemType.KindOfQuantity; // Needed to allow both run-time and compile-time check.
27
- }
28
- /** The first presentation format in the list of Formats. */
29
- get defaultPresentationFormat() { return this.presentationFormats[0]; }
30
- /** A list of presentation formats. */
31
- get presentationFormats() { return this._presentationFormats; }
32
- get persistenceUnit() { return this._persistenceUnit; }
33
- get relativeError() { return this._relativeError; }
34
- /**
35
- *
36
- * @param format The Format to add to this KindOfQuantity
37
- * @param isDefault
38
- */
39
- addPresentationFormat(format, isDefault = false) {
40
- // TODO: Add some sort of validation?
41
- (isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);
42
- }
43
- /** Parses the format string into the parts that make up an Override Format
44
- * @param formatString
45
- */
46
- parseFormatString(formatString) {
47
- const match = formatString.split(core_quantity_1.formatStringRgx); // split string based on regex groups
48
- if (undefined === match[1])
49
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The format string, ${formatString}, on KindOfQuantity '${this.fullName}' is missing a format.`);
50
- const returnValue = { name: match[1] };
51
- if (undefined !== match[2] && undefined !== match[3]) {
52
- const overrideString = match[2];
53
- const tokens = [];
54
- let prevPos = 1; // Initial position is the character directly after the opening '(' in the override string.
55
- let currPos;
56
- // TODO need to include `,` as a valid search argument.
57
- while (-1 !== (currPos = overrideString.indexOf(")", prevPos))) { // eslint-disable-line
58
- tokens.push(overrideString.substr(prevPos, currPos - prevPos));
59
- prevPos = currPos + 1;
60
- }
61
- if (overrideString.length > 0 && undefined === tokens.find((token) => {
62
- return "" !== token; // there is at least one token that is not empty.
63
- })) {
64
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
65
- }
66
- // The first override parameter overrides the default precision of the format
67
- const precisionIndx = 0;
68
- if (tokens.length >= precisionIndx + 1) {
69
- if (tokens[precisionIndx].length > 0) {
70
- const precision = Number.parseInt(tokens[precisionIndx], 10);
71
- if (Number.isNaN(precision))
72
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The format string '${formatString}' on KindOfQuantity '${this.fullName}' has a precision override '${tokens[precisionIndx]}' that is not number.`);
73
- returnValue.precision = precision;
74
- }
75
- }
76
- }
77
- let i = 4;
78
- while (i < match.length) {
79
- if (undefined === match[i])
80
- break;
81
- // Unit override required
82
- if (undefined === match[i + 1])
83
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
84
- if (undefined === returnValue.unitAndLabels)
85
- returnValue.unitAndLabels = [];
86
- if (undefined !== match[i + 2]) // matches '|'
87
- returnValue.unitAndLabels.push([match[i + 1], match[i + 3]]); // add unit name and label override
88
- else
89
- returnValue.unitAndLabels.push([match[i + 1], undefined]); // add unit name
90
- i += 4;
91
- }
92
- return returnValue;
93
- }
94
- /** Creates an OverrideFormat in the context of this KindOfQuantity.
95
- * @param parent The Format to override.
96
- * @param precision The precision override
97
- * @param unitLabelOverrides The list of unit and label overrides.
98
- */
99
- createFormatOverride(parent, precision, unitLabelOverrides) {
100
- if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)
101
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Cannot add presentation format to KindOfQuantity '${this.name}' because the number of unit overrides is inconsistent with the number in the Format '${parent.name}'.`);
102
- if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)
103
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);
104
- // TODO: Check compatibility of Unit overrides with the persistence unit
105
- return new OverrideFormat_1.OverrideFormat(parent, precision, unitLabelOverrides);
106
- }
107
- async processPresentationUnits(presentationUnitsJson) {
108
- const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
109
- for (const formatString of presUnitsArr) {
110
- const presFormatOverride = this.parseFormatString(formatString);
111
- const format = await this.schema.lookupItem(presFormatOverride.name);
112
- if (undefined === format || format.schemaItemType !== ECObjects_1.SchemaItemType.Format)
113
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
114
- if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
115
- this.addPresentationFormat(format);
116
- continue;
117
- }
118
- let unitAndLabels;
119
- if (undefined !== presFormatOverride.unitAndLabels) {
120
- if (4 < presFormatOverride.unitAndLabels.length)
121
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
122
- unitAndLabels = [];
123
- for (const unitOverride of presFormatOverride.unitAndLabels) {
124
- const unit = await this.schema.lookupItem(unitOverride[0]);
125
- if (undefined === unit)
126
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
127
- unitAndLabels.push([unit, unitOverride[1]]);
128
- }
129
- }
130
- const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
131
- this.addPresentationFormat(overrideFormat);
132
- }
133
- }
134
- processPresentationUnitsSync(presentationUnitsJson) {
135
- const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
136
- for (const formatString of presUnitsArr) {
137
- const presFormatOverride = this.parseFormatString(formatString);
138
- const format = this.schema.lookupItemSync(presFormatOverride.name);
139
- if (undefined === format || format.schemaItemType !== ECObjects_1.SchemaItemType.Format)
140
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
141
- if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
142
- this.addPresentationFormat(format);
143
- continue;
144
- }
145
- let unitAndLabels;
146
- if (undefined !== presFormatOverride.unitAndLabels) {
147
- if (4 < presFormatOverride.unitAndLabels.length)
148
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
149
- unitAndLabels = [];
150
- for (const unitOverride of presFormatOverride.unitAndLabels) {
151
- const unit = this.schema.lookupItemSync(unitOverride[0]);
152
- if (undefined === unit)
153
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
154
- unitAndLabels.push([unit, unitOverride[1]]);
155
- }
156
- }
157
- const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
158
- this.addPresentationFormat(overrideFormat);
159
- }
160
- }
161
- /**
162
- * Save this KindOfQuantity's properties to an object for serializing to JSON.
163
- * @param standalone Serialization includes only this object (as opposed to the full schema).
164
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
165
- */
166
- toJSON(standalone = false, includeSchemaVersion = false) {
167
- const schemaJson = super.toJSON(standalone, includeSchemaVersion);
168
- schemaJson.relativeError = this.relativeError;
169
- schemaJson.persistenceUnit = this.persistenceUnit.fullName;
170
- if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)
171
- schemaJson.presentationUnits = this.presentationFormats.map((format) => format.fullName);
172
- return schemaJson;
173
- }
174
- /** @internal */
175
- async toXml(schemaXml) {
176
- const itemElement = await super.toXml(schemaXml);
177
- const persistenceUnit = await this.persistenceUnit;
178
- if (undefined !== persistenceUnit) {
179
- const unitName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);
180
- itemElement.setAttribute("persistenceUnit", unitName);
181
- }
182
- if (undefined !== this.presentationFormats) {
183
- const presUnitStrings = this.presentationFormats.map((format) => {
184
- if (!OverrideFormat_1.OverrideFormat.isOverrideFormat(format))
185
- return XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);
186
- return format.fullNameXml(this.schema);
187
- });
188
- itemElement.setAttribute("presentationUnits", presUnitStrings.join(";"));
189
- }
190
- itemElement.setAttribute("relativeError", this.relativeError.toString());
191
- return itemElement;
192
- }
193
- fromJSONSync(kindOfQuantityProps) {
194
- super.fromJSONSync(kindOfQuantityProps);
195
- this._relativeError = kindOfQuantityProps.relativeError;
196
- const persistenceUnit = this.schema.lookupItemSync(kindOfQuantityProps.persistenceUnit);
197
- if (undefined === persistenceUnit)
198
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
199
- if (persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.Unit && persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.InvertedUnit)
200
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
201
- this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
202
- if (undefined !== kindOfQuantityProps.presentationUnits)
203
- this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);
204
- }
205
- async fromJSON(kindOfQuantityProps) {
206
- await super.fromJSON(kindOfQuantityProps);
207
- this._relativeError = kindOfQuantityProps.relativeError;
208
- const persistenceUnit = await this.schema.lookupItem(kindOfQuantityProps.persistenceUnit);
209
- if (undefined === persistenceUnit)
210
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
211
- if (persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.Unit && persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.InvertedUnit)
212
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
213
- this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
214
- if (undefined !== kindOfQuantityProps.presentationUnits)
215
- await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);
216
- }
217
- }
218
- exports.KindOfQuantity = KindOfQuantity;
219
- /**
220
- * @internal
221
- * An abstract class used for schema editing.
222
- */
223
- class MutableKindOfQuantity extends KindOfQuantity {
224
- }
225
- exports.MutableKindOfQuantity = MutableKindOfQuantity;
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.MutableKindOfQuantity = exports.KindOfQuantity = 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 core_quantity_1 = require("@itwin/core-quantity");
16
+ const OverrideFormat_1 = require("./OverrideFormat");
17
+ const SchemaItem_1 = require("./SchemaItem");
18
+ /** A Typescript class representation of a KindOfQuantity.
19
+ * @beta
20
+ */
21
+ class KindOfQuantity extends SchemaItem_1.SchemaItem {
22
+ constructor(schema, name) {
23
+ super(schema, name);
24
+ this._relativeError = 1.0;
25
+ this._presentationFormats = new Array();
26
+ this.schemaItemType = ECObjects_1.SchemaItemType.KindOfQuantity; // Needed to allow both run-time and compile-time check.
27
+ }
28
+ /** The first presentation format in the list of Formats. */
29
+ get defaultPresentationFormat() { return this.presentationFormats[0]; }
30
+ /** A list of presentation formats. */
31
+ get presentationFormats() { return this._presentationFormats; }
32
+ get persistenceUnit() { return this._persistenceUnit; }
33
+ get relativeError() { return this._relativeError; }
34
+ /**
35
+ *
36
+ * @param format The Format to add to this KindOfQuantity
37
+ * @param isDefault
38
+ */
39
+ addPresentationFormat(format, isDefault = false) {
40
+ // TODO: Add some sort of validation?
41
+ (isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);
42
+ }
43
+ /** Parses the format string into the parts that make up an Override Format
44
+ * @param formatString
45
+ */
46
+ parseFormatString(formatString) {
47
+ const match = formatString.split(core_quantity_1.formatStringRgx); // split string based on regex groups
48
+ if (undefined === match[1])
49
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The format string, ${formatString}, on KindOfQuantity '${this.fullName}' is missing a format.`);
50
+ const returnValue = { name: match[1] };
51
+ if (undefined !== match[2] && undefined !== match[3]) {
52
+ const overrideString = match[2];
53
+ const tokens = [];
54
+ let prevPos = 1; // Initial position is the character directly after the opening '(' in the override string.
55
+ let currPos;
56
+ // TODO need to include `,` as a valid search argument.
57
+ while (-1 !== (currPos = overrideString.indexOf(")", prevPos))) { // eslint-disable-line
58
+ tokens.push(overrideString.substr(prevPos, currPos - prevPos));
59
+ prevPos = currPos + 1;
60
+ }
61
+ if (overrideString.length > 0 && undefined === tokens.find((token) => {
62
+ return "" !== token; // there is at least one token that is not empty.
63
+ })) {
64
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
65
+ }
66
+ // The first override parameter overrides the default precision of the format
67
+ const precisionIndx = 0;
68
+ if (tokens.length >= precisionIndx + 1) {
69
+ if (tokens[precisionIndx].length > 0) {
70
+ const precision = Number.parseInt(tokens[precisionIndx], 10);
71
+ if (Number.isNaN(precision))
72
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The format string '${formatString}' on KindOfQuantity '${this.fullName}' has a precision override '${tokens[precisionIndx]}' that is not number.`);
73
+ returnValue.precision = precision;
74
+ }
75
+ }
76
+ }
77
+ let i = 4;
78
+ while (i < match.length) {
79
+ if (undefined === match[i])
80
+ break;
81
+ // Unit override required
82
+ if (undefined === match[i + 1])
83
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
84
+ if (undefined === returnValue.unitAndLabels)
85
+ returnValue.unitAndLabels = [];
86
+ if (undefined !== match[i + 2]) // matches '|'
87
+ returnValue.unitAndLabels.push([match[i + 1], match[i + 3]]); // add unit name and label override
88
+ else
89
+ returnValue.unitAndLabels.push([match[i + 1], undefined]); // add unit name
90
+ i += 4;
91
+ }
92
+ return returnValue;
93
+ }
94
+ /** Creates an OverrideFormat in the context of this KindOfQuantity.
95
+ * @param parent The Format to override.
96
+ * @param precision The precision override
97
+ * @param unitLabelOverrides The list of unit and label overrides.
98
+ */
99
+ createFormatOverride(parent, precision, unitLabelOverrides) {
100
+ if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)
101
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Cannot add presentation format to KindOfQuantity '${this.name}' because the number of unit overrides is inconsistent with the number in the Format '${parent.name}'.`);
102
+ if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)
103
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);
104
+ // TODO: Check compatibility of Unit overrides with the persistence unit
105
+ return new OverrideFormat_1.OverrideFormat(parent, precision, unitLabelOverrides);
106
+ }
107
+ async processPresentationUnits(presentationUnitsJson) {
108
+ const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
109
+ for (const formatString of presUnitsArr) {
110
+ const presFormatOverride = this.parseFormatString(formatString);
111
+ const format = await this.schema.lookupItem(presFormatOverride.name);
112
+ if (undefined === format || format.schemaItemType !== ECObjects_1.SchemaItemType.Format)
113
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
114
+ if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
115
+ this.addPresentationFormat(format);
116
+ continue;
117
+ }
118
+ let unitAndLabels;
119
+ if (undefined !== presFormatOverride.unitAndLabels) {
120
+ if (4 < presFormatOverride.unitAndLabels.length)
121
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
122
+ unitAndLabels = [];
123
+ for (const unitOverride of presFormatOverride.unitAndLabels) {
124
+ const unit = await this.schema.lookupItem(unitOverride[0]);
125
+ if (undefined === unit)
126
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
127
+ unitAndLabels.push([unit, unitOverride[1]]);
128
+ }
129
+ }
130
+ const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
131
+ this.addPresentationFormat(overrideFormat);
132
+ }
133
+ }
134
+ processPresentationUnitsSync(presentationUnitsJson) {
135
+ const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
136
+ for (const formatString of presUnitsArr) {
137
+ const presFormatOverride = this.parseFormatString(formatString);
138
+ const format = this.schema.lookupItemSync(presFormatOverride.name);
139
+ if (undefined === format || format.schemaItemType !== ECObjects_1.SchemaItemType.Format)
140
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
141
+ if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
142
+ this.addPresentationFormat(format);
143
+ continue;
144
+ }
145
+ let unitAndLabels;
146
+ if (undefined !== presFormatOverride.unitAndLabels) {
147
+ if (4 < presFormatOverride.unitAndLabels.length)
148
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
149
+ unitAndLabels = [];
150
+ for (const unitOverride of presFormatOverride.unitAndLabels) {
151
+ const unit = this.schema.lookupItemSync(unitOverride[0]);
152
+ if (undefined === unit)
153
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
154
+ unitAndLabels.push([unit, unitOverride[1]]);
155
+ }
156
+ }
157
+ const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
158
+ this.addPresentationFormat(overrideFormat);
159
+ }
160
+ }
161
+ /**
162
+ * Save this KindOfQuantity's properties to an object for serializing to JSON.
163
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
164
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
165
+ */
166
+ toJSON(standalone = false, includeSchemaVersion = false) {
167
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
168
+ schemaJson.relativeError = this.relativeError;
169
+ schemaJson.persistenceUnit = this.persistenceUnit.fullName;
170
+ if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)
171
+ schemaJson.presentationUnits = this.presentationFormats.map((format) => format.fullName);
172
+ return schemaJson;
173
+ }
174
+ /** @internal */
175
+ async toXml(schemaXml) {
176
+ const itemElement = await super.toXml(schemaXml);
177
+ const persistenceUnit = await this.persistenceUnit;
178
+ if (undefined !== persistenceUnit) {
179
+ const unitName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);
180
+ itemElement.setAttribute("persistenceUnit", unitName);
181
+ }
182
+ if (undefined !== this.presentationFormats) {
183
+ const presUnitStrings = this.presentationFormats.map((format) => {
184
+ if (!OverrideFormat_1.OverrideFormat.isOverrideFormat(format))
185
+ return XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);
186
+ return format.fullNameXml(this.schema);
187
+ });
188
+ itemElement.setAttribute("presentationUnits", presUnitStrings.join(";"));
189
+ }
190
+ itemElement.setAttribute("relativeError", this.relativeError.toString());
191
+ return itemElement;
192
+ }
193
+ fromJSONSync(kindOfQuantityProps) {
194
+ super.fromJSONSync(kindOfQuantityProps);
195
+ this._relativeError = kindOfQuantityProps.relativeError;
196
+ const persistenceUnit = this.schema.lookupItemSync(kindOfQuantityProps.persistenceUnit);
197
+ if (undefined === persistenceUnit)
198
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
199
+ if (persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.Unit && persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.InvertedUnit)
200
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
201
+ this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
202
+ if (undefined !== kindOfQuantityProps.presentationUnits)
203
+ this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);
204
+ }
205
+ async fromJSON(kindOfQuantityProps) {
206
+ await super.fromJSON(kindOfQuantityProps);
207
+ this._relativeError = kindOfQuantityProps.relativeError;
208
+ const persistenceUnit = await this.schema.lookupItem(kindOfQuantityProps.persistenceUnit);
209
+ if (undefined === persistenceUnit)
210
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
211
+ if (persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.Unit && persistenceUnit.schemaItemType !== ECObjects_1.SchemaItemType.InvertedUnit)
212
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
213
+ this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
214
+ if (undefined !== kindOfQuantityProps.presentationUnits)
215
+ await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);
216
+ }
217
+ }
218
+ exports.KindOfQuantity = KindOfQuantity;
219
+ /**
220
+ * @internal
221
+ * An abstract class used for schema editing.
222
+ */
223
+ class MutableKindOfQuantity extends KindOfQuantity {
224
+ }
225
+ exports.MutableKindOfQuantity = MutableKindOfQuantity;
226
226
  //# sourceMappingURL=KindOfQuantity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KindOfQuantity.js","sourceRoot":"","sources":["../../../src/Metadata/KindOfQuantity.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAE/D,wDAAuD;AAGvD,qDAAkD;AAElD,6CAA0C;AAS1C;;GAEG;AACH,MAAa,cAAe,SAAQ,uBAAU;IAgB5C,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAfZ,mBAAc,GAAW,GAAG,CAAC;QAC7B,yBAAoB,GAAmC,IAAI,KAAK,EAA2B,CAAC;QAepG,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,cAAc,CAAC,CAAC,wDAAwD;IAC/G,CAAC;IAbD,4DAA4D;IAC5D,IAAW,yBAAyB,KAA0C,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnH,sCAAsC;IACtC,IAAW,mBAAmB,KAAqC,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAEtG,IAAW,eAAe,KAA0D,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEnH,IAAW,aAAa,KAAK,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IAO1D;;;;OAIG;IACO,qBAAqB,CAAC,MAA+B,EAAE,YAAqB,KAAK;QACzF,qCAAqC;QACrC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxG,CAAC;IAED;;OAEG;IACK,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CAAC,eAAe,CAAC,CAAC;QAEtG,IAAI,SAAS,KAAK,mBAAmB,CAAC,iBAAiB;YACrD,IAAI,CAAC,4BAA4B,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IAC7E,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,mBAAwC;QACrE,MAAM,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,mBAAmB,CAAC,aAAa,CAAC;QAExD,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAO,mBAAmB,CAAC,eAAe,CAAC,CAAC;QAChG,IAAI,SAAS,KAAK,eAAe;YAC/B,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,aAAa,EAAE,YAAY,mBAAmB,CAAC,eAAe,kBAAkB,CAAC,CAAC;QAE7H,IAAI,eAAe,CAAC,cAAc,KAAK,0BAAc,CAAC,IAAI,IAAI,eAAe,CAAC,cAAc,KAAK,0BAAc,CAAC,YAAY;YAC1H,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,aAAa,EAAE,YAAY,mBAAmB,CAAC,eAAe,iCAAiC,CAAC,CAAC;QAE5I,IAAI,CAAC,gBAAgB,GAAG,IAAI,wCAAuB,CAAC,eAAe,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,eAAe,CAAC,CAAC;QAEtG,IAAI,SAAS,KAAK,mBAAmB,CAAC,iBAAiB;YACrD,MAAM,IAAI,CAAC,wBAAwB,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IAC/E,CAAC;CACF;AAzPD,wCAyPC;AACD;;;GAGG;AACH,MAAsB,qBAAsB,SAAQ,cAAc;CAIjE;AAJD,sDAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { KindOfQuantityProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedInvertedUnit, LazyLoadedUnit } from \"../Interfaces\";\r\nimport { formatStringRgx } from \"@itwin/core-quantity\";\r\nimport { Format } from \"./Format\";\r\nimport { InvertedUnit } from \"./InvertedUnit\";\r\nimport { OverrideFormat } from \"./OverrideFormat\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { Unit } from \"./Unit\";\r\n\r\ninterface OverrideFormatProps {\r\n name: string;\r\n precision?: number;\r\n unitAndLabels?: Array<[string, string | undefined]>; // Tuple of [unit name | unit label]\r\n}\r\n\r\n/** A Typescript class representation of a KindOfQuantity.\r\n * @beta\r\n */\r\nexport class KindOfQuantity extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.KindOfQuantity; // eslint-disable-line\r\n protected _relativeError: number = 1.0;\r\n protected _presentationFormats: Array<Format | OverrideFormat> = new Array<Format | OverrideFormat>();\r\n protected _persistenceUnit?: LazyLoadedUnit | LazyLoadedInvertedUnit;\r\n\r\n /** The first presentation format in the list of Formats. */\r\n public get defaultPresentationFormat(): Format | OverrideFormat | undefined { return this.presentationFormats[0]; }\r\n\r\n /** A list of presentation formats. */\r\n public get presentationFormats(): Array<Format | OverrideFormat> { return this._presentationFormats; }\r\n\r\n public get persistenceUnit(): LazyLoadedUnit | LazyLoadedInvertedUnit | undefined { return this._persistenceUnit; }\r\n\r\n public get relativeError() { return this._relativeError; }\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.KindOfQuantity; // Needed to allow both run-time and compile-time check.\r\n }\r\n\r\n /**\r\n *\r\n * @param format The Format to add to this KindOfQuantity\r\n * @param isDefault\r\n */\r\n protected addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean = false) {\r\n // TODO: Add some sort of validation?\r\n (isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);\r\n }\r\n\r\n /** Parses the format string into the parts that make up an Override Format\r\n * @param formatString\r\n */\r\n private parseFormatString(formatString: string): OverrideFormatProps {\r\n const match = formatString.split(formatStringRgx); // split string based on regex groups\r\n if (undefined === match[1])\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string, ${formatString}, on KindOfQuantity '${this.fullName}' is missing a format.`);\r\n\r\n const returnValue: OverrideFormatProps = { name: match[1] };\r\n\r\n if (undefined !== match[2] && undefined !== match[3]) {\r\n const overrideString = match[2];\r\n const tokens: string[] = [];\r\n let prevPos = 1; // Initial position is the character directly after the opening '(' in the override string.\r\n let currPos;\r\n\r\n // TODO need to include `,` as a valid search argument.\r\n while (-1 !== (currPos = overrideString.indexOf(\")\", prevPos))) { // eslint-disable-line\r\n tokens.push(overrideString.substr(prevPos, currPos - prevPos));\r\n prevPos = currPos + 1;\r\n }\r\n\r\n if (overrideString.length > 0 && undefined === tokens.find((token) => {\r\n return \"\" !== token; // there is at least one token that is not empty.\r\n })) {\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n }\r\n\r\n // The first override parameter overrides the default precision of the format\r\n const precisionIndx: number = 0;\r\n\r\n if (tokens.length >= precisionIndx + 1) {\r\n if (tokens[precisionIndx].length > 0) {\r\n const precision = Number.parseInt(tokens[precisionIndx], 10);\r\n if (Number.isNaN(precision))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string '${formatString}' on KindOfQuantity '${this.fullName}' has a precision override '${tokens[precisionIndx]}' that is not number.`);\r\n returnValue.precision = precision;\r\n }\r\n }\r\n }\r\n\r\n let i = 4;\r\n while (i < match.length) {\r\n if (undefined === match[i])\r\n break;\r\n // Unit override required\r\n if (undefined === match[i + 1])\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n\r\n if (undefined === returnValue.unitAndLabels)\r\n returnValue.unitAndLabels = [];\r\n\r\n if (undefined !== match[i + 2]) // matches '|'\r\n returnValue.unitAndLabels.push([match[i + 1], match[i + 3]]); // add unit name and label override\r\n else\r\n returnValue.unitAndLabels.push([match[i + 1], undefined]); // add unit name\r\n\r\n i += 4;\r\n }\r\n\r\n return returnValue;\r\n }\r\n\r\n /** Creates an OverrideFormat in the context of this KindOfQuantity.\r\n * @param parent The Format to override.\r\n * @param precision The precision override\r\n * @param unitLabelOverrides The list of unit and label overrides.\r\n */\r\n protected createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat {\r\n if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add presentation format to KindOfQuantity '${this.name}' because the number of unit overrides is inconsistent with the number in the Format '${parent.name}'.`);\r\n\r\n if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);\r\n\r\n // TODO: Check compatibility of Unit overrides with the persistence unit\r\n\r\n return new OverrideFormat(parent, precision, unitLabelOverrides);\r\n }\r\n\r\n private async processPresentationUnits(presentationUnitsJson: string | string[]): Promise<void> {\r\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\r\n for (const formatString of presUnitsArr) {\r\n const presFormatOverride: OverrideFormatProps = this.parseFormatString(formatString);\r\n\r\n const format = await this.schema.lookupItem<Format>(presFormatOverride.name);\r\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\r\n\r\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\r\n this.addPresentationFormat(format);\r\n continue;\r\n }\r\n\r\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\r\n if (undefined !== presFormatOverride.unitAndLabels) {\r\n if (4 < presFormatOverride.unitAndLabels.length)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n\r\n unitAndLabels = [];\r\n for (const unitOverride of presFormatOverride.unitAndLabels) {\r\n const unit = await this.schema.lookupItem<Unit | InvertedUnit>(unitOverride[0]);\r\n if (undefined === unit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\r\n\r\n unitAndLabels.push([unit, unitOverride[1]]);\r\n }\r\n }\r\n\r\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\r\n this.addPresentationFormat(overrideFormat);\r\n }\r\n }\r\n\r\n private processPresentationUnitsSync(presentationUnitsJson: string | string[]): void {\r\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\r\n for (const formatString of presUnitsArr) {\r\n const presFormatOverride: OverrideFormatProps = this.parseFormatString(formatString);\r\n\r\n const format = this.schema.lookupItemSync<Format>(presFormatOverride.name);\r\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\r\n\r\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\r\n this.addPresentationFormat(format);\r\n continue;\r\n }\r\n\r\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\r\n if (undefined !== presFormatOverride.unitAndLabels) {\r\n if (4 < presFormatOverride.unitAndLabels.length)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n\r\n unitAndLabels = [];\r\n for (const unitOverride of presFormatOverride.unitAndLabels) {\r\n const unit = this.schema.lookupItemSync<Unit | InvertedUnit>(unitOverride[0]);\r\n if (undefined === unit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\r\n\r\n unitAndLabels.push([unit, unitOverride[1]]);\r\n }\r\n }\r\n\r\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\r\n this.addPresentationFormat(overrideFormat);\r\n }\r\n }\r\n\r\n /**\r\n * Save this KindOfQuantity's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): KindOfQuantityProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.relativeError = this.relativeError;\r\n schemaJson.persistenceUnit = this.persistenceUnit!.fullName;\r\n if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)\r\n schemaJson.presentationUnits = this.presentationFormats.map((format: Format | OverrideFormat) => format.fullName);\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n const persistenceUnit = await this.persistenceUnit;\r\n if (undefined !== persistenceUnit) {\r\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);\r\n itemElement.setAttribute(\"persistenceUnit\", unitName);\r\n }\r\n\r\n if (undefined !== this.presentationFormats) {\r\n const presUnitStrings = this.presentationFormats.map((format: Format | OverrideFormat) => {\r\n if (!OverrideFormat.isOverrideFormat(format))\r\n return XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);\r\n return format.fullNameXml(this.schema);\r\n });\r\n itemElement.setAttribute(\"presentationUnits\", presUnitStrings.join(\";\"));\r\n }\r\n itemElement.setAttribute(\"relativeError\", this.relativeError.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(kindOfQuantityProps: KindOfQuantityProps): void {\r\n super.fromJSONSync(kindOfQuantityProps);\r\n this._relativeError = kindOfQuantityProps.relativeError;\r\n\r\n const persistenceUnit = this.schema.lookupItemSync<Unit>(kindOfQuantityProps.persistenceUnit);\r\n if (undefined === persistenceUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\r\n\r\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\r\n\r\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n\r\n if (undefined !== kindOfQuantityProps.presentationUnits)\r\n this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);\r\n }\r\n\r\n public override async fromJSON(kindOfQuantityProps: KindOfQuantityProps): Promise<void> {\r\n await super.fromJSON(kindOfQuantityProps);\r\n this._relativeError = kindOfQuantityProps.relativeError;\r\n\r\n const persistenceUnit = await this.schema.lookupItem<Unit>(kindOfQuantityProps.persistenceUnit);\r\n if (undefined === persistenceUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\r\n\r\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\r\n\r\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n\r\n if (undefined !== kindOfQuantityProps.presentationUnits)\r\n await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableKindOfQuantity extends KindOfQuantity {\r\n public abstract override addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean): void;\r\n public abstract override createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"KindOfQuantity.js","sourceRoot":"","sources":["../../../src/Metadata/KindOfQuantity.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAE/D,wDAAuD;AAGvD,qDAAkD;AAElD,6CAA0C;AAS1C;;GAEG;AACH,MAAa,cAAe,SAAQ,uBAAU;IAgB5C,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAfZ,mBAAc,GAAW,GAAG,CAAC;QAC7B,yBAAoB,GAAmC,IAAI,KAAK,EAA2B,CAAC;QAepG,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,cAAc,CAAC,CAAC,wDAAwD;IAC/G,CAAC;IAbD,4DAA4D;IAC5D,IAAW,yBAAyB,KAA0C,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnH,sCAAsC;IACtC,IAAW,mBAAmB,KAAqC,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAEtG,IAAW,eAAe,KAA0D,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEnH,IAAW,aAAa,KAAK,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IAO1D;;;;OAIG;I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CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IAC/E,CAAC;CACF;AAzPD,wCAyPC;AACD;;;GAGG;AACH,MAAsB,qBAAsB,SAAQ,cAAc;CAIjE;AAJD,sDAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\nimport { KindOfQuantityProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedInvertedUnit, LazyLoadedUnit } from \"../Interfaces\";\nimport { formatStringRgx } from \"@itwin/core-quantity\";\nimport { Format } from \"./Format\";\nimport { InvertedUnit } from \"./InvertedUnit\";\nimport { OverrideFormat } from \"./OverrideFormat\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\nimport { Unit } from \"./Unit\";\n\ninterface OverrideFormatProps {\n name: string;\n precision?: number;\n unitAndLabels?: Array<[string, string | undefined]>; // Tuple of [unit name | unit label]\n}\n\n/** A Typescript class representation of a KindOfQuantity.\n * @beta\n */\nexport class KindOfQuantity extends SchemaItem {\n public override readonly schemaItemType!: SchemaItemType.KindOfQuantity; // eslint-disable-line\n protected _relativeError: number = 1.0;\n protected _presentationFormats: Array<Format | OverrideFormat> = new Array<Format | OverrideFormat>();\n protected _persistenceUnit?: LazyLoadedUnit | LazyLoadedInvertedUnit;\n\n /** The first presentation format in the list of Formats. */\n public get defaultPresentationFormat(): Format | OverrideFormat | undefined { return this.presentationFormats[0]; }\n\n /** A list of presentation formats. */\n public get presentationFormats(): Array<Format | OverrideFormat> { return this._presentationFormats; }\n\n public get persistenceUnit(): LazyLoadedUnit | LazyLoadedInvertedUnit | undefined { return this._persistenceUnit; }\n\n public get relativeError() { return this._relativeError; }\n\n constructor(schema: Schema, name: string) {\n super(schema, name);\n this.schemaItemType = SchemaItemType.KindOfQuantity; // Needed to allow both run-time and compile-time check.\n }\n\n /**\n *\n * @param format The Format to add to this KindOfQuantity\n * @param isDefault\n */\n protected addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean = false) {\n // TODO: Add some sort of validation?\n (isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);\n }\n\n /** Parses the format string into the parts that make up an Override Format\n * @param formatString\n */\n private parseFormatString(formatString: string): OverrideFormatProps {\n const match = formatString.split(formatStringRgx); // split string based on regex groups\n if (undefined === match[1])\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string, ${formatString}, on KindOfQuantity '${this.fullName}' is missing a format.`);\n\n const returnValue: OverrideFormatProps = { name: match[1] };\n\n if (undefined !== match[2] && undefined !== match[3]) {\n const overrideString = match[2];\n const tokens: string[] = [];\n let prevPos = 1; // Initial position is the character directly after the opening '(' in the override string.\n let currPos;\n\n // TODO need to include `,` as a valid search argument.\n while (-1 !== (currPos = overrideString.indexOf(\")\", prevPos))) { // eslint-disable-line\n tokens.push(overrideString.substr(prevPos, currPos - prevPos));\n prevPos = currPos + 1;\n }\n\n if (overrideString.length > 0 && undefined === tokens.find((token) => {\n return \"\" !== token; // there is at least one token that is not empty.\n })) {\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n }\n\n // The first override parameter overrides the default precision of the format\n const precisionIndx: number = 0;\n\n if (tokens.length >= precisionIndx + 1) {\n if (tokens[precisionIndx].length > 0) {\n const precision = Number.parseInt(tokens[precisionIndx], 10);\n if (Number.isNaN(precision))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string '${formatString}' on KindOfQuantity '${this.fullName}' has a precision override '${tokens[precisionIndx]}' that is not number.`);\n returnValue.precision = precision;\n }\n }\n }\n\n let i = 4;\n while (i < match.length) {\n if (undefined === match[i])\n break;\n // Unit override required\n if (undefined === match[i + 1])\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n\n if (undefined === returnValue.unitAndLabels)\n returnValue.unitAndLabels = [];\n\n if (undefined !== match[i + 2]) // matches '|'\n returnValue.unitAndLabels.push([match[i + 1], match[i + 3]]); // add unit name and label override\n else\n returnValue.unitAndLabels.push([match[i + 1], undefined]); // add unit name\n\n i += 4;\n }\n\n return returnValue;\n }\n\n /** Creates an OverrideFormat in the context of this KindOfQuantity.\n * @param parent The Format to override.\n * @param precision The precision override\n * @param unitLabelOverrides The list of unit and label overrides.\n */\n protected createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat {\n if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add presentation format to KindOfQuantity '${this.name}' because the number of unit overrides is inconsistent with the number in the Format '${parent.name}'.`);\n\n if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);\n\n // TODO: Check compatibility of Unit overrides with the persistence unit\n\n return new OverrideFormat(parent, precision, unitLabelOverrides);\n }\n\n private async processPresentationUnits(presentationUnitsJson: string | string[]): Promise<void> {\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\n for (const formatString of presUnitsArr) {\n const presFormatOverride: OverrideFormatProps = this.parseFormatString(formatString);\n\n const format = await this.schema.lookupItem<Format>(presFormatOverride.name);\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\n\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\n this.addPresentationFormat(format);\n continue;\n }\n\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\n if (undefined !== presFormatOverride.unitAndLabels) {\n if (4 < presFormatOverride.unitAndLabels.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n\n unitAndLabels = [];\n for (const unitOverride of presFormatOverride.unitAndLabels) {\n const unit = await this.schema.lookupItem<Unit | InvertedUnit>(unitOverride[0]);\n if (undefined === unit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\n\n unitAndLabels.push([unit, unitOverride[1]]);\n }\n }\n\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\n this.addPresentationFormat(overrideFormat);\n }\n }\n\n private processPresentationUnitsSync(presentationUnitsJson: string | string[]): void {\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\n for (const formatString of presUnitsArr) {\n const presFormatOverride: OverrideFormatProps = this.parseFormatString(formatString);\n\n const format = this.schema.lookupItemSync<Format>(presFormatOverride.name);\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\n\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\n this.addPresentationFormat(format);\n continue;\n }\n\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\n if (undefined !== presFormatOverride.unitAndLabels) {\n if (4 < presFormatOverride.unitAndLabels.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n\n unitAndLabels = [];\n for (const unitOverride of presFormatOverride.unitAndLabels) {\n const unit = this.schema.lookupItemSync<Unit | InvertedUnit>(unitOverride[0]);\n if (undefined === unit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\n\n unitAndLabels.push([unit, unitOverride[1]]);\n }\n }\n\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\n this.addPresentationFormat(overrideFormat);\n }\n }\n\n /**\n * Save this KindOfQuantity's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): KindOfQuantityProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.relativeError = this.relativeError;\n schemaJson.persistenceUnit = this.persistenceUnit!.fullName;\n if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)\n schemaJson.presentationUnits = this.presentationFormats.map((format: Format | OverrideFormat) => format.fullName);\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n\n const persistenceUnit = await this.persistenceUnit;\n if (undefined !== persistenceUnit) {\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);\n itemElement.setAttribute(\"persistenceUnit\", unitName);\n }\n\n if (undefined !== this.presentationFormats) {\n const presUnitStrings = this.presentationFormats.map((format: Format | OverrideFormat) => {\n if (!OverrideFormat.isOverrideFormat(format))\n return XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);\n return format.fullNameXml(this.schema);\n });\n itemElement.setAttribute(\"presentationUnits\", presUnitStrings.join(\";\"));\n }\n itemElement.setAttribute(\"relativeError\", this.relativeError.toString());\n\n return itemElement;\n }\n\n public override fromJSONSync(kindOfQuantityProps: KindOfQuantityProps): void {\n super.fromJSONSync(kindOfQuantityProps);\n this._relativeError = kindOfQuantityProps.relativeError;\n\n const persistenceUnit = this.schema.lookupItemSync<Unit>(kindOfQuantityProps.persistenceUnit);\n if (undefined === persistenceUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\n\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\n\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n\n if (undefined !== kindOfQuantityProps.presentationUnits)\n this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);\n }\n\n public override async fromJSON(kindOfQuantityProps: KindOfQuantityProps): Promise<void> {\n await super.fromJSON(kindOfQuantityProps);\n this._relativeError = kindOfQuantityProps.relativeError;\n\n const persistenceUnit = await this.schema.lookupItem<Unit>(kindOfQuantityProps.persistenceUnit);\n if (undefined === persistenceUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\n\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\n\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n\n if (undefined !== kindOfQuantityProps.presentationUnits)\n await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);\n }\n}\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableKindOfQuantity extends KindOfQuantity {\n public abstract override addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean): void;\n public abstract override createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}