@itwin/ecschema-metadata 5.0.0-dev.98 → 5.1.0-dev.0
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 +6 -1
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/Context.d.ts +3 -3
- package/lib/cjs/Context.d.ts.map +1 -1
- package/lib/cjs/Context.js +6 -6
- package/lib/cjs/Context.js.map +1 -1
- package/lib/cjs/DelayedPromise.d.ts +9 -8
- package/lib/cjs/DelayedPromise.d.ts.map +1 -1
- package/lib/cjs/DelayedPromise.js +2 -2
- package/lib/cjs/DelayedPromise.js.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
- package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
- package/lib/cjs/Deserialization/Helper.js +27 -26
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Deserialization/JsonParser.js +150 -150
- package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.d.ts +34 -34
- package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.js +3 -3
- package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
- package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.js +49 -49
- package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +0 -5
- package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.js +6 -11
- package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/cjs/ECName.d.ts +2 -2
- package/lib/cjs/ECName.js +4 -4
- package/lib/cjs/ECName.js.map +1 -1
- package/lib/cjs/ECObjects.d.ts +23 -11
- package/lib/cjs/ECObjects.d.ts.map +1 -1
- package/lib/cjs/ECObjects.js +47 -24
- package/lib/cjs/ECObjects.js.map +1 -1
- package/lib/cjs/Exception.d.ts +4 -4
- package/lib/cjs/Exception.d.ts.map +1 -1
- package/lib/cjs/Exception.js +60 -60
- package/lib/cjs/Exception.js.map +1 -1
- package/lib/cjs/Interfaces.d.ts +30 -34
- package/lib/cjs/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Metadata/Class.d.ts +107 -19
- package/lib/cjs/Metadata/Class.d.ts.map +1 -1
- package/lib/cjs/Metadata/Class.js +127 -47
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.d.ts +12 -9
- package/lib/cjs/Metadata/Constant.d.ts.map +1 -1
- package/lib/cjs/Metadata/Constant.js +12 -9
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.d.ts +2 -2
- package/lib/cjs/Metadata/CustomAttribute.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +5 -3
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js +7 -5
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.d.ts +20 -3
- package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/EntityClass.js +32 -14
- package/lib/cjs/Metadata/EntityClass.js.map +1 -1
- package/lib/cjs/Metadata/Enumeration.d.ts +16 -9
- package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/cjs/Metadata/Enumeration.js +20 -13
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +32 -24
- package/lib/cjs/Metadata/Format.d.ts.map +1 -1
- package/lib/cjs/Metadata/Format.js +47 -27
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.d.ts +11 -7
- package/lib/cjs/Metadata/InvertedUnit.d.ts.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.js +16 -10
- package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.d.ts +24 -15
- package/lib/cjs/Metadata/KindOfQuantity.d.ts.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.js +54 -29
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.d.ts +16 -3
- package/lib/cjs/Metadata/Mixin.d.ts.map +1 -1
- package/lib/cjs/Metadata/Mixin.js +20 -7
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts +12 -12
- package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.js +27 -19
- package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.d.ts +10 -2
- package/lib/cjs/Metadata/Phenomenon.d.ts.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.js +11 -3
- package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
- package/lib/cjs/Metadata/Property.d.ts +46 -28
- package/lib/cjs/Metadata/Property.d.ts.map +1 -1
- package/lib/cjs/Metadata/Property.js +46 -22
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.d.ts +6 -3
- package/lib/cjs/Metadata/PropertyCategory.d.ts.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.js +12 -5
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.d.ts +48 -25
- package/lib/cjs/Metadata/RelationshipClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.js +54 -34
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +50 -28
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +64 -42
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +10 -19
- package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.js +12 -20
- package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
- package/lib/cjs/Metadata/Unit.d.ts +17 -21
- package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
- package/lib/cjs/Metadata/Unit.js +20 -22
- package/lib/cjs/Metadata/Unit.js.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.d.ts +3 -1
- package/lib/cjs/Metadata/UnitSystem.d.ts.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.js +4 -2
- package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
- package/lib/cjs/PropertyTypes.d.ts +11 -11
- package/lib/cjs/PropertyTypes.d.ts.map +1 -1
- package/lib/cjs/PropertyTypes.js +28 -20
- package/lib/cjs/PropertyTypes.js.map +1 -1
- package/lib/cjs/SchemaFormatsProvider.d.ts +39 -0
- package/lib/cjs/SchemaFormatsProvider.d.ts.map +1 -0
- package/lib/cjs/SchemaFormatsProvider.js +146 -0
- package/lib/cjs/SchemaFormatsProvider.js.map +1 -0
- package/lib/cjs/SchemaJsonLocater.d.ts +5 -5
- package/lib/cjs/SchemaJsonLocater.js +4 -4
- package/lib/cjs/SchemaJsonLocater.js.map +1 -1
- package/lib/cjs/SchemaKey.d.ts +6 -6
- package/lib/cjs/SchemaKey.d.ts.map +1 -1
- package/lib/cjs/SchemaKey.js +9 -9
- package/lib/cjs/SchemaKey.js.map +1 -1
- package/lib/cjs/SchemaLoader.d.ts +3 -3
- package/lib/cjs/SchemaLoader.js +4 -4
- package/lib/cjs/SchemaLoader.js.map +1 -1
- package/lib/cjs/SchemaPartVisitorDelegate.d.ts +2 -2
- package/lib/cjs/SchemaPartVisitorDelegate.js +1 -1
- package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
- package/lib/cjs/UnitConversion/Graph.js.map +1 -1
- package/lib/cjs/UnitConversion/Parser.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-metadata.d.ts +2 -1
- package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
- package/lib/cjs/ecschema-metadata.js +1 -0
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaGraph.js +3 -3
- package/lib/cjs/utils/SchemaGraph.js.map +1 -1
- package/lib/esm/Constants.js.map +1 -1
- package/lib/esm/Context.d.ts +3 -3
- package/lib/esm/Context.d.ts.map +1 -1
- package/lib/esm/Context.js +7 -7
- package/lib/esm/Context.js.map +1 -1
- package/lib/esm/DelayedPromise.d.ts +9 -8
- package/lib/esm/DelayedPromise.d.ts.map +1 -1
- package/lib/esm/DelayedPromise.js +2 -2
- package/lib/esm/DelayedPromise.js.map +1 -1
- package/lib/esm/Deserialization/AbstractParser.js.map +1 -1
- package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
- package/lib/esm/Deserialization/Helper.js +28 -27
- package/lib/esm/Deserialization/Helper.js.map +1 -1
- package/lib/esm/Deserialization/JsonParser.js +151 -151
- package/lib/esm/Deserialization/JsonParser.js.map +1 -1
- package/lib/esm/Deserialization/JsonProps.d.ts +34 -34
- package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/esm/Deserialization/JsonProps.js +3 -3
- package/lib/esm/Deserialization/JsonProps.js.map +1 -1
- package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -1
- package/lib/esm/Deserialization/XmlParser.js +50 -50
- package/lib/esm/Deserialization/XmlParser.js.map +1 -1
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +0 -5
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
- package/lib/esm/Deserialization/XmlSerializationUtils.js +7 -12
- package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/esm/ECName.d.ts +2 -2
- package/lib/esm/ECName.js +5 -5
- package/lib/esm/ECName.js.map +1 -1
- package/lib/esm/ECObjects.d.ts +23 -11
- package/lib/esm/ECObjects.d.ts.map +1 -1
- package/lib/esm/ECObjects.js +48 -25
- package/lib/esm/ECObjects.js.map +1 -1
- package/lib/esm/Exception.d.ts +4 -4
- package/lib/esm/Exception.d.ts.map +1 -1
- package/lib/esm/Exception.js +58 -58
- package/lib/esm/Exception.js.map +1 -1
- package/lib/esm/Interfaces.d.ts +30 -34
- package/lib/esm/Interfaces.d.ts.map +1 -1
- package/lib/esm/Interfaces.js.map +1 -1
- package/lib/esm/Metadata/Class.d.ts +107 -19
- package/lib/esm/Metadata/Class.d.ts.map +1 -1
- package/lib/esm/Metadata/Class.js +128 -48
- package/lib/esm/Metadata/Class.js.map +1 -1
- package/lib/esm/Metadata/Constant.d.ts +12 -9
- package/lib/esm/Metadata/Constant.d.ts.map +1 -1
- package/lib/esm/Metadata/Constant.js +13 -10
- package/lib/esm/Metadata/Constant.js.map +1 -1
- package/lib/esm/Metadata/CustomAttribute.d.ts +2 -2
- package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -1
- package/lib/esm/Metadata/CustomAttribute.js.map +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.d.ts +5 -3
- package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.js +8 -6
- package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/esm/Metadata/EntityClass.d.ts +20 -3
- package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/esm/Metadata/EntityClass.js +33 -15
- package/lib/esm/Metadata/EntityClass.js.map +1 -1
- package/lib/esm/Metadata/Enumeration.d.ts +16 -9
- package/lib/esm/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/esm/Metadata/Enumeration.js +21 -14
- package/lib/esm/Metadata/Enumeration.js.map +1 -1
- package/lib/esm/Metadata/Format.d.ts +32 -24
- package/lib/esm/Metadata/Format.d.ts.map +1 -1
- package/lib/esm/Metadata/Format.js +48 -28
- package/lib/esm/Metadata/Format.js.map +1 -1
- package/lib/esm/Metadata/InvertedUnit.d.ts +11 -7
- package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -1
- package/lib/esm/Metadata/InvertedUnit.js +17 -11
- package/lib/esm/Metadata/InvertedUnit.js.map +1 -1
- package/lib/esm/Metadata/KindOfQuantity.d.ts +24 -15
- package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -1
- package/lib/esm/Metadata/KindOfQuantity.js +55 -30
- package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/esm/Metadata/Mixin.d.ts +16 -3
- package/lib/esm/Metadata/Mixin.d.ts.map +1 -1
- package/lib/esm/Metadata/Mixin.js +21 -8
- package/lib/esm/Metadata/Mixin.js.map +1 -1
- package/lib/esm/Metadata/OverrideFormat.d.ts +12 -12
- package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -1
- package/lib/esm/Metadata/OverrideFormat.js +28 -20
- package/lib/esm/Metadata/OverrideFormat.js.map +1 -1
- package/lib/esm/Metadata/Phenomenon.d.ts +10 -2
- package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -1
- package/lib/esm/Metadata/Phenomenon.js +12 -4
- package/lib/esm/Metadata/Phenomenon.js.map +1 -1
- package/lib/esm/Metadata/Property.d.ts +46 -28
- package/lib/esm/Metadata/Property.d.ts.map +1 -1
- package/lib/esm/Metadata/Property.js +47 -23
- package/lib/esm/Metadata/Property.js.map +1 -1
- package/lib/esm/Metadata/PropertyCategory.d.ts +6 -3
- package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -1
- package/lib/esm/Metadata/PropertyCategory.js +13 -6
- package/lib/esm/Metadata/PropertyCategory.js.map +1 -1
- package/lib/esm/Metadata/RelationshipClass.d.ts +48 -25
- package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -1
- package/lib/esm/Metadata/RelationshipClass.js +55 -35
- package/lib/esm/Metadata/RelationshipClass.js.map +1 -1
- package/lib/esm/Metadata/Schema.d.ts +50 -28
- package/lib/esm/Metadata/Schema.d.ts.map +1 -1
- package/lib/esm/Metadata/Schema.js +65 -43
- package/lib/esm/Metadata/Schema.js.map +1 -1
- package/lib/esm/Metadata/SchemaItem.d.ts +10 -19
- package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/esm/Metadata/SchemaItem.js +13 -21
- package/lib/esm/Metadata/SchemaItem.js.map +1 -1
- package/lib/esm/Metadata/Unit.d.ts +17 -21
- package/lib/esm/Metadata/Unit.d.ts.map +1 -1
- package/lib/esm/Metadata/Unit.js +21 -23
- package/lib/esm/Metadata/Unit.js.map +1 -1
- package/lib/esm/Metadata/UnitSystem.d.ts +3 -1
- package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -1
- package/lib/esm/Metadata/UnitSystem.js +5 -3
- package/lib/esm/Metadata/UnitSystem.js.map +1 -1
- package/lib/esm/PropertyTypes.d.ts +11 -11
- package/lib/esm/PropertyTypes.d.ts.map +1 -1
- package/lib/esm/PropertyTypes.js +29 -21
- package/lib/esm/PropertyTypes.js.map +1 -1
- package/lib/esm/SchemaFormatsProvider.d.ts +39 -0
- package/lib/esm/SchemaFormatsProvider.d.ts.map +1 -0
- package/lib/esm/SchemaFormatsProvider.js +142 -0
- package/lib/esm/SchemaFormatsProvider.js.map +1 -0
- package/lib/esm/SchemaJsonLocater.d.ts +5 -5
- package/lib/esm/SchemaJsonLocater.js +4 -4
- package/lib/esm/SchemaJsonLocater.js.map +1 -1
- package/lib/esm/SchemaKey.d.ts +6 -6
- package/lib/esm/SchemaKey.d.ts.map +1 -1
- package/lib/esm/SchemaKey.js +10 -10
- package/lib/esm/SchemaKey.js.map +1 -1
- package/lib/esm/SchemaLoader.d.ts +3 -3
- package/lib/esm/SchemaLoader.js +5 -5
- package/lib/esm/SchemaLoader.js.map +1 -1
- package/lib/esm/SchemaPartVisitorDelegate.d.ts +2 -2
- package/lib/esm/SchemaPartVisitorDelegate.js +1 -1
- package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -1
- package/lib/esm/UnitConversion/Graph.js.map +1 -1
- package/lib/esm/UnitConversion/Parser.js.map +1 -1
- package/lib/esm/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/esm/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/esm/UnitConversion/UnitTree.js.map +1 -1
- package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/esm/Validation/SchemaWalker.js.map +1 -1
- package/lib/esm/ecschema-metadata.d.ts +2 -1
- package/lib/esm/ecschema-metadata.d.ts.map +1 -1
- package/lib/esm/ecschema-metadata.js +1 -0
- package/lib/esm/ecschema-metadata.js.map +1 -1
- package/lib/esm/utils/SchemaGraph.js +4 -4
- package/lib/esm/utils/SchemaGraph.js.map +1 -1
- package/package.json +8 -6
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { SchemaReadHelper } from "../Deserialization/Helper";
|
|
9
9
|
import { PrimitiveType, primitiveTypeToString, SchemaItemType } from "../ECObjects";
|
|
10
|
-
import {
|
|
10
|
+
import { ECSchemaError, ECSchemaStatus } from "../Exception";
|
|
11
11
|
import { ECName } from "../ECName";
|
|
12
12
|
import { SchemaItem } from "./SchemaItem";
|
|
13
13
|
/**
|
|
14
14
|
* A Typescript class representation of an ECEnumeration.
|
|
15
|
-
* @
|
|
15
|
+
* @public @preview
|
|
16
16
|
*/
|
|
17
17
|
export class Enumeration extends SchemaItem {
|
|
18
18
|
schemaItemType = Enumeration.schemaItemType;
|
|
19
|
+
/** @internal */
|
|
19
20
|
static get schemaItemType() { return SchemaItemType.Enumeration; }
|
|
20
21
|
_type;
|
|
21
22
|
_isStrict;
|
|
@@ -23,6 +24,7 @@ export class Enumeration extends SchemaItem {
|
|
|
23
24
|
get enumerators() { return this._enumerators; }
|
|
24
25
|
get type() { return this._type; }
|
|
25
26
|
get isStrict() { return this._isStrict; }
|
|
27
|
+
/** @internal */
|
|
26
28
|
constructor(schema, name, primitiveType) {
|
|
27
29
|
super(schema, name);
|
|
28
30
|
this._type = primitiveType;
|
|
@@ -50,9 +52,9 @@ export class Enumeration extends SchemaItem {
|
|
|
50
52
|
findDuplicateEnumerators(name, value) {
|
|
51
53
|
this._enumerators.forEach((element) => {
|
|
52
54
|
if (element.name.toLowerCase() === name.toLowerCase())
|
|
53
|
-
throw new
|
|
55
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
|
|
54
56
|
if (element.value === value)
|
|
55
|
-
throw new
|
|
57
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
@@ -62,23 +64,25 @@ export class Enumeration extends SchemaItem {
|
|
|
62
64
|
* @param label A localized display label that is used instead of the name in a GUI.
|
|
63
65
|
* @param description A localized description for the enumerator.
|
|
64
66
|
* @return AnyEnumerator object
|
|
67
|
+
* @internal
|
|
65
68
|
*/
|
|
66
69
|
createEnumerator(name, value, label, description) {
|
|
67
70
|
if (this.isInt && typeof (value) === "string") // throws if backing type is int and value is string
|
|
68
|
-
throw new
|
|
71
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
|
|
69
72
|
if (!this.isInt && typeof (value) === "number") // also throws if backing type is string and value is number
|
|
70
|
-
throw new
|
|
73
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
|
|
71
74
|
this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any
|
|
72
75
|
if (!ECName.validate(name))
|
|
73
|
-
throw new
|
|
76
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
|
|
74
77
|
return { name, value, label, description };
|
|
75
78
|
}
|
|
76
79
|
/**
|
|
77
80
|
* Adds enumerator to list of enumerators on this Enumeration
|
|
78
81
|
* @param enumerator The enumerator to add
|
|
82
|
+
* @internal
|
|
79
83
|
*/
|
|
80
84
|
addEnumerator(enumerator) {
|
|
81
|
-
this.
|
|
85
|
+
this._enumerators.push(enumerator);
|
|
82
86
|
}
|
|
83
87
|
/**
|
|
84
88
|
* Save this Enumeration's properties to an object for serializing to JSON.
|
|
@@ -131,19 +135,19 @@ export class Enumeration extends SchemaItem {
|
|
|
131
135
|
if (SchemaReadHelper.isECSpecVersionNewer({ readVersion: enumerationProps.originalECSpecMajorVersion, writeVersion: enumerationProps.originalECSpecMinorVersion }))
|
|
132
136
|
this._type = PrimitiveType.String;
|
|
133
137
|
else
|
|
134
|
-
throw new
|
|
138
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
else {
|
|
138
142
|
const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;
|
|
139
143
|
if (!primitiveTypePattern.test(enumerationProps.type))
|
|
140
|
-
throw new
|
|
144
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be "${(this.isInt) ? "int" : "string"}", not "${(this.isInt) ? "string" : "int"}".`);
|
|
141
145
|
}
|
|
142
146
|
this._isStrict = enumerationProps.isStrict;
|
|
143
147
|
if (undefined !== enumerationProps.enumerators) {
|
|
144
148
|
enumerationProps.enumerators.forEach((enumerator) => {
|
|
145
149
|
// Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.
|
|
146
|
-
// Throws
|
|
150
|
+
// Throws ECSchemaError if there are duplicate names or values present in the enumeration
|
|
147
151
|
this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));
|
|
148
152
|
});
|
|
149
153
|
}
|
|
@@ -152,7 +156,7 @@ export class Enumeration extends SchemaItem {
|
|
|
152
156
|
this.fromJSONSync(enumerationProps);
|
|
153
157
|
}
|
|
154
158
|
/**
|
|
155
|
-
* @
|
|
159
|
+
* @internal
|
|
156
160
|
*/
|
|
157
161
|
setIsStrict(isStrict) {
|
|
158
162
|
this._isStrict = isStrict;
|
|
@@ -169,14 +173,17 @@ export class Enumeration extends SchemaItem {
|
|
|
169
173
|
* Type assertion to check if the SchemaItem is of type Enumeration.
|
|
170
174
|
* @param item The SchemaItem to check.
|
|
171
175
|
* @returns The item cast to Enumeration if it is an Enumeration, undefined otherwise.
|
|
176
|
+
* @internal
|
|
172
177
|
*/
|
|
173
178
|
static assertIsEnumeration(item) {
|
|
174
179
|
if (!this.isEnumeration(item))
|
|
175
|
-
throw new
|
|
180
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);
|
|
176
181
|
}
|
|
177
182
|
}
|
|
178
|
-
/**
|
|
183
|
+
/**
|
|
179
184
|
* An abstract class used for schema editing.
|
|
185
|
+
*
|
|
186
|
+
* @internal
|
|
180
187
|
*/
|
|
181
188
|
export class MutableEnumeration extends Enumeration {
|
|
182
189
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAiB,gBAA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;gBACnE,4JAA4J;gBAC5J,0FAA0F;gBAC1F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;YACzH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,gBAAkC;QAC/D,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,WAAW,CAAC,QAAiB;QACrC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,IAAiB;QAC3C,OAAO,IAAI,EAAE,cAAc,KAAK,cAAc,CAAC,WAAW,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAiB;QACjD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YAC3B,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,qBAAqB,EAAE,aAAa,cAAc,CAAC,WAAW,iBAAiB,CAAC,CAAC;IAC9H,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;CAI3D","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 { ECSpecVersion, SchemaReadHelper } from \"../Deserialization/Helper\";\nimport { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { ECName } from \"../ECName\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\n\n/** @beta */\nexport interface Enumerator<T> {\n readonly name: string;\n readonly value: T;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** @beta */\nexport type AnyEnumerator = Enumerator<string | number>;\n\n/**\n * A Typescript class representation of an ECEnumeration.\n * @beta\n */\nexport class Enumeration extends SchemaItem {\n public override readonly schemaItemType = Enumeration.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.Enumeration; }\n protected _type?: PrimitiveType.Integer | PrimitiveType.String;\n protected _isStrict: boolean;\n protected _enumerators: AnyEnumerator[];\n\n public get enumerators() { return this._enumerators; }\n public get type() { return this._type; }\n public get isStrict() { return this._isStrict; }\n\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\n super(schema, name);\n this._type = primitiveType;\n this._isStrict = true;\n this._enumerators = [];\n }\n\n public get isInt(): boolean { return this._type === PrimitiveType.Integer; }\n public get isString(): boolean { return this._type === PrimitiveType.String; }\n\n /**\n * Gets an enumerator that matches the name provided.\n * @param name The ECName of the Enumerator to find.\n */\n public getEnumeratorByName(name: string): AnyEnumerator | undefined {\n return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());\n }\n\n /**\n * Gets an enumerator that matches the value provided.\n * @param value The value of the Enumerator to find.\n */\n public getEnumerator(value: string): Enumerator<string> | undefined;\n public getEnumerator(value: number): Enumerator<number> | undefined;\n public getEnumerator(value: string | number): AnyEnumerator | undefined {\n return this.enumerators.find((item) => item.value === value);\n }\n\n /**\n * Checks whether there already exists an enumerator with this name or this value\n * @param name The name of the enumerator we are trying to create\n * @param value The value of the enumerator we are trying to create\n * @internal\n */\n private findDuplicateEnumerators(name: string, value: string | number) {\n this._enumerators.forEach((element: AnyEnumerator) => { // Name and value must be unique within the ECEnumerations\n if (element.name.toLowerCase() === name.toLowerCase())\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\n if (element.value === value)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);\n });\n }\n\n /**\n * Creates an Enumerator with the provided name and value as well as optional parameters label and description\n * @param name The name of the enumerator\n * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.\n * @param label A localized display label that is used instead of the name in a GUI.\n * @param description A localized description for the enumerator.\n * @return AnyEnumerator object\n */\n public createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator {\n if (this.isInt && typeof (value) === \"string\") // throws if backing type is int and value is string\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);\n if (!this.isInt && typeof (value) === \"number\") // also throws if backing type is string and value is number\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);\n this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any\n if (!ECName.validate(name))\n throw new ECObjectsError(ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);\n return { name, value, label, description };\n }\n\n /**\n * Adds enumerator to list of enumerators on this Enumeration\n * @param enumerator The enumerator to add\n */\n protected addEnumerator(enumerator: AnyEnumerator) {\n this.enumerators.push(enumerator);\n }\n\n /**\n * Save this Enumeration'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): EnumerationProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.type = (this.isInt) ? \"int\" : \"string\";\n schemaJson.isStrict = this.isStrict;\n schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {\n const enumJson: any = { name, value };\n if (undefined !== label)\n enumJson.label = label;\n if (undefined !== description)\n enumJson.description = description;\n return enumJson;\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 if (undefined !== this.type)\n itemElement.setAttribute(\"backingTypeName\", primitiveTypeToString(this.type));\n itemElement.setAttribute(\"isStrict\", String(this.isStrict));\n\n for (const enumerator of this.enumerators) {\n const enumElement = schemaXml.createElement(\"ECEnumerator\");\n enumElement.setAttribute(\"name\", enumerator.name);\n const enumValue = typeof enumerator.value === \"string\" ? enumerator.value : enumerator.value.toString();\n enumElement.setAttribute(\"value\", enumValue);\n if (undefined !== enumerator.label)\n enumElement.setAttribute(\"displayLabel\", enumerator.label);\n if (undefined !== enumerator.description)\n enumElement.setAttribute(\"description\", enumerator.description);\n itemElement.appendChild(enumElement);\n }\n\n return itemElement;\n }\n\n public override fromJSONSync(enumerationProps: EnumerationProps) {\n super.fromJSONSync(enumerationProps);\n if (undefined === this._type) {\n if (/int/i.test(enumerationProps.type)) {\n this._type = PrimitiveType.Integer;\n } else if (/string/i.test(enumerationProps.type)) {\n this._type = PrimitiveType.String;\n } else {\n if (SchemaReadHelper.isECSpecVersionNewer({readVersion: enumerationProps.originalECSpecMajorVersion, writeVersion: enumerationProps.originalECSpecMinorVersion} as ECSpecVersion))\n this._type = PrimitiveType.String;\n else\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\n }\n } else {\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\n if (!primitiveTypePattern.test(enumerationProps.type))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be \"${(this.isInt) ? \"int\" : \"string\"}\", not \"${(this.isInt) ? \"string\" : \"int\"}\".`);\n }\n this._isStrict = enumerationProps.isStrict;\n\n if (undefined !== enumerationProps.enumerators) {\n enumerationProps.enumerators.forEach((enumerator: EnumeratorProps) => {\n // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.\n // Throws ECObjectsError if there are duplicate names or values present in the enumeration\n this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));\n });\n }\n }\n\n public override async fromJSON(enumerationProps: EnumerationProps) {\n this.fromJSONSync(enumerationProps);\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setIsStrict(isStrict: boolean) {\n this._isStrict = isStrict;\n }\n\n /**\n * Type guard to check if the SchemaItem is of type Enumeration.\n * @param item The SchemaItem to check.\n * @returns True if the item is an Enumeration, false otherwise.\n */\n public static isEnumeration(item?: SchemaItem): item is Enumeration {\n return item?.schemaItemType === SchemaItemType.Enumeration;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type Enumeration.\n * @param item The SchemaItem to check.\n * @returns The item cast to Enumeration if it is an Enumeration, undefined otherwise.\n */\n public static assertIsEnumeration(item?: SchemaItem): asserts item is Enumeration {\n if (!this.isEnumeration(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);\n }\n}\n\n/** @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableEnumeration extends Enumeration {\n public abstract override addEnumerator(enumerator: AnyEnumerator): void;\n public abstract override setIsStrict(isStrict: boolean): void;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAiB,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,UA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CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,gBAAkC;QAC/D,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,WAAW,CAAC,QAAiB;QACrC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,IAAiB;QAC3C,OAAO,IAAI,EAAE,cAAc,KAAK,cAAc,CAAC,WAAW,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAiB;QACjD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YAC3B,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,qBAAqB,EAAE,aAAa,cAAc,CAAC,WAAW,iBAAiB,CAAC,CAAC;IAC5H,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;CAI3D","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 { ECSpecVersion, SchemaReadHelper } from \"../Deserialization/Helper\";\r\nimport { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\r\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\r\nimport { ECSchemaError, ECSchemaStatus } from \"../Exception\";\r\nimport { ECName } from \"../ECName\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\n\r\n/** @public @preview */\r\nexport interface Enumerator<T> {\r\n readonly name: string;\r\n readonly value: T;\r\n readonly label?: string;\r\n readonly description?: string;\r\n}\r\n\r\n/** @public @preview */\r\nexport type AnyEnumerator = Enumerator<string | number>;\r\n\r\n/**\r\n * A Typescript class representation of an ECEnumeration.\r\n * @public @preview\r\n */\r\nexport class Enumeration extends SchemaItem {\r\n public override readonly schemaItemType = Enumeration.schemaItemType;\r\n /** @internal */\r\n public static override get schemaItemType() { return SchemaItemType.Enumeration; }\r\n private _type?: PrimitiveType.Integer | PrimitiveType.String;\r\n private _isStrict: boolean;\r\n private _enumerators: AnyEnumerator[];\r\n\r\n public get enumerators(): ReadonlyArray<AnyEnumerator> { return this._enumerators; }\r\n public get type() { return this._type; }\r\n public get isStrict() { return this._isStrict; }\r\n\r\n /** @internal */\r\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\r\n super(schema, name);\r\n this._type = primitiveType;\r\n this._isStrict = true;\r\n this._enumerators = [];\r\n }\r\n\r\n public get isInt(): boolean { return this._type === PrimitiveType.Integer; }\r\n public get isString(): boolean { return this._type === PrimitiveType.String; }\r\n\r\n /**\r\n * Gets an enumerator that matches the name provided.\r\n * @param name The ECName of the Enumerator to find.\r\n */\r\n public getEnumeratorByName(name: string): AnyEnumerator | undefined {\r\n return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());\r\n }\r\n\r\n /**\r\n * Gets an enumerator that matches the value provided.\r\n * @param value The value of the Enumerator to find.\r\n */\r\n public getEnumerator(value: string): Enumerator<string> | undefined;\r\n public getEnumerator(value: number): Enumerator<number> | undefined;\r\n public getEnumerator(value: string | number): AnyEnumerator | undefined {\r\n return this.enumerators.find((item) => item.value === value);\r\n }\r\n\r\n /**\r\n * Checks whether there already exists an enumerator with this name or this value\r\n * @param name The name of the enumerator we are trying to create\r\n * @param value The value of the enumerator we are trying to create\r\n * @internal\r\n */\r\n private findDuplicateEnumerators(name: string, value: string | number) {\r\n this._enumerators.forEach((element: AnyEnumerator) => { // Name and value must be unique within the ECEnumerations\r\n if (element.name.toLowerCase() === name.toLowerCase())\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\r\n if (element.value === value)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);\r\n });\r\n }\r\n\r\n /**\r\n * Creates an Enumerator with the provided name and value as well as optional parameters label and description\r\n * @param name The name of the enumerator\r\n * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.\r\n * @param label A localized display label that is used instead of the name in a GUI.\r\n * @param description A localized description for the enumerator.\r\n * @return AnyEnumerator object\r\n * @internal\r\n */\r\n public createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator {\r\n if (this.isInt && typeof (value) === \"string\") // throws if backing type is int and value is string\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);\r\n if (!this.isInt && typeof (value) === \"number\") // also throws if backing type is string and value is number\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);\r\n this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any\r\n if (!ECName.validate(name))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);\r\n return { name, value, label, description };\r\n }\r\n\r\n /**\r\n * Adds enumerator to list of enumerators on this Enumeration\r\n * @param enumerator The enumerator to add\r\n * @internal\r\n */\r\n protected addEnumerator(enumerator: AnyEnumerator) {\r\n this._enumerators.push(enumerator);\r\n }\r\n\r\n /**\r\n * Save this Enumeration'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): EnumerationProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.type = (this.isInt) ? \"int\" : \"string\";\r\n schemaJson.isStrict = this.isStrict;\r\n schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {\r\n const enumJson: any = { name, value };\r\n if (undefined !== label)\r\n enumJson.label = label;\r\n if (undefined !== description)\r\n enumJson.description = description;\r\n return enumJson;\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 if (undefined !== this.type)\r\n itemElement.setAttribute(\"backingTypeName\", primitiveTypeToString(this.type));\r\n itemElement.setAttribute(\"isStrict\", String(this.isStrict));\r\n\r\n for (const enumerator of this.enumerators) {\r\n const enumElement = schemaXml.createElement(\"ECEnumerator\");\r\n enumElement.setAttribute(\"name\", enumerator.name);\r\n const enumValue = typeof enumerator.value === \"string\" ? enumerator.value : enumerator.value.toString();\r\n enumElement.setAttribute(\"value\", enumValue);\r\n if (undefined !== enumerator.label)\r\n enumElement.setAttribute(\"displayLabel\", enumerator.label);\r\n if (undefined !== enumerator.description)\r\n enumElement.setAttribute(\"description\", enumerator.description);\r\n itemElement.appendChild(enumElement);\r\n }\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(enumerationProps: EnumerationProps) {\r\n super.fromJSONSync(enumerationProps);\r\n if (undefined === this._type) {\r\n if (/int/i.test(enumerationProps.type)) {\r\n this._type = PrimitiveType.Integer;\r\n } else if (/string/i.test(enumerationProps.type)) {\r\n this._type = PrimitiveType.String;\r\n } else {\r\n if (SchemaReadHelper.isECSpecVersionNewer({ readVersion: enumerationProps.originalECSpecMajorVersion, writeVersion: enumerationProps.originalECSpecMinorVersion } as ECSpecVersion))\r\n this._type = PrimitiveType.String;\r\n else\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\r\n }\r\n } else {\r\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\r\n if (!primitiveTypePattern.test(enumerationProps.type))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be \"${(this.isInt) ? \"int\" : \"string\"}\", not \"${(this.isInt) ? \"string\" : \"int\"}\".`);\r\n }\r\n this._isStrict = enumerationProps.isStrict;\r\n\r\n if (undefined !== enumerationProps.enumerators) {\r\n enumerationProps.enumerators.forEach((enumerator: EnumeratorProps) => {\r\n // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.\r\n // Throws ECSchemaError if there are duplicate names or values present in the enumeration\r\n this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));\r\n });\r\n }\r\n }\r\n\r\n public override async fromJSON(enumerationProps: EnumerationProps) {\r\n this.fromJSONSync(enumerationProps);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n protected setIsStrict(isStrict: boolean) {\r\n this._isStrict = isStrict;\r\n }\r\n\r\n /**\r\n * Type guard to check if the SchemaItem is of type Enumeration.\r\n * @param item The SchemaItem to check.\r\n * @returns True if the item is an Enumeration, false otherwise.\r\n */\r\n public static isEnumeration(item?: SchemaItem): item is Enumeration {\r\n return item?.schemaItemType === SchemaItemType.Enumeration;\r\n }\r\n\r\n /**\r\n * Type assertion to check if the SchemaItem is of type Enumeration.\r\n * @param item The SchemaItem to check.\r\n * @returns The item cast to Enumeration if it is an Enumeration, undefined otherwise.\r\n * @internal\r\n */\r\n public static assertIsEnumeration(item?: SchemaItem): asserts item is Enumeration {\r\n if (!this.isEnumeration(item))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);\r\n }\r\n}\r\n\r\n/**\r\n * An abstract class used for schema editing.\r\n *\r\n * @internal\r\n */\r\nexport abstract class MutableEnumeration extends Enumeration {\r\n public abstract override addEnumerator(enumerator: AnyEnumerator): void;\r\n public abstract override setIsStrict(isStrict: boolean): void;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { SchemaItemFormatProps } from "../Deserialization/JsonProps";
|
|
5
5
|
import { SchemaItemType } from "../ECObjects";
|
|
6
|
-
import {
|
|
7
|
-
import { InvertedUnit } from "./InvertedUnit";
|
|
6
|
+
import { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from "@itwin/core-quantity";
|
|
8
7
|
import { Schema } from "./Schema";
|
|
9
8
|
import { SchemaItem } from "./SchemaItem";
|
|
10
|
-
import {
|
|
9
|
+
import { LazyLoadedInvertedUnit, LazyLoadedUnit } from "../Interfaces";
|
|
11
10
|
/**
|
|
12
|
-
* @
|
|
11
|
+
* @public @preview
|
|
13
12
|
*/
|
|
14
13
|
export declare class Format extends SchemaItem {
|
|
15
14
|
readonly schemaItemType: SchemaItemType;
|
|
15
|
+
/** @internal */
|
|
16
16
|
static get schemaItemType(): SchemaItemType;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
private _base;
|
|
18
|
+
private _units?;
|
|
19
|
+
/** @internal */
|
|
19
20
|
constructor(schema: Schema, name: string);
|
|
20
21
|
get roundFactor(): number;
|
|
21
22
|
get type(): FormatType;
|
|
@@ -31,15 +32,21 @@ export declare class Format extends SchemaItem {
|
|
|
31
32
|
get formatTraits(): FormatTraits;
|
|
32
33
|
get spacer(): string | undefined;
|
|
33
34
|
get includeZero(): boolean | undefined;
|
|
34
|
-
get units():
|
|
35
|
+
get units(): ReadonlyArray<[LazyLoadedUnit | LazyLoadedInvertedUnit, string | undefined]> | undefined;
|
|
35
36
|
private parseFormatTraits;
|
|
36
37
|
hasFormatTrait(formatTrait: FormatTraits): boolean;
|
|
37
38
|
/**
|
|
38
39
|
* Adds a Unit, or InvertedUnit, with an optional label override.
|
|
39
40
|
* @param unit The Unit, or InvertedUnit, to add to this Format.
|
|
40
41
|
* @param label A label that overrides the label defined within the Unit when a value is formatted.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
protected addUnit(unit: LazyLoadedUnit | LazyLoadedInvertedUnit, label?: string): void;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param precision
|
|
48
|
+
* @internal
|
|
41
49
|
*/
|
|
42
|
-
protected addUnit(unit: Unit | InvertedUnit, label?: string): void;
|
|
43
50
|
protected setPrecision(precision: number): void;
|
|
44
51
|
private typecheck;
|
|
45
52
|
fromJSONSync(formatProps: SchemaItemFormatProps): void;
|
|
@@ -53,61 +60,61 @@ export declare class Format extends SchemaItem {
|
|
|
53
60
|
/** @internal */
|
|
54
61
|
toXml(schemaXml: Document): Promise<Element>;
|
|
55
62
|
/**
|
|
56
|
-
* @
|
|
63
|
+
* @internal
|
|
57
64
|
*/
|
|
58
65
|
protected setFormatType(formatType: FormatType): void;
|
|
59
66
|
/**
|
|
60
|
-
* @
|
|
67
|
+
* @internal
|
|
61
68
|
*/
|
|
62
69
|
protected setRoundFactor(roundFactor: number): void;
|
|
63
70
|
/**
|
|
64
|
-
* @
|
|
71
|
+
* @internal
|
|
65
72
|
*/
|
|
66
73
|
protected setShowSignOption(signOption: ShowSignOption): void;
|
|
67
74
|
/**
|
|
68
|
-
* @
|
|
75
|
+
* @internal
|
|
69
76
|
*/
|
|
70
77
|
protected setDecimalSeparator(separator: string): void;
|
|
71
78
|
/**
|
|
72
|
-
* @
|
|
79
|
+
* @internal
|
|
73
80
|
*/
|
|
74
81
|
protected setThousandSeparator(separator: string): void;
|
|
75
82
|
/**
|
|
76
|
-
* @
|
|
83
|
+
* @internal
|
|
77
84
|
*/
|
|
78
85
|
protected setUomSeparator(separator: string): void;
|
|
79
86
|
/**
|
|
80
|
-
* @
|
|
87
|
+
* @internal
|
|
81
88
|
*/
|
|
82
89
|
protected setStationSeparator(separator: string): void;
|
|
83
90
|
/**
|
|
84
|
-
* @
|
|
91
|
+
* @internal
|
|
85
92
|
*/
|
|
86
93
|
protected setStationOffsetSize(stationOffsetSize: number): void;
|
|
87
94
|
/**
|
|
88
|
-
* @
|
|
95
|
+
* @internal
|
|
89
96
|
*/
|
|
90
97
|
protected setScientificType(scientificType: ScientificType): void;
|
|
91
98
|
/**
|
|
92
|
-
* @
|
|
99
|
+
* @internal
|
|
93
100
|
*/
|
|
94
101
|
protected setMinWidth(minWidth: number): void;
|
|
95
102
|
/**
|
|
96
|
-
* @
|
|
103
|
+
* @internal
|
|
97
104
|
*/
|
|
98
105
|
protected setSpacer(spacer: string): void;
|
|
99
106
|
/**
|
|
100
|
-
* @
|
|
107
|
+
* @internal
|
|
101
108
|
*/
|
|
102
109
|
protected setIncludeZero(includeZero: boolean): void;
|
|
103
110
|
/**
|
|
104
|
-
* @
|
|
111
|
+
* @internal
|
|
105
112
|
*/
|
|
106
113
|
protected setFormatTraits(formatTraits: FormatTraits): void;
|
|
107
114
|
/**
|
|
108
|
-
* @
|
|
115
|
+
* @internal
|
|
109
116
|
*/
|
|
110
|
-
protected setUnits(units: Array<[
|
|
117
|
+
protected setUnits(units: Array<[LazyLoadedUnit | LazyLoadedInvertedUnit, string | undefined]>): void;
|
|
111
118
|
/** Type guard to check if the SchemaItem is of type Format.
|
|
112
119
|
* @param item The SchemaItem to check.
|
|
113
120
|
* @returns True if the item is a Format, false otherwise.
|
|
@@ -117,6 +124,7 @@ export declare class Format extends SchemaItem {
|
|
|
117
124
|
* Type assertion to check if the SchemaItem is of type Format.
|
|
118
125
|
* @param item The SchemaItem to check.
|
|
119
126
|
* @returns The item cast to Format if it is a Format, undefined otherwise.
|
|
127
|
+
* @internal
|
|
120
128
|
*/
|
|
121
129
|
static assertIsFormat(item?: SchemaItem): asserts item is Format;
|
|
122
130
|
}
|
|
@@ -125,7 +133,7 @@ export declare class Format extends SchemaItem {
|
|
|
125
133
|
* An abstract class used for schema editing.
|
|
126
134
|
*/
|
|
127
135
|
export declare abstract class MutableFormat extends Format {
|
|
128
|
-
abstract addUnit(unit:
|
|
136
|
+
abstract addUnit(unit: LazyLoadedUnit | LazyLoadedInvertedUnit, label?: string): void;
|
|
129
137
|
abstract setPrecision(precision: number): void;
|
|
130
138
|
abstract setFormatType(formatType: FormatType): void;
|
|
131
139
|
abstract setRoundFactor(roundFactor: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Format.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Format.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,
|
|
1
|
+
{"version":3,"file":"Format.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Format.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EACO,gBAAgB,EAAE,YAAY,EAAuB,UAAU,EAAE,mBAAmB,EAChG,cAAc,EAAE,cAAc,EAC/B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGvE;;GAEG;AACH,qBAAa,MAAO,SAAQ,UAAU;IACpC,SAAyB,cAAc,iBAAyB;IAChE,gBAAgB;IAChB,WAA2B,cAAc,mBAAoC;IAC7E,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,MAAM,CAAC,CAAuE;IAEtF,gBAAgB;gBACJ,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAKxC,IAAW,WAAW,IAAI,MAAM,CAAmC;IACnE,IAAW,IAAI,IAAI,UAAU,CAA4B;IACzD,IAAW,SAAS,IAAI,gBAAgB,GAAG,mBAA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a,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;aAC3C,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;aACzC,iBAAiB,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI;aACnD,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aAC5C,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aAC7C,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aACxC,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aAC5C,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CACrE"}
|
|
@@ -7,19 +7,22 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { XmlSerializationUtils } from "../Deserialization/XmlSerializationUtils";
|
|
9
9
|
import { SchemaItemType } from "../ECObjects";
|
|
10
|
-
import {
|
|
10
|
+
import { ECSchemaError, ECSchemaStatus } from "../Exception";
|
|
11
11
|
import { BaseFormat, FormatTraits, formatTraitsToArray, FormatType, ShowSignOption, } from "@itwin/core-quantity";
|
|
12
12
|
import { InvertedUnit } from "./InvertedUnit";
|
|
13
13
|
import { SchemaItem } from "./SchemaItem";
|
|
14
14
|
import { Unit } from "./Unit";
|
|
15
|
+
import { DelayedPromiseWithProps } from "../DelayedPromise";
|
|
15
16
|
/**
|
|
16
|
-
* @
|
|
17
|
+
* @public @preview
|
|
17
18
|
*/
|
|
18
19
|
export class Format extends SchemaItem {
|
|
19
20
|
schemaItemType = Format.schemaItemType;
|
|
21
|
+
/** @internal */
|
|
20
22
|
static get schemaItemType() { return SchemaItemType.Format; }
|
|
21
23
|
_base;
|
|
22
24
|
_units;
|
|
25
|
+
/** @internal */
|
|
23
26
|
constructor(schema, name) {
|
|
24
27
|
super(schema, name);
|
|
25
28
|
this._base = new BaseFormat(name);
|
|
@@ -38,7 +41,9 @@ export class Format extends SchemaItem {
|
|
|
38
41
|
get formatTraits() { return this._base.formatTraits; }
|
|
39
42
|
get spacer() { return this._base.spacer; }
|
|
40
43
|
get includeZero() { return this._base.includeZero; }
|
|
41
|
-
get units() {
|
|
44
|
+
get units() {
|
|
45
|
+
return this._units;
|
|
46
|
+
}
|
|
42
47
|
parseFormatTraits(formatTraitsFromJson) {
|
|
43
48
|
return this._base.parseFormatTraits(formatTraitsFromJson);
|
|
44
49
|
}
|
|
@@ -49,6 +54,7 @@ export class Format extends SchemaItem {
|
|
|
49
54
|
* Adds a Unit, or InvertedUnit, with an optional label override.
|
|
50
55
|
* @param unit The Unit, or InvertedUnit, to add to this Format.
|
|
51
56
|
* @param label A label that overrides the label defined within the Unit when a value is formatted.
|
|
57
|
+
* @internal
|
|
52
58
|
*/
|
|
53
59
|
addUnit(unit, label) {
|
|
54
60
|
if (undefined === this._units)
|
|
@@ -56,11 +62,16 @@ export class Format extends SchemaItem {
|
|
|
56
62
|
else { // Validate that a duplicate is not added.
|
|
57
63
|
for (const existingUnit of this._units) {
|
|
58
64
|
if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())
|
|
59
|
-
throw new
|
|
65
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
this._units.push([unit, label]);
|
|
63
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @param precision
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
64
75
|
setPrecision(precision) { this._base.precision = precision; }
|
|
65
76
|
typecheck(formatProps) {
|
|
66
77
|
this._base.loadFormatProperties(formatProps);
|
|
@@ -69,12 +80,12 @@ export class Format extends SchemaItem {
|
|
|
69
80
|
this._base.includeZero = formatProps.composite.includeZero;
|
|
70
81
|
if (undefined !== formatProps.composite.spacer) {
|
|
71
82
|
if (formatProps.composite.spacer.length > 1)
|
|
72
|
-
throw new
|
|
83
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);
|
|
73
84
|
this._base.spacer = formatProps.composite.spacer;
|
|
74
85
|
}
|
|
75
86
|
// Composite requires 1-4 units
|
|
76
87
|
if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)
|
|
77
|
-
throw new
|
|
88
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);
|
|
78
89
|
}
|
|
79
90
|
}
|
|
80
91
|
fromJSONSync(formatProps) {
|
|
@@ -86,8 +97,11 @@ export class Format extends SchemaItem {
|
|
|
86
97
|
for (const unit of formatProps.composite.units) {
|
|
87
98
|
const newUnit = this.schema.lookupItemSync(unit.name);
|
|
88
99
|
if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))
|
|
89
|
-
throw new
|
|
90
|
-
|
|
100
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, ``);
|
|
101
|
+
if (Unit.isUnit(newUnit))
|
|
102
|
+
this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
|
|
103
|
+
else if (InvertedUnit.isInvertedUnit(newUnit))
|
|
104
|
+
this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
async fromJSON(formatProps) {
|
|
@@ -99,8 +113,11 @@ export class Format extends SchemaItem {
|
|
|
99
113
|
for (const unit of formatProps.composite.units) {
|
|
100
114
|
const newUnit = await this.schema.lookupItem(unit.name);
|
|
101
115
|
if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))
|
|
102
|
-
throw new
|
|
103
|
-
|
|
116
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECJson, ``);
|
|
117
|
+
if (Unit.isUnit(newUnit))
|
|
118
|
+
this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
|
|
119
|
+
else if (InvertedUnit.isInvertedUnit(newUnit))
|
|
120
|
+
this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
|
|
104
121
|
}
|
|
105
122
|
}
|
|
106
123
|
/**
|
|
@@ -179,98 +196,100 @@ export class Format extends SchemaItem {
|
|
|
179
196
|
compositeElement.setAttribute("spacer", this.spacer);
|
|
180
197
|
if (undefined !== this.includeZero)
|
|
181
198
|
compositeElement.setAttribute("includeZero", this.includeZero.toString());
|
|
182
|
-
|
|
199
|
+
for (const [unit, label] of this.units) {
|
|
200
|
+
const resolvedUnit = await unit;
|
|
183
201
|
const unitElement = schemaXml.createElement("Unit");
|
|
184
202
|
if (undefined !== label)
|
|
185
203
|
unitElement.setAttribute("label", label);
|
|
186
|
-
const unitName = XmlSerializationUtils.createXmlTypedName(this.schema,
|
|
204
|
+
const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, resolvedUnit.schema, resolvedUnit.name);
|
|
187
205
|
unitElement.textContent = unitName;
|
|
188
206
|
compositeElement.appendChild(unitElement);
|
|
189
|
-
}
|
|
207
|
+
}
|
|
208
|
+
;
|
|
190
209
|
itemElement.appendChild(compositeElement);
|
|
191
210
|
}
|
|
192
211
|
return itemElement;
|
|
193
212
|
}
|
|
194
213
|
/**
|
|
195
|
-
* @
|
|
214
|
+
* @internal
|
|
196
215
|
*/
|
|
197
216
|
setFormatType(formatType) {
|
|
198
217
|
this._base.type = formatType;
|
|
199
218
|
}
|
|
200
219
|
/**
|
|
201
|
-
* @
|
|
220
|
+
* @internal
|
|
202
221
|
*/
|
|
203
222
|
setRoundFactor(roundFactor) {
|
|
204
223
|
this._base.roundFactor = roundFactor;
|
|
205
224
|
}
|
|
206
225
|
/**
|
|
207
|
-
* @
|
|
226
|
+
* @internal
|
|
208
227
|
*/
|
|
209
228
|
setShowSignOption(signOption) {
|
|
210
229
|
this._base.showSignOption = signOption;
|
|
211
230
|
}
|
|
212
231
|
/**
|
|
213
|
-
* @
|
|
232
|
+
* @internal
|
|
214
233
|
*/
|
|
215
234
|
setDecimalSeparator(separator) {
|
|
216
235
|
this._base.decimalSeparator = separator;
|
|
217
236
|
}
|
|
218
237
|
/**
|
|
219
|
-
* @
|
|
238
|
+
* @internal
|
|
220
239
|
*/
|
|
221
240
|
setThousandSeparator(separator) {
|
|
222
241
|
this._base.thousandSeparator = separator;
|
|
223
242
|
}
|
|
224
243
|
/**
|
|
225
|
-
* @
|
|
244
|
+
* @internal
|
|
226
245
|
*/
|
|
227
246
|
setUomSeparator(separator) {
|
|
228
247
|
this._base.uomSeparator = separator;
|
|
229
248
|
}
|
|
230
249
|
/**
|
|
231
|
-
* @
|
|
250
|
+
* @internal
|
|
232
251
|
*/
|
|
233
252
|
setStationSeparator(separator) {
|
|
234
253
|
this._base.stationSeparator = separator;
|
|
235
254
|
}
|
|
236
255
|
/**
|
|
237
|
-
* @
|
|
256
|
+
* @internal
|
|
238
257
|
*/
|
|
239
258
|
setStationOffsetSize(stationOffsetSize) {
|
|
240
259
|
this._base.stationOffsetSize = stationOffsetSize;
|
|
241
260
|
}
|
|
242
261
|
/**
|
|
243
|
-
* @
|
|
262
|
+
* @internal
|
|
244
263
|
*/
|
|
245
264
|
setScientificType(scientificType) {
|
|
246
265
|
this._base.scientificType = scientificType;
|
|
247
266
|
}
|
|
248
267
|
/**
|
|
249
|
-
* @
|
|
268
|
+
* @internal
|
|
250
269
|
*/
|
|
251
270
|
setMinWidth(minWidth) {
|
|
252
271
|
this._base.minWidth = minWidth;
|
|
253
272
|
}
|
|
254
273
|
/**
|
|
255
|
-
* @
|
|
274
|
+
* @internal
|
|
256
275
|
*/
|
|
257
276
|
setSpacer(spacer) {
|
|
258
277
|
this._base.spacer = spacer;
|
|
259
278
|
}
|
|
260
279
|
/**
|
|
261
|
-
* @
|
|
280
|
+
* @internal
|
|
262
281
|
*/
|
|
263
282
|
setIncludeZero(includeZero) {
|
|
264
283
|
this._base.includeZero = includeZero;
|
|
265
284
|
}
|
|
266
285
|
/**
|
|
267
|
-
* @
|
|
286
|
+
* @internal
|
|
268
287
|
*/
|
|
269
288
|
setFormatTraits(formatTraits) {
|
|
270
289
|
this._base.formatTraits = formatTraits;
|
|
271
290
|
}
|
|
272
291
|
/**
|
|
273
|
-
* @
|
|
292
|
+
* @internal
|
|
274
293
|
*/
|
|
275
294
|
setUnits(units) {
|
|
276
295
|
this._units = units;
|
|
@@ -288,10 +307,11 @@ export class Format extends SchemaItem {
|
|
|
288
307
|
* Type assertion to check if the SchemaItem is of type Format.
|
|
289
308
|
* @param item The SchemaItem to check.
|
|
290
309
|
* @returns The item cast to Format if it is a Format, undefined otherwise.
|
|
310
|
+
* @internal
|
|
291
311
|
*/
|
|
292
312
|
static assertIsFormat(item) {
|
|
293
313
|
if (!this.isFormat(item))
|
|
294
|
-
throw new
|
|
314
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Format}' (Format)`);
|
|
295
315
|
}
|
|
296
316
|
}
|
|
297
317
|
/**
|