@itwin/ecschema-metadata 4.0.0-dev.52 → 4.0.0-dev.55

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 (117) hide show
  1. package/lib/cjs/Constants.d.ts +23 -23
  2. package/lib/cjs/Constants.js +33 -33
  3. package/lib/cjs/Constants.js.map +1 -1
  4. package/lib/cjs/Context.d.ts +139 -139
  5. package/lib/cjs/Context.js +204 -204
  6. package/lib/cjs/DelayedPromise.d.ts +88 -88
  7. package/lib/cjs/DelayedPromise.d.ts.map +1 -1
  8. package/lib/cjs/DelayedPromise.js +91 -91
  9. package/lib/cjs/DelayedPromise.js.map +1 -1
  10. package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
  11. package/lib/cjs/Deserialization/AbstractParser.d.ts.map +1 -1
  12. package/lib/cjs/Deserialization/AbstractParser.js +11 -11
  13. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  14. package/lib/cjs/Deserialization/Helper.js +843 -843
  15. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  16. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  17. package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
  18. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  19. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  20. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  21. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  22. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  23. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  24. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  25. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  26. package/lib/cjs/ECName.d.ts +30 -30
  27. package/lib/cjs/ECName.js +85 -85
  28. package/lib/cjs/ECObjects.d.ts +162 -162
  29. package/lib/cjs/ECObjects.js +453 -453
  30. package/lib/cjs/Exception.d.ts +43 -43
  31. package/lib/cjs/Exception.js +84 -84
  32. package/lib/cjs/Interfaces.d.ts +66 -66
  33. package/lib/cjs/Interfaces.d.ts.map +1 -1
  34. package/lib/cjs/Interfaces.js +9 -9
  35. package/lib/cjs/Metadata/Class.d.ts +243 -243
  36. package/lib/cjs/Metadata/Class.js +558 -558
  37. package/lib/cjs/Metadata/Class.js.map +1 -1
  38. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  39. package/lib/cjs/Metadata/Constant.js +123 -123
  40. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  41. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  42. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  43. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  44. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  45. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  46. package/lib/cjs/Metadata/EntityClass.js +230 -230
  47. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  48. package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
  49. package/lib/cjs/Metadata/Enumeration.js +159 -159
  50. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  51. package/lib/cjs/Metadata/Format.d.ts +98 -98
  52. package/lib/cjs/Metadata/Format.js +242 -242
  53. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  54. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  55. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  56. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  57. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  58. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  59. package/lib/cjs/Metadata/Mixin.js +113 -113
  60. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  61. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  62. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  63. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  64. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  65. package/lib/cjs/Metadata/Property.d.ts +197 -197
  66. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  67. package/lib/cjs/Metadata/Property.js +491 -491
  68. package/lib/cjs/Metadata/Property.js.map +1 -1
  69. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  70. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  71. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  72. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  73. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  74. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  75. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  76. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  77. package/lib/cjs/Metadata/Schema.js +520 -520
  78. package/lib/cjs/Metadata/Schema.js.map +1 -1
  79. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  80. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  81. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  82. package/lib/cjs/Metadata/Unit.js +162 -162
  83. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  84. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  85. package/lib/cjs/PropertyTypes.d.ts +49 -49
  86. package/lib/cjs/PropertyTypes.js +91 -91
  87. package/lib/cjs/PropertyTypes.js.map +1 -1
  88. package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
  89. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
  90. package/lib/cjs/SchemaJsonLocater.js +42 -42
  91. package/lib/cjs/SchemaKey.d.ts +110 -110
  92. package/lib/cjs/SchemaKey.js +219 -219
  93. package/lib/cjs/SchemaLoader.d.ts +23 -23
  94. package/lib/cjs/SchemaLoader.js +47 -47
  95. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  96. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  97. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  98. package/lib/cjs/UnitConversion/Graph.js +83 -83
  99. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  100. package/lib/cjs/UnitConversion/Parser.js +42 -42
  101. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  102. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  103. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  104. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  105. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  106. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  107. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  108. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  109. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +234 -234
  110. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  111. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  112. package/lib/cjs/ecschema-metadata.d.ts +51 -51
  113. package/lib/cjs/ecschema-metadata.js +100 -96
  114. package/lib/cjs/ecschema-metadata.js.map +1 -1
  115. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  116. package/lib/cjs/utils/SchemaGraph.js +65 -65
  117. package/package.json +8 -8
