@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.
Files changed (121) hide show
  1. package/CHANGELOG.md +13 -3
  2. package/lib/cjs/Constants.d.ts +23 -23
  3. package/lib/cjs/Constants.js +33 -33
  4. package/lib/cjs/Constants.js.map +1 -1
  5. package/lib/cjs/Context.d.ts +139 -139
  6. package/lib/cjs/Context.js +204 -204
  7. package/lib/cjs/DelayedPromise.d.ts +88 -88
  8. package/lib/cjs/DelayedPromise.d.ts.map +1 -1
  9. package/lib/cjs/DelayedPromise.js +91 -91
  10. package/lib/cjs/DelayedPromise.js.map +1 -1
  11. package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
  12. package/lib/cjs/Deserialization/AbstractParser.d.ts.map +1 -1
  13. package/lib/cjs/Deserialization/AbstractParser.js +11 -11
  14. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  15. package/lib/cjs/Deserialization/Helper.js +843 -843
  16. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  17. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  18. package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
  19. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  20. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  21. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  22. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  23. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  24. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  25. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  26. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  27. package/lib/cjs/ECName.d.ts +30 -30
  28. package/lib/cjs/ECName.js +85 -85
  29. package/lib/cjs/ECObjects.d.ts +162 -162
  30. package/lib/cjs/ECObjects.js +453 -453
  31. package/lib/cjs/Exception.d.ts +43 -43
  32. package/lib/cjs/Exception.js +84 -84
  33. package/lib/cjs/Interfaces.d.ts +66 -66
  34. package/lib/cjs/Interfaces.d.ts.map +1 -1
  35. package/lib/cjs/Interfaces.js +9 -9
  36. package/lib/cjs/Metadata/Class.d.ts +243 -243
  37. package/lib/cjs/Metadata/Class.js +558 -558
  38. package/lib/cjs/Metadata/Class.js.map +1 -1
  39. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  40. package/lib/cjs/Metadata/Constant.js +123 -123
  41. package/lib/cjs/Metadata/Constant.js.map +1 -1
  42. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  43. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  44. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  45. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  46. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  47. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  48. package/lib/cjs/Metadata/EntityClass.js +230 -230
  49. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  50. package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
  51. package/lib/cjs/Metadata/Enumeration.js +159 -159
  52. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  53. package/lib/cjs/Metadata/Format.d.ts +98 -98
  54. package/lib/cjs/Metadata/Format.js +242 -242
  55. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  56. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  57. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  58. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  59. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  60. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  61. package/lib/cjs/Metadata/Mixin.js +113 -113
  62. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  63. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  64. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  65. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  66. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  67. package/lib/cjs/Metadata/Property.d.ts +197 -197
  68. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  69. package/lib/cjs/Metadata/Property.js +491 -491
  70. package/lib/cjs/Metadata/Property.js.map +1 -1
  71. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  72. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  73. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  74. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  75. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  76. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  77. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  78. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  79. package/lib/cjs/Metadata/Schema.js +520 -520
  80. package/lib/cjs/Metadata/Schema.js.map +1 -1
  81. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  82. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  83. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  84. package/lib/cjs/Metadata/Unit.js +162 -162
  85. package/lib/cjs/Metadata/Unit.js.map +1 -1
  86. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  87. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  88. package/lib/cjs/PropertyTypes.d.ts +49 -49
  89. package/lib/cjs/PropertyTypes.js +91 -91
  90. package/lib/cjs/PropertyTypes.js.map +1 -1
  91. package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
  92. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
  93. package/lib/cjs/SchemaJsonLocater.js +42 -42
  94. package/lib/cjs/SchemaKey.d.ts +110 -110
  95. package/lib/cjs/SchemaKey.js +219 -219
  96. package/lib/cjs/SchemaLoader.d.ts +23 -23
  97. package/lib/cjs/SchemaLoader.js +47 -47
  98. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  99. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  100. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  101. package/lib/cjs/UnitConversion/Graph.js +83 -83
  102. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  103. package/lib/cjs/UnitConversion/Parser.js +42 -42
  104. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  105. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  106. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  107. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  108. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  109. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  110. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  111. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  112. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +234 -236
  113. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  114. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  115. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  116. package/lib/cjs/ecschema-metadata.d.ts +51 -51
  117. package/lib/cjs/ecschema-metadata.js +100 -96
  118. package/lib/cjs/ecschema-metadata.js.map +1 -1
  119. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  120. package/lib/cjs/utils/SchemaGraph.js +65 -65
  121. package/package.json +11 -11
