@itwin/ecschema-metadata 4.0.0-dev.8 → 4.0.0-dev.80
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 +41 -1
- package/lib/cjs/Constants.d.ts +23 -23
- package/lib/cjs/Constants.js +33 -33
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/Context.d.ts +139 -139
- package/lib/cjs/Context.js +204 -204
- package/lib/cjs/DelayedPromise.d.ts +88 -88
- package/lib/cjs/DelayedPromise.d.ts.map +1 -1
- package/lib/cjs/DelayedPromise.js +91 -91
- package/lib/cjs/DelayedPromise.js.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
- package/lib/cjs/Deserialization/AbstractParser.d.ts.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.js +11 -11
- package/lib/cjs/Deserialization/Helper.d.ts +251 -251
- package/lib/cjs/Deserialization/Helper.js +843 -843
- package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
- package/lib/cjs/Deserialization/JsonParser.js +680 -680
- package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
- package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.js +9 -9
- package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
- package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
- package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
- package/lib/cjs/Deserialization/XmlParser.js +973 -973
- package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
- package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
- package/lib/cjs/ECName.d.ts +30 -30
- package/lib/cjs/ECName.js +85 -85
- package/lib/cjs/ECObjects.d.ts +162 -162
- package/lib/cjs/ECObjects.js +453 -453
- package/lib/cjs/Exception.d.ts +43 -43
- package/lib/cjs/Exception.js +84 -84
- package/lib/cjs/Interfaces.d.ts +66 -66
- package/lib/cjs/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Interfaces.js +9 -9
- package/lib/cjs/Metadata/Class.d.ts +243 -243
- package/lib/cjs/Metadata/Class.js +558 -558
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.d.ts +64 -64
- package/lib/cjs/Metadata/Constant.js +123 -123
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
- package/lib/cjs/Metadata/CustomAttribute.js +27 -27
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
- package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
- package/lib/cjs/Metadata/EntityClass.js +230 -230
- package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
- package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/cjs/Metadata/Enumeration.js +159 -159
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +98 -98
- package/lib/cjs/Metadata/Format.js +242 -242
- package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
- package/lib/cjs/Metadata/InvertedUnit.js +97 -97
- package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
- package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.d.ts +54 -54
- package/lib/cjs/Metadata/Mixin.js +113 -113
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
- package/lib/cjs/Metadata/OverrideFormat.js +88 -88
- package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
- package/lib/cjs/Metadata/Phenomenon.js +59 -59
- package/lib/cjs/Metadata/Property.d.ts +197 -197
- package/lib/cjs/Metadata/Property.d.ts.map +1 -1
- package/lib/cjs/Metadata/Property.js +491 -491
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
- package/lib/cjs/Metadata/PropertyCategory.js +61 -61
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
- package/lib/cjs/Metadata/RelationshipClass.js +349 -349
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +291 -291
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +520 -520
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
- package/lib/cjs/Metadata/SchemaItem.js +136 -136
- package/lib/cjs/Metadata/Unit.d.ts +76 -76
- package/lib/cjs/Metadata/Unit.js +162 -162
- package/lib/cjs/Metadata/Unit.js.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
- package/lib/cjs/Metadata/UnitSystem.js +29 -29
- package/lib/cjs/PropertyTypes.d.ts +49 -49
- package/lib/cjs/PropertyTypes.js +91 -91
- package/lib/cjs/PropertyTypes.js.map +1 -1
- package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
- package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaJsonLocater.js +42 -42
- package/lib/cjs/SchemaKey.d.ts +110 -110
- package/lib/cjs/SchemaKey.js +219 -219
- package/lib/cjs/SchemaLoader.d.ts +23 -23
- package/lib/cjs/SchemaLoader.js +47 -47
- package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
- package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
- package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
- package/lib/cjs/UnitConversion/Graph.js +83 -83
- package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
- package/lib/cjs/UnitConversion/Parser.js +42 -42
- package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
- package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
- package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
- package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
- package/lib/cjs/UnitConversion/UnitTree.js +169 -169
- package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js +234 -236
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
- package/lib/cjs/Validation/SchemaWalker.js +53 -53
- package/lib/cjs/ecschema-metadata.d.ts +51 -51
- package/lib/cjs/ecschema-metadata.js +100 -96
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
- package/lib/cjs/utils/SchemaGraph.js +65 -65
- package/package.json +12 -12
|
@@ -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
|
package/lib/cjs/Metadata/Unit.js
CHANGED
|
@@ -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() {
|
|
31
|
-
get offset() {
|
|
32
|
-
get denominator() {
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../../src/Metadata/Unit.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AAC,WAAW,GAAG,SAAS,CAAC,UAAU,CAAC;QAE1C,IAAI,SAAS,KAAK,SAAS,CAAC,SAAS,EAAE;YACrC,IAAI,SAAS,CAAC,SAAS,KAAK,IAAI,CAAC,UAAU;gBACzC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC;SACzC;QAED,IAAI,SAAS,KAAK,SAAS,CAAC,WAAW,EAAE;YACvC,IAAI,SAAS,CAAC,WAAW,KAAK,IAAI,CAAC,YAAY;gBAC7C,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,WAAW,CAAC;SAC7C;QAED,IAAI,SAAS,KAAK,SAAS,CAAC,MAAM,EAAE;YAClC,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO;gBACnC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;SACnC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,SAAoB;QACjD,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAkB;QAC9C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;CACF;AApKD,oBAoKC;AACD;;;GAGG;AACH,MAAsB,WAAY,SAAQ,IAAI;CAK7C;AALD,kCAKC","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 { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { UnitProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { Phenomenon } from \"./Phenomenon\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { UnitSystem } from \"./UnitSystem\";\r\n\r\n/**\r\n * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a\r\n * first-class concept is to allow the iModel to not be dependent on any hard-coded Units\r\n * @beta\r\n */\r\nexport class Unit extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Unit; // eslint-disable-line\r\n protected _phenomenon?: LazyLoadedPhenomenon;\r\n protected _unitSystem?: LazyLoadedUnitSystem;\r\n protected _definition: string;\r\n protected _numerator?: number;\r\n protected _denominator?: number;\r\n protected _offset?: number;\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Unit;\r\n this._definition = \"\";\r\n }\r\n\r\n public get phenomenon(): LazyLoadedPhenomenon | undefined { return this._phenomenon; }\r\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\r\n public get definition(): string { return this._definition; }\r\n public get numerator(): number { return this._numerator ?? 1.0; }\r\n public get offset(): number { return this._offset ?? 0.0; }\r\n public get denominator(): number { return this._denominator ?? 1.0; }\r\n public get hasNumerator(): boolean { return (this._numerator !== undefined); }\r\n public get hasOffset(): boolean { return (this._offset !== undefined); }\r\n public get hasDenominator(): boolean { return (this._denominator !== undefined); }\r\n\r\n /**\r\n * Returns true if a conversion can be calculated between the input units\r\n * @alpha\r\n */\r\n public static async areCompatible(unitA: Unit, unitB: Unit): Promise<boolean> {\r\n const unitAPhenomenon = await unitA.phenomenon;\r\n const unitBPhenomenon = await unitB.phenomenon;\r\n\r\n if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * @alpha\r\n */\r\n public static isUnit(object: any): object is Unit {\r\n return SchemaItem.isSchemaItem(object) && object.schemaItemType === SchemaItemType.Unit;\r\n }\r\n\r\n /**\r\n * Save this Unit'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): UnitProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.phenomenon = this.phenomenon!.fullName;\r\n schemaJson.unitSystem = this.unitSystem!.fullName;\r\n schemaJson.definition = this.definition;\r\n if (this.hasNumerator)\r\n schemaJson.numerator = this.numerator;\r\n if (this.hasDenominator)\r\n schemaJson.denominator = this.denominator;\r\n if (this.hasOffset)\r\n schemaJson.offset = this.offset;\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\r\n const phenomenon = await this.phenomenon;\r\n if (undefined !== phenomenon) {\r\n const phenomenonName = XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);\r\n itemElement.setAttribute(\"phenomenon\", phenomenonName);\r\n }\r\n\r\n const unitSystem = await this.unitSystem;\r\n if (undefined !== unitSystem) {\r\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\r\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\r\n }\r\n\r\n itemElement.setAttribute(\"definition\", this.definition);\r\n if (this.hasNumerator)\r\n itemElement.setAttribute(\"numerator\", this.numerator.toString());\r\n if (this.hasDenominator)\r\n itemElement.setAttribute(\"denominator\", this.denominator.toString());\r\n if (this.hasOffset)\r\n itemElement.setAttribute(\"offset\", this.offset.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(unitProps: UnitProps) {\r\n super.fromJSONSync(unitProps);\r\n\r\n const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);\r\n if (!phenomenonSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n this._phenomenon = new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(phenomenonSchemaItemKey,\r\n async () => {\r\n const phenom = await this.schema.lookupItem<Phenomenon>(phenomenonSchemaItemKey);\r\n if (undefined === phenom)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n return phenom;\r\n });\r\n\r\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);\r\n if (!unitSystemSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\r\n async () => {\r\n const unitSystem = await this.schema.lookupItem<UnitSystem>(unitSystemSchemaItemKey);\r\n if (undefined === unitSystem)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n return unitSystem;\r\n });\r\n\r\n if (this._definition !== \"\" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);\r\n else if (this._definition === \"\")\r\n this._definition = unitProps.definition;\r\n\r\n if (undefined !== unitProps.numerator) {\r\n if (unitProps.numerator !== this._numerator)\r\n this._numerator = unitProps.numerator;\r\n }\r\n\r\n if (undefined !== unitProps.denominator) {\r\n if (unitProps.denominator !== this._denominator)\r\n this._denominator = unitProps.denominator;\r\n }\r\n\r\n if (undefined !== unitProps.offset) {\r\n if (unitProps.offset !== this._offset)\r\n this._offset = unitProps.offset;\r\n }\r\n }\r\n\r\n public override async fromJSON(unitProps: UnitProps) {\r\n this.fromJSONSync(unitProps);\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setPhenomenon(phenomenon: LazyLoadedPhenomenon) {\r\n this._phenomenon = phenomenon;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\r\n this._unitSystem = unitSystem;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setDefinition(definition: string) {\r\n this._definition = definition;\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableUnit extends Unit {\r\n public abstract override setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;\r\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;\r\n public abstract override setDefinition(definition: string): Promise<void>;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../../src/Metadata/Unit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAK/D,6CAA0C;AAG1C;;;;GAIG;AACH,MAAa,IAAK,SAAQ,uBAAU;IASlC,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,IAAI,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB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AI,SAAS,KAAK,SAAS,CAAC,MAAM,EAAE;YAClC,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO;gBACnC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;SACnC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,SAAoB;QACjD,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAkB;QAC9C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;CACF;AApKD,oBAoKC;AACD;;;GAGG;AACH,MAAsB,WAAY,SAAQ,IAAI;CAK7C;AALD,kCAKC","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 { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { UnitProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { Phenomenon } from \"./Phenomenon\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { UnitSystem } from \"./UnitSystem\";\r\n\r\n/**\r\n * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a\r\n * first-class concept is to allow the iModel to not be dependent on any hard-coded Units\r\n * @beta\r\n */\r\nexport class Unit extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Unit; // eslint-disable-line\r\n protected _phenomenon?: LazyLoadedPhenomenon;\r\n protected _unitSystem?: LazyLoadedUnitSystem;\r\n protected _definition: string;\r\n protected _numerator?: number;\r\n protected _denominator?: number;\r\n protected _offset?: number;\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Unit;\r\n this._definition = \"\";\r\n }\r\n\r\n public get phenomenon(): LazyLoadedPhenomenon | undefined { return this._phenomenon; }\r\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\r\n public get definition(): string { return this._definition; }\r\n public get numerator(): number { return this._numerator ?? 1.0; }\r\n public get offset(): number { return this._offset ?? 0.0; }\r\n public get denominator(): number { return this._denominator ?? 1.0; }\r\n public get hasNumerator(): boolean { return (this._numerator !== undefined); }\r\n public get hasOffset(): boolean { return (this._offset !== undefined); }\r\n public get hasDenominator(): boolean { return (this._denominator !== undefined); }\r\n\r\n /**\r\n * Returns true if a conversion can be calculated between the input units\r\n * @alpha\r\n */\r\n public static async areCompatible(unitA: Unit, unitB: Unit): Promise<boolean> {\r\n const unitAPhenomenon = await unitA.phenomenon;\r\n const unitBPhenomenon = await unitB.phenomenon;\r\n\r\n if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * @alpha\r\n */\r\n public static isUnit(object: any): object is Unit {\r\n return SchemaItem.isSchemaItem(object) && object.schemaItemType === SchemaItemType.Unit;\r\n }\r\n\r\n /**\r\n * Save this Unit'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): UnitProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.phenomenon = this.phenomenon!.fullName;\r\n schemaJson.unitSystem = this.unitSystem!.fullName;\r\n schemaJson.definition = this.definition;\r\n if (this.hasNumerator)\r\n schemaJson.numerator = this.numerator;\r\n if (this.hasDenominator)\r\n schemaJson.denominator = this.denominator;\r\n if (this.hasOffset)\r\n schemaJson.offset = this.offset;\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\r\n const phenomenon = await this.phenomenon;\r\n if (undefined !== phenomenon) {\r\n const phenomenonName = XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);\r\n itemElement.setAttribute(\"phenomenon\", phenomenonName);\r\n }\r\n\r\n const unitSystem = await this.unitSystem;\r\n if (undefined !== unitSystem) {\r\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\r\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\r\n }\r\n\r\n itemElement.setAttribute(\"definition\", this.definition);\r\n if (this.hasNumerator)\r\n itemElement.setAttribute(\"numerator\", this.numerator.toString());\r\n if (this.hasDenominator)\r\n itemElement.setAttribute(\"denominator\", this.denominator.toString());\r\n if (this.hasOffset)\r\n itemElement.setAttribute(\"offset\", this.offset.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(unitProps: UnitProps) {\r\n super.fromJSONSync(unitProps);\r\n\r\n const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);\r\n if (!phenomenonSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n this._phenomenon = new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(phenomenonSchemaItemKey,\r\n async () => {\r\n const phenom = await this.schema.lookupItem<Phenomenon>(phenomenonSchemaItemKey);\r\n if (undefined === phenom)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n return phenom;\r\n });\r\n\r\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);\r\n if (!unitSystemSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\r\n async () => {\r\n const unitSystem = await this.schema.lookupItem<UnitSystem>(unitSystemSchemaItemKey);\r\n if (undefined === unitSystem)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n return unitSystem;\r\n });\r\n\r\n if (this._definition !== \"\" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);\r\n else if (this._definition === \"\")\r\n this._definition = unitProps.definition;\r\n\r\n if (undefined !== unitProps.numerator) {\r\n if (unitProps.numerator !== this._numerator)\r\n this._numerator = unitProps.numerator;\r\n }\r\n\r\n if (undefined !== unitProps.denominator) {\r\n if (unitProps.denominator !== this._denominator)\r\n this._denominator = unitProps.denominator;\r\n }\r\n\r\n if (undefined !== unitProps.offset) {\r\n if (unitProps.offset !== this._offset)\r\n this._offset = unitProps.offset;\r\n }\r\n }\r\n\r\n public override async fromJSON(unitProps: UnitProps) {\r\n this.fromJSONSync(unitProps);\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setPhenomenon(phenomenon: LazyLoadedPhenomenon) {\r\n this._phenomenon = phenomenon;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\r\n this._unitSystem = unitSystem;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setDefinition(definition: string) {\r\n this._definition = definition;\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableUnit extends Unit {\r\n public abstract override setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;\r\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;\r\n public abstract override setDefinition(definition: string): Promise<void>;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
@@ -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
|