@@ -1,77 +1,77 @@
1
- /** @packageDocumentation
2
- * @module Metadata
3
- */
4
- import { UnitProps } from "../Deserialization/JsonProps";
5
- import { SchemaItemType } from "../ECObjects";
6
- import { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from "../Interfaces";
7
- import { Schema } from "./Schema";
8
- import { SchemaItem } from "./SchemaItem";
9
- /**
10
- * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a
11
- * first-class concept is to allow the iModel to not be dependent on any hard-coded Units
12
- * @beta
13
- */
14
- export declare class Unit extends SchemaItem {
15
- readonly schemaItemType: SchemaItemType.Unit;
16
- protected _phenomenon?: LazyLoadedPhenomenon;
17
- protected _unitSystem?: LazyLoadedUnitSystem;
18
- protected _definition: string;
19
- protected _numerator?: number;
20
- protected _denominator?: number;
21
- protected _offset?: number;
22
- constructor(schema: Schema, name: string);
23
- get phenomenon(): LazyLoadedPhenomenon | undefined;
24
- get unitSystem(): LazyLoadedUnitSystem | undefined;
25
- get definition(): string;
26
- get numerator(): number;
27
- get offset(): number;
28
- get denominator(): number;
29
- get hasNumerator(): boolean;
30
- get hasOffset(): boolean;
31
- get hasDenominator(): boolean;
32
- /**
33
- * Returns true if a conversion can be calculated between the input units
34
- * @alpha
35
- */
36
- static areCompatible(unitA: Unit, unitB: Unit): Promise<boolean>;
37
- /**
38
- * @alpha
39
- */
40
- static isUnit(object: any): object is Unit;
41
- /**
42
- * Save this Unit's properties to an object for serializing to JSON.
43
- * @param standalone Serialization includes only this object (as opposed to the full schema).
44
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
45
- */
46
- toJSON(standalone?: boolean, includeSchemaVersion?: boolean): UnitProps;
47
- /** @internal */
48
- toXml(schemaXml: Document): Promise<Element>;
49
- fromJSONSync(unitProps: UnitProps): void;
50
- fromJSON(unitProps: UnitProps): Promise<void>;
51
- /**
52
- * @alpha
53
- * Used for schema editing.
54
- */
55
- protected setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;
56
- /**
57
- * @alpha
58
- * Used for schema editing.
59
- */
60
- protected setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;
61
- /**
62
- * @alpha
63
- * Used for schema editing.
64
- */
65
- protected setDefinition(definition: string): Promise<void>;
66
- }
67
- /**
68
- * @internal
69
- * An abstract class used for schema editing.
70
- */
71
- export declare abstract class MutableUnit extends Unit {
72
- abstract setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;
73
- abstract setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;
74
- abstract setDefinition(definition: string): Promise<void>;
75
- abstract setDisplayLabel(displayLabel: string): void;
76
- }
1
+ /** @packageDocumentation
2
+ * @module Metadata
3
+ */
4
+ import { UnitProps } from "../Deserialization/JsonProps";
5
+ import { SchemaItemType } from "../ECObjects";
6
+ import { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from "../Interfaces";
7
+ import { Schema } from "./Schema";
8
+ import { SchemaItem } from "./SchemaItem";
9
+ /**
10
+ * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a
11
+ * first-class concept is to allow the iModel to not be dependent on any hard-coded Units
12
+ * @beta
13
+ */
14
+ export declare class Unit extends SchemaItem {
15
+ readonly schemaItemType: SchemaItemType.Unit;
16
+ protected _phenomenon?: LazyLoadedPhenomenon;
17
+ protected _unitSystem?: LazyLoadedUnitSystem;
18
+ protected _definition: string;
19
+ protected _numerator?: number;
20
+ protected _denominator?: number;
21
+ protected _offset?: number;
22
+ constructor(schema: Schema, name: string);
23
+ get phenomenon(): LazyLoadedPhenomenon | undefined;
24
+ get unitSystem(): LazyLoadedUnitSystem | undefined;
25
+ get definition(): string;
26
+ get numerator(): number;
27
+ get offset(): number;
28
+ get denominator(): number;
29
+ get hasNumerator(): boolean;
30
+ get hasOffset(): boolean;
31
+ get hasDenominator(): boolean;
32
+ /**
33
+ * Returns true if a conversion can be calculated between the input units
34
+ * @alpha
35
+ */
36
+ static areCompatible(unitA: Unit, unitB: Unit): Promise<boolean>;
37
+ /**
38
+ * @alpha
39
+ */
40
+ static isUnit(object: any): object is Unit;
41
+ /**
42
+ * Save this Unit's properties to an object for serializing to JSON.
43
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
44
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
45
+ */
46
+ toJSON(standalone?: boolean, includeSchemaVersion?: boolean): UnitProps;
47
+ /** @internal */
48
+ toXml(schemaXml: Document): Promise<Element>;
49
+ fromJSONSync(unitProps: UnitProps): void;
50
+ fromJSON(unitProps: UnitProps): Promise<void>;
51
+ /**
52
+ * @alpha
53
+ * Used for schema editing.
54
+ */
55
+ protected setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;
56
+ /**
57
+ * @alpha
58
+ * Used for schema editing.
59
+ */
60
+ protected setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;
61
+ /**
62
+ * @alpha
63
+ * Used for schema editing.
64
+ */
65
+ protected setDefinition(definition: string): Promise<void>;
66
+ }
67
+ /**
68
+ * @internal
69
+ * An abstract class used for schema editing.
70
+ */
71
+ export declare abstract class MutableUnit extends Unit {
72
+ abstract setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;
73
+ abstract setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;
74
+ abstract setDefinition(definition: string): Promise<void>;
75
+ abstract setDisplayLabel(displayLabel: string): void;
76
+ }
77
77
  //# sourceMappingURL=Unit.d.ts.map
@@ -1,163 +1,163 @@
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.MutableUnit = exports.Unit = void 0;
11
- const DelayedPromise_1 = require("../DelayedPromise");
12
- const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
13
- const ECObjects_1 = require("../ECObjects");
14
- const Exception_1 = require("../Exception");
15
- const SchemaItem_1 = require("./SchemaItem");
16
- /**
17
- * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a
18
- * first-class concept is to allow the iModel to not be dependent on any hard-coded Units
19
- * @beta
20
- */
21
- class Unit extends SchemaItem_1.SchemaItem {
22
- constructor(schema, name) {
23
- super(schema, name);
24
- this.schemaItemType = ECObjects_1.SchemaItemType.Unit;
25
- this._definition = "";
26
- }
27
- get phenomenon() { return this._phenomenon; }
28
- get unitSystem() { return this._unitSystem; }
29
- get definition() { return this._definition; }
30
- get numerator() { return this._numerator ?? 1.0; }
31
- get offset() { return this._offset ?? 0.0; }
32
- get denominator() { return this._denominator ?? 1.0; }
33
- get hasNumerator() { return (this._numerator !== undefined); }
34
- get hasOffset() { return (this._offset !== undefined); }
35
- get hasDenominator() { return (this._denominator !== undefined); }
36
- /**
37
- * Returns true if a conversion can be calculated between the input units
38
- * @alpha
39
- */
40
- static async areCompatible(unitA, unitB) {
41
- const unitAPhenomenon = await unitA.phenomenon;
42
- const unitBPhenomenon = await unitB.phenomenon;
43
- if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))
44
- return false;
45
- return true;
46
- }
47
- /**
48
- * @alpha
49
- */
50
- static isUnit(object) {
51
- return SchemaItem_1.SchemaItem.isSchemaItem(object) && object.schemaItemType === ECObjects_1.SchemaItemType.Unit;
52
- }
53
- /**
54
- * Save this Unit's properties to an object for serializing to JSON.
55
- * @param standalone Serialization includes only this object (as opposed to the full schema).
56
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
57
- */
58
- toJSON(standalone = false, includeSchemaVersion = false) {
59
- const schemaJson = super.toJSON(standalone, includeSchemaVersion);
60
- schemaJson.phenomenon = this.phenomenon.fullName;
61
- schemaJson.unitSystem = this.unitSystem.fullName;
62
- schemaJson.definition = this.definition;
63
- if (this.hasNumerator)
64
- schemaJson.numerator = this.numerator;
65
- if (this.hasDenominator)
66
- schemaJson.denominator = this.denominator;
67
- if (this.hasOffset)
68
- schemaJson.offset = this.offset;
69
- return schemaJson;
70
- }
71
- /** @internal */
72
- async toXml(schemaXml) {
73
- const itemElement = await super.toXml(schemaXml);
74
- const phenomenon = await this.phenomenon;
75
- if (undefined !== phenomenon) {
76
- const phenomenonName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);
77
- itemElement.setAttribute("phenomenon", phenomenonName);
78
- }
79
- const unitSystem = await this.unitSystem;
80
- if (undefined !== unitSystem) {
81
- const unitSystemName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);
82
- itemElement.setAttribute("unitSystem", unitSystemName);
83
- }
84
- itemElement.setAttribute("definition", this.definition);
85
- if (this.hasNumerator)
86
- itemElement.setAttribute("numerator", this.numerator.toString());
87
- if (this.hasDenominator)
88
- itemElement.setAttribute("denominator", this.denominator.toString());
89
- if (this.hasOffset)
90
- itemElement.setAttribute("offset", this.offset.toString());
91
- return itemElement;
92
- }
93
- fromJSONSync(unitProps) {
94
- super.fromJSONSync(unitProps);
95
- const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);
96
- if (!phenomenonSchemaItemKey)
97
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);
98
- this._phenomenon = new DelayedPromise_1.DelayedPromiseWithProps(phenomenonSchemaItemKey, async () => {
99
- const phenom = await this.schema.lookupItem(phenomenonSchemaItemKey);
100
- if (undefined === phenom)
101
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);
102
- return phenom;
103
- });
104
- const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);
105
- if (!unitSystemSchemaItemKey)
106
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);
107
- this._unitSystem = new DelayedPromise_1.DelayedPromiseWithProps(unitSystemSchemaItemKey, async () => {
108
- const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey);
109
- if (undefined === unitSystem)
110
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);
111
- return unitSystem;
112
- });
113
- if (this._definition !== "" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())
114
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);
115
- else if (this._definition === "")
116
- this._definition = unitProps.definition;
117
- if (undefined !== unitProps.numerator) {
118
- if (unitProps.numerator !== this._numerator)
119
- this._numerator = unitProps.numerator;
120
- }
121
- if (undefined !== unitProps.denominator) {
122
- if (unitProps.denominator !== this._denominator)
123
- this._denominator = unitProps.denominator;
124
- }
125
- if (undefined !== unitProps.offset) {
126
- if (unitProps.offset !== this._offset)
127
- this._offset = unitProps.offset;
128
- }
129
- }
130
- async fromJSON(unitProps) {
131
- this.fromJSONSync(unitProps);
132
- }
133
- /**
134
- * @alpha
135
- * Used for schema editing.
136
- */
137
- async setPhenomenon(phenomenon) {
138
- this._phenomenon = phenomenon;
139
- }
140
- /**
141
- * @alpha
142
- * Used for schema editing.
143
- */
144
- async setUnitSystem(unitSystem) {
145
- this._unitSystem = unitSystem;
146
- }
147
- /**
148
- * @alpha
149
- * Used for schema editing.
150
- */
151
- async setDefinition(definition) {
152
- this._definition = definition;
153
- }
154
- }
155
- exports.Unit = Unit;
156
- /**
157
- * @internal
158
- * An abstract class used for schema editing.
159
- */
160
- class MutableUnit extends Unit {
161
- }
162
- exports.MutableUnit = MutableUnit;
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.MutableUnit = exports.Unit = void 0;
11
+ const DelayedPromise_1 = require("../DelayedPromise");
12
+ const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
13
+ const ECObjects_1 = require("../ECObjects");
14
+ const Exception_1 = require("../Exception");
15
+ const SchemaItem_1 = require("./SchemaItem");
16
+ /**
17
+ * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a
18
+ * first-class concept is to allow the iModel to not be dependent on any hard-coded Units
19
+ * @beta
20
+ */
21
+ class Unit extends SchemaItem_1.SchemaItem {
22
+ constructor(schema, name) {
23
+ super(schema, name);
24
+ this.schemaItemType = ECObjects_1.SchemaItemType.Unit;
25
+ this._definition = "";
26
+ }
27
+ get phenomenon() { return this._phenomenon; }
28
+ get unitSystem() { return this._unitSystem; }
29
+ get definition() { return this._definition; }
30
+ get numerator() { return this._numerator ?? 1.0; }
31
+ get offset() { return this._offset ?? 0.0; }
32
+ get denominator() { return this._denominator ?? 1.0; }
33
+ get hasNumerator() { return (this._numerator !== undefined); }
34
+ get hasOffset() { return (this._offset !== undefined); }
35
+ get hasDenominator() { return (this._denominator !== undefined); }
36
+ /**
37
+ * Returns true if a conversion can be calculated between the input units
38
+ * @alpha
39
+ */
40
+ static async areCompatible(unitA, unitB) {
41
+ const unitAPhenomenon = await unitA.phenomenon;
42
+ const unitBPhenomenon = await unitB.phenomenon;
43
+ if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))
44
+ return false;
45
+ return true;
46
+ }
47
+ /**
48
+ * @alpha
49
+ */
50
+ static isUnit(object) {
51
+ return SchemaItem_1.SchemaItem.isSchemaItem(object) && object.schemaItemType === ECObjects_1.SchemaItemType.Unit;
52
+ }
53
+ /**
54
+ * Save this Unit's properties to an object for serializing to JSON.
55
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
56
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
57
+ */
58
+ toJSON(standalone = false, includeSchemaVersion = false) {
59
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
60
+ schemaJson.phenomenon = this.phenomenon.fullName;
61
+ schemaJson.unitSystem = this.unitSystem.fullName;
62
+ schemaJson.definition = this.definition;
63
+ if (this.hasNumerator)
64
+ schemaJson.numerator = this.numerator;
65
+ if (this.hasDenominator)
66
+ schemaJson.denominator = this.denominator;
67
+ if (this.hasOffset)
68
+ schemaJson.offset = this.offset;
69
+ return schemaJson;
70
+ }
71
+ /** @internal */
72
+ async toXml(schemaXml) {
73
+ const itemElement = await super.toXml(schemaXml);
74
+ const phenomenon = await this.phenomenon;
75
+ if (undefined !== phenomenon) {
76
+ const phenomenonName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);
77
+ itemElement.setAttribute("phenomenon", phenomenonName);
78
+ }
79
+ const unitSystem = await this.unitSystem;
80
+ if (undefined !== unitSystem) {
81
+ const unitSystemName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);
82
+ itemElement.setAttribute("unitSystem", unitSystemName);
83
+ }
84
+ itemElement.setAttribute("definition", this.definition);
85
+ if (this.hasNumerator)
86
+ itemElement.setAttribute("numerator", this.numerator.toString());
87
+ if (this.hasDenominator)
88
+ itemElement.setAttribute("denominator", this.denominator.toString());
89
+ if (this.hasOffset)
90
+ itemElement.setAttribute("offset", this.offset.toString());
91
+ return itemElement;
92
+ }
93
+ fromJSONSync(unitProps) {
94
+ super.fromJSONSync(unitProps);
95
+ const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);
96
+ if (!phenomenonSchemaItemKey)
97
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);
98
+ this._phenomenon = new DelayedPromise_1.DelayedPromiseWithProps(phenomenonSchemaItemKey, async () => {
99
+ const phenom = await this.schema.lookupItem(phenomenonSchemaItemKey);
100
+ if (undefined === phenom)
101
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);
102
+ return phenom;
103
+ });
104
+ const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);
105
+ if (!unitSystemSchemaItemKey)
106
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);
107
+ this._unitSystem = new DelayedPromise_1.DelayedPromiseWithProps(unitSystemSchemaItemKey, async () => {
108
+ const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey);
109
+ if (undefined === unitSystem)
110
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);
111
+ return unitSystem;
112
+ });
113
+ if (this._definition !== "" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())
114
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);
115
+ else if (this._definition === "")
116
+ this._definition = unitProps.definition;
117
+ if (undefined !== unitProps.numerator) {
118
+ if (unitProps.numerator !== this._numerator)
119
+ this._numerator = unitProps.numerator;
120
+ }
121
+ if (undefined !== unitProps.denominator) {
122
+ if (unitProps.denominator !== this._denominator)
123
+ this._denominator = unitProps.denominator;
124
+ }
125
+ if (undefined !== unitProps.offset) {
126
+ if (unitProps.offset !== this._offset)
127
+ this._offset = unitProps.offset;
128
+ }
129
+ }
130
+ async fromJSON(unitProps) {
131
+ this.fromJSONSync(unitProps);
132
+ }
133
+ /**
134
+ * @alpha
135
+ * Used for schema editing.
136
+ */
137
+ async setPhenomenon(phenomenon) {
138
+ this._phenomenon = phenomenon;
139
+ }
140
+ /**
141
+ * @alpha
142
+ * Used for schema editing.
143
+ */
144
+ async setUnitSystem(unitSystem) {
145
+ this._unitSystem = unitSystem;
146
+ }
147
+ /**
148
+ * @alpha
149
+ * Used for schema editing.
150
+ */
151
+ async setDefinition(definition) {
152
+ this._definition = definition;
153
+ }
154
+ }
155
+ exports.Unit = Unit;
156
+ /**
157
+ * @internal
158
+ * An abstract class used for schema editing.
159
+ */
160
+ class MutableUnit extends Unit {
161
+ }
162
+ exports.MutableUnit = MutableUnit;
163
163
  //# sourceMappingURL=Unit.js.map
