@itwin/ecschema-metadata 4.0.0-dev.7 → 4.0.0-dev.70
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.
- package/CHANGELOG.md +13 -3
- package/lib/cjs/Constants.d.ts +23 -23
- package/lib/cjs/Constants.js +33 -33
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/Context.d.ts +139 -139
- package/lib/cjs/Context.js +204 -204
- package/lib/cjs/DelayedPromise.d.ts +88 -88
- package/lib/cjs/DelayedPromise.d.ts.map +1 -1
- package/lib/cjs/DelayedPromise.js +91 -91
- package/lib/cjs/DelayedPromise.js.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
- package/lib/cjs/Deserialization/AbstractParser.d.ts.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.js +11 -11
- package/lib/cjs/Deserialization/Helper.d.ts +251 -251
- package/lib/cjs/Deserialization/Helper.js +843 -843
- package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
- package/lib/cjs/Deserialization/JsonParser.js +680 -680
- package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
- package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.js +9 -9
- package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
- package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
- package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
- package/lib/cjs/Deserialization/XmlParser.js +973 -973
- package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
- package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
- package/lib/cjs/ECName.d.ts +30 -30
- package/lib/cjs/ECName.js +85 -85
- package/lib/cjs/ECObjects.d.ts +162 -162
- package/lib/cjs/ECObjects.js +453 -453
- package/lib/cjs/Exception.d.ts +43 -43
- package/lib/cjs/Exception.js +84 -84
- package/lib/cjs/Interfaces.d.ts +66 -66
- package/lib/cjs/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Interfaces.js +9 -9
- package/lib/cjs/Metadata/Class.d.ts +243 -243
- package/lib/cjs/Metadata/Class.js +558 -558
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.d.ts +64 -64
- package/lib/cjs/Metadata/Constant.js +123 -123
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
- package/lib/cjs/Metadata/CustomAttribute.js +27 -27
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
- package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
- package/lib/cjs/Metadata/EntityClass.js +230 -230
- package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
- package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/cjs/Metadata/Enumeration.js +159 -159
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +98 -98
- package/lib/cjs/Metadata/Format.js +242 -242
- package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
- package/lib/cjs/Metadata/InvertedUnit.js +97 -97
- package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
- package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.d.ts +54 -54
- package/lib/cjs/Metadata/Mixin.js +113 -113
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
- package/lib/cjs/Metadata/OverrideFormat.js +88 -88
- package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
- package/lib/cjs/Metadata/Phenomenon.js +59 -59
- package/lib/cjs/Metadata/Property.d.ts +197 -197
- package/lib/cjs/Metadata/Property.d.ts.map +1 -1
- package/lib/cjs/Metadata/Property.js +491 -491
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
- package/lib/cjs/Metadata/PropertyCategory.js +61 -61
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
- package/lib/cjs/Metadata/RelationshipClass.js +349 -349
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +291 -291
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +520 -520
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
- package/lib/cjs/Metadata/SchemaItem.js +136 -136
- package/lib/cjs/Metadata/Unit.d.ts +76 -76
- package/lib/cjs/Metadata/Unit.js +162 -162
- package/lib/cjs/Metadata/Unit.js.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
- package/lib/cjs/Metadata/UnitSystem.js +29 -29
- package/lib/cjs/PropertyTypes.d.ts +49 -49
- package/lib/cjs/PropertyTypes.js +91 -91
- package/lib/cjs/PropertyTypes.js.map +1 -1
- package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
- package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaJsonLocater.js +42 -42
- package/lib/cjs/SchemaKey.d.ts +110 -110
- package/lib/cjs/SchemaKey.js +219 -219
- package/lib/cjs/SchemaLoader.d.ts +23 -23
- package/lib/cjs/SchemaLoader.js +47 -47
- package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
- package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
- package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
- package/lib/cjs/UnitConversion/Graph.js +83 -83
- package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
- package/lib/cjs/UnitConversion/Parser.js +42 -42
- package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
- package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
- package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
- package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
- package/lib/cjs/UnitConversion/UnitTree.js +169 -169
- package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js +234 -236
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
- package/lib/cjs/Validation/SchemaWalker.js +53 -53
- package/lib/cjs/ecschema-metadata.d.ts +51 -51
- package/lib/cjs/ecschema-metadata.js +100 -96
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
- package/lib/cjs/utils/SchemaGraph.js +65 -65
- package/package.json +11 -11
|
@@ -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,50 +1,50 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Metadata
|
|
3
|
-
*/
|
|
4
|
-
import { InvertedUnitProps } from "../Deserialization/JsonProps";
|
|
5
|
-
import { SchemaItemType } from "../ECObjects";
|
|
6
|
-
import { LazyLoadedUnit, LazyLoadedUnitSystem } from "../Interfaces";
|
|
7
|
-
import { Schema } from "./Schema";
|
|
8
|
-
import { SchemaItem } from "./SchemaItem";
|
|
9
|
-
/**
|
|
10
|
-
* An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.
|
|
11
|
-
* @beta
|
|
12
|
-
*/
|
|
13
|
-
export declare class InvertedUnit extends SchemaItem {
|
|
14
|
-
readonly schemaItemType: SchemaItemType.InvertedUnit;
|
|
15
|
-
protected _invertsUnit?: LazyLoadedUnit;
|
|
16
|
-
protected _unitSystem?: LazyLoadedUnitSystem;
|
|
17
|
-
constructor(schema: Schema, name: string);
|
|
18
|
-
get invertsUnit(): LazyLoadedUnit | undefined;
|
|
19
|
-
get unitSystem(): LazyLoadedUnitSystem | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Save this InvertedUnit's properties to an object for serializing to JSON.
|
|
22
|
-
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
23
|
-
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
24
|
-
*/
|
|
25
|
-
toJSON(standalone?: boolean, includeSchemaVersion?: boolean): InvertedUnitProps;
|
|
26
|
-
/** @internal */
|
|
27
|
-
toXml(schemaXml: Document): Promise<Element>;
|
|
28
|
-
fromJSONSync(invertedUnitProps: InvertedUnitProps): void;
|
|
29
|
-
fromJSON(invertedUnitProps: InvertedUnitProps): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* @alpha
|
|
32
|
-
* Used for schema editing
|
|
33
|
-
*/
|
|
34
|
-
protected setInvertsUnit(invertsUnit: LazyLoadedUnit): void;
|
|
35
|
-
/**
|
|
36
|
-
* @alpha
|
|
37
|
-
* Used for schema editing
|
|
38
|
-
*/
|
|
39
|
-
protected setUnitSystem(unitSystem: LazyLoadedUnitSystem): void;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @internal
|
|
43
|
-
* An abstract class used for schema editing.
|
|
44
|
-
*/
|
|
45
|
-
export declare abstract class MutableInvertedUnit extends InvertedUnit {
|
|
46
|
-
abstract setInvertsUnit(invertsUnit: LazyLoadedUnit): void;
|
|
47
|
-
abstract setUnitSystem(unitSystem: LazyLoadedUnitSystem): void;
|
|
48
|
-
abstract setDisplayLabel(displayLabel: string): void;
|
|
49
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Metadata
|
|
3
|
+
*/
|
|
4
|
+
import { InvertedUnitProps } from "../Deserialization/JsonProps";
|
|
5
|
+
import { SchemaItemType } from "../ECObjects";
|
|
6
|
+
import { LazyLoadedUnit, LazyLoadedUnitSystem } from "../Interfaces";
|
|
7
|
+
import { Schema } from "./Schema";
|
|
8
|
+
import { SchemaItem } from "./SchemaItem";
|
|
9
|
+
/**
|
|
10
|
+
* An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export declare class InvertedUnit extends SchemaItem {
|
|
14
|
+
readonly schemaItemType: SchemaItemType.InvertedUnit;
|
|
15
|
+
protected _invertsUnit?: LazyLoadedUnit;
|
|
16
|
+
protected _unitSystem?: LazyLoadedUnitSystem;
|
|
17
|
+
constructor(schema: Schema, name: string);
|
|
18
|
+
get invertsUnit(): LazyLoadedUnit | undefined;
|
|
19
|
+
get unitSystem(): LazyLoadedUnitSystem | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Save this InvertedUnit's properties to an object for serializing to JSON.
|
|
22
|
+
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
23
|
+
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
24
|
+
*/
|
|
25
|
+
toJSON(standalone?: boolean, includeSchemaVersion?: boolean): InvertedUnitProps;
|
|
26
|
+
/** @internal */
|
|
27
|
+
toXml(schemaXml: Document): Promise<Element>;
|
|
28
|
+
fromJSONSync(invertedUnitProps: InvertedUnitProps): void;
|
|
29
|
+
fromJSON(invertedUnitProps: InvertedUnitProps): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* @alpha
|
|
32
|
+
* Used for schema editing
|
|
33
|
+
*/
|
|
34
|
+
protected setInvertsUnit(invertsUnit: LazyLoadedUnit): void;
|
|
35
|
+
/**
|
|
36
|
+
* @alpha
|
|
37
|
+
* Used for schema editing
|
|
38
|
+
*/
|
|
39
|
+
protected setUnitSystem(unitSystem: LazyLoadedUnitSystem): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
* An abstract class used for schema editing.
|
|
44
|
+
*/
|
|
45
|
+
export declare abstract class MutableInvertedUnit extends InvertedUnit {
|
|
46
|
+
abstract setInvertsUnit(invertsUnit: LazyLoadedUnit): void;
|
|
47
|
+
abstract setUnitSystem(unitSystem: LazyLoadedUnitSystem): void;
|
|
48
|
+
abstract setDisplayLabel(displayLabel: string): void;
|
|
49
|
+
}
|
|
50
50
|
//# sourceMappingURL=InvertedUnit.d.ts.map
|