@itwin/ecschema-metadata 5.0.0-dev.59 → 5.0.0-dev.61
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/lib/cjs/Context.d.ts +36 -15
- package/lib/cjs/Context.d.ts.map +1 -1
- package/lib/cjs/Context.js +10 -18
- package/lib/cjs/Context.js.map +1 -1
- package/lib/cjs/Deserialization/Helper.d.ts +3 -3
- package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.js +2 -1
- package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
- package/lib/cjs/ECObjects.d.ts +21 -1
- package/lib/cjs/ECObjects.d.ts.map +1 -1
- package/lib/cjs/ECObjects.js +34 -2
- package/lib/cjs/ECObjects.js.map +1 -1
- package/lib/cjs/Interfaces.d.ts +7 -0
- package/lib/cjs/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Metadata/Class.d.ts +24 -2
- package/lib/cjs/Metadata/Class.d.ts.map +1 -1
- package/lib/cjs/Metadata/Class.js +40 -10
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.d.ts +14 -1
- package/lib/cjs/Metadata/Constant.d.ts.map +1 -1
- package/lib/cjs/Metadata/Constant.js +23 -2
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +15 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js +21 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.d.ts +17 -3
- package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/EntityClass.js +28 -6
- package/lib/cjs/Metadata/EntityClass.js.map +1 -1
- package/lib/cjs/Metadata/Enumeration.d.ts +14 -1
- package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/cjs/Metadata/Enumeration.js +19 -1
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +13 -1
- package/lib/cjs/Metadata/Format.d.ts.map +1 -1
- package/lib/cjs/Metadata/Format.js +24 -3
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.d.ts +8 -1
- package/lib/cjs/Metadata/InvertedUnit.d.ts.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.js +15 -3
- package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.d.ts +14 -1
- package/lib/cjs/Metadata/KindOfQuantity.d.ts.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.js +40 -13
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.d.ts +15 -1
- package/lib/cjs/Metadata/Mixin.d.ts.map +1 -1
- package/lib/cjs/Metadata/Mixin.js +22 -2
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.d.ts +14 -1
- package/lib/cjs/Metadata/Phenomenon.d.ts.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.js +21 -1
- package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
- package/lib/cjs/Metadata/Property.d.ts +1 -1
- package/lib/cjs/Metadata/Property.d.ts.map +1 -1
- package/lib/cjs/Metadata/Property.js +11 -6
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.d.ts +14 -1
- package/lib/cjs/Metadata/PropertyCategory.d.ts.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.js +20 -1
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.d.ts +15 -1
- package/lib/cjs/Metadata/RelationshipClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.js +29 -6
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +114 -6
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +125 -24
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +11 -2
- package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.js +6 -1
- package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
- package/lib/cjs/Metadata/Unit.d.ts +8 -1
- package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
- package/lib/cjs/Metadata/Unit.js +15 -3
- package/lib/cjs/Metadata/Unit.js.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.d.ts +14 -1
- package/lib/cjs/Metadata/UnitSystem.d.ts.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.js +22 -1
- package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
- package/lib/cjs/SchemaJsonLocater.d.ts +2 -2
- package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaJsonLocater.js +1 -1
- package/lib/cjs/SchemaJsonLocater.js.map +1 -1
- package/lib/cjs/SchemaKey.d.ts +6 -0
- package/lib/cjs/SchemaKey.d.ts.map +1 -1
- package/lib/cjs/SchemaKey.js +6 -0
- package/lib/cjs/SchemaKey.js.map +1 -1
- package/lib/cjs/SchemaLoader.d.ts +2 -2
- package/lib/cjs/SchemaLoader.d.ts.map +1 -1
- package/lib/cjs/SchemaLoader.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.d.ts +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.js +5 -5
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js +3 -3
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/esm/Context.d.ts +36 -15
- package/lib/esm/Context.d.ts.map +1 -1
- package/lib/esm/Context.js +8 -16
- package/lib/esm/Context.js.map +1 -1
- package/lib/esm/Deserialization/Helper.d.ts +3 -3
- package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
- package/lib/esm/Deserialization/Helper.js.map +1 -1
- package/lib/esm/Deserialization/XmlParser.js +2 -1
- package/lib/esm/Deserialization/XmlParser.js.map +1 -1
- package/lib/esm/ECObjects.d.ts +21 -1
- package/lib/esm/ECObjects.d.ts.map +1 -1
- package/lib/esm/ECObjects.js +32 -1
- package/lib/esm/ECObjects.js.map +1 -1
- package/lib/esm/Interfaces.d.ts +7 -0
- package/lib/esm/Interfaces.d.ts.map +1 -1
- package/lib/esm/Interfaces.js.map +1 -1
- package/lib/esm/Metadata/Class.d.ts +24 -2
- package/lib/esm/Metadata/Class.d.ts.map +1 -1
- package/lib/esm/Metadata/Class.js +41 -11
- package/lib/esm/Metadata/Class.js.map +1 -1
- package/lib/esm/Metadata/Constant.d.ts +14 -1
- package/lib/esm/Metadata/Constant.d.ts.map +1 -1
- package/lib/esm/Metadata/Constant.js +23 -2
- package/lib/esm/Metadata/Constant.js.map +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.d.ts +15 -1
- package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.js +21 -1
- package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/esm/Metadata/EntityClass.d.ts +17 -3
- package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/esm/Metadata/EntityClass.js +28 -6
- package/lib/esm/Metadata/EntityClass.js.map +1 -1
- package/lib/esm/Metadata/Enumeration.d.ts +14 -1
- package/lib/esm/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/esm/Metadata/Enumeration.js +19 -1
- package/lib/esm/Metadata/Enumeration.js.map +1 -1
- package/lib/esm/Metadata/Format.d.ts +13 -1
- package/lib/esm/Metadata/Format.d.ts.map +1 -1
- package/lib/esm/Metadata/Format.js +24 -3
- package/lib/esm/Metadata/Format.js.map +1 -1
- package/lib/esm/Metadata/InvertedUnit.d.ts +8 -1
- package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -1
- package/lib/esm/Metadata/InvertedUnit.js +15 -3
- package/lib/esm/Metadata/InvertedUnit.js.map +1 -1
- package/lib/esm/Metadata/KindOfQuantity.d.ts +14 -1
- package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -1
- package/lib/esm/Metadata/KindOfQuantity.js +40 -13
- package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/esm/Metadata/Mixin.d.ts +15 -1
- package/lib/esm/Metadata/Mixin.d.ts.map +1 -1
- package/lib/esm/Metadata/Mixin.js +23 -3
- package/lib/esm/Metadata/Mixin.js.map +1 -1
- package/lib/esm/Metadata/Phenomenon.d.ts +14 -1
- package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -1
- package/lib/esm/Metadata/Phenomenon.js +21 -1
- package/lib/esm/Metadata/Phenomenon.js.map +1 -1
- package/lib/esm/Metadata/Property.d.ts +1 -1
- package/lib/esm/Metadata/Property.d.ts.map +1 -1
- package/lib/esm/Metadata/Property.js +12 -7
- package/lib/esm/Metadata/Property.js.map +1 -1
- package/lib/esm/Metadata/PropertyCategory.d.ts +14 -1
- package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -1
- package/lib/esm/Metadata/PropertyCategory.js +20 -1
- package/lib/esm/Metadata/PropertyCategory.js.map +1 -1
- package/lib/esm/Metadata/RelationshipClass.d.ts +15 -1
- package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -1
- package/lib/esm/Metadata/RelationshipClass.js +30 -7
- package/lib/esm/Metadata/RelationshipClass.js.map +1 -1
- package/lib/esm/Metadata/Schema.d.ts +114 -6
- package/lib/esm/Metadata/Schema.d.ts.map +1 -1
- package/lib/esm/Metadata/Schema.js +125 -24
- package/lib/esm/Metadata/Schema.js.map +1 -1
- package/lib/esm/Metadata/SchemaItem.d.ts +11 -2
- package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/esm/Metadata/SchemaItem.js +7 -2
- package/lib/esm/Metadata/SchemaItem.js.map +1 -1
- package/lib/esm/Metadata/Unit.d.ts +8 -1
- package/lib/esm/Metadata/Unit.d.ts.map +1 -1
- package/lib/esm/Metadata/Unit.js +15 -3
- package/lib/esm/Metadata/Unit.js.map +1 -1
- package/lib/esm/Metadata/UnitSystem.d.ts +14 -1
- package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -1
- package/lib/esm/Metadata/UnitSystem.js +22 -1
- package/lib/esm/Metadata/UnitSystem.js.map +1 -1
- package/lib/esm/SchemaJsonLocater.d.ts +2 -2
- package/lib/esm/SchemaJsonLocater.d.ts.map +1 -1
- package/lib/esm/SchemaJsonLocater.js +1 -1
- package/lib/esm/SchemaJsonLocater.js.map +1 -1
- package/lib/esm/SchemaKey.d.ts +6 -0
- package/lib/esm/SchemaKey.d.ts.map +1 -1
- package/lib/esm/SchemaKey.js +6 -0
- package/lib/esm/SchemaKey.js.map +1 -1
- package/lib/esm/SchemaLoader.d.ts +2 -2
- package/lib/esm/SchemaLoader.d.ts.map +1 -1
- package/lib/esm/SchemaLoader.js.map +1 -1
- package/lib/esm/UnitConversion/UnitConversion.d.ts +1 -1
- package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -1
- package/lib/esm/UnitConversion/UnitConversion.js +5 -5
- package/lib/esm/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/esm/UnitProvider/SchemaUnitProvider.js +3 -3
- package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/esm/Validation/SchemaWalker.d.ts +1 -1
- package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -1
- package/lib/esm/Validation/SchemaWalker.js.map +1 -1
- package/package.json +6 -6
|
@@ -13,12 +13,15 @@ const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtil
|
|
|
13
13
|
const ECObjects_1 = require("../ECObjects");
|
|
14
14
|
const Exception_1 = require("../Exception");
|
|
15
15
|
const SchemaItem_1 = require("./SchemaItem");
|
|
16
|
+
const Unit_1 = require("./Unit");
|
|
17
|
+
const UnitSystem_1 = require("./UnitSystem");
|
|
16
18
|
/**
|
|
17
19
|
* An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.
|
|
18
20
|
* @beta
|
|
19
21
|
*/
|
|
20
22
|
class InvertedUnit extends SchemaItem_1.SchemaItem {
|
|
21
|
-
schemaItemType =
|
|
23
|
+
schemaItemType = InvertedUnit.schemaItemType;
|
|
24
|
+
static get schemaItemType() { return ECObjects_1.SchemaItemType.InvertedUnit; }
|
|
22
25
|
_invertsUnit; // required
|
|
23
26
|
_unitSystem; // required
|
|
24
27
|
get invertsUnit() { return this._invertsUnit; }
|
|
@@ -29,6 +32,15 @@ class InvertedUnit extends SchemaItem_1.SchemaItem {
|
|
|
29
32
|
static isInvertedUnit(object) {
|
|
30
33
|
return SchemaItem_1.SchemaItem.isSchemaItem(object) && object.schemaItemType === ECObjects_1.SchemaItemType.InvertedUnit;
|
|
31
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Type assertion to check if the SchemaItem is of type InvertedUnit.
|
|
37
|
+
* @param item The SchemaItem to check.
|
|
38
|
+
* @returns The item cast to InvertedUnit if it is an InvertedUnit, undefined otherwise.
|
|
39
|
+
*/
|
|
40
|
+
static assertIsInvertedUnit(item) {
|
|
41
|
+
if (!this.isInvertedUnit(item))
|
|
42
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidSchemaItemType, `Expected '${ECObjects_1.SchemaItemType.InvertedUnit}' (InvertedUnit)`);
|
|
43
|
+
}
|
|
32
44
|
/**
|
|
33
45
|
* Save this InvertedUnit's properties to an object for serializing to JSON.
|
|
34
46
|
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
@@ -59,7 +71,7 @@ class InvertedUnit extends SchemaItem_1.SchemaItem {
|
|
|
59
71
|
super.fromJSONSync(invertedUnitProps);
|
|
60
72
|
const unitSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.invertsUnit);
|
|
61
73
|
this._invertsUnit = new DelayedPromise_1.DelayedPromiseWithProps(unitSchemaItemKey, async () => {
|
|
62
|
-
const invertsUnit = await this.schema.lookupItem(unitSchemaItemKey);
|
|
74
|
+
const invertsUnit = await this.schema.lookupItem(unitSchemaItemKey, Unit_1.Unit);
|
|
63
75
|
if (undefined === invertsUnit)
|
|
64
76
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the invertsUnit ${invertedUnitProps.invertsUnit}.`);
|
|
65
77
|
return invertsUnit;
|
|
@@ -68,7 +80,7 @@ class InvertedUnit extends SchemaItem_1.SchemaItem {
|
|
|
68
80
|
if (!unitSystemSchemaItemKey)
|
|
69
81
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);
|
|
70
82
|
this._unitSystem = new DelayedPromise_1.DelayedPromiseWithProps(unitSystemSchemaItemKey, async () => {
|
|
71
|
-
const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey);
|
|
83
|
+
const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey, UnitSystem_1.UnitSystem);
|
|
72
84
|
if (undefined === unitSystem)
|
|
73
85
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);
|
|
74
86
|
return unitSystem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvertedUnit.js","sourceRoot":"","sources":["../../../src/Metadata/InvertedUnit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAG/D,6CAA0C;
|
|
1
|
+
{"version":3,"file":"InvertedUnit.js","sourceRoot":"","sources":["../../../src/Metadata/InvertedUnit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAG/D,6CAA0C;AAC1C,iCAA8B;AAC9B,6CAA0C;AAE1C;;;GAGG;AACH,MAAa,YAAa,SAAQ,uBAAU;IACjB,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC;IAC/D,MAAM,KAAc,cAAc,KAAK,OAAO,0BAAc,CAAC,YAAY,CAAC,CAAC,CAAC;IACzE,YAAY,CAAkB,CAAC,WAAW;IAC1C,WAAW,CAAwB,CAAC,WAAW;IAEzD,IAAW,WAAW,KAAiC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAClF,IAAW,UAAU,KAAuC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAEtF;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,MAAW;QACtC,OAAO,uBAAU,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,cAAc,KAAK,0BAAc,CAAC,YAAY,CAAC;IAClG,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,oBAAoB,CAAC,IAAiB;QAClD,IAAG,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;YAC3B,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,qBAAqB,EAAE,aAAa,0BAAc,CAAC,YAAY,kBAAkB,CAAC,CAAC;IAChI,CAAC;IAED;;;;OAIG;IACa,MAAM,CAAC,aAAsB,KAAK,EAAE,uBAAgC,KAA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GD,oCAmGC;AAED;;;GAGG;AACH,MAAsB,mBAAoB,SAAQ,YAAY;CAI7D;AAJD,kDAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\nimport { InvertedUnitProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedUnit, LazyLoadedUnitSystem } from \"../Interfaces\";\nimport { SchemaItemKey } from \"../SchemaKey\";\nimport { SchemaItem } from \"./SchemaItem\";\nimport { Unit } from \"./Unit\";\nimport { UnitSystem } from \"./UnitSystem\";\n\n/**\n * An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.\n * @beta\n */\nexport class InvertedUnit extends SchemaItem {\n public override readonly schemaItemType = InvertedUnit.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.InvertedUnit; }\n protected _invertsUnit?: LazyLoadedUnit; // required\n protected _unitSystem?: LazyLoadedUnitSystem; // required\n\n public get invertsUnit(): LazyLoadedUnit | undefined { return this._invertsUnit; }\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\n\n /**\n * @alpha\n */\n public static isInvertedUnit(object: any): object is InvertedUnit {\n return SchemaItem.isSchemaItem(object) && object.schemaItemType === SchemaItemType.InvertedUnit;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type InvertedUnit.\n * @param item The SchemaItem to check.\n * @returns The item cast to InvertedUnit if it is an InvertedUnit, undefined otherwise.\n */\n public static assertIsInvertedUnit(item?: SchemaItem): asserts item is InvertedUnit {\n if(!this.isInvertedUnit(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.InvertedUnit}' (InvertedUnit)`);\n }\n\n /**\n * Save this InvertedUnit's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): InvertedUnitProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.invertsUnit = this.invertsUnit!.fullName;\n schemaJson.unitSystem = this.unitSystem!.fullName;\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n\n const unitSystem = await this.unitSystem;\n if (undefined !== unitSystem) {\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\n }\n\n const invertsUnit = await this.invertsUnit;\n if (undefined !== invertsUnit) {\n const invertsUnitName = XmlSerializationUtils.createXmlTypedName(this.schema, invertsUnit.schema, invertsUnit.name);\n itemElement.setAttribute(\"invertsUnit\", invertsUnitName);\n }\n\n return itemElement;\n }\n\n public override fromJSONSync(invertedUnitProps: InvertedUnitProps) {\n super.fromJSONSync(invertedUnitProps);\n const unitSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.invertsUnit);\n this._invertsUnit = new DelayedPromiseWithProps<SchemaItemKey, Unit>(unitSchemaItemKey,\n async () => {\n const invertsUnit = await this.schema.lookupItem(unitSchemaItemKey, Unit);\n if (undefined === invertsUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the invertsUnit ${invertedUnitProps.invertsUnit}.`);\n return invertsUnit;\n });\n\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.unitSystem);\n if (!unitSystemSchemaItemKey)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\n async () => {\n const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey, UnitSystem);\n if (undefined === unitSystem)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);\n return unitSystem;\n });\n }\n\n public override async fromJSON(invertedUnitProps: InvertedUnitProps) {\n this.fromJSONSync(invertedUnitProps);\n }\n\n /**\n * @alpha\n * Used for schema editing\n */\n protected setInvertsUnit(invertsUnit: LazyLoadedUnit) {\n this._invertsUnit = invertsUnit;\n }\n\n /**\n * @alpha\n * Used for schema editing\n */\n protected setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\n this._unitSystem = unitSystem;\n }\n}\n\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableInvertedUnit extends InvertedUnit {\n public abstract override setInvertsUnit(invertsUnit: LazyLoadedUnit): void;\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): void;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
@@ -13,7 +13,8 @@ import { Unit } from "./Unit";
|
|
|
13
13
|
* @beta
|
|
14
14
|
*/
|
|
15
15
|
export declare class KindOfQuantity extends SchemaItem {
|
|
16
|
-
readonly schemaItemType
|
|
16
|
+
readonly schemaItemType: SchemaItemType;
|
|
17
|
+
static get schemaItemType(): SchemaItemType;
|
|
17
18
|
protected _relativeError: number;
|
|
18
19
|
protected _presentationFormats: Array<Format | OverrideFormat>;
|
|
19
20
|
protected _persistenceUnit?: LazyLoadedUnit | LazyLoadedInvertedUnit;
|
|
@@ -53,6 +54,18 @@ export declare class KindOfQuantity extends SchemaItem {
|
|
|
53
54
|
* Used for schema editing.
|
|
54
55
|
*/
|
|
55
56
|
protected setRelativeError(relativeError: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Type guard to check if the SchemaItem is of type KindOfQuantity.
|
|
59
|
+
* @param item The SchemaItem to check.
|
|
60
|
+
* @returns True if the item is a KindOfQuantity, false otherwise.
|
|
61
|
+
*/
|
|
62
|
+
static isKindOfQuantity(item?: SchemaItem): item is KindOfQuantity;
|
|
63
|
+
/**
|
|
64
|
+
* Type assertion to check if the SchemaItem is of type KindOfQuantity.
|
|
65
|
+
* @param item The SchemaItem to check.
|
|
66
|
+
* @returns The item cast to KindOfQuantity if it is a KindOfQuantity, undefined otherwise.
|
|
67
|
+
*/
|
|
68
|
+
static assertIsKindOfQuantity(item?: SchemaItem): asserts item is KindOfQuantity;
|
|
56
69
|
}
|
|
57
70
|
/**
|
|
58
71
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KindOfQuantity.d.ts","sourceRoot":"","sources":["../../../src/Metadata/KindOfQuantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C,SAAyB,cAAc,
|
|
1
|
+
{"version":3,"file":"KindOfQuantity.d.ts","sourceRoot":"","sources":["../../../src/Metadata/KindOfQuantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,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S,CAAC,CAAC,GAAG,cAAc;YAY3I,wBAAwB;IAkCtC,OAAO,CAAC,4BAA4B;IAkCpC;;;;OAIG;IACa,MAAM,CAAC,UAAU,GAAE,OAAe,EAAE,oBAAoB,GAAE,OAAe,GAAG,mBAAmB;IAS/G,gBAAgB;IACM,KAAK,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAsBlD,YAAY,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,IAAI;IAoBtD,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBvF;;;OAGG;IACH,SAAS,CAAC,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI;IAIvD;;;;OAIG;WACW,gBAAgB,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,IAAI,cAAc;IAIzE;;;;OAIG;WACW,sBAAsB,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,cAAc;CAIxF;AACD;;;GAGG;AACH,8BAAsB,qBAAsB,SAAQ,cAAc;aACvC,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI;aAChF,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,GAAG,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,cAAc;aAC/I,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CACrE"}
|
|
@@ -12,13 +12,17 @@ const DelayedPromise_1 = require("../DelayedPromise");
|
|
|
12
12
|
const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
|
|
13
13
|
const ECObjects_1 = require("../ECObjects");
|
|
14
14
|
const Exception_1 = require("../Exception");
|
|
15
|
+
const Format_1 = require("./Format");
|
|
16
|
+
const InvertedUnit_1 = require("./InvertedUnit");
|
|
15
17
|
const OverrideFormat_1 = require("./OverrideFormat");
|
|
16
18
|
const SchemaItem_1 = require("./SchemaItem");
|
|
19
|
+
const Unit_1 = require("./Unit");
|
|
17
20
|
/** A Typescript class representation of a KindOfQuantity.
|
|
18
21
|
* @beta
|
|
19
22
|
*/
|
|
20
23
|
class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
21
|
-
schemaItemType =
|
|
24
|
+
schemaItemType = KindOfQuantity.schemaItemType;
|
|
25
|
+
static get schemaItemType() { return ECObjects_1.SchemaItemType.KindOfQuantity; }
|
|
22
26
|
_relativeError = 1.0;
|
|
23
27
|
_presentationFormats = new Array();
|
|
24
28
|
_persistenceUnit;
|
|
@@ -55,7 +59,7 @@ class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
|
55
59
|
const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
|
|
56
60
|
for (const formatString of presUnitsArr) {
|
|
57
61
|
const presFormatOverride = OverrideFormat_1.OverrideFormat.parseFormatString(formatString);
|
|
58
|
-
const format = await this.schema.lookupItem(presFormatOverride.name);
|
|
62
|
+
const format = await this.schema.lookupItem(presFormatOverride.name, Format_1.Format);
|
|
59
63
|
if (undefined === format || format.schemaItemType !== ECObjects_1.SchemaItemType.Format)
|
|
60
64
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
|
|
61
65
|
if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
|
|
@@ -68,10 +72,10 @@ class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
|
68
72
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
|
|
69
73
|
unitAndLabels = [];
|
|
70
74
|
for (const unitOverride of presFormatOverride.unitAndLabels) {
|
|
71
|
-
const
|
|
72
|
-
if (undefined ===
|
|
75
|
+
const unitOrInverted = await this.schema.lookupItem(unitOverride[0]);
|
|
76
|
+
if (undefined === unitOrInverted || (!Unit_1.Unit.isUnit(unitOrInverted) && !InvertedUnit_1.InvertedUnit.isInvertedUnit(unitOrInverted)))
|
|
73
77
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
|
|
74
|
-
unitAndLabels.push([
|
|
78
|
+
unitAndLabels.push([unitOrInverted, unitOverride[1]]);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
|
|
@@ -82,7 +86,7 @@ class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
|
82
86
|
const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
|
|
83
87
|
for (const formatString of presUnitsArr) {
|
|
84
88
|
const presFormatOverride = OverrideFormat_1.OverrideFormat.parseFormatString(formatString);
|
|
85
|
-
const format = this.schema.lookupItemSync(presFormatOverride.name);
|
|
89
|
+
const format = this.schema.lookupItemSync(presFormatOverride.name, Format_1.Format);
|
|
86
90
|
if (undefined === format || format.schemaItemType !== ECObjects_1.SchemaItemType.Format)
|
|
87
91
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
|
|
88
92
|
if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
|
|
@@ -95,10 +99,10 @@ class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
|
95
99
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, ``);
|
|
96
100
|
unitAndLabels = [];
|
|
97
101
|
for (const unitOverride of presFormatOverride.unitAndLabels) {
|
|
98
|
-
const
|
|
99
|
-
if (undefined ===
|
|
102
|
+
const unitOrInverted = this.schema.lookupItemSync(unitOverride[0]);
|
|
103
|
+
if (undefined === unitOrInverted || (!Unit_1.Unit.isUnit(unitOrInverted) && !InvertedUnit_1.InvertedUnit.isInvertedUnit(unitOrInverted)))
|
|
100
104
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
|
|
101
|
-
unitAndLabels.push([
|
|
105
|
+
unitAndLabels.push([unitOrInverted, unitOverride[1]]);
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
|
|
@@ -143,9 +147,12 @@ class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
|
143
147
|
const persistenceUnit = this.schema.lookupItemSync(kindOfQuantityProps.persistenceUnit);
|
|
144
148
|
if (undefined === persistenceUnit)
|
|
145
149
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
|
|
146
|
-
if (
|
|
150
|
+
if (!Unit_1.Unit.isUnit(persistenceUnit) && !InvertedUnit_1.InvertedUnit.isInvertedUnit(persistenceUnit))
|
|
147
151
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
|
|
148
|
-
|
|
152
|
+
if (Unit_1.Unit.isUnit(persistenceUnit))
|
|
153
|
+
this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
|
|
154
|
+
else
|
|
155
|
+
this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
|
|
149
156
|
if (undefined !== kindOfQuantityProps.presentationUnits)
|
|
150
157
|
this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);
|
|
151
158
|
}
|
|
@@ -155,9 +162,12 @@ class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
|
155
162
|
const persistenceUnit = await this.schema.lookupItem(kindOfQuantityProps.persistenceUnit);
|
|
156
163
|
if (undefined === persistenceUnit)
|
|
157
164
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
|
|
158
|
-
if (
|
|
165
|
+
if (!Unit_1.Unit.isUnit(persistenceUnit) && !InvertedUnit_1.InvertedUnit.isInvertedUnit(persistenceUnit))
|
|
159
166
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
|
|
160
|
-
|
|
167
|
+
if (Unit_1.Unit.isUnit(persistenceUnit))
|
|
168
|
+
this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
|
|
169
|
+
else
|
|
170
|
+
this._persistenceUnit = new DelayedPromise_1.DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
|
|
161
171
|
if (undefined !== kindOfQuantityProps.presentationUnits)
|
|
162
172
|
await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);
|
|
163
173
|
}
|
|
@@ -168,6 +178,23 @@ class KindOfQuantity extends SchemaItem_1.SchemaItem {
|
|
|
168
178
|
setRelativeError(relativeError) {
|
|
169
179
|
this._relativeError = relativeError;
|
|
170
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Type guard to check if the SchemaItem is of type KindOfQuantity.
|
|
183
|
+
* @param item The SchemaItem to check.
|
|
184
|
+
* @returns True if the item is a KindOfQuantity, false otherwise.
|
|
185
|
+
*/
|
|
186
|
+
static isKindOfQuantity(item) {
|
|
187
|
+
return item?.schemaItemType === ECObjects_1.SchemaItemType.KindOfQuantity;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Type assertion to check if the SchemaItem is of type KindOfQuantity.
|
|
191
|
+
* @param item The SchemaItem to check.
|
|
192
|
+
* @returns The item cast to KindOfQuantity if it is a KindOfQuantity, undefined otherwise.
|
|
193
|
+
*/
|
|
194
|
+
static assertIsKindOfQuantity(item) {
|
|
195
|
+
if (!this.isKindOfQuantity(item))
|
|
196
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidSchemaItemType, `Expected '${ECObjects_1.SchemaItemType.KindOfQuantity}' (KindOfQuantity)`);
|
|
197
|
+
}
|
|
171
198
|
}
|
|
172
199
|
exports.KindOfQuantity = KindOfQuantity;
|
|
173
200
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KindOfQuantity.js","sourceRoot":"","sources":["../../../src/Metadata/KindOfQuantity.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAI/D,qDAAuE;AACvE,6CAA0C;AAG1C;;GAEG;AACH,MAAa,cAAe,SAAQ,uBAAU;IACnB,cAAc,GAAG,0BAAc,CAAC,cAAc,CAAC,CAAC,wDAAwD;IACvH,cAAc,GAAW,GAAG,CAAC;IAC7B,oBAAoB,GAAmC,IAAI,KAAK,EAA2B,CAAC;IAC5F,gBAAgB,CAA2C;IAErE,4DAA4D;IAC5D,IAAW,yBAAyB,KAA0C,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnH,sCAAsC;IACtC,IAAW,mBAAmB,KAAqC,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAEtG,IAAW,eAAe,KAA0D,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACnH,IAAc,eAAe,CAAC,KAA0D,IAAI,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC;IAE5H,IAAW,aAAa,KAAK,OAAO,IAAI,CAAC,cAAc,CAAC,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SAAS,KAAK,mBAAmB,CAAC,iBAAiB;YACrD,MAAM,IAAI,CAAC,wBAAwB,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACO,gBAAgB,CAAC,aAAqB;QAC9C,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;CACF;AA9LD,wCA8LC;AACD;;;GAGG;AACH,MAAsB,qBAAsB,SAAQ,cAAc;CAIjE;AAJD,sDAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\nimport { KindOfQuantityProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedInvertedUnit, LazyLoadedUnit } from \"../Interfaces\";\nimport { Format } from \"./Format\";\nimport { InvertedUnit } from \"./InvertedUnit\";\nimport { OverrideFormat, OverrideFormatProps } from \"./OverrideFormat\";\nimport { SchemaItem } from \"./SchemaItem\";\nimport { Unit } from \"./Unit\";\n\n/** A Typescript class representation of a KindOfQuantity.\n * @beta\n */\nexport class KindOfQuantity extends SchemaItem {\n public override readonly schemaItemType = SchemaItemType.KindOfQuantity; // Needed to allow both run-time and compile-time check.\n protected _relativeError: number = 1.0;\n protected _presentationFormats: Array<Format | OverrideFormat> = new Array<Format | OverrideFormat>();\n protected _persistenceUnit?: LazyLoadedUnit | LazyLoadedInvertedUnit;\n\n /** The first presentation format in the list of Formats. */\n public get defaultPresentationFormat(): Format | OverrideFormat | undefined { return this.presentationFormats[0]; }\n\n /** A list of presentation formats. */\n public get presentationFormats(): Array<Format | OverrideFormat> { return this._presentationFormats; }\n\n public get persistenceUnit(): LazyLoadedUnit | LazyLoadedInvertedUnit | undefined { return this._persistenceUnit; }\n protected set persistenceUnit(value: LazyLoadedUnit | LazyLoadedInvertedUnit | undefined) { this._persistenceUnit = value; }\n\n public get relativeError() { return this._relativeError; }\n\n /**\n *\n * @param format The Format to add to this KindOfQuantity\n * @param isDefault\n */\n protected addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean = false) {\n // TODO: Add some sort of validation?\n (isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);\n }\n\n /** Creates an OverrideFormat in the context of this KindOfQuantity.\n * @param parent The Format to override.\n * @param precision The precision override\n * @param unitLabelOverrides The list of unit and label overrides.\n */\n protected createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat {\n if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add presentation format to KindOfQuantity '${this.name}' because the number of unit overrides is inconsistent with the number in the Format '${parent.name}'.`);\n\n if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);\n\n // TODO: Check compatibility of Unit overrides with the persistence unit\n\n return new OverrideFormat(parent, precision, unitLabelOverrides);\n }\n\n private async processPresentationUnits(presentationUnitsJson: string | string[]): Promise<void> {\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\n for (const formatString of presUnitsArr) {\n const presFormatOverride: OverrideFormatProps = OverrideFormat.parseFormatString(formatString);\n\n const format = await this.schema.lookupItem<Format>(presFormatOverride.name);\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\n\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\n this.addPresentationFormat(format);\n continue;\n }\n\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\n if (undefined !== presFormatOverride.unitAndLabels) {\n if (4 < presFormatOverride.unitAndLabels.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n\n unitAndLabels = [];\n for (const unitOverride of presFormatOverride.unitAndLabels) {\n const unit = await this.schema.lookupItem<Unit | InvertedUnit>(unitOverride[0]);\n if (undefined === unit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\n\n unitAndLabels.push([unit, unitOverride[1]]);\n }\n }\n\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\n this.addPresentationFormat(overrideFormat);\n }\n }\n\n private processPresentationUnitsSync(presentationUnitsJson: string | string[]): void {\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\n for (const formatString of presUnitsArr) {\n const presFormatOverride: OverrideFormatProps = OverrideFormat.parseFormatString(formatString);\n\n const format = this.schema.lookupItemSync<Format>(presFormatOverride.name);\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\n\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\n this.addPresentationFormat(format);\n continue;\n }\n\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\n if (undefined !== presFormatOverride.unitAndLabels) {\n if (4 < presFormatOverride.unitAndLabels.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n\n unitAndLabels = [];\n for (const unitOverride of presFormatOverride.unitAndLabels) {\n const unit = this.schema.lookupItemSync<Unit | InvertedUnit>(unitOverride[0]);\n if (undefined === unit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\n\n unitAndLabels.push([unit, unitOverride[1]]);\n }\n }\n\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\n this.addPresentationFormat(overrideFormat);\n }\n }\n\n /**\n * Save this KindOfQuantity's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): KindOfQuantityProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.relativeError = this.relativeError;\n schemaJson.persistenceUnit = this.persistenceUnit!.fullName;\n if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)\n schemaJson.presentationUnits = this.presentationFormats.map((format: Format | OverrideFormat) => format.fullName);\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n\n const persistenceUnit = await this.persistenceUnit;\n if (undefined !== persistenceUnit) {\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);\n itemElement.setAttribute(\"persistenceUnit\", unitName);\n }\n\n if (undefined !== this.presentationFormats) {\n const presUnitStrings = this.presentationFormats.map((format: Format | OverrideFormat) => {\n if (!OverrideFormat.isOverrideFormat(format))\n return XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);\n return format.fullNameXml(this.schema);\n });\n itemElement.setAttribute(\"presentationUnits\", presUnitStrings.join(\";\"));\n }\n itemElement.setAttribute(\"relativeError\", this.relativeError.toString());\n\n return itemElement;\n }\n\n public override fromJSONSync(kindOfQuantityProps: KindOfQuantityProps): void {\n super.fromJSONSync(kindOfQuantityProps);\n this._relativeError = kindOfQuantityProps.relativeError;\n\n const persistenceUnit = this.schema.lookupItemSync<Unit>(kindOfQuantityProps.persistenceUnit);\n if (undefined === persistenceUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\n\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\n\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n\n if (undefined !== kindOfQuantityProps.presentationUnits)\n this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);\n }\n\n public override async fromJSON(kindOfQuantityProps: KindOfQuantityProps): Promise<void> {\n await super.fromJSON(kindOfQuantityProps);\n this._relativeError = kindOfQuantityProps.relativeError;\n\n const persistenceUnit = await this.schema.lookupItem<Unit>(kindOfQuantityProps.persistenceUnit);\n if (undefined === persistenceUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\n\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\n\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n\n if (undefined !== kindOfQuantityProps.presentationUnits)\n await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);\n }\n\n /**\n * @alpha\n * Used for schema editing.\n */\n protected setRelativeError(relativeError: number): void {\n this._relativeError = relativeError;\n }\n}\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableKindOfQuantity extends KindOfQuantity {\n public abstract override addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean): void;\n public abstract override createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"KindOfQuantity.js","sourceRoot":"","sources":["../../../src/Metadata/KindOfQuantity.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAE/D,qCAAkC;AAClC,iDAA8C;AAC9C,qDAAuE;AACvE,6CAA0C;AAC1C,iCAA8B;AAE9B;;GAEG;AACH,MAAa,cAAe,SAAQ,uBAAU;IACnB,cAAc,GAAG,cAAc,CAAC,cAAc,CAAC;IACjE,MAAM,KAAc,cAAc,KAAK,OAAO,0BAAc,CAAC,cAAc,CAAC,CAAC,CAAC;IAC3E,cAAc,GAAW,GAAG,CAAC;IAC7B,oBAAoB,GAAmC,IAAI,KAAK,EAA2B,CAAC;IAC5F,gBAAgB,CAA2C;IAErE,4DAA4D;IAC5D,IAAW,yBAAyB,KAA0C,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnH,sCAAsC;IACtC,IAAW,mBAAmB,KAAqC,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAEtG,IAAW,eAAe,KAA0D,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACnH,IAAc,eAAe,CAAC,KAA0D,IAAI,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC;IAE5H,IAAW,aAAa,KAAK,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IAE1D;;;;OAIG;IACO,qBAAqB,CAAC,MAA+B,EAAE,YAAqB,KAAK;QACzF,qCAAqC;QACrC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,C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C,aAAa,EAAE,YAAY,mBAAmB,CAAC,eAAe,iCAAiC,CAAC,CAAC;QAE5I,IAAG,WAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC7B,IAAI,CAAC,gBAAgB,GAAG,IAAI,wCAAuB,CAAC,eAAe,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,eAAe,CAAC,CAAC;;YAEtG,IAAI,CAAC,gBAAgB,GAAG,IAAI,wCAAuB,CAAC,eAAe,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,eAAe,CAAC,CAAC;QAGxG,IAAI,SAAS,KAAK,mBAAmB,CAAC,iBAAiB;YACrD,MAAM,IAAI,CAAC,wBAAwB,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACO,gBAAgB,CAAC,aAAqB;QAC9C,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,gBAAgB,CAAC,IAAiB;QAC9C,OAAO,IAAI,EAAE,cAAc,KAAK,0BAAc,CAAC,cAAc,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,sBAAsB,CAAC,IAAiB;QACpD,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;YAC9B,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,qBAAqB,EAAE,aAAa,0BAAc,CAAC,cAAc,oBAAoB,CAAC,CAAC;IACpI,CAAC;CACF;AAzND,wCAyNC;AACD;;;GAGG;AACH,MAAsB,qBAAsB,SAAQ,cAAc;CAIjE;AAJD,sDAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\nimport { KindOfQuantityProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedInvertedUnit, LazyLoadedUnit } from \"../Interfaces\";\nimport { Format } from \"./Format\";\nimport { InvertedUnit } from \"./InvertedUnit\";\nimport { OverrideFormat, OverrideFormatProps } from \"./OverrideFormat\";\nimport { SchemaItem } from \"./SchemaItem\";\nimport { Unit } from \"./Unit\";\n\n/** A Typescript class representation of a KindOfQuantity.\n * @beta\n */\nexport class KindOfQuantity extends SchemaItem {\n public override readonly schemaItemType = KindOfQuantity.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.KindOfQuantity; }\n protected _relativeError: number = 1.0;\n protected _presentationFormats: Array<Format | OverrideFormat> = new Array<Format | OverrideFormat>();\n protected _persistenceUnit?: LazyLoadedUnit | LazyLoadedInvertedUnit;\n\n /** The first presentation format in the list of Formats. */\n public get defaultPresentationFormat(): Format | OverrideFormat | undefined { return this.presentationFormats[0]; }\n\n /** A list of presentation formats. */\n public get presentationFormats(): Array<Format | OverrideFormat> { return this._presentationFormats; }\n\n public get persistenceUnit(): LazyLoadedUnit | LazyLoadedInvertedUnit | undefined { return this._persistenceUnit; }\n protected set persistenceUnit(value: LazyLoadedUnit | LazyLoadedInvertedUnit | undefined) { this._persistenceUnit = value; }\n\n public get relativeError() { return this._relativeError; }\n\n /**\n *\n * @param format The Format to add to this KindOfQuantity\n * @param isDefault\n */\n protected addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean = false) {\n // TODO: Add some sort of validation?\n (isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);\n }\n\n /** Creates an OverrideFormat in the context of this KindOfQuantity.\n * @param parent The Format to override.\n * @param precision The precision override\n * @param unitLabelOverrides The list of unit and label overrides.\n */\n protected createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat {\n if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add presentation format to KindOfQuantity '${this.name}' because the number of unit overrides is inconsistent with the number in the Format '${parent.name}'.`);\n\n if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);\n\n // TODO: Check compatibility of Unit overrides with the persistence unit\n\n return new OverrideFormat(parent, precision, unitLabelOverrides);\n }\n\n private async processPresentationUnits(presentationUnitsJson: string | string[]): Promise<void> {\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\n for (const formatString of presUnitsArr) {\n const presFormatOverride: OverrideFormatProps = OverrideFormat.parseFormatString(formatString);\n\n const format = await this.schema.lookupItem(presFormatOverride.name, Format);\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\n\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\n this.addPresentationFormat(format);\n continue;\n }\n\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\n if (undefined !== presFormatOverride.unitAndLabels) {\n if (4 < presFormatOverride.unitAndLabels.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n\n unitAndLabels = [];\n for (const unitOverride of presFormatOverride.unitAndLabels) {\n const unitOrInverted = await this.schema.lookupItem(unitOverride[0]);\n if (undefined === unitOrInverted || (!Unit.isUnit(unitOrInverted) && !InvertedUnit.isInvertedUnit(unitOrInverted)))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\n\n unitAndLabels.push([unitOrInverted, unitOverride[1]]);\n }\n }\n\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\n this.addPresentationFormat(overrideFormat);\n }\n }\n\n private processPresentationUnitsSync(presentationUnitsJson: string | string[]): void {\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\n for (const formatString of presUnitsArr) {\n const presFormatOverride: OverrideFormatProps = OverrideFormat.parseFormatString(formatString);\n\n const format = this.schema.lookupItemSync(presFormatOverride.name, Format);\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\n\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\n this.addPresentationFormat(format);\n continue;\n }\n\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\n if (undefined !== presFormatOverride.unitAndLabels) {\n if (4 < presFormatOverride.unitAndLabels.length)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n\n unitAndLabels = [];\n for (const unitOverride of presFormatOverride.unitAndLabels) {\n const unitOrInverted = this.schema.lookupItemSync(unitOverride[0]);\n if (undefined === unitOrInverted || (!Unit.isUnit(unitOrInverted) && !InvertedUnit.isInvertedUnit(unitOrInverted)))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\n\n unitAndLabels.push([unitOrInverted, unitOverride[1]]);\n }\n }\n\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\n this.addPresentationFormat(overrideFormat);\n }\n }\n\n /**\n * Save this KindOfQuantity's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): KindOfQuantityProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.relativeError = this.relativeError;\n schemaJson.persistenceUnit = this.persistenceUnit!.fullName;\n if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)\n schemaJson.presentationUnits = this.presentationFormats.map((format: Format | OverrideFormat) => format.fullName);\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n\n const persistenceUnit = await this.persistenceUnit;\n if (undefined !== persistenceUnit) {\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);\n itemElement.setAttribute(\"persistenceUnit\", unitName);\n }\n\n if (undefined !== this.presentationFormats) {\n const presUnitStrings = this.presentationFormats.map((format: Format | OverrideFormat) => {\n if (!OverrideFormat.isOverrideFormat(format))\n return XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);\n return format.fullNameXml(this.schema);\n });\n itemElement.setAttribute(\"presentationUnits\", presUnitStrings.join(\";\"));\n }\n itemElement.setAttribute(\"relativeError\", this.relativeError.toString());\n\n return itemElement;\n }\n\n public override fromJSONSync(kindOfQuantityProps: KindOfQuantityProps): void {\n super.fromJSONSync(kindOfQuantityProps);\n this._relativeError = kindOfQuantityProps.relativeError;\n\n const persistenceUnit = this.schema.lookupItemSync(kindOfQuantityProps.persistenceUnit);\n if (undefined === persistenceUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\n\n if (!Unit.isUnit(persistenceUnit) && !InvertedUnit.isInvertedUnit(persistenceUnit))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\n\n if(Unit.isUnit(persistenceUnit))\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n else\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n\n if (undefined !== kindOfQuantityProps.presentationUnits)\n this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);\n }\n\n public override async fromJSON(kindOfQuantityProps: KindOfQuantityProps): Promise<void> {\n await super.fromJSON(kindOfQuantityProps);\n this._relativeError = kindOfQuantityProps.relativeError;\n\n const persistenceUnit = await this.schema.lookupItem(kindOfQuantityProps.persistenceUnit);\n if (undefined === persistenceUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\n\n if (!Unit.isUnit(persistenceUnit) && !InvertedUnit.isInvertedUnit(persistenceUnit))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\n\n if(Unit.isUnit(persistenceUnit))\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n else\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\n\n\n if (undefined !== kindOfQuantityProps.presentationUnits)\n await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);\n }\n\n /**\n * @alpha\n * Used for schema editing.\n */\n protected setRelativeError(relativeError: number): void {\n this._relativeError = relativeError;\n }\n\n /**\n * Type guard to check if the SchemaItem is of type KindOfQuantity.\n * @param item The SchemaItem to check.\n * @returns True if the item is a KindOfQuantity, false otherwise.\n */\n public static isKindOfQuantity(item?: SchemaItem): item is KindOfQuantity {\n return item?.schemaItemType === SchemaItemType.KindOfQuantity;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type KindOfQuantity.\n * @param item The SchemaItem to check.\n * @returns The item cast to KindOfQuantity if it is a KindOfQuantity, undefined otherwise.\n */\n public static assertIsKindOfQuantity(item?: SchemaItem): asserts item is KindOfQuantity {\n if (!this.isKindOfQuantity(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.KindOfQuantity}' (KindOfQuantity)`);\n }\n}\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableKindOfQuantity extends KindOfQuantity {\n public abstract override addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean): void;\n public abstract override createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
@@ -9,12 +9,14 @@ import { EntityClass } from "./EntityClass";
|
|
|
9
9
|
import { NavigationProperty } from "./Property";
|
|
10
10
|
import { RelationshipClass } from "./RelationshipClass";
|
|
11
11
|
import { Schema } from "./Schema";
|
|
12
|
+
import { SchemaItem } from "./SchemaItem";
|
|
12
13
|
/**
|
|
13
14
|
* A Typescript class representation of a Mixin.
|
|
14
15
|
* @beta
|
|
15
16
|
*/
|
|
16
17
|
export declare class Mixin extends ECClass {
|
|
17
|
-
readonly schemaItemType
|
|
18
|
+
readonly schemaItemType: SchemaItemType;
|
|
19
|
+
static get schemaItemType(): SchemaItemType;
|
|
18
20
|
protected _appliesTo?: LazyLoadedEntityClass;
|
|
19
21
|
get appliesTo(): LazyLoadedEntityClass | undefined;
|
|
20
22
|
constructor(schema: Schema, name: string);
|
|
@@ -41,6 +43,18 @@ export declare class Mixin extends ECClass {
|
|
|
41
43
|
fromJSONSync(mixinProps: MixinProps): void;
|
|
42
44
|
fromJSON(mixinProps: MixinProps): Promise<void>;
|
|
43
45
|
applicableTo(entityClass: EntityClass): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Type guard to check if the SchemaItem is of type Mixin.
|
|
48
|
+
* @param item The SchemaItem to check.
|
|
49
|
+
* @returns True if the item is a Mixin, false otherwise.
|
|
50
|
+
*/
|
|
51
|
+
static isMixin(item?: SchemaItem): item is Mixin;
|
|
52
|
+
/**
|
|
53
|
+
* Type assertion to check if the SchemaItem is of type Mixin.
|
|
54
|
+
* @param item The SchemaItem to check.
|
|
55
|
+
* @returns The item cast to Mixin if it is a Mixin, undefined otherwise.
|
|
56
|
+
*/
|
|
57
|
+
static assertIsMixin(item?: SchemaItem): asserts item is Mixin;
|
|
44
58
|
}
|
|
45
59
|
/**
|
|
46
60
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mixin.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Mixin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,EAAmB,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAA0D,WAAW,EAAE,MAAM,eAAe,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"Mixin.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Mixin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,EAAmB,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAA0D,WAAW,EAAE,MAAM,eAAe,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,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AI;aACtD,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;aACpJ,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,kBAAkB;aAC/I,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CACrE"}
|
|
@@ -19,7 +19,8 @@ const EntityClass_1 = require("./EntityClass");
|
|
|
19
19
|
* @beta
|
|
20
20
|
*/
|
|
21
21
|
class Mixin extends Class_1.ECClass {
|
|
22
|
-
schemaItemType =
|
|
22
|
+
schemaItemType = Mixin.schemaItemType;
|
|
23
|
+
static get schemaItemType() { return ECObjects_1.SchemaItemType.Mixin; }
|
|
23
24
|
_appliesTo;
|
|
24
25
|
get appliesTo() {
|
|
25
26
|
return this._appliesTo;
|
|
@@ -86,7 +87,7 @@ class Mixin extends Class_1.ECClass {
|
|
|
86
87
|
if (!entityClassSchemaItemKey)
|
|
87
88
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);
|
|
88
89
|
this._appliesTo = new DelayedPromise_1.DelayedPromiseWithProps(entityClassSchemaItemKey, async () => {
|
|
89
|
-
const appliesTo = await this.schema.lookupItem(entityClassSchemaItemKey);
|
|
90
|
+
const appliesTo = await this.schema.lookupItem(entityClassSchemaItemKey, EntityClass_1.EntityClass);
|
|
90
91
|
if (undefined === appliesTo)
|
|
91
92
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);
|
|
92
93
|
return appliesTo;
|
|
@@ -103,6 +104,25 @@ class Mixin extends Class_1.ECClass {
|
|
|
103
104
|
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidType, `Unable to locate the appliesTo ${this.appliesTo.fullName}.`);
|
|
104
105
|
return appliesTo.is(entityClass);
|
|
105
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Type guard to check if the SchemaItem is of type Mixin.
|
|
109
|
+
* @param item The SchemaItem to check.
|
|
110
|
+
* @returns True if the item is a Mixin, false otherwise.
|
|
111
|
+
*/
|
|
112
|
+
static isMixin(item) {
|
|
113
|
+
if (item && item.schemaItemType === ECObjects_1.SchemaItemType.Mixin)
|
|
114
|
+
return true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Type assertion to check if the SchemaItem is of type Mixin.
|
|
119
|
+
* @param item The SchemaItem to check.
|
|
120
|
+
* @returns The item cast to Mixin if it is a Mixin, undefined otherwise.
|
|
121
|
+
*/
|
|
122
|
+
static assertIsMixin(item) {
|
|
123
|
+
if (!this.isMixin(item))
|
|
124
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidSchemaItemType, `Expected '${ECObjects_1.SchemaItemType.Mixin}' (Mixin)`);
|
|
125
|
+
}
|
|
106
126
|
}
|
|
107
127
|
exports.Mixin = Mixin;
|
|
108
128
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mixin.js","sourceRoot":"","sources":["../../../src/Metadata/Mixin.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAAkF;AAClF,4CAA+D;AAG/D,mCAAkC;AAClC,+CAAoG;AAKpG;;;GAGG;AACH,MAAa,KAAM,SAAQ,eAAO;IACP,cAAc,GAAG,0BAAc,CAAC,KAAK,CAAC;IACrD,UAAU,CAAyB;IAE7C,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EA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C,CAAC;YACtF,IAAI,SAAS,KAAK,SAAS;gBACzB,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,aAAa,EAAE,kCAAkC,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC;YACrH,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CAAC;IACP,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,UAAsB;QACnD,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,WAAwB;QAChD,IAAI,CAAC,IAAI,CAAC,SAAS;YACjB,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,WAAW,EAAE,uCAAuC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAEjH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC;QACvC,IAAI,SAAS,KAAK,SAAS;YACzB,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,WAAW,EAAE,kCAAkC,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC;QAEtH,OAAO,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;CACF;AArGD,sBAqGC;AACD;;;GAGG;AACH,MAAsB,YAAa,SAAQ,KAAK;CAK/C;AALD,oCAKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\nimport { MixinProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { ECClassModifier, SchemaItemType, StrengthDirection } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedEntityClass } from \"../Interfaces\";\nimport { SchemaItemKey } from \"../SchemaKey\";\nimport { ECClass } from \"./Class\";\nimport { createNavigationProperty, createNavigationPropertySync, EntityClass } from \"./EntityClass\";\nimport { NavigationProperty } from \"./Property\";\nimport { RelationshipClass } from \"./RelationshipClass\";\nimport { Schema } from \"./Schema\";\n\n/**\n * A Typescript class representation of a Mixin.\n * @beta\n */\nexport class Mixin extends ECClass {\n public override readonly schemaItemType = SchemaItemType.Mixin;\n protected _appliesTo?: LazyLoadedEntityClass;\n\n public get appliesTo(): LazyLoadedEntityClass | undefined {\n return this._appliesTo;\n }\n\n constructor(schema: Schema, name: string) {\n super(schema, name, ECClassModifier.Abstract);\n }\n\n /**\n *\n * @param name\n * @param relationship\n * @param direction\n */\n protected async createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\n return this.addProperty(await createNavigationProperty(this, name, relationship, direction));\n }\n\n protected createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\n return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));\n }\n\n /**\n * @alpha Used for schema editing.\n */\n protected setAppliesTo(appliesTo: LazyLoadedEntityClass) {\n this._appliesTo = appliesTo;\n }\n /**\n * Save this Mixin's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): MixinProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n if (undefined !== this.appliesTo) {\n schemaJson.appliesTo = this.appliesTo.fullName;\n }\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n\n // When CustomAttributes are added, there must be a check to see if the ECCustomAttributes\n // already exist for this item before creating a new one to apply IsMixin\n const customAttributes = schemaXml.createElement(\"ECCustomAttributes\");\n const isMixinElement = schemaXml.createElement(\"IsMixin\");\n const coreCustomSchema = this.schema.getReferenceSync(\"CoreCustomAttributes\");\n if (undefined !== coreCustomSchema) {\n const xmlns = `CoreCustomAttributes.${coreCustomSchema.schemaKey.version.toString()}`;\n isMixinElement.setAttribute(\"xmlns\", xmlns);\n }\n\n const appliesToElement = schemaXml.createElement(\"AppliesToEntityClass\");\n const appliesTo = await this.appliesTo;\n if (undefined !== appliesTo) {\n const appliesToName = XmlSerializationUtils.createXmlTypedName(this.schema, appliesTo.schema, appliesTo.name);\n appliesToElement.textContent = appliesToName;\n isMixinElement.appendChild(appliesToElement);\n }\n\n customAttributes.appendChild(isMixinElement);\n itemElement.appendChild(customAttributes);\n\n return itemElement;\n }\n\n public override fromJSONSync(mixinProps: MixinProps) {\n super.fromJSONSync(mixinProps);\n const entityClassSchemaItemKey = this.schema.getSchemaItemKey(mixinProps.appliesTo);\n if (!entityClassSchemaItemKey)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);\n this._appliesTo = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(entityClassSchemaItemKey,\n async () => {\n const appliesTo = await this.schema.lookupItem<EntityClass>(entityClassSchemaItemKey);\n if (undefined === appliesTo)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);\n return appliesTo;\n });\n }\n\n public override async fromJSON(mixinProps: MixinProps) {\n this.fromJSONSync(mixinProps);\n }\n\n public async applicableTo(entityClass: EntityClass) {\n if (!this.appliesTo)\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `appliesTo is undefined in the class ${this.fullName}.`);\n\n const appliesTo = await this.appliesTo;\n if (appliesTo === undefined)\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `Unable to locate the appliesTo ${this.appliesTo.fullName}.`);\n\n return appliesTo.is(entityClass);\n }\n}\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableMixin extends Mixin {\n public abstract override setAppliesTo(entityClass: LazyLoadedEntityClass): void;\n public abstract override createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;\n public abstract override createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Mixin.js","sourceRoot":"","sources":["../../../src/Metadata/Mixin.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAAkF;AAClF,4CAA+D;AAG/D,mCAAkC;AAClC,+CAAoG;AAMpG;;;GAGG;AACH,MAAa,KAAM,SAAQ,eAAO;IACP,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC;IACxD,MAAM,KAAc,cAAc,KAAK,OAAO,0BAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IAClE,UAAU,CAAyB;IAE7C,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,2BAAe,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,wBAAwB,CAAC,IAAY,EAAE,YAAwC,EAAE,SAAqC;QACpI,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,IAAA,sCAAwB,EAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAC/F,CAAC;IAES,4BAA4B,CAAC,IAAY,EAAE,YAAwC,EAAE,SAAqC;QAClI,OAAO,IAAI,CAAC,WAAW,CAAC,IAAA,0CAA4B,EAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED;;OAEG;IACO,YAAY,CAAC,SAAgC;QACrD,IAAI,CAAC,UAAU,GA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AAI,CAAC,SAAS,CAAC;QACvC,IAAI,SAAS,KAAK,SAAS;YACzB,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,WAAW,EAAE,kCAAkC,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC;QAEtH,OAAO,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,IAAiB;QACrC,IAAI,IAAI,IAAI,IAAI,CAAC,cAAc,KAAK,0BAAc,CAAC,KAAK;YACtD,OAAO,IAAI,CAAC;QAEd,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,IAAiB;QAC3C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACrB,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,qBAAqB,EAAE,aAAa,0BAAc,CAAC,KAAK,WAAW,CAAC,CAAC;IAClH,CAAC;CACF;AA5HD,sBA4HC;AACD;;;GAGG;AACH,MAAsB,YAAa,SAAQ,KAAK;CAK/C;AALD,oCAKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\nimport { MixinProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { ECClassModifier, SchemaItemType, StrengthDirection } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedEntityClass } from \"../Interfaces\";\nimport { SchemaItemKey } from \"../SchemaKey\";\nimport { ECClass } from \"./Class\";\nimport { createNavigationProperty, createNavigationPropertySync, EntityClass } from \"./EntityClass\";\nimport { NavigationProperty } from \"./Property\";\nimport { RelationshipClass } from \"./RelationshipClass\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\n\n/**\n * A Typescript class representation of a Mixin.\n * @beta\n */\nexport class Mixin extends ECClass {\n public override readonly schemaItemType = Mixin.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.Mixin; }\n protected _appliesTo?: LazyLoadedEntityClass;\n\n public get appliesTo(): LazyLoadedEntityClass | undefined {\n return this._appliesTo;\n }\n\n constructor(schema: Schema, name: string) {\n super(schema, name, ECClassModifier.Abstract);\n }\n\n /**\n *\n * @param name\n * @param relationship\n * @param direction\n */\n protected async createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\n return this.addProperty(await createNavigationProperty(this, name, relationship, direction));\n }\n\n protected createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\n return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));\n }\n\n /**\n * @alpha Used for schema editing.\n */\n protected setAppliesTo(appliesTo: LazyLoadedEntityClass) {\n this._appliesTo = appliesTo;\n }\n /**\n * Save this Mixin's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): MixinProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n if (undefined !== this.appliesTo) {\n schemaJson.appliesTo = this.appliesTo.fullName;\n }\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n\n // When CustomAttributes are added, there must be a check to see if the ECCustomAttributes\n // already exist for this item before creating a new one to apply IsMixin\n const customAttributes = schemaXml.createElement(\"ECCustomAttributes\");\n const isMixinElement = schemaXml.createElement(\"IsMixin\");\n const coreCustomSchema = this.schema.getReferenceSync(\"CoreCustomAttributes\");\n if (undefined !== coreCustomSchema) {\n const xmlns = `CoreCustomAttributes.${coreCustomSchema.schemaKey.version.toString()}`;\n isMixinElement.setAttribute(\"xmlns\", xmlns);\n }\n\n const appliesToElement = schemaXml.createElement(\"AppliesToEntityClass\");\n const appliesTo = await this.appliesTo;\n if (undefined !== appliesTo) {\n const appliesToName = XmlSerializationUtils.createXmlTypedName(this.schema, appliesTo.schema, appliesTo.name);\n appliesToElement.textContent = appliesToName;\n isMixinElement.appendChild(appliesToElement);\n }\n\n customAttributes.appendChild(isMixinElement);\n itemElement.appendChild(customAttributes);\n\n return itemElement;\n }\n\n public override fromJSONSync(mixinProps: MixinProps) {\n super.fromJSONSync(mixinProps);\n const entityClassSchemaItemKey = this.schema.getSchemaItemKey(mixinProps.appliesTo);\n if (!entityClassSchemaItemKey)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);\n this._appliesTo = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(entityClassSchemaItemKey,\n async () => {\n const appliesTo = await this.schema.lookupItem(entityClassSchemaItemKey, EntityClass);\n if (undefined === appliesTo)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);\n return appliesTo;\n });\n }\n\n public override async fromJSON(mixinProps: MixinProps) {\n this.fromJSONSync(mixinProps);\n }\n\n public async applicableTo(entityClass: EntityClass) {\n if (!this.appliesTo)\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `appliesTo is undefined in the class ${this.fullName}.`);\n\n const appliesTo = await this.appliesTo;\n if (appliesTo === undefined)\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `Unable to locate the appliesTo ${this.appliesTo.fullName}.`);\n\n return appliesTo.is(entityClass);\n }\n\n /**\n * Type guard to check if the SchemaItem is of type Mixin.\n * @param item The SchemaItem to check.\n * @returns True if the item is a Mixin, false otherwise.\n */\n public static isMixin(item?: SchemaItem): item is Mixin {\n if (item && item.schemaItemType === SchemaItemType.Mixin)\n return true;\n\n return false;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type Mixin.\n * @param item The SchemaItem to check.\n * @returns The item cast to Mixin if it is a Mixin, undefined otherwise.\n */\n public static assertIsMixin(item?: SchemaItem): asserts item is Mixin {\n if (!this.isMixin(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Mixin}' (Mixin)`);\n }\n}\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableMixin extends Mixin {\n public abstract override setAppliesTo(entityClass: LazyLoadedEntityClass): void;\n public abstract override createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;\n public abstract override createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
@@ -7,7 +7,8 @@ import { Schema } from "./Schema";
|
|
|
7
7
|
import { SchemaItem } from "./SchemaItem";
|
|
8
8
|
/** @beta */
|
|
9
9
|
export declare class Phenomenon extends SchemaItem {
|
|
10
|
-
readonly schemaItemType
|
|
10
|
+
readonly schemaItemType: SchemaItemType;
|
|
11
|
+
static get schemaItemType(): SchemaItemType;
|
|
11
12
|
protected _definition: string;
|
|
12
13
|
constructor(schema: Schema, name: string);
|
|
13
14
|
get definition(): string;
|
|
@@ -22,6 +23,18 @@ export declare class Phenomenon extends SchemaItem {
|
|
|
22
23
|
fromJSONSync(phenomenonProps: PhenomenonProps): void;
|
|
23
24
|
fromJSON(phenomenonProps: PhenomenonProps): Promise<void>;
|
|
24
25
|
protected setDefinition(definition: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Type guard to check if the SchemaItem is of type Phenomenon.
|
|
28
|
+
* @param item The SchemaItem to check.
|
|
29
|
+
* @returns True if the item is a Phenomenon, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
static isPhenomenon(item?: SchemaItem): item is Phenomenon;
|
|
32
|
+
/**
|
|
33
|
+
* Type assertion to check if the SchemaItem is of type Phenomenon.
|
|
34
|
+
* @param item The SchemaItem to check.
|
|
35
|
+
* @returns The item cast to Phenomenon if it is a Phenomenon, undefined otherwise.
|
|
36
|
+
*/
|
|
37
|
+
static assertIsPhenomenon(item?: SchemaItem): asserts item is Phenomenon;
|
|
25
38
|
}
|
|
26
39
|
/**
|
|
27
40
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Phenomenon.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Phenomenon.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,YAAY;AACZ,qBAAa,UAAW,SAAQ,UAAU;IACxC,SAAyB,cAAc,
|
|
1
|
+
{"version":3,"file":"Phenomenon.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Phenomenon.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,YAAY;AACZ,qBAAa,UAAW,SAAQ,UAAU;IACxC,SAAyB,cAAc,iBAA6B;IACpE,WAA2B,cAAc,mBAAwC;IACjF,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;gBAElB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAKxC,IAAW,UAAU,IAAI,MAAM,CAA6B;IAE5D;;;;OAIG;IACa,MAAM,CAAC,UAAU,GAAE,OAAe,EAAE,oBAAoB,GAAE,OAAe,GAAG,eAAe;IAM3G,gBAAgB;IACM,KAAK,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAMlD,YAAY,CAAC,eAAe,EAAE,eAAe;IAQvC,QAAQ,CAAC,eAAe,EAAE,eAAe;cAI/C,aAAa,CAAC,UAAU,EAAE,MAAM;IAIhD;;;;OAIG;WACW,YAAY,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,IAAI,UAAU;IAOjE;;;;OAIG;WACW,kBAAkB,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,UAAU;CAIhF;AAED;;;GAGG;AACH,8BAAsB,iBAAkB,SAAQ,UAAU;aAC/B,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;aAChD,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CACrE"}
|
|
@@ -13,7 +13,8 @@ const Exception_1 = require("../Exception");
|
|
|
13
13
|
const SchemaItem_1 = require("./SchemaItem");
|
|
14
14
|
/** @beta */
|
|
15
15
|
class Phenomenon extends SchemaItem_1.SchemaItem {
|
|
16
|
-
schemaItemType =
|
|
16
|
+
schemaItemType = Phenomenon.schemaItemType;
|
|
17
|
+
static get schemaItemType() { return ECObjects_1.SchemaItemType.Phenomenon; }
|
|
17
18
|
_definition; // Contains a combination of Phenomena names which form this Phenomenon. Each Phenomena name is separated by a * and may have an exponent, specified using parentheses
|
|
18
19
|
constructor(schema, name) {
|
|
19
20
|
super(schema, name);
|
|
@@ -49,6 +50,25 @@ class Phenomenon extends SchemaItem_1.SchemaItem {
|
|
|
49
50
|
async setDefinition(definition) {
|
|
50
51
|
this._definition = definition;
|
|
51
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Type guard to check if the SchemaItem is of type Phenomenon.
|
|
55
|
+
* @param item The SchemaItem to check.
|
|
56
|
+
* @returns True if the item is a Phenomenon, false otherwise.
|
|
57
|
+
*/
|
|
58
|
+
static isPhenomenon(item) {
|
|
59
|
+
if (item && item.schemaItemType === ECObjects_1.SchemaItemType.Phenomenon)
|
|
60
|
+
return true;
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Type assertion to check if the SchemaItem is of type Phenomenon.
|
|
65
|
+
* @param item The SchemaItem to check.
|
|
66
|
+
* @returns The item cast to Phenomenon if it is a Phenomenon, undefined otherwise.
|
|
67
|
+
*/
|
|
68
|
+
static assertIsPhenomenon(item) {
|
|
69
|
+
if (!this.isPhenomenon(item))
|
|
70
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidSchemaItemType, `Expected '${ECObjects_1.SchemaItemType.Phenomenon}' (Phenomenon)`);
|
|
71
|
+
}
|
|
52
72
|
}
|
|
53
73
|
exports.Phenomenon = Phenomenon;
|
|
54
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Phenomenon.js","sourceRoot":"","sources":["../../../src/Metadata/Phenomenon.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,4CAA8C;AAC9C,4CAA+D;AAE/D,6CAA0C;AAE1C,YAAY;AACZ,MAAa,UAAW,SAAQ,uBAAU;IACf,cAAc,GAAG,0BAAc,CAAC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"Phenomenon.js","sourceRoot":"","sources":["../../../src/Metadata/Phenomenon.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,4CAA8C;AAC9C,4CAA+D;AAE/D,6CAA0C;AAE1C,YAAY;AACZ,MAAa,UAAW,SAAQ,uBAAU;IACf,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;IAC7D,MAAM,KAAc,cAAc,KAAK,OAAO,0BAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IACvE,WAAW,CAAS,CAAC,sKAAsK;IAErM,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WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,IAAiB;QAC1C,IAAI,IAAI,IAAI,IAAI,CAAC,cAAc,KAAK,0BAAc,CAAC,UAAU;YAC3D,OAAO,IAAI,CAAC;QAEd,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,kBAAkB,CAAC,IAAiB;QAChD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YAC1B,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,qBAAqB,EAAE,aAAa,0BAAc,CAAC,UAAU,gBAAgB,CAAC,CAAC;IAC5H,CAAC;CACF;AAnED,gCAmEC;AAED;;;GAGG;AACH,MAAsB,iBAAkB,SAAQ,UAAU;CAGzD;AAHD,8CAGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { PhenomenonProps } from \"../Deserialization/JsonProps\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\n\n/** @beta */\nexport class Phenomenon extends SchemaItem {\n public override readonly schemaItemType = Phenomenon.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.Phenomenon; }\n protected _definition: string; // Contains a combination of Phenomena names which form this Phenomenon. Each Phenomena name is separated by a * and may have an exponent, specified using parentheses\n\n constructor(schema: Schema, name: string) {\n super(schema, name);\n this._definition = \"\";\n }\n\n public get definition(): string { return this._definition; }\n\n /**\n * Save this Phenomenon's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): PhenomenonProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.definition = this.definition;\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n itemElement.setAttribute(\"definition\", this.definition);\n return itemElement;\n }\n\n public override fromJSONSync(phenomenonProps: PhenomenonProps) {\n super.fromJSONSync(phenomenonProps);\n if (this._definition !== \"\" && phenomenonProps.definition.toLowerCase() !== this._definition.toLowerCase())\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Phenomenon ${this.name} has an invalid 'definition' attribute.`);\n else if (this._definition === \"\")\n this._definition = phenomenonProps.definition;\n }\n\n public override async fromJSON(phenomenonProps: PhenomenonProps) {\n this.fromJSONSync(phenomenonProps);\n }\n\n protected async setDefinition(definition: string) {\n this._definition = definition;\n }\n\n /**\n * Type guard to check if the SchemaItem is of type Phenomenon.\n * @param item The SchemaItem to check.\n * @returns True if the item is a Phenomenon, false otherwise.\n */\n public static isPhenomenon(item?: SchemaItem): item is Phenomenon {\n if (item && item.schemaItemType === SchemaItemType.Phenomenon)\n return true;\n\n return false;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type Phenomenon.\n * @param item The SchemaItem to check.\n * @returns The item cast to Phenomenon if it is a Phenomenon, undefined otherwise.\n */\n public static assertIsPhenomenon(item?: SchemaItem): asserts item is Phenomenon {\n if (!this.isPhenomenon(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Phenomenon}' (Phenomenon)`);\n }\n}\n\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutablePhenomenon extends Phenomenon {\n public abstract override setDefinition(definition: string): Promise<void>;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|
|
@@ -10,7 +10,7 @@ import { ECClass, StructClass } from "./Class";
|
|
|
10
10
|
import { CustomAttribute, CustomAttributeContainerProps, CustomAttributeSet } from "./CustomAttribute";
|
|
11
11
|
import { KindOfQuantity } from "./KindOfQuantity";
|
|
12
12
|
import { PropertyCategory } from "./PropertyCategory";
|
|
13
|
-
import { RelationshipClass } from "./RelationshipClass";
|
|
13
|
+
import { type RelationshipClass } from "./RelationshipClass";
|
|
14
14
|
import { Schema } from "./Schema";
|
|
15
15
|
/**
|
|
16
16
|
* A common abstract class for all ECProperty types.
|