@@ -1,21 +1,21 @@
1
- /** @packageDocumentation
2
- * @module Metadata
3
- */
4
- import { SchemaItemType } from "../ECObjects";
5
- import { Schema } from "./Schema";
6
- import { SchemaItem } from "./SchemaItem";
7
- /**
8
- * @beta
9
- */
10
- export declare class UnitSystem extends SchemaItem {
11
- readonly schemaItemType: SchemaItemType.UnitSystem;
12
- constructor(schema: Schema, name: string);
13
- }
14
- /**
15
- * @internal
16
- * Used for schema editing.
17
- */
18
- export declare abstract class MutableUnitSystem extends UnitSystem {
19
- abstract setDisplayLabel(displayLabel: string): void;
20
- }
1
+ /** @packageDocumentation
2
+ * @module Metadata
3
+ */
4
+ import { SchemaItemType } from "../ECObjects";
5
+ import { Schema } from "./Schema";
6
+ import { SchemaItem } from "./SchemaItem";
7
+ /**
8
+ * @beta
9
+ */
10
+ export declare class UnitSystem extends SchemaItem {
11
+ readonly schemaItemType: SchemaItemType.UnitSystem;
12
+ constructor(schema: Schema, name: string);
13
+ }
14
+ /**
15
+ * @internal
16
+ * Used for schema editing.
17
+ */
18
+ export declare abstract class MutableUnitSystem extends UnitSystem {
19
+ abstract setDisplayLabel(displayLabel: string): void;
20
+ }
21
21
  //# sourceMappingURL=UnitSystem.d.ts.map