@@ -1,160 +1,160 @@
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.MutableEnumeration = exports.Enumeration = void 0;
11
- const ECObjects_1 = require("../ECObjects");
12
- const Exception_1 = require("../Exception");
13
- const ECName_1 = require("../ECName");
14
- const SchemaItem_1 = require("./SchemaItem");
15
- /**
16
- * A Typescript class representation of an ECEnumeration.
17
- * @beta
18
- */
19
- class Enumeration extends SchemaItem_1.SchemaItem {
20
- constructor(schema, name, primitiveType) {
21
- super(schema, name);
22
- this.schemaItemType = ECObjects_1.SchemaItemType.Enumeration;
23
- this._type = primitiveType;
24
- this._isStrict = true;
25
- this._enumerators = [];
26
- }
27
- get enumerators() { return this._enumerators; }
28
- get type() { return this._type; }
29
- get isStrict() { return this._isStrict; }
30
- get isInt() { return this._type === ECObjects_1.PrimitiveType.Integer; }
31
- get isString() { return this._type === ECObjects_1.PrimitiveType.String; }
32
- /**
33
- * Gets an enumerator that matches the name provided.
34
- * @param name The ECName of the Enumerator to find.
35
- */
36
- getEnumeratorByName(name) {
37
- return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());
38
- }
39
- getEnumerator(value) {
40
- return this.enumerators.find((item) => item.value === value);
41
- }
42
- /**
43
- * Checks whether there already exists an enumerator with this name or this value
44
- * @param name The name of the enumerator we are trying to create
45
- * @param value The value of the enumerator we are trying to create
46
- * @internal
47
- */
48
- findDuplicateEnumerators(name, value) {
49
- this._enumerators.forEach((element) => {
50
- if (element.name.toLowerCase() === name.toLowerCase())
51
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
52
- if (element.value === value)
53
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
54
- });
55
- }
56
- /**
57
- * Creates an Enumerator with the provided name and value as well as optional parameters label and description
58
- * @param name The name of the enumerator
59
- * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
60
- * @param label A localized display label that is used instead of the name in a GUI.
61
- * @param description A localized description for the enumerator.
62
- * @return AnyEnumerator object
63
- */
64
- createEnumerator(name, value, label, description) {
65
- if (this.isInt && typeof (value) === "string") // throws if backing type is int and value is string
66
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
67
- if (!this.isInt && typeof (value) === "number") // also throws if backing type is string and value is number
68
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
69
- this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any
70
- if (!ECName_1.ECName.validate(name))
71
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
72
- return { name, value, label, description };
73
- }
74
- /**
75
- * Adds enumerator to list of enumerators on this Enumeration
76
- * @param enumerator The enumerator to add
77
- */
78
- addEnumerator(enumerator) {
79
- this.enumerators.push(enumerator);
80
- }
81
- /**
82
- * Save this Enumeration's properties to an object for serializing to JSON.
83
- * @param standalone Serialization includes only this object (as opposed to the full schema).
84
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
85
- */
86
- toJSON(standalone = false, includeSchemaVersion = false) {
87
- const schemaJson = super.toJSON(standalone, includeSchemaVersion);
88
- schemaJson.type = (this.isInt) ? "int" : "string";
89
- schemaJson.isStrict = this.isStrict;
90
- schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {
91
- const enumJson = { name, value };
92
- if (undefined !== label)
93
- enumJson.label = label;
94
- if (undefined !== description)
95
- enumJson.description = description;
96
- return enumJson;
97
- });
98
- return schemaJson;
99
- }
100
- /** @internal */
101
- async toXml(schemaXml) {
102
- const itemElement = await super.toXml(schemaXml);
103
- if (undefined !== this.type)
104
- itemElement.setAttribute("backingTypeName", (0, ECObjects_1.primitiveTypeToString)(this.type));
105
- itemElement.setAttribute("isStrict", String(this.isStrict));
106
- for (const enumerator of this.enumerators) {
107
- const enumElement = schemaXml.createElement("ECEnumerator");
108
- enumElement.setAttribute("name", enumerator.name);
109
- const enumValue = typeof enumerator.value === "string" ? enumerator.value : enumerator.value.toString();
110
- enumElement.setAttribute("value", enumValue);
111
- if (undefined !== enumerator.label)
112
- enumElement.setAttribute("displayLabel", enumerator.label);
113
- if (undefined !== enumerator.description)
114
- enumElement.setAttribute("description", enumerator.description);
115
- itemElement.appendChild(enumElement);
116
- }
117
- return itemElement;
118
- }
119
- fromJSONSync(enumerationProps) {
120
- super.fromJSONSync(enumerationProps);
121
- if (undefined === this._type) {
122
- if (/int/i.test(enumerationProps.type))
123
- this._type = ECObjects_1.PrimitiveType.Integer;
124
- else if (/string/i.test(enumerationProps.type))
125
- this._type = ECObjects_1.PrimitiveType.String;
126
- else
127
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
128
- }
129
- else {
130
- const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;
131
- if (!primitiveTypePattern.test(enumerationProps.type))
132
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be "${(this.isInt) ? "int" : "string"}", not "${(this.isInt) ? "string" : "int"}".`);
133
- }
134
- this._isStrict = enumerationProps.isStrict;
135
- if (undefined !== enumerationProps.enumerators) {
136
- enumerationProps.enumerators.forEach((enumerator) => {
137
- // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.
138
- // Throws ECObjectsError if there are duplicate names or values present in the enumeration
139
- this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));
140
- });
141
- }
142
- }
143
- async fromJSON(enumerationProps) {
144
- this.fromJSONSync(enumerationProps);
145
- }
146
- /**
147
- * @alpha Used in schema editing.
148
- */
149
- setIsStrict(isStrict) {
150
- this._isStrict = isStrict;
151
- }
152
- }
153
- exports.Enumeration = Enumeration;
154
- /** @internal
155
- * An abstract class used for schema editing.
156
- */
157
- class MutableEnumeration extends Enumeration {
158
- }
159
- exports.MutableEnumeration = MutableEnumeration;
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.MutableEnumeration = exports.Enumeration = void 0;
11
+ const ECObjects_1 = require("../ECObjects");
12
+ const Exception_1 = require("../Exception");
13
+ const ECName_1 = require("../ECName");
14
+ const SchemaItem_1 = require("./SchemaItem");
15
+ /**
16
+ * A Typescript class representation of an ECEnumeration.
17
+ * @beta
18
+ */
19
+ class Enumeration extends SchemaItem_1.SchemaItem {
20
+ get enumerators() { return this._enumerators; }
21
+ get type() { return this._type; }
22
+ get isStrict() { return this._isStrict; }
23
+ constructor(schema, name, primitiveType) {
24
+ super(schema, name);
25
+ this.schemaItemType = ECObjects_1.SchemaItemType.Enumeration;
26
+ this._type = primitiveType;
27
+ this._isStrict = true;
28
+ this._enumerators = [];
29
+ }
30
+ get isInt() { return this._type === ECObjects_1.PrimitiveType.Integer; }
31
+ get isString() { return this._type === ECObjects_1.PrimitiveType.String; }
32
+ /**
33
+ * Gets an enumerator that matches the name provided.
34
+ * @param name The ECName of the Enumerator to find.
35
+ */
36
+ getEnumeratorByName(name) {
37
+ return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());
38
+ }
39
+ getEnumerator(value) {
40
+ return this.enumerators.find((item) => item.value === value);
41
+ }
42
+ /**
43
+ * Checks whether there already exists an enumerator with this name or this value
44
+ * @param name The name of the enumerator we are trying to create
45
+ * @param value The value of the enumerator we are trying to create
46
+ * @internal
47
+ */
48
+ findDuplicateEnumerators(name, value) {
49
+ this._enumerators.forEach((element) => {
50
+ if (element.name.toLowerCase() === name.toLowerCase())
51
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
52
+ if (element.value === value)
53
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
54
+ });
55
+ }
56
+ /**
57
+ * Creates an Enumerator with the provided name and value as well as optional parameters label and description
58
+ * @param name The name of the enumerator
59
+ * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
60
+ * @param label A localized display label that is used instead of the name in a GUI.
61
+ * @param description A localized description for the enumerator.
62
+ * @return AnyEnumerator object
63
+ */
64
+ createEnumerator(name, value, label, description) {
65
+ if (this.isInt && typeof (value) === "string") // throws if backing type is int and value is string
66
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
67
+ if (!this.isInt && typeof (value) === "number") // also throws if backing type is string and value is number
68
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
69
+ this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any
70
+ if (!ECName_1.ECName.validate(name))
71
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
72
+ return { name, value, label, description };
73
+ }
74
+ /**
75
+ * Adds enumerator to list of enumerators on this Enumeration
76
+ * @param enumerator The enumerator to add
77
+ */
78
+ addEnumerator(enumerator) {
79
+ this.enumerators.push(enumerator);
80
+ }
81
+ /**
82
+ * Save this Enumeration's properties to an object for serializing to JSON.
83
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
84
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
85
+ */
86
+ toJSON(standalone = false, includeSchemaVersion = false) {
87
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
88
+ schemaJson.type = (this.isInt) ? "int" : "string";
89
+ schemaJson.isStrict = this.isStrict;
90
+ schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {
91
+ const enumJson = { name, value };
92
+ if (undefined !== label)
93
+ enumJson.label = label;
94
+ if (undefined !== description)
95
+ enumJson.description = description;
96
+ return enumJson;
97
+ });
98
+ return schemaJson;
99
+ }
100
+ /** @internal */
101
+ async toXml(schemaXml) {
102
+ const itemElement = await super.toXml(schemaXml);
103
+ if (undefined !== this.type)
104
+ itemElement.setAttribute("backingTypeName", (0, ECObjects_1.primitiveTypeToString)(this.type));
105
+ itemElement.setAttribute("isStrict", String(this.isStrict));
106
+ for (const enumerator of this.enumerators) {
107
+ const enumElement = schemaXml.createElement("ECEnumerator");
108
+ enumElement.setAttribute("name", enumerator.name);
109
+ const enumValue = typeof enumerator.value === "string" ? enumerator.value : enumerator.value.toString();
110
+ enumElement.setAttribute("value", enumValue);
111
+ if (undefined !== enumerator.label)
112
+ enumElement.setAttribute("displayLabel", enumerator.label);
113
+ if (undefined !== enumerator.description)
114
+ enumElement.setAttribute("description", enumerator.description);
115
+ itemElement.appendChild(enumElement);
116
+ }
117
+ return itemElement;
118
+ }
119
+ fromJSONSync(enumerationProps) {
120
+ super.fromJSONSync(enumerationProps);
121
+ if (undefined === this._type) {
122
+ if (/int/i.test(enumerationProps.type))
123
+ this._type = ECObjects_1.PrimitiveType.Integer;
124
+ else if (/string/i.test(enumerationProps.type))
125
+ this._type = ECObjects_1.PrimitiveType.String;
126
+ else
127
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
128
+ }
129
+ else {
130
+ const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;
131
+ if (!primitiveTypePattern.test(enumerationProps.type))
132
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be "${(this.isInt) ? "int" : "string"}", not "${(this.isInt) ? "string" : "int"}".`);
133
+ }
134
+ this._isStrict = enumerationProps.isStrict;
135
+ if (undefined !== enumerationProps.enumerators) {
136
+ enumerationProps.enumerators.forEach((enumerator) => {
137
+ // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.
138
+ // Throws ECObjectsError if there are duplicate names or values present in the enumeration
139
+ this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));
140
+ });
141
+ }
142
+ }
143
+ async fromJSON(enumerationProps) {
144
+ this.fromJSONSync(enumerationProps);
145
+ }
146
+ /**
147
+ * @alpha Used in schema editing.
148
+ */
149
+ setIsStrict(isStrict) {
150
+ this._isStrict = isStrict;
151
+ }
152
+ }
153
+ exports.Enumeration = Enumeration;
154
+ /** @internal
155
+ * An abstract class used for schema editing.
156
+ */
157
+ class MutableEnumeration extends Enumeration {
158
+ }
159
+ exports.MutableEnumeration = MutableEnumeration;
160
160
  //# sourceMappingURL=Enumeration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,4CAAoF;AACpF,4CAA+D;AAC/D,sCAAmC;AAEnC,6CAA0C;AAa1C;;;GAGG;AACH,MAAa,WAAY,SAAQ,uBAAU;IAUzC,YAAY,MAAc,EAAE,IAAY,EAAE,aAA4D;QACpG,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,WAAW,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI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C,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;SAChN;QACD,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC;QAE3C,IAAI,SAAS,KAAK,gBAAgB,CAAC,WAAW,EAAE;YAC9C,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAA2B,EAAE,EAAE;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;SACJ;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;CAEF;AA/JD,kCA+JC;AAED;;GAEG;AACH,MAAsB,kBAAmB,SAAQ,WAAW;CAI3D;AAJD,gDAIC","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 { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\r\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { ECName } from \"../ECName\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\n\r\n/** @beta */\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/** @beta */\r\nexport type AnyEnumerator = Enumerator<string | number>;\r\n\r\n/**\r\n * A Typescript class representation of an ECEnumeration.\r\n * @beta\r\n */\r\nexport class Enumeration extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Enumeration; // eslint-disable-line\r\n protected _type?: PrimitiveType.Integer | PrimitiveType.String;\r\n protected _isStrict: boolean;\r\n protected _enumerators: AnyEnumerator[];\r\n\r\n public get enumerators() { return this._enumerators; }\r\n public get type() { return this._type; }\r\n public get isStrict() { return this._isStrict; }\r\n\r\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Enumeration;\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 ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\r\n if (element.value === value)\r\n throw new ECObjectsError(ECObjectsStatus.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 */\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 ECObjectsError(ECObjectsStatus.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 ECObjectsError(ECObjectsStatus.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 ECObjectsError(ECObjectsStatus.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 */\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 throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\r\n } else {\r\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\r\n if (!primitiveTypePattern.test(enumerationProps.type))\r\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\"}\".`);\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 ECObjectsError 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 * @alpha Used in schema editing.\r\n */\r\n protected setIsStrict(isStrict: boolean) {\r\n this._isStrict = isStrict;\r\n }\r\n\r\n}\r\n\r\n/** @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class 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"]}
