@itwin/ecschema-metadata 3.7.0-dev.6 → 3.7.0-dev.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/CHANGELOG.md +6 -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,243 +1,243 @@
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.MutableFormat = exports.Format = void 0;
11
- const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
12
- const ECObjects_1 = require("../ECObjects");
13
- const Exception_1 = require("../Exception");
14
- const core_quantity_1 = require("@itwin/core-quantity");
15
- const SchemaItem_1 = require("./SchemaItem");
16
- /**
17
- * @beta
18
- */
19
- class Format extends SchemaItem_1.SchemaItem {
20
- constructor(schema, name) {
21
- super(schema, name);
22
- this.schemaItemType = ECObjects_1.SchemaItemType.Format;
23
- this._base = new core_quantity_1.BaseFormat(name);
24
- }
25
- get roundFactor() { return this._base.roundFactor; }
26
- get type() { return this._base.type; }
27
- get precision() { return this._base.precision; }
28
- get minWidth() { return this._base.minWidth; }
29
- get scientificType() { return this._base.scientificType; }
30
- get showSignOption() { return this._base.showSignOption; }
31
- get decimalSeparator() { return this._base.decimalSeparator; }
32
- get thousandSeparator() { return this._base.thousandSeparator; }
33
- get uomSeparator() { return this._base.uomSeparator; }
34
- get stationSeparator() { return this._base.stationSeparator; }
35
- get stationOffsetSize() { return this._base.stationOffsetSize; }
36
- get formatTraits() { return this._base.formatTraits; }
37
- get spacer() { return this._base.spacer; }
38
- get includeZero() { return this._base.includeZero; }
39
- get units() { return this._units; }
40
- parseFormatTraits(formatTraitsFromJson) {
41
- return this._base.parseFormatTraits(formatTraitsFromJson);
42
- }
43
- hasFormatTrait(formatTrait) {
44
- return this._base.hasFormatTraitSet(formatTrait);
45
- }
46
- /**
47
- * Adds a Unit, or InvertedUnit, with an optional label override.
48
- * @param unit The Unit, or InvertedUnit, to add to this Format.
49
- * @param label A label that overrides the label defined within the Unit when a value is formatted.
50
- */
51
- addUnit(unit, label) {
52
- if (undefined === this._units)
53
- this._units = [];
54
- else { // Validate that a duplicate is not added.
55
- for (const existingUnit of this._units) {
56
- if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())
57
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.
58
- }
59
- }
60
- this._units.push([unit, label]);
61
- }
62
- setPrecision(precision) { this._base.precision = precision; }
63
- typecheck(formatProps) {
64
- this._base.loadFormatProperties(formatProps);
65
- if (undefined !== formatProps.composite) { // TODO: This is duplicated below when the units need to be processed...
66
- if (undefined !== formatProps.composite.includeZero)
67
- this._base.includeZero = formatProps.composite.includeZero;
68
- if (undefined !== formatProps.composite.spacer) {
69
- if (formatProps.composite.spacer.length > 1)
70
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);
71
- this._base.spacer = formatProps.composite.spacer;
72
- }
73
- // Composite requires 1-4 units
74
- if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)
75
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);
76
- }
77
- }
78
- fromJSONSync(formatProps) {
79
- super.fromJSONSync(formatProps);
80
- this.typecheck(formatProps);
81
- if (undefined === formatProps.composite)
82
- return;
83
- // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation
84
- for (const unit of formatProps.composite.units) {
85
- const newUnit = this.schema.lookupItemSync(unit.name);
86
- if (undefined === newUnit)
87
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
88
- this.addUnit(newUnit, unit.label);
89
- }
90
- }
91
- async fromJSON(formatProps) {
92
- await super.fromJSON(formatProps);
93
- this.typecheck(formatProps);
94
- if (undefined === formatProps.composite)
95
- return;
96
- // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation
97
- for (const unit of formatProps.composite.units) {
98
- const newUnit = await this.schema.lookupItem(unit.name);
99
- if (undefined === newUnit)
100
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
101
- this.addUnit(newUnit, unit.label);
102
- }
103
- }
104
- /**
105
- * Save this Format's properties to an object for serializing to JSON.
106
- * @param standalone Serialization includes only this object (as opposed to the full schema).
107
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
108
- */
109
- toJSON(standalone = false, includeSchemaVersion = false) {
110
- const schemaJson = super.toJSON(standalone, includeSchemaVersion);
111
- schemaJson.type = (0, core_quantity_1.formatTypeToString)(this.type);
112
- schemaJson.precision = this.precision;
113
- // this._spacer = " ";
114
- // this._includeZero = true;
115
- // Serialize the minimal amount of information needed so anything that is the same as the default, do not serialize.
116
- if (0.0 !== this.roundFactor)
117
- schemaJson.roundFactor = this.roundFactor;
118
- if (core_quantity_1.ShowSignOption.OnlyNegative !== this.showSignOption)
119
- schemaJson.showSignOption = (0, core_quantity_1.showSignOptionToString)(this.showSignOption);
120
- if (core_quantity_1.FormatTraits.Uninitialized !== this.formatTraits)
121
- schemaJson.formatTraits = (0, core_quantity_1.formatTraitsToArray)(this.formatTraits);
122
- if ("." !== this.decimalSeparator)
123
- schemaJson.decimalSeparator = this.decimalSeparator;
124
- if ("," !== this.thousandSeparator)
125
- schemaJson.thousandSeparator = this.thousandSeparator;
126
- if (" " !== this.uomSeparator)
127
- schemaJson.uomSeparator = this.uomSeparator;
128
- if (undefined !== this.minWidth)
129
- schemaJson.minWidth = this.minWidth;
130
- if (core_quantity_1.FormatType.Scientific === this.type && undefined !== this.scientificType)
131
- schemaJson.scientificType = (0, core_quantity_1.scientificTypeToString)(this.scientificType);
132
- if (core_quantity_1.FormatType.Station === this.type) {
133
- if (undefined !== this.stationOffsetSize)
134
- schemaJson.stationOffsetSize = this.stationOffsetSize;
135
- if (" " !== this.stationSeparator)
136
- schemaJson.stationSeparator = this.stationSeparator;
137
- }
138
- if (undefined === this.units)
139
- return schemaJson;
140
- schemaJson.composite = {};
141
- if (" " !== this.spacer)
142
- schemaJson.composite.spacer = this.spacer;
143
- if (true !== this.includeZero)
144
- schemaJson.composite.includeZero = this.includeZero;
145
- schemaJson.composite.units = [];
146
- for (const unit of this.units) {
147
- schemaJson.composite.units.push({
148
- name: unit[0].fullName,
149
- label: unit[1],
150
- });
151
- }
152
- return schemaJson;
153
- }
154
- /** @internal */
155
- async toXml(schemaXml) {
156
- const itemElement = await super.toXml(schemaXml);
157
- itemElement.setAttribute("type", (0, core_quantity_1.formatTypeToString)(this.type).toLowerCase());
158
- itemElement.setAttribute("precision", this.precision.toString());
159
- itemElement.setAttribute("roundFactor", this.roundFactor.toString());
160
- itemElement.setAttribute("showSignOption", (0, core_quantity_1.showSignOptionToString)(this.showSignOption));
161
- itemElement.setAttribute("decimalSeparator", this.decimalSeparator);
162
- itemElement.setAttribute("thousandSeparator", this.thousandSeparator);
163
- itemElement.setAttribute("uomSeparator", this.uomSeparator);
164
- itemElement.setAttribute("stationSeparator", this.stationSeparator);
165
- if (undefined !== this.minWidth)
166
- itemElement.setAttribute("minWidth", this.minWidth.toString());
167
- if (undefined !== this.scientificType)
168
- itemElement.setAttribute("scientificType", (0, core_quantity_1.scientificTypeToString)(this.scientificType));
169
- if (undefined !== this.stationOffsetSize)
170
- itemElement.setAttribute("stationOffsetSize", this.stationOffsetSize.toString());
171
- const formatTraits = (0, core_quantity_1.formatTraitsToArray)(this.formatTraits);
172
- if (formatTraits.length > 0)
173
- itemElement.setAttribute("formatTraits", formatTraits.join("|"));
174
- if (undefined !== this.units) {
175
- const compositeElement = schemaXml.createElement("Composite");
176
- if (undefined !== this.spacer)
177
- compositeElement.setAttribute("spacer", this.spacer);
178
- if (undefined !== this.includeZero)
179
- compositeElement.setAttribute("includeZero", this.includeZero.toString());
180
- this.units.forEach(([unit, label]) => {
181
- const unitElement = schemaXml.createElement("Unit");
182
- if (undefined !== label)
183
- unitElement.setAttribute("label", label);
184
- const unitName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, unit.schema, unit.name);
185
- unitElement.textContent = unitName;
186
- compositeElement.appendChild(unitElement);
187
- });
188
- itemElement.appendChild(compositeElement);
189
- }
190
- return itemElement;
191
- }
192
- /**
193
- * @alpha Used in schema editing.
194
- */
195
- setFormatType(formatType) {
196
- this._base.type = formatType;
197
- }
198
- /**
199
- * @alpha Used in schema editing.
200
- */
201
- setRoundFactor(roundFactor) {
202
- this._base.roundFactor = roundFactor;
203
- }
204
- /**
205
- * @alpha Used in schema editing.
206
- */
207
- setShowSignOption(signOption) {
208
- this._base.showSignOption = signOption;
209
- }
210
- /**
211
- * @alpha Used in schema editing.
212
- */
213
- setDecimalSeparator(separator) {
214
- this._base.decimalSeparator = separator;
215
- }
216
- /**
217
- * @alpha Used in schema editing.
218
- */
219
- setThousandSeparator(separator) {
220
- this._base.thousandSeparator = separator;
221
- }
222
- /**
223
- * @alpha Used in schema editing.
224
- */
225
- setUomSeparator(separator) {
226
- this._base.uomSeparator = separator;
227
- }
228
- /**
229
- * @alpha Used in schema editing.
230
- */
231
- setStationSeparator(separator) {
232
- this._base.stationSeparator = separator;
233
- }
234
- }
235
- exports.Format = Format;
236
- /**
237
- * @internal
238
- * An abstract class used for schema editing.
239
- */
240
- class MutableFormat extends Format {
241
- }
242
- exports.MutableFormat = MutableFormat;
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.MutableFormat = exports.Format = void 0;
11
+ const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
12
+ const ECObjects_1 = require("../ECObjects");
13
+ const Exception_1 = require("../Exception");
14
+ const core_quantity_1 = require("@itwin/core-quantity");
15
+ const SchemaItem_1 = require("./SchemaItem");
16
+ /**
17
+ * @beta
18
+ */
19
+ class Format extends SchemaItem_1.SchemaItem {
20
+ constructor(schema, name) {
21
+ super(schema, name);
22
+ this.schemaItemType = ECObjects_1.SchemaItemType.Format;
23
+ this._base = new core_quantity_1.BaseFormat(name);
24
+ }
25
+ get roundFactor() { return this._base.roundFactor; }
26
+ get type() { return this._base.type; }
27
+ get precision() { return this._base.precision; }
28
+ get minWidth() { return this._base.minWidth; }
29
+ get scientificType() { return this._base.scientificType; }
30
+ get showSignOption() { return this._base.showSignOption; }
31
+ get decimalSeparator() { return this._base.decimalSeparator; }
32
+ get thousandSeparator() { return this._base.thousandSeparator; }
33
+ get uomSeparator() { return this._base.uomSeparator; }
34
+ get stationSeparator() { return this._base.stationSeparator; }
35
+ get stationOffsetSize() { return this._base.stationOffsetSize; }
36
+ get formatTraits() { return this._base.formatTraits; }
37
+ get spacer() { return this._base.spacer; }
38
+ get includeZero() { return this._base.includeZero; }
39
+ get units() { return this._units; }
40
+ parseFormatTraits(formatTraitsFromJson) {
41
+ return this._base.parseFormatTraits(formatTraitsFromJson);
42
+ }
43
+ hasFormatTrait(formatTrait) {
44
+ return this._base.hasFormatTraitSet(formatTrait);
45
+ }
46
+ /**
47
+ * Adds a Unit, or InvertedUnit, with an optional label override.
48
+ * @param unit The Unit, or InvertedUnit, to add to this Format.
49
+ * @param label A label that overrides the label defined within the Unit when a value is formatted.
50
+ */
51
+ addUnit(unit, label) {
52
+ if (undefined === this._units)
53
+ this._units = [];
54
+ else { // Validate that a duplicate is not added.
55
+ for (const existingUnit of this._units) {
56
+ if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())
57
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.
58
+ }
59
+ }
60
+ this._units.push([unit, label]);
61
+ }
62
+ setPrecision(precision) { this._base.precision = precision; }
63
+ typecheck(formatProps) {
64
+ this._base.loadFormatProperties(formatProps);
65
+ if (undefined !== formatProps.composite) { // TODO: This is duplicated below when the units need to be processed...
66
+ if (undefined !== formatProps.composite.includeZero)
67
+ this._base.includeZero = formatProps.composite.includeZero;
68
+ if (undefined !== formatProps.composite.spacer) {
69
+ if (formatProps.composite.spacer.length > 1)
70
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);
71
+ this._base.spacer = formatProps.composite.spacer;
72
+ }
73
+ // Composite requires 1-4 units
74
+ if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)
75
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);
76
+ }
77
+ }
78
+ fromJSONSync(formatProps) {
79
+ super.fromJSONSync(formatProps);
80
+ this.typecheck(formatProps);
81
+ if (undefined === formatProps.composite)
82
+ return;
83
+ // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation
84
+ for (const unit of formatProps.composite.units) {
85
+ const newUnit = this.schema.lookupItemSync(unit.name);
86
+ if (undefined === newUnit)
87
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
88
+ this.addUnit(newUnit, unit.label);
89
+ }
90
+ }
91
+ async fromJSON(formatProps) {
92
+ await super.fromJSON(formatProps);
93
+ this.typecheck(formatProps);
94
+ if (undefined === formatProps.composite)
95
+ return;
96
+ // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation
97
+ for (const unit of formatProps.composite.units) {
98
+ const newUnit = await this.schema.lookupItem(unit.name);
99
+ if (undefined === newUnit)
100
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
101
+ this.addUnit(newUnit, unit.label);
102
+ }
103
+ }
104
+ /**
105
+ * Save this Format's properties to an object for serializing to JSON.
106
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
107
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
108
+ */
109
+ toJSON(standalone = false, includeSchemaVersion = false) {
110
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
111
+ schemaJson.type = (0, core_quantity_1.formatTypeToString)(this.type);
112
+ schemaJson.precision = this.precision;
113
+ // this._spacer = " ";
114
+ // this._includeZero = true;
115
+ // Serialize the minimal amount of information needed so anything that is the same as the default, do not serialize.
116
+ if (0.0 !== this.roundFactor)
117
+ schemaJson.roundFactor = this.roundFactor;
118
+ if (core_quantity_1.ShowSignOption.OnlyNegative !== this.showSignOption)
119
+ schemaJson.showSignOption = (0, core_quantity_1.showSignOptionToString)(this.showSignOption);
120
+ if (core_quantity_1.FormatTraits.Uninitialized !== this.formatTraits)
121
+ schemaJson.formatTraits = (0, core_quantity_1.formatTraitsToArray)(this.formatTraits);
122
+ if ("." !== this.decimalSeparator)
123
+ schemaJson.decimalSeparator = this.decimalSeparator;
124
+ if ("," !== this.thousandSeparator)
125
+ schemaJson.thousandSeparator = this.thousandSeparator;
126
+ if (" " !== this.uomSeparator)
127
+ schemaJson.uomSeparator = this.uomSeparator;
128
+ if (undefined !== this.minWidth)
129
+ schemaJson.minWidth = this.minWidth;
130
+ if (core_quantity_1.FormatType.Scientific === this.type && undefined !== this.scientificType)
131
+ schemaJson.scientificType = (0, core_quantity_1.scientificTypeToString)(this.scientificType);
132
+ if (core_quantity_1.FormatType.Station === this.type) {
133
+ if (undefined !== this.stationOffsetSize)
134
+ schemaJson.stationOffsetSize = this.stationOffsetSize;
135
+ if (" " !== this.stationSeparator)
136
+ schemaJson.stationSeparator = this.stationSeparator;
137
+ }
138
+ if (undefined === this.units)
139
+ return schemaJson;
140
+ schemaJson.composite = {};
141
+ if (" " !== this.spacer)
142
+ schemaJson.composite.spacer = this.spacer;
143
+ if (true !== this.includeZero)
144
+ schemaJson.composite.includeZero = this.includeZero;
145
+ schemaJson.composite.units = [];
146
+ for (const unit of this.units) {
147
+ schemaJson.composite.units.push({
148
+ name: unit[0].fullName,
149
+ label: unit[1],
150
+ });
151
+ }
152
+ return schemaJson;
153
+ }
154
+ /** @internal */
155
+ async toXml(schemaXml) {
156
+ const itemElement = await super.toXml(schemaXml);
157
+ itemElement.setAttribute("type", (0, core_quantity_1.formatTypeToString)(this.type).toLowerCase());
158
+ itemElement.setAttribute("precision", this.precision.toString());
159
+ itemElement.setAttribute("roundFactor", this.roundFactor.toString());
160
+ itemElement.setAttribute("showSignOption", (0, core_quantity_1.showSignOptionToString)(this.showSignOption));
161
+ itemElement.setAttribute("decimalSeparator", this.decimalSeparator);
162
+ itemElement.setAttribute("thousandSeparator", this.thousandSeparator);
163
+ itemElement.setAttribute("uomSeparator", this.uomSeparator);
164
+ itemElement.setAttribute("stationSeparator", this.stationSeparator);
165
+ if (undefined !== this.minWidth)
166
+ itemElement.setAttribute("minWidth", this.minWidth.toString());
167
+ if (undefined !== this.scientificType)
168
+ itemElement.setAttribute("scientificType", (0, core_quantity_1.scientificTypeToString)(this.scientificType));
169
+ if (undefined !== this.stationOffsetSize)
170
+ itemElement.setAttribute("stationOffsetSize", this.stationOffsetSize.toString());
171
+ const formatTraits = (0, core_quantity_1.formatTraitsToArray)(this.formatTraits);
172
+ if (formatTraits.length > 0)
173
+ itemElement.setAttribute("formatTraits", formatTraits.join("|"));
174
+ if (undefined !== this.units) {
175
+ const compositeElement = schemaXml.createElement("Composite");
176
+ if (undefined !== this.spacer)
177
+ compositeElement.setAttribute("spacer", this.spacer);
178
+ if (undefined !== this.includeZero)
179
+ compositeElement.setAttribute("includeZero", this.includeZero.toString());
180
+ this.units.forEach(([unit, label]) => {
181
+ const unitElement = schemaXml.createElement("Unit");
182
+ if (undefined !== label)
183
+ unitElement.setAttribute("label", label);
184
+ const unitName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, unit.schema, unit.name);
185
+ unitElement.textContent = unitName;
186
+ compositeElement.appendChild(unitElement);
187
+ });
188
+ itemElement.appendChild(compositeElement);
189
+ }
190
+ return itemElement;
191
+ }
192
+ /**
193
+ * @alpha Used in schema editing.
194
+ */
195
+ setFormatType(formatType) {
196
+ this._base.type = formatType;
197
+ }
198
+ /**
199
+ * @alpha Used in schema editing.
200
+ */
201
+ setRoundFactor(roundFactor) {
202
+ this._base.roundFactor = roundFactor;
203
+ }
204
+ /**
205
+ * @alpha Used in schema editing.
206
+ */
207
+ setShowSignOption(signOption) {
208
+ this._base.showSignOption = signOption;
209
+ }
210
+ /**
211
+ * @alpha Used in schema editing.
212
+ */
213
+ setDecimalSeparator(separator) {
214
+ this._base.decimalSeparator = separator;
215
+ }
216
+ /**
217
+ * @alpha Used in schema editing.
218
+ */
219
+ setThousandSeparator(separator) {
220
+ this._base.thousandSeparator = separator;
221
+ }
222
+ /**
223
+ * @alpha Used in schema editing.
224
+ */
225
+ setUomSeparator(separator) {
226
+ this._base.uomSeparator = separator;
227
+ }
228
+ /**
229
+ * @alpha Used in schema editing.
230
+ */
231
+ setStationSeparator(separator) {
232
+ this._base.stationSeparator = separator;
233
+ }
234
+ }
235
+ exports.Format = Format;
236
+ /**
237
+ * @internal
238
+ * An abstract class used for schema editing.
239
+ */
240
+ class MutableFormat extends Format {
241
+ }
242
+ exports.MutableFormat = MutableFormat;
243
243
  //# sourceMappingURL=Format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Format.js","sourceRoot":"","sources":["../../../src/Metadata/Format.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAC/D,wDAC8G;AAG9G,6CAA0C;AAG1C;;GAEG;AACH,MAAa,MAAO,SAAQ,uBAAU;IAKpC,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,MAAM,CAAC;QAE5C,IAAI,CAAC,KAAK,GAAG,IAAI,0BAAU,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,IAAW,WAAW,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,IAAW,IAAI,KAAiB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,IAAW,SAAS,KAA6C,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/F,IAAW,QAAQ,KAAyB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzE,IAAW,cAAc,KAAiC,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;IAC7F,IAAW,cAAc,KAAqB,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;IACjF,IAAW,gBAAgB,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAA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C,SAAiB;QAC9C,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAC3C,CAAC;IAED;;OAEG;IACO,eAAe,CAAC,SAAiB;QACzC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,mBAAmB,CAAC,SAAiB;QAC7C,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAC1C,CAAC;CACF;AApQD,wBAoQC;AAED;;;GAGG;AACH,MAAsB,aAAc,SAAQ,MAAM;CAWjD;AAXD,sCAWC","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 { FormatProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { BaseFormat, DecimalPrecision, FormatTraits, formatTraitsToArray, FormatType, formatTypeToString, FractionalPrecision,\r\n ScientificType, scientificTypeToString, ShowSignOption, showSignOptionToString} from \"@itwin/core-quantity\";\r\nimport { InvertedUnit } from \"./InvertedUnit\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { Unit } from \"./Unit\";\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class Format extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Format; // eslint-disable-line\r\n protected _base: BaseFormat;\r\n protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Format;\r\n\r\n this._base = new BaseFormat(name);\r\n }\r\n\r\n public get roundFactor(): number { return this._base.roundFactor; }\r\n public get type(): FormatType { return this._base.type; }\r\n public get precision(): DecimalPrecision | FractionalPrecision { return this._base.precision; }\r\n public get minWidth(): number | undefined { return this._base.minWidth; }\r\n public get scientificType(): ScientificType | undefined { return this._base.scientificType; }\r\n public get showSignOption(): ShowSignOption { return this._base.showSignOption; }\r\n public get decimalSeparator(): string { return this._base.decimalSeparator; }\r\n public get thousandSeparator(): string { return this._base.thousandSeparator; }\r\n public get uomSeparator(): string { return this._base.uomSeparator; }\r\n public get stationSeparator(): string { return this._base.stationSeparator; }\r\n public get stationOffsetSize(): number | undefined { return this._base.stationOffsetSize; }\r\n public get formatTraits(): FormatTraits { return this._base.formatTraits; }\r\n public get spacer(): string | undefined { return this._base.spacer; }\r\n public get includeZero(): boolean | undefined { return this._base.includeZero; }\r\n public get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined { return this._units; }\r\n\r\n private parseFormatTraits(formatTraitsFromJson: string | string[]) {\r\n return this._base.parseFormatTraits(formatTraitsFromJson);\r\n }\r\n\r\n public hasFormatTrait(formatTrait: FormatTraits) {\r\n return this._base.hasFormatTraitSet(formatTrait);\r\n }\r\n\r\n /**\r\n * Adds a Unit, or InvertedUnit, with an optional label override.\r\n * @param unit The Unit, or InvertedUnit, to add to this Format.\r\n * @param label A label that overrides the label defined within the Unit when a value is formatted.\r\n */\r\n protected addUnit(unit: Unit | InvertedUnit, label?: string) {\r\n if (undefined === this._units)\r\n this._units = [];\r\n else { // Validate that a duplicate is not added.\r\n for (const existingUnit of this._units) {\r\n if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.\r\n }\r\n }\r\n\r\n this._units.push([unit, label]);\r\n }\r\n\r\n protected setPrecision(precision: number) { this._base.precision = precision; }\r\n\r\n private typecheck(formatProps: FormatProps) {\r\n this._base.loadFormatProperties(formatProps);\r\n\r\n if (undefined !== formatProps.composite) { // TODO: This is duplicated below when the units need to be processed...\r\n if (undefined !== formatProps.composite.includeZero)\r\n this._base.includeZero = formatProps.composite.includeZero;\r\n\r\n if (undefined !== formatProps.composite.spacer) {\r\n if (formatProps.composite.spacer.length > 1)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);\r\n this._base.spacer = formatProps.composite.spacer;\r\n }\r\n\r\n // Composite requires 1-4 units\r\n if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);\r\n }\r\n }\r\n\r\n public override fromJSONSync(formatProps: FormatProps) {\r\n super.fromJSONSync(formatProps);\r\n this.typecheck(formatProps);\r\n if (undefined === formatProps.composite)\r\n return;\r\n\r\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\r\n for (const unit of formatProps.composite.units) {\r\n const newUnit = this.schema.lookupItemSync<Unit | InvertedUnit>(unit.name);\r\n if (undefined === newUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n this.addUnit(newUnit, unit.label);\r\n }\r\n }\r\n\r\n public override async fromJSON(formatProps: FormatProps) {\r\n await super.fromJSON(formatProps);\r\n this.typecheck(formatProps);\r\n if (undefined === formatProps.composite)\r\n return;\r\n\r\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\r\n for (const unit of formatProps.composite.units) {\r\n const newUnit = await this.schema.lookupItem<Unit | InvertedUnit>(unit.name);\r\n if (undefined === newUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n this.addUnit(newUnit, unit.label);\r\n }\r\n }\r\n\r\n /**\r\n * Save this Format'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): FormatProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.type = formatTypeToString(this.type);\r\n schemaJson.precision = this.precision;\r\n\r\n // this._spacer = \" \";\r\n // this._includeZero = true;\r\n\r\n // Serialize the minimal amount of information needed so anything that is the same as the default, do not serialize.\r\n if (0.0 !== this.roundFactor)\r\n schemaJson.roundFactor = this.roundFactor;\r\n if (ShowSignOption.OnlyNegative !== this.showSignOption)\r\n schemaJson.showSignOption = showSignOptionToString(this.showSignOption);\r\n if (FormatTraits.Uninitialized !== this.formatTraits)\r\n schemaJson.formatTraits = formatTraitsToArray(this.formatTraits);\r\n if (\".\" !== this.decimalSeparator)\r\n schemaJson.decimalSeparator = this.decimalSeparator;\r\n if (\",\" !== this.thousandSeparator)\r\n schemaJson.thousandSeparator = this.thousandSeparator;\r\n if (\" \" !== this.uomSeparator)\r\n schemaJson.uomSeparator = this.uomSeparator;\r\n\r\n if (undefined !== this.minWidth)\r\n schemaJson.minWidth = this.minWidth;\r\n\r\n if (FormatType.Scientific === this.type && undefined !== this.scientificType)\r\n schemaJson.scientificType = scientificTypeToString(this.scientificType);\r\n\r\n if (FormatType.Station === this.type) {\r\n if (undefined !== this.stationOffsetSize)\r\n schemaJson.stationOffsetSize = this.stationOffsetSize;\r\n if (\" \" !== this.stationSeparator)\r\n schemaJson.stationSeparator = this.stationSeparator;\r\n }\r\n\r\n if (undefined === this.units)\r\n return schemaJson;\r\n\r\n schemaJson.composite = {};\r\n\r\n if (\" \" !== this.spacer)\r\n schemaJson.composite.spacer = this.spacer;\r\n\r\n if (true !== this.includeZero)\r\n schemaJson.composite.includeZero = this.includeZero;\r\n\r\n schemaJson.composite.units = [];\r\n for (const unit of this.units) {\r\n schemaJson.composite.units.push({\r\n name: unit[0].fullName,\r\n label: unit[1],\r\n });\r\n }\r\n\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 itemElement.setAttribute(\"type\", formatTypeToString(this.type).toLowerCase());\r\n itemElement.setAttribute(\"precision\", this.precision.toString());\r\n itemElement.setAttribute(\"roundFactor\", this.roundFactor.toString());\r\n itemElement.setAttribute(\"showSignOption\", showSignOptionToString(this.showSignOption));\r\n itemElement.setAttribute(\"decimalSeparator\", this.decimalSeparator);\r\n itemElement.setAttribute(\"thousandSeparator\", this.thousandSeparator);\r\n itemElement.setAttribute(\"uomSeparator\", this.uomSeparator);\r\n itemElement.setAttribute(\"stationSeparator\", this.stationSeparator);\r\n\r\n if (undefined !== this.minWidth)\r\n itemElement.setAttribute(\"minWidth\", this.minWidth.toString());\r\n if (undefined !== this.scientificType)\r\n itemElement.setAttribute(\"scientificType\", scientificTypeToString(this.scientificType));\r\n if (undefined !== this.stationOffsetSize)\r\n itemElement.setAttribute(\"stationOffsetSize\", this.stationOffsetSize.toString());\r\n\r\n const formatTraits = formatTraitsToArray(this.formatTraits);\r\n if (formatTraits.length > 0)\r\n itemElement.setAttribute(\"formatTraits\", formatTraits.join(\"|\"));\r\n\r\n if (undefined !== this.units) {\r\n const compositeElement = schemaXml.createElement(\"Composite\");\r\n if (undefined !== this.spacer)\r\n compositeElement.setAttribute(\"spacer\", this.spacer);\r\n if (undefined !== this.includeZero)\r\n compositeElement.setAttribute(\"includeZero\", this.includeZero.toString());\r\n\r\n this.units.forEach(([unit, label]) => {\r\n const unitElement = schemaXml.createElement(\"Unit\");\r\n if (undefined !== label)\r\n unitElement.setAttribute(\"label\", label);\r\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, unit.schema, unit.name);\r\n unitElement.textContent = unitName;\r\n compositeElement.appendChild(unitElement);\r\n });\r\n\r\n itemElement.appendChild(compositeElement);\r\n }\r\n\r\n return itemElement;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setFormatType(formatType: FormatType) {\r\n this._base.type = formatType;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setRoundFactor(roundFactor: number) {\r\n this._base.roundFactor = roundFactor;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setShowSignOption(signOption: ShowSignOption) {\r\n this._base.showSignOption = signOption;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setDecimalSeparator(separator: string) {\r\n this._base.decimalSeparator = separator;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setThousandSeparator(separator: string) {\r\n this._base.thousandSeparator = separator;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setUomSeparator(separator: string) {\r\n this._base.uomSeparator = separator;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setStationSeparator(separator: string) {\r\n this._base.stationSeparator = separator;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableFormat extends Format {\r\n public abstract override addUnit(unit: Unit | InvertedUnit, label?: string): void;\r\n public abstract override setPrecision(precision: number): void;\r\n public abstract override setFormatType(formatType: FormatType): void;\r\n public abstract override setRoundFactor(roundFactor: number): void;\r\n public abstract override setShowSignOption(signOption: ShowSignOption): void;\r\n public abstract override setDecimalSeparator(separator: string): void;\r\n public abstract override setThousandSeparator(separator: string): void;\r\n public abstract override setUomSeparator(separator: string): void;\r\n public abstract override setStationSeparator(separator: string): void;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"Format.js","sourceRoot":"","sources":["../../../src/Metadata/Format.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAC/D,wDAC8G;AAG9G,6CAA0C;AAG1C;;GAEG;AACH,MAAa,MAAO,SAAQ,uB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GAAG,6CAAqB,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/F,WAAW,CAAC,WAAW,GAAG,QAAQ,CAAC;gBACnC,gBAAgB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC;YAEH,WAAW,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;SAC3C;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;OAEG;IACO,aAAa,CAAC,UAAsB;QAC5C,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACO,cAAc,CAAC,WAAmB;QAC1C,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;IACvC,CAAC;IAED;;OAEG;IACO,iBAAiB,CAAC,UAA0B;QACpD,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,UAAU,CAAC;IACzC,CAAC;IAED;;OAEG;IACO,mBAAmB,CAAC,SAAiB;QAC7C,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAC1C,CAAC;IAED;;OAEG;IACO,oBAAoB,CAAC,SAAiB;QAC9C,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAC3C,CAAC;IAED;;OAEG;IACO,eAAe,CAAC,SAAiB;QACzC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,mBAAmB,CAAC,SAAiB;QAC7C,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAC1C,CAAC;CACF;AApQD,wBAoQC;AAED;;;GAGG;AACH,MAAsB,aAAc,SAAQ,MAAM;CAWjD;AAXD,sCAWC","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 { FormatProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { BaseFormat, DecimalPrecision, FormatTraits, formatTraitsToArray, FormatType, formatTypeToString, FractionalPrecision,\n ScientificType, scientificTypeToString, ShowSignOption, showSignOptionToString} from \"@itwin/core-quantity\";\nimport { InvertedUnit } from \"./InvertedUnit\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\nimport { Unit } from \"./Unit\";\n\n/**\n * @beta\n */\nexport class Format extends SchemaItem {\n public override readonly schemaItemType!: SchemaItemType.Format; // eslint-disable-line\n protected _base: BaseFormat;\n protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;\n\n constructor(schema: Schema, name: string) {\n super(schema, name);\n this.schemaItemType = SchemaItemType.Format;\n\n this._base = new BaseFormat(name);\n }\n\n public get roundFactor(): number { return this._base.roundFactor; }\n public get type(): FormatType { return this._base.type; }\n public get precision(): DecimalPrecision | FractionalPrecision { return this._base.precision; }\n public get minWidth(): number | undefined { return this._base.minWidth; }\n public get scientificType(): ScientificType | undefined { return this._base.scientificType; }\n public get showSignOption(): ShowSignOption { return this._base.showSignOption; }\n public get decimalSeparator(): string { return this._base.decimalSeparator; }\n public get thousandSeparator(): string { return this._base.thousandSeparator; }\n public get uomSeparator(): string { return this._base.uomSeparator; }\n public get stationSeparator(): string { return this._base.stationSeparator; }\n public get stationOffsetSize(): number | undefined { return this._base.stationOffsetSize; }\n public get formatTraits(): FormatTraits { return this._base.formatTraits; }\n public get spacer(): string | undefined { return this._base.spacer; }\n public get includeZero(): boolean | undefined { return this._base.includeZero; }\n public get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined { return this._units; }\n\n private parseFormatTraits(formatTraitsFromJson: string | string[]) {\n return this._base.parseFormatTraits(formatTraitsFromJson);\n }\n\n public hasFormatTrait(formatTrait: FormatTraits) {\n return this._base.hasFormatTraitSet(formatTrait);\n }\n\n /**\n * Adds a Unit, or InvertedUnit, with an optional label override.\n * @param unit The Unit, or InvertedUnit, to add to this Format.\n * @param label A label that overrides the label defined within the Unit when a value is formatted.\n */\n protected addUnit(unit: Unit | InvertedUnit, label?: string) {\n if (undefined === this._units)\n this._units = [];\n else { // Validate that a duplicate is not added.\n for (const existingUnit of this._units) {\n if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.\n }\n }\n\n this._units.push([unit, label]);\n }\n\n protected setPrecision(precision: number) { this._base.precision = precision; }\n\n private typecheck(formatProps: FormatProps) {\n this._base.loadFormatProperties(formatProps);\n\n if (undefined !== formatProps.composite) { // TODO: This is duplicated below when the units need to be processed...\n if (undefined !== formatProps.composite.includeZero)\n this._base.includeZero = formatProps.composite.includeZero;\n\n if (undefined !== formatProps.composite.spacer) {\n if (formatProps.composite.spacer.length > 1)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);\n this._base.spacer = formatProps.composite.spacer;\n }\n\n // Composite requires 1-4 units\n if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);\n }\n }\n\n public override fromJSONSync(formatProps: FormatProps) {\n super.fromJSONSync(formatProps);\n this.typecheck(formatProps);\n if (undefined === formatProps.composite)\n return;\n\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\n for (const unit of formatProps.composite.units) {\n const newUnit = this.schema.lookupItemSync<Unit | InvertedUnit>(unit.name);\n if (undefined === newUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n this.addUnit(newUnit, unit.label);\n }\n }\n\n public override async fromJSON(formatProps: FormatProps) {\n await super.fromJSON(formatProps);\n this.typecheck(formatProps);\n if (undefined === formatProps.composite)\n return;\n\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\n for (const unit of formatProps.composite.units) {\n const newUnit = await this.schema.lookupItem<Unit | InvertedUnit>(unit.name);\n if (undefined === newUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n this.addUnit(newUnit, unit.label);\n }\n }\n\n /**\n * Save this Format'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): FormatProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.type = formatTypeToString(this.type);\n schemaJson.precision = this.precision;\n\n // this._spacer = \" \";\n // this._includeZero = true;\n\n // Serialize the minimal amount of information needed so anything that is the same as the default, do not serialize.\n if (0.0 !== this.roundFactor)\n schemaJson.roundFactor = this.roundFactor;\n if (ShowSignOption.OnlyNegative !== this.showSignOption)\n schemaJson.showSignOption = showSignOptionToString(this.showSignOption);\n if (FormatTraits.Uninitialized !== this.formatTraits)\n schemaJson.formatTraits = formatTraitsToArray(this.formatTraits);\n if (\".\" !== this.decimalSeparator)\n schemaJson.decimalSeparator = this.decimalSeparator;\n if (\",\" !== this.thousandSeparator)\n schemaJson.thousandSeparator = this.thousandSeparator;\n if (\" \" !== this.uomSeparator)\n schemaJson.uomSeparator = this.uomSeparator;\n\n if (undefined !== this.minWidth)\n schemaJson.minWidth = this.minWidth;\n\n if (FormatType.Scientific === this.type && undefined !== this.scientificType)\n schemaJson.scientificType = scientificTypeToString(this.scientificType);\n\n if (FormatType.Station === this.type) {\n if (undefined !== this.stationOffsetSize)\n schemaJson.stationOffsetSize = this.stationOffsetSize;\n if (\" \" !== this.stationSeparator)\n schemaJson.stationSeparator = this.stationSeparator;\n }\n\n if (undefined === this.units)\n return schemaJson;\n\n schemaJson.composite = {};\n\n if (\" \" !== this.spacer)\n schemaJson.composite.spacer = this.spacer;\n\n if (true !== this.includeZero)\n schemaJson.composite.includeZero = this.includeZero;\n\n schemaJson.composite.units = [];\n for (const unit of this.units) {\n schemaJson.composite.units.push({\n name: unit[0].fullName,\n label: unit[1],\n });\n }\n\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n itemElement.setAttribute(\"type\", formatTypeToString(this.type).toLowerCase());\n itemElement.setAttribute(\"precision\", this.precision.toString());\n itemElement.setAttribute(\"roundFactor\", this.roundFactor.toString());\n itemElement.setAttribute(\"showSignOption\", showSignOptionToString(this.showSignOption));\n itemElement.setAttribute(\"decimalSeparator\", this.decimalSeparator);\n itemElement.setAttribute(\"thousandSeparator\", this.thousandSeparator);\n itemElement.setAttribute(\"uomSeparator\", this.uomSeparator);\n itemElement.setAttribute(\"stationSeparator\", this.stationSeparator);\n\n if (undefined !== this.minWidth)\n itemElement.setAttribute(\"minWidth\", this.minWidth.toString());\n if (undefined !== this.scientificType)\n itemElement.setAttribute(\"scientificType\", scientificTypeToString(this.scientificType));\n if (undefined !== this.stationOffsetSize)\n itemElement.setAttribute(\"stationOffsetSize\", this.stationOffsetSize.toString());\n\n const formatTraits = formatTraitsToArray(this.formatTraits);\n if (formatTraits.length > 0)\n itemElement.setAttribute(\"formatTraits\", formatTraits.join(\"|\"));\n\n if (undefined !== this.units) {\n const compositeElement = schemaXml.createElement(\"Composite\");\n if (undefined !== this.spacer)\n compositeElement.setAttribute(\"spacer\", this.spacer);\n if (undefined !== this.includeZero)\n compositeElement.setAttribute(\"includeZero\", this.includeZero.toString());\n\n this.units.forEach(([unit, label]) => {\n const unitElement = schemaXml.createElement(\"Unit\");\n if (undefined !== label)\n unitElement.setAttribute(\"label\", label);\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, unit.schema, unit.name);\n unitElement.textContent = unitName;\n compositeElement.appendChild(unitElement);\n });\n\n itemElement.appendChild(compositeElement);\n }\n\n return itemElement;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setFormatType(formatType: FormatType) {\n this._base.type = formatType;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setRoundFactor(roundFactor: number) {\n this._base.roundFactor = roundFactor;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setShowSignOption(signOption: ShowSignOption) {\n this._base.showSignOption = signOption;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setDecimalSeparator(separator: string) {\n this._base.decimalSeparator = separator;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setThousandSeparator(separator: string) {\n this._base.thousandSeparator = separator;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setUomSeparator(separator: string) {\n this._base.uomSeparator = separator;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setStationSeparator(separator: string) {\n this._base.stationSeparator = separator;\n }\n}\n\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableFormat extends Format {\n public abstract override addUnit(unit: Unit | InvertedUnit, label?: string): void;\n public abstract override setPrecision(precision: number): void;\n public abstract override setFormatType(formatType: FormatType): void;\n public abstract override setRoundFactor(roundFactor: number): void;\n public abstract override setShowSignOption(signOption: ShowSignOption): void;\n public abstract override setDecimalSeparator(separator: string): void;\n public abstract override setThousandSeparator(separator: string): void;\n public abstract override setUomSeparator(separator: string): void;\n public abstract override setStationSeparator(separator: string): void;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}