@@ -1,30 +1,30 @@
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.MutableUnitSystem = exports.UnitSystem = void 0;
11
- const ECObjects_1 = require("../ECObjects");
12
- const SchemaItem_1 = require("./SchemaItem");
13
- /**
14
- * @beta
15
- */
16
- class UnitSystem extends SchemaItem_1.SchemaItem {
17
- constructor(schema, name) {
18
- super(schema, name);
19
- this.schemaItemType = ECObjects_1.SchemaItemType.UnitSystem;
20
- }
21
- }
22
- exports.UnitSystem = UnitSystem;
23
- /**
24
- * @internal
25
- * Used for schema editing.
26
- */
27
- class MutableUnitSystem extends UnitSystem {
28
- }
29
- exports.MutableUnitSystem = MutableUnitSystem;
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.MutableUnitSystem = exports.UnitSystem = void 0;
11
+ const ECObjects_1 = require("../ECObjects");
12
+ const SchemaItem_1 = require("./SchemaItem");
13
+ /**
14
+ * @beta
15
+ */
16
+ class UnitSystem extends SchemaItem_1.SchemaItem {
17
+ constructor(schema, name) {
18
+ super(schema, name);
19
+ this.schemaItemType = ECObjects_1.SchemaItemType.UnitSystem;
20
+ }
21
+ }
22
+ exports.UnitSystem = UnitSystem;
23
+ /**
24
+ * @internal
25
+ * Used for schema editing.
26
+ */
27
+ class MutableUnitSystem extends UnitSystem {
28
+ }
29
+ exports.MutableUnitSystem = MutableUnitSystem;
30
30
  //# sourceMappingURL=UnitSystem.js.map