1
+ {"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,4CAAoF;AACpF,4CAA+D;AAC/D,sCAAmC;AAEnC,6CAA0C;AAa1C;;;GAGG;AACH,MAAa,WAAY,SAAQ,uBAAU;IAMzC,IAAW,WAAW,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhD,YAAY,MAAc,EAAE,IAAY,EAAE,aAA4D;QACpG,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAA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AK,IAAI,CAAC,CAAC;SAChN;QACD,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC;QAE3C,IAAI,SAAS,KAAK,gBAAgB,CAAC,WAAW,EAAE;YAC9C,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAA2B,EAAE,EAAE;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;SACJ;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;CAEF;AA/JD,kCA+JC;AAED;;GAEG;AACH,MAAsB,kBAAmB,SAAQ,WAAW;CAI3D;AAJD,gDAIC","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 { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\r\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { ECName } from \"../ECName\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\n\r\n/** @beta */\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/** @beta */\r\nexport type AnyEnumerator = Enumerator<string | number>;\r\n\r\n/**\r\n * A Typescript class representation of an ECEnumeration.\r\n * @beta\r\n */\r\nexport class Enumeration extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Enumeration; // eslint-disable-line\r\n protected _type?: PrimitiveType.Integer | PrimitiveType.String;\r\n protected _isStrict: boolean;\r\n protected _enumerators: AnyEnumerator[];\r\n\r\n public get enumerators() { return this._enumerators; }\r\n public get type() { return this._type; }\r\n public get isStrict() { return this._isStrict; }\r\n\r\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Enumeration;\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 ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\r\n if (element.value === value)\r\n throw new ECObjectsError(ECObjectsStatus.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 */\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 ECObjectsError(ECObjectsStatus.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 ECObjectsError(ECObjectsStatus.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 ECObjectsError(ECObjectsStatus.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 */\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 throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\r\n } else {\r\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\r\n if (!primitiveTypePattern.test(enumerationProps.type))\r\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\"}\".`);\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 ECObjectsError 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 * @alpha Used in schema editing.\r\n */\r\n protected setIsStrict(isStrict: boolean) {\r\n this._isStrict = isStrict;\r\n }\r\n\r\n}\r\n\r\n/** @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class 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"]}
@@ -1,99 +1,99 @@
1
- /** @packageDocumentation
2
- * @module Metadata
3
- */
4
- import { FormatProps } from "../Deserialization/JsonProps";
5
- import { SchemaItemType } from "../ECObjects";
6
- import { BaseFormat, DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from "@itwin/core-quantity";
7
- import { InvertedUnit } from "./InvertedUnit";
8
- import { Schema } from "./Schema";
9
- import { SchemaItem } from "./SchemaItem";
10
- import { Unit } from "./Unit";
11
- /**
12
- * @beta
13
- */
14
- export declare class Format extends SchemaItem {
15
- readonly schemaItemType: SchemaItemType.Format;
16
- protected _base: BaseFormat;
17
- protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;
18
- constructor(schema: Schema, name: string);
19
- get roundFactor(): number;
20
- get type(): FormatType;
21
- get precision(): DecimalPrecision | FractionalPrecision;
22
- get minWidth(): number | undefined;
23
- get scientificType(): ScientificType | undefined;
24
- get showSignOption(): ShowSignOption;
25
- get decimalSeparator(): string;
26
- get thousandSeparator(): string;
27
- get uomSeparator(): string;
28
- get stationSeparator(): string;
29
- get stationOffsetSize(): number | undefined;
30
- get formatTraits(): FormatTraits;
31
- get spacer(): string | undefined;
32
- get includeZero(): boolean | undefined;
33
- get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined;
34
- private parseFormatTraits;
35
- hasFormatTrait(formatTrait: FormatTraits): boolean;
36
- /**
37
- * Adds a Unit, or InvertedUnit, with an optional label override.
38
- * @param unit The Unit, or InvertedUnit, to add to this Format.
39
- * @param label A label that overrides the label defined within the Unit when a value is formatted.
40
- */
41
- protected addUnit(unit: Unit | InvertedUnit, label?: string): void;
42
- protected setPrecision(precision: number): void;
43
- private typecheck;
44
- fromJSONSync(formatProps: FormatProps): void;
45
- fromJSON(formatProps: FormatProps): Promise<void>;
46
- /**
47
- * Save this Format's properties to an object for serializing to JSON.
48
- * @param standalone Serialization includes only this object (as opposed to the full schema).
49
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
50
- */
51
- toJSON(standalone?: boolean, includeSchemaVersion?: boolean): FormatProps;
52
- /** @internal */
53
- toXml(schemaXml: Document): Promise<Element>;
54
- /**
55
- * @alpha Used in schema editing.
56
- */
57
- protected setFormatType(formatType: FormatType): void;
58
- /**
59
- * @alpha Used in schema editing.
60
- */
61
- protected setRoundFactor(roundFactor: number): void;
62
- /**
63
- * @alpha Used in schema editing.
64
- */
65
- protected setShowSignOption(signOption: ShowSignOption): void;
66
- /**
67
- * @alpha Used in schema editing.
68
- */
69
- protected setDecimalSeparator(separator: string): void;
70
- /**
71
- * @alpha Used in schema editing.
72
- */
73
- protected setThousandSeparator(separator: string): void;
74
- /**
75
- * @alpha Used in schema editing.
76
- */
77
- protected setUomSeparator(separator: string): void;
78
- /**
79
- * @alpha Used in schema editing.
80
- */
81
- protected setStationSeparator(separator: string): void;
82
- }
83
- /**
84
- * @internal
85
- * An abstract class used for schema editing.
86
- */
87
- export declare abstract class MutableFormat extends Format {
88
- abstract addUnit(unit: Unit | InvertedUnit, label?: string): void;
89
- abstract setPrecision(precision: number): void;
90
- abstract setFormatType(formatType: FormatType): void;
91
- abstract setRoundFactor(roundFactor: number): void;
92
- abstract setShowSignOption(signOption: ShowSignOption): void;
93
- abstract setDecimalSeparator(separator: string): void;
94
- abstract setThousandSeparator(separator: string): void;
95
- abstract setUomSeparator(separator: string): void;
96
- abstract setStationSeparator(separator: string): void;
97
- abstract setDisplayLabel(displayLabel: string): void;
98
- }
1
+ /** @packageDocumentation
2
+ * @module Metadata
3
+ */
4
+ import { FormatProps } from "../Deserialization/JsonProps";
5
+ import { SchemaItemType } from "../ECObjects";
6
+ import { BaseFormat, DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from "@itwin/core-quantity";
7
+ import { InvertedUnit } from "./InvertedUnit";
8
+ import { Schema } from "./Schema";
9
+ import { SchemaItem } from "./SchemaItem";
10
+ import { Unit } from "./Unit";
11
+ /**
12
+ * @beta
13
+ */
14
+ export declare class Format extends SchemaItem {
15
+ readonly schemaItemType: SchemaItemType.Format;
16
+ protected _base: BaseFormat;
17
+ protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;
18
+ constructor(schema: Schema, name: string);
19
+ get roundFactor(): number;
20
+ get type(): FormatType;
21
+ get precision(): DecimalPrecision | FractionalPrecision;
22
+ get minWidth(): number | undefined;
23
+ get scientificType(): ScientificType | undefined;
24
+ get showSignOption(): ShowSignOption;
25
+ get decimalSeparator(): string;
26
+ get thousandSeparator(): string;
27
+ get uomSeparator(): string;
28
+ get stationSeparator(): string;
29
+ get stationOffsetSize(): number | undefined;
30
+ get formatTraits(): FormatTraits;
31
+ get spacer(): string | undefined;
32
+ get includeZero(): boolean | undefined;
33
+ get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined;
34
+ private parseFormatTraits;
35
+ hasFormatTrait(formatTrait: FormatTraits): boolean;
36
+ /**
37
+ * Adds a Unit, or InvertedUnit, with an optional label override.
38
+ * @param unit The Unit, or InvertedUnit, to add to this Format.
39
+ * @param label A label that overrides the label defined within the Unit when a value is formatted.
40
+ */
41
+ protected addUnit(unit: Unit | InvertedUnit, label?: string): void;
42
+ protected setPrecision(precision: number): void;
43
+ private typecheck;
44
+ fromJSONSync(formatProps: FormatProps): void;
45
+ fromJSON(formatProps: FormatProps): Promise<void>;
46
+ /**
47
+ * Save this Format's properties to an object for serializing to JSON.
48
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
49
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
50
+ */
51
+ toJSON(standalone?: boolean, includeSchemaVersion?: boolean): FormatProps;
52
+ /** @internal */
53
+ toXml(schemaXml: Document): Promise<Element>;
54
+ /**
55
+ * @alpha Used in schema editing.
56
+ */
57
+ protected setFormatType(formatType: FormatType): void;
58
+ /**
59
+ * @alpha Used in schema editing.
60
+ */
61
+ protected setRoundFactor(roundFactor: number): void;
62
+ /**
63
+ * @alpha Used in schema editing.
64
+ */
65
+ protected setShowSignOption(signOption: ShowSignOption): void;
66
+ /**
67
+ * @alpha Used in schema editing.
68
+ */
69
+ protected setDecimalSeparator(separator: string): void;
70
+ /**
71
+ * @alpha Used in schema editing.
72
+ */
73
+ protected setThousandSeparator(separator: string): void;
74
+ /**
75
+ * @alpha Used in schema editing.
76
+ */
77
+ protected setUomSeparator(separator: string): void;
78
+ /**
79
+ * @alpha Used in schema editing.
80
+ */
81
+ protected setStationSeparator(separator: string): void;
82
+ }
83
+ /**
84
+ * @internal
85
+ * An abstract class used for schema editing.
86
+ */
87
+ export declare abstract class MutableFormat extends Format {
88
+ abstract addUnit(unit: Unit | InvertedUnit, label?: string): void;
89
+ abstract setPrecision(precision: number): void;
90
+ abstract setFormatType(formatType: FormatType): void;
91
+ abstract setRoundFactor(roundFactor: number): void;
92
+ abstract setShowSignOption(signOption: ShowSignOption): void;
93
+ abstract setDecimalSeparator(separator: string): void;
94
+ abstract setThousandSeparator(separator: string): void;
95
+ abstract setUomSeparator(separator: string): void;
96
+ abstract setStationSeparator(separator: string): void;
97
+ abstract setDisplayLabel(displayLabel: string): void;
98
+ }
99
99
  //# sourceMappingURL=Format.d.ts.map