@itwin/ecschema-metadata 4.8.0-dev.9 → 4.9.0-dev.1
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 +36 -1
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/DelayedPromise.js.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.d.ts +4 -0
- package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
- package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/cjs/ECName.js.map +1 -1
- package/lib/cjs/ECObjects.js.map +1 -1
- package/lib/cjs/Exception.js.map +1 -1
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Metadata/Class.d.ts +0 -6
- package/lib/cjs/Metadata/Class.d.ts.map +1 -1
- package/lib/cjs/Metadata/Class.js +0 -8
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +7 -3
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js +16 -10
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.js.map +1 -1
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.js +3 -1
- package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +14 -0
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +21 -0
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +5 -0
- package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.js +7 -0
- package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
- package/lib/cjs/PropertyTypes.js.map +1 -1
- package/lib/cjs/SchemaJsonLocater.js.map +1 -1
- package/lib/cjs/SchemaKey.js.map +1 -1
- package/lib/cjs/SchemaLoader.js.map +1 -1
- package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
- package/lib/cjs/UnitConversion/Graph.js.map +1 -1
- package/lib/cjs/UnitConversion/Parser.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaGraph.js.map +1 -1
- package/lib/esm/Constants.d.ts +24 -0
- package/lib/esm/Constants.d.ts.map +1 -0
- package/lib/esm/Constants.js +30 -0
- package/lib/esm/Constants.js.map +1 -0
- package/lib/esm/Context.d.ts +219 -0
- package/lib/esm/Context.d.ts.map +1 -0
- package/lib/esm/Context.js +321 -0
- package/lib/esm/Context.js.map +1 -0
- package/lib/esm/DelayedPromise.d.ts +89 -0
- package/lib/esm/DelayedPromise.d.ts.map +1 -0
- package/lib/esm/DelayedPromise.js +88 -0
- package/lib/esm/DelayedPromise.js.map +1 -0
- package/lib/esm/Deserialization/AbstractParser.d.ts +46 -0
- package/lib/esm/Deserialization/AbstractParser.d.ts.map +1 -0
- package/lib/esm/Deserialization/AbstractParser.js +8 -0
- package/lib/esm/Deserialization/AbstractParser.js.map +1 -0
- package/lib/esm/Deserialization/Helper.d.ts +263 -0
- package/lib/esm/Deserialization/Helper.d.ts.map +1 -0
- package/lib/esm/Deserialization/Helper.js +871 -0
- package/lib/esm/Deserialization/Helper.js.map +1 -0
- package/lib/esm/Deserialization/JsonParser.d.ts +166 -0
- package/lib/esm/Deserialization/JsonParser.d.ts.map +1 -0
- package/lib/esm/Deserialization/JsonParser.js +677 -0
- package/lib/esm/Deserialization/JsonParser.js.map +1 -0
- package/lib/esm/Deserialization/JsonProps.d.ts +273 -0
- package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -0
- package/lib/esm/Deserialization/JsonProps.js +9 -0
- package/lib/esm/Deserialization/JsonProps.js.map +1 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.d.ts +35 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.d.ts.map +1 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.js +74 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -0
- package/lib/esm/Deserialization/XmlParser.d.ts +86 -0
- package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -0
- package/lib/esm/Deserialization/XmlParser.js +970 -0
- package/lib/esm/Deserialization/XmlParser.js.map +1 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +55 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.js +172 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -0
- package/lib/esm/ECName.d.ts +31 -0
- package/lib/esm/ECName.d.ts.map +1 -0
- package/lib/esm/ECName.js +82 -0
- package/lib/esm/ECName.js.map +1 -0
- package/lib/esm/ECObjects.d.ts +166 -0
- package/lib/esm/ECObjects.d.ts.map +1 -0
- package/lib/esm/ECObjects.js +422 -0
- package/lib/esm/ECObjects.js.map +1 -0
- package/lib/esm/Exception.d.ts +45 -0
- package/lib/esm/Exception.d.ts.map +1 -0
- package/lib/esm/Exception.js +82 -0
- package/lib/esm/Exception.js.map +1 -0
- package/lib/esm/Interfaces.d.ts +79 -0
- package/lib/esm/Interfaces.d.ts.map +1 -0
- package/lib/esm/Interfaces.js +9 -0
- package/lib/esm/Interfaces.js.map +1 -0
- package/lib/esm/Metadata/Class.d.ts +245 -0
- package/lib/esm/Metadata/Class.d.ts.map +1 -0
- package/lib/esm/Metadata/Class.js +552 -0
- package/lib/esm/Metadata/Class.js.map +1 -0
- package/lib/esm/Metadata/Constant.d.ts +65 -0
- package/lib/esm/Metadata/Constant.d.ts.map +1 -0
- package/lib/esm/Metadata/Constant.js +119 -0
- package/lib/esm/Metadata/Constant.js.map +1 -0
- package/lib/esm/Metadata/CustomAttribute.d.ts +24 -0
- package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -0
- package/lib/esm/Metadata/CustomAttribute.js +24 -0
- package/lib/esm/Metadata/CustomAttribute.js.map +1 -0
- package/lib/esm/Metadata/CustomAttributeClass.d.ts +44 -0
- package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -0
- package/lib/esm/Metadata/CustomAttributeClass.js +70 -0
- package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -0
- package/lib/esm/Metadata/EntityClass.d.ts +78 -0
- package/lib/esm/Metadata/EntityClass.d.ts.map +1 -0
- package/lib/esm/Metadata/EntityClass.js +224 -0
- package/lib/esm/Metadata/EntityClass.js.map +1 -0
- package/lib/esm/Metadata/Enumeration.d.ts +87 -0
- package/lib/esm/Metadata/Enumeration.d.ts.map +1 -0
- package/lib/esm/Metadata/Enumeration.js +155 -0
- package/lib/esm/Metadata/Enumeration.js.map +1 -0
- package/lib/esm/Metadata/Format.d.ts +99 -0
- package/lib/esm/Metadata/Format.d.ts.map +1 -0
- package/lib/esm/Metadata/Format.js +238 -0
- package/lib/esm/Metadata/Format.js.map +1 -0
- package/lib/esm/Metadata/InvertedUnit.d.ts +50 -0
- package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -0
- package/lib/esm/Metadata/InvertedUnit.js +93 -0
- package/lib/esm/Metadata/InvertedUnit.js.map +1 -0
- package/lib/esm/Metadata/KindOfQuantity.d.ts +72 -0
- package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -0
- package/lib/esm/Metadata/KindOfQuantity.js +229 -0
- package/lib/esm/Metadata/KindOfQuantity.js.map +1 -0
- package/lib/esm/Metadata/Mixin.d.ts +55 -0
- package/lib/esm/Metadata/Mixin.d.ts.map +1 -0
- package/lib/esm/Metadata/Mixin.js +109 -0
- package/lib/esm/Metadata/Mixin.js.map +1 -0
- package/lib/esm/Metadata/OverrideFormat.d.ts +68 -0
- package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -0
- package/lib/esm/Metadata/OverrideFormat.js +124 -0
- package/lib/esm/Metadata/OverrideFormat.js.map +1 -0
- package/lib/esm/Metadata/Phenomenon.d.ts +34 -0
- package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -0
- package/lib/esm/Metadata/Phenomenon.js +55 -0
- package/lib/esm/Metadata/Phenomenon.js.map +1 -0
- package/lib/esm/Metadata/Property.d.ts +247 -0
- package/lib/esm/Metadata/Property.d.ts.map +1 -0
- package/lib/esm/Metadata/Property.js +565 -0
- package/lib/esm/Metadata/Property.js.map +1 -0
- package/lib/esm/Metadata/PropertyCategory.d.ts +40 -0
- package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -0
- package/lib/esm/Metadata/PropertyCategory.js +57 -0
- package/lib/esm/Metadata/PropertyCategory.js.map +1 -0
- package/lib/esm/Metadata/RelationshipClass.d.ts +170 -0
- package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -0
- package/lib/esm/Metadata/RelationshipClass.js +380 -0
- package/lib/esm/Metadata/RelationshipClass.js.map +1 -0
- package/lib/esm/Metadata/Schema.d.ts +330 -0
- package/lib/esm/Metadata/Schema.d.ts.map +1 -0
- package/lib/esm/Metadata/Schema.js +570 -0
- package/lib/esm/Metadata/Schema.js.map +1 -0
- package/lib/esm/Metadata/SchemaItem.d.ts +67 -0
- package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -0
- package/lib/esm/Metadata/SchemaItem.js +140 -0
- package/lib/esm/Metadata/SchemaItem.js.map +1 -0
- package/lib/esm/Metadata/Unit.d.ts +77 -0
- package/lib/esm/Metadata/Unit.d.ts.map +1 -0
- package/lib/esm/Metadata/Unit.js +158 -0
- package/lib/esm/Metadata/Unit.js.map +1 -0
- package/lib/esm/Metadata/UnitSystem.d.ts +21 -0
- package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -0
- package/lib/esm/Metadata/UnitSystem.js +25 -0
- package/lib/esm/Metadata/UnitSystem.js.map +1 -0
- package/lib/esm/PropertyTypes.d.ts +50 -0
- package/lib/esm/PropertyTypes.d.ts.map +1 -0
- package/lib/esm/PropertyTypes.js +88 -0
- package/lib/esm/PropertyTypes.js.map +1 -0
- package/lib/esm/SchemaJsonLocater.d.ts +42 -0
- package/lib/esm/SchemaJsonLocater.d.ts.map +1 -0
- package/lib/esm/SchemaJsonLocater.js +54 -0
- package/lib/esm/SchemaJsonLocater.js.map +1 -0
- package/lib/esm/SchemaKey.d.ts +111 -0
- package/lib/esm/SchemaKey.d.ts.map +1 -0
- package/lib/esm/SchemaKey.js +214 -0
- package/lib/esm/SchemaKey.js.map +1 -0
- package/lib/esm/SchemaLoader.d.ts +32 -0
- package/lib/esm/SchemaLoader.d.ts.map +1 -0
- package/lib/esm/SchemaLoader.js +53 -0
- package/lib/esm/SchemaLoader.js.map +1 -0
- package/lib/esm/SchemaPartVisitorDelegate.d.ts +275 -0
- package/lib/esm/SchemaPartVisitorDelegate.d.ts.map +1 -0
- package/lib/esm/SchemaPartVisitorDelegate.js +209 -0
- package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -0
- package/lib/esm/UnitConversion/Graph.d.ts +35 -0
- package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
- package/lib/esm/UnitConversion/Graph.js +80 -0
- package/lib/esm/UnitConversion/Graph.js.map +1 -0
- package/lib/esm/UnitConversion/Parser.d.ts +9 -0
- package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
- package/lib/esm/UnitConversion/Parser.js +39 -0
- package/lib/esm/UnitConversion/Parser.js.map +1 -0
- package/lib/esm/UnitConversion/UnitConversion.d.ts +46 -0
- package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitConversion.js +74 -0
- package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
- package/lib/esm/UnitConversion/UnitConverter.d.ts +40 -0
- package/lib/esm/UnitConversion/UnitConverter.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitConverter.js +113 -0
- package/lib/esm/UnitConversion/UnitConverter.js.map +1 -0
- package/lib/esm/UnitConversion/UnitTree.d.ts +44 -0
- package/lib/esm/UnitConversion/UnitTree.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitTree.js +165 -0
- package/lib/esm/UnitConversion/UnitTree.js.map +1 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts +78 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts.map +1 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.js +231 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -0
- package/lib/esm/Validation/SchemaWalker.d.ts +24 -0
- package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -0
- package/lib/esm/Validation/SchemaWalker.js +50 -0
- package/lib/esm/Validation/SchemaWalker.js.map +1 -0
- package/lib/esm/ecschema-metadata.d.ts +52 -0
- package/lib/esm/ecschema-metadata.d.ts.map +1 -0
- package/lib/esm/ecschema-metadata.js +55 -0
- package/lib/esm/ecschema-metadata.js.map +1 -0
- package/lib/esm/utils/SchemaGraph.d.ts +44 -0
- package/lib/esm/utils/SchemaGraph.d.ts.map +1 -0
- package/lib/esm/utils/SchemaGraph.js +111 -0
- package/lib/esm/utils/SchemaGraph.js.map +1 -0
- package/package.json +9 -7
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Metadata
|
|
7
|
+
*/
|
|
8
|
+
import { DelayedPromiseWithProps } from "../DelayedPromise";
|
|
9
|
+
import { XmlSerializationUtils } from "../Deserialization/XmlSerializationUtils";
|
|
10
|
+
import { SchemaItemType } from "../ECObjects";
|
|
11
|
+
import { ECObjectsError, ECObjectsStatus } from "../Exception";
|
|
12
|
+
import { formatStringRgx } from "@itwin/core-quantity";
|
|
13
|
+
import { OverrideFormat } from "./OverrideFormat";
|
|
14
|
+
import { SchemaItem } from "./SchemaItem";
|
|
15
|
+
/** A Typescript class representation of a KindOfQuantity.
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
export class KindOfQuantity extends SchemaItem {
|
|
19
|
+
/** The first presentation format in the list of Formats. */
|
|
20
|
+
get defaultPresentationFormat() { return this.presentationFormats[0]; }
|
|
21
|
+
/** A list of presentation formats. */
|
|
22
|
+
get presentationFormats() { return this._presentationFormats; }
|
|
23
|
+
get persistenceUnit() { return this._persistenceUnit; }
|
|
24
|
+
set persistenceUnit(value) { this._persistenceUnit = value; }
|
|
25
|
+
get relativeError() { return this._relativeError; }
|
|
26
|
+
constructor(schema, name) {
|
|
27
|
+
super(schema, name);
|
|
28
|
+
this._relativeError = 1.0;
|
|
29
|
+
this._presentationFormats = new Array();
|
|
30
|
+
this.schemaItemType = SchemaItemType.KindOfQuantity; // Needed to allow both run-time and compile-time check.
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param format The Format to add to this KindOfQuantity
|
|
35
|
+
* @param isDefault
|
|
36
|
+
*/
|
|
37
|
+
addPresentationFormat(format, isDefault = false) {
|
|
38
|
+
// TODO: Add some sort of validation?
|
|
39
|
+
(isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);
|
|
40
|
+
}
|
|
41
|
+
/** Parses the format string into the parts that make up an Override Format
|
|
42
|
+
* @param formatString
|
|
43
|
+
*/
|
|
44
|
+
parseFormatString(formatString) {
|
|
45
|
+
const match = formatString.split(formatStringRgx); // split string based on regex groups
|
|
46
|
+
if (undefined === match[1])
|
|
47
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string, ${formatString}, on KindOfQuantity '${this.fullName}' is missing a format.`);
|
|
48
|
+
const returnValue = { name: match[1] };
|
|
49
|
+
if (undefined !== match[2] && undefined !== match[3]) {
|
|
50
|
+
const overrideString = match[2];
|
|
51
|
+
const tokens = [];
|
|
52
|
+
let prevPos = 1; // Initial position is the character directly after the opening '(' in the override string.
|
|
53
|
+
let currPos;
|
|
54
|
+
// TODO need to include `,` as a valid search argument.
|
|
55
|
+
while (-1 !== (currPos = overrideString.indexOf(")", prevPos))) { // eslint-disable-line
|
|
56
|
+
tokens.push(overrideString.substring(prevPos, currPos));
|
|
57
|
+
prevPos = currPos + 1;
|
|
58
|
+
}
|
|
59
|
+
if (overrideString.length > 0 && undefined === tokens.find((token) => {
|
|
60
|
+
return "" !== token; // there is at least one token that is not empty.
|
|
61
|
+
})) {
|
|
62
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
|
|
63
|
+
}
|
|
64
|
+
// The first override parameter overrides the default precision of the format
|
|
65
|
+
const precisionIndx = 0;
|
|
66
|
+
if (tokens.length >= precisionIndx + 1) {
|
|
67
|
+
if (tokens[precisionIndx].length > 0) {
|
|
68
|
+
const precision = Number.parseInt(tokens[precisionIndx], 10);
|
|
69
|
+
if (Number.isNaN(precision))
|
|
70
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string '${formatString}' on KindOfQuantity '${this.fullName}' has a precision override '${tokens[precisionIndx]}' that is not number.`);
|
|
71
|
+
returnValue.precision = precision;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let i = 4;
|
|
76
|
+
while (i < match.length - 1) { // The regex match ends with an empty last value, which causes problems when exactly 4 unit overrides as specified, so ignore this last empty value
|
|
77
|
+
if (undefined === match[i])
|
|
78
|
+
break;
|
|
79
|
+
// Unit override required
|
|
80
|
+
if (undefined === match[i + 1])
|
|
81
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
|
|
82
|
+
if (undefined === returnValue.unitAndLabels)
|
|
83
|
+
returnValue.unitAndLabels = [];
|
|
84
|
+
if (undefined !== match[i + 2]) // matches '|'
|
|
85
|
+
returnValue.unitAndLabels.push([match[i + 1], match[i + 3] ?? ""]); // add unit name and label override (if '|' matches and next value is undefined, save it as an empty string)
|
|
86
|
+
else
|
|
87
|
+
returnValue.unitAndLabels.push([match[i + 1], undefined]); // add unit name
|
|
88
|
+
i += 4;
|
|
89
|
+
}
|
|
90
|
+
return returnValue;
|
|
91
|
+
}
|
|
92
|
+
/** Creates an OverrideFormat in the context of this KindOfQuantity.
|
|
93
|
+
* @param parent The Format to override.
|
|
94
|
+
* @param precision The precision override
|
|
95
|
+
* @param unitLabelOverrides The list of unit and label overrides.
|
|
96
|
+
*/
|
|
97
|
+
createFormatOverride(parent, precision, unitLabelOverrides) {
|
|
98
|
+
if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)
|
|
99
|
+
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}'.`);
|
|
100
|
+
if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)
|
|
101
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);
|
|
102
|
+
// TODO: Check compatibility of Unit overrides with the persistence unit
|
|
103
|
+
return new OverrideFormat(parent, precision, unitLabelOverrides);
|
|
104
|
+
}
|
|
105
|
+
async processPresentationUnits(presentationUnitsJson) {
|
|
106
|
+
const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
|
|
107
|
+
for (const formatString of presUnitsArr) {
|
|
108
|
+
const presFormatOverride = this.parseFormatString(formatString);
|
|
109
|
+
const format = await this.schema.lookupItem(presFormatOverride.name);
|
|
110
|
+
if (undefined === format || format.schemaItemType !== SchemaItemType.Format)
|
|
111
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
|
|
112
|
+
if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
|
|
113
|
+
this.addPresentationFormat(format);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
let unitAndLabels;
|
|
117
|
+
if (undefined !== presFormatOverride.unitAndLabels) {
|
|
118
|
+
if (4 < presFormatOverride.unitAndLabels.length)
|
|
119
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
|
|
120
|
+
unitAndLabels = [];
|
|
121
|
+
for (const unitOverride of presFormatOverride.unitAndLabels) {
|
|
122
|
+
const unit = await this.schema.lookupItem(unitOverride[0]);
|
|
123
|
+
if (undefined === unit)
|
|
124
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
|
|
125
|
+
unitAndLabels.push([unit, unitOverride[1]]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
|
|
129
|
+
this.addPresentationFormat(overrideFormat);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
processPresentationUnitsSync(presentationUnitsJson) {
|
|
133
|
+
const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(";");
|
|
134
|
+
for (const formatString of presUnitsArr) {
|
|
135
|
+
const presFormatOverride = this.parseFormatString(formatString);
|
|
136
|
+
const format = this.schema.lookupItemSync(presFormatOverride.name);
|
|
137
|
+
if (undefined === format || format.schemaItemType !== SchemaItemType.Format)
|
|
138
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);
|
|
139
|
+
if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {
|
|
140
|
+
this.addPresentationFormat(format);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
let unitAndLabels;
|
|
144
|
+
if (undefined !== presFormatOverride.unitAndLabels) {
|
|
145
|
+
if (4 < presFormatOverride.unitAndLabels.length)
|
|
146
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
|
|
147
|
+
unitAndLabels = [];
|
|
148
|
+
for (const unitOverride of presFormatOverride.unitAndLabels) {
|
|
149
|
+
const unit = this.schema.lookupItemSync(unitOverride[0]);
|
|
150
|
+
if (undefined === unit)
|
|
151
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);
|
|
152
|
+
unitAndLabels.push([unit, unitOverride[1]]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const overrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);
|
|
156
|
+
this.addPresentationFormat(overrideFormat);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Save this KindOfQuantity's properties to an object for serializing to JSON.
|
|
161
|
+
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
162
|
+
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
163
|
+
*/
|
|
164
|
+
toJSON(standalone = false, includeSchemaVersion = false) {
|
|
165
|
+
const schemaJson = super.toJSON(standalone, includeSchemaVersion);
|
|
166
|
+
schemaJson.relativeError = this.relativeError;
|
|
167
|
+
schemaJson.persistenceUnit = this.persistenceUnit.fullName;
|
|
168
|
+
if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)
|
|
169
|
+
schemaJson.presentationUnits = this.presentationFormats.map((format) => format.fullName);
|
|
170
|
+
return schemaJson;
|
|
171
|
+
}
|
|
172
|
+
/** @internal */
|
|
173
|
+
async toXml(schemaXml) {
|
|
174
|
+
const itemElement = await super.toXml(schemaXml);
|
|
175
|
+
const persistenceUnit = await this.persistenceUnit;
|
|
176
|
+
if (undefined !== persistenceUnit) {
|
|
177
|
+
const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);
|
|
178
|
+
itemElement.setAttribute("persistenceUnit", unitName);
|
|
179
|
+
}
|
|
180
|
+
if (undefined !== this.presentationFormats) {
|
|
181
|
+
const presUnitStrings = this.presentationFormats.map((format) => {
|
|
182
|
+
if (!OverrideFormat.isOverrideFormat(format))
|
|
183
|
+
return XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);
|
|
184
|
+
return format.fullNameXml(this.schema);
|
|
185
|
+
});
|
|
186
|
+
itemElement.setAttribute("presentationUnits", presUnitStrings.join(";"));
|
|
187
|
+
}
|
|
188
|
+
itemElement.setAttribute("relativeError", this.relativeError.toString());
|
|
189
|
+
return itemElement;
|
|
190
|
+
}
|
|
191
|
+
fromJSONSync(kindOfQuantityProps) {
|
|
192
|
+
super.fromJSONSync(kindOfQuantityProps);
|
|
193
|
+
this._relativeError = kindOfQuantityProps.relativeError;
|
|
194
|
+
const persistenceUnit = this.schema.lookupItemSync(kindOfQuantityProps.persistenceUnit);
|
|
195
|
+
if (undefined === persistenceUnit)
|
|
196
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
|
|
197
|
+
if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)
|
|
198
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
|
|
199
|
+
this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
|
|
200
|
+
if (undefined !== kindOfQuantityProps.presentationUnits)
|
|
201
|
+
this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);
|
|
202
|
+
}
|
|
203
|
+
async fromJSON(kindOfQuantityProps) {
|
|
204
|
+
await super.fromJSON(kindOfQuantityProps);
|
|
205
|
+
this._relativeError = kindOfQuantityProps.relativeError;
|
|
206
|
+
const persistenceUnit = await this.schema.lookupItem(kindOfQuantityProps.persistenceUnit);
|
|
207
|
+
if (undefined === persistenceUnit)
|
|
208
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);
|
|
209
|
+
if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)
|
|
210
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);
|
|
211
|
+
this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);
|
|
212
|
+
if (undefined !== kindOfQuantityProps.presentationUnits)
|
|
213
|
+
await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* @alpha
|
|
217
|
+
* Used for schema editing.
|
|
218
|
+
*/
|
|
219
|
+
setRelativeError(relativeError) {
|
|
220
|
+
this._relativeError = relativeError;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* @internal
|
|
225
|
+
* An abstract class used for schema editing.
|
|
226
|
+
*/
|
|
227
|
+
export class MutableKindOfQuantity extends KindOfQuantity {
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=KindOfQuantity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KindOfQuantity.js","sourceRoot":"","sources":["../../../src/Metadata/KindOfQuantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAS1C;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAM5C,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,C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,CAAC,MAAM,CAAC,UAAU,CAAO,mBAAmB,CAAC,eAAe,CAAC,CAAC;QAChG,IAAI,SAAS,KAAK,eAAe;YAC/B,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,aAAa,EAAE,YAAY,mBAAmB,CAAC,eAAe,kBAAkB,CAAC,CAAC;QAE7H,IAAI,eAAe,CAAC,cAAc,KAAK,cAAc,CAAC,IAAI,IAAI,eAAe,CAAC,cAAc,KAAK,cAAc,CAAC,YAAY;YAC1H,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,aAAa,EAAE,YAAY,mBAAmB,CAAC,eAAe,iCAAiC,CAAC,CAAC;QAE5I,IAAI,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,eAAe,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,eAAe,CAAC,CAAC;QAEtG,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;CACF;AACD;;;GAGG;AACH,MAAM,OAAgB,qBAAsB,SAAQ,cAAc;CAIjE","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 { KindOfQuantityProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedInvertedUnit, LazyLoadedUnit } from \"../Interfaces\";\r\nimport { formatStringRgx } from \"@itwin/core-quantity\";\r\nimport { Format } from \"./Format\";\r\nimport { InvertedUnit } from \"./InvertedUnit\";\r\nimport { OverrideFormat } from \"./OverrideFormat\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { Unit } from \"./Unit\";\r\n\r\ninterface OverrideFormatProps {\r\n name: string;\r\n precision?: number;\r\n unitAndLabels?: Array<[string, string | undefined]>; // Tuple of [unit name | unit label]\r\n}\r\n\r\n/** A Typescript class representation of a KindOfQuantity.\r\n * @beta\r\n */\r\nexport class KindOfQuantity extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.KindOfQuantity; // eslint-disable-line\r\n protected _relativeError: number = 1.0;\r\n protected _presentationFormats: Array<Format | OverrideFormat> = new Array<Format | OverrideFormat>();\r\n protected _persistenceUnit?: LazyLoadedUnit | LazyLoadedInvertedUnit;\r\n\r\n /** The first presentation format in the list of Formats. */\r\n public get defaultPresentationFormat(): Format | OverrideFormat | undefined { return this.presentationFormats[0]; }\r\n\r\n /** A list of presentation formats. */\r\n public get presentationFormats(): Array<Format | OverrideFormat> { return this._presentationFormats; }\r\n\r\n public get persistenceUnit(): LazyLoadedUnit | LazyLoadedInvertedUnit | undefined { return this._persistenceUnit; }\r\n protected set persistenceUnit(value: LazyLoadedUnit | LazyLoadedInvertedUnit | undefined) { this._persistenceUnit = value; }\r\n\r\n public get relativeError() { return this._relativeError; }\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.KindOfQuantity; // Needed to allow both run-time and compile-time check.\r\n }\r\n\r\n /**\r\n *\r\n * @param format The Format to add to this KindOfQuantity\r\n * @param isDefault\r\n */\r\n protected addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean = false) {\r\n // TODO: Add some sort of validation?\r\n (isDefault) ? this._presentationFormats.splice(0, 0, format) : this._presentationFormats.push(format);\r\n }\r\n\r\n /** Parses the format string into the parts that make up an Override Format\r\n * @param formatString\r\n */\r\n private parseFormatString(formatString: string): OverrideFormatProps {\r\n const match = formatString.split(formatStringRgx); // split string based on regex groups\r\n if (undefined === match[1])\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string, ${formatString}, on KindOfQuantity '${this.fullName}' is missing a format.`);\r\n\r\n const returnValue: OverrideFormatProps = { name: match[1] };\r\n\r\n if (undefined !== match[2] && undefined !== match[3]) {\r\n const overrideString = match[2];\r\n const tokens: string[] = [];\r\n let prevPos = 1; // Initial position is the character directly after the opening '(' in the override string.\r\n let currPos;\r\n\r\n // TODO need to include `,` as a valid search argument.\r\n while (-1 !== (currPos = overrideString.indexOf(\")\", prevPos))) { // eslint-disable-line\r\n tokens.push(overrideString.substring(prevPos, currPos));\r\n prevPos = currPos + 1;\r\n }\r\n\r\n if (overrideString.length > 0 && undefined === tokens.find((token) => {\r\n return \"\" !== token; // there is at least one token that is not empty.\r\n })) {\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n }\r\n\r\n // The first override parameter overrides the default precision of the format\r\n const precisionIndx: number = 0;\r\n\r\n if (tokens.length >= precisionIndx + 1) {\r\n if (tokens[precisionIndx].length > 0) {\r\n const precision = Number.parseInt(tokens[precisionIndx], 10);\r\n if (Number.isNaN(precision))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The format string '${formatString}' on KindOfQuantity '${this.fullName}' has a precision override '${tokens[precisionIndx]}' that is not number.`);\r\n returnValue.precision = precision;\r\n }\r\n }\r\n }\r\n\r\n let i = 4;\r\n while (i < match.length - 1) { // The regex match ends with an empty last value, which causes problems when exactly 4 unit overrides as specified, so ignore this last empty value\r\n if (undefined === match[i])\r\n break;\r\n // Unit override required\r\n if (undefined === match[i + 1])\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n\r\n if (undefined === returnValue.unitAndLabels)\r\n returnValue.unitAndLabels = [];\r\n\r\n if (undefined !== match[i + 2]) // matches '|'\r\n returnValue.unitAndLabels.push([match[i + 1], match[i + 3] ?? \"\"]); // add unit name and label override (if '|' matches and next value is undefined, save it as an empty string)\r\n else\r\n returnValue.unitAndLabels.push([match[i + 1], undefined]); // add unit name\r\n\r\n i += 4;\r\n }\r\n\r\n return returnValue;\r\n }\r\n\r\n /** Creates an OverrideFormat in the context of this KindOfQuantity.\r\n * @param parent The Format to override.\r\n * @param precision The precision override\r\n * @param unitLabelOverrides The list of unit and label overrides.\r\n */\r\n protected createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat {\r\n if (unitLabelOverrides && parent.units && parent.units.length !== unitLabelOverrides.length)\r\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}'.`);\r\n\r\n if (parent.units && 0 === parent.units.length && unitLabelOverrides && 0 < unitLabelOverrides.length)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Cannot add a presentation format to KindOfQuantity '${this.name}' without any units and no unit overrides.`);\r\n\r\n // TODO: Check compatibility of Unit overrides with the persistence unit\r\n\r\n return new OverrideFormat(parent, precision, unitLabelOverrides);\r\n }\r\n\r\n private async processPresentationUnits(presentationUnitsJson: string | string[]): Promise<void> {\r\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\r\n for (const formatString of presUnitsArr) {\r\n const presFormatOverride: OverrideFormatProps = this.parseFormatString(formatString);\r\n\r\n const format = await this.schema.lookupItem<Format>(presFormatOverride.name);\r\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\r\n\r\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\r\n this.addPresentationFormat(format);\r\n continue;\r\n }\r\n\r\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\r\n if (undefined !== presFormatOverride.unitAndLabels) {\r\n if (4 < presFormatOverride.unitAndLabels.length)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n\r\n unitAndLabels = [];\r\n for (const unitOverride of presFormatOverride.unitAndLabels) {\r\n const unit = await this.schema.lookupItem<Unit | InvertedUnit>(unitOverride[0]);\r\n if (undefined === unit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\r\n\r\n unitAndLabels.push([unit, unitOverride[1]]);\r\n }\r\n }\r\n\r\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\r\n this.addPresentationFormat(overrideFormat);\r\n }\r\n }\r\n\r\n private processPresentationUnitsSync(presentationUnitsJson: string | string[]): void {\r\n const presUnitsArr = Array.isArray(presentationUnitsJson) ? presentationUnitsJson : presentationUnitsJson.split(\";\");\r\n for (const formatString of presUnitsArr) {\r\n const presFormatOverride: OverrideFormatProps = this.parseFormatString(formatString);\r\n\r\n const format = this.schema.lookupItemSync<Format>(presFormatOverride.name);\r\n if (undefined === format || format.schemaItemType !== SchemaItemType.Format)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate Format '${presFormatOverride.name}' for the presentation unit on KindOfQuantity ${this.fullName}.`);\r\n\r\n if (undefined === presFormatOverride.precision && undefined === presFormatOverride.unitAndLabels) {\r\n this.addPresentationFormat(format);\r\n continue;\r\n }\r\n\r\n let unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined;\r\n if (undefined !== presFormatOverride.unitAndLabels) {\r\n if (4 < presFormatOverride.unitAndLabels.length)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n\r\n unitAndLabels = [];\r\n for (const unitOverride of presFormatOverride.unitAndLabels) {\r\n const unit = this.schema.lookupItemSync<Unit | InvertedUnit>(unitOverride[0]);\r\n if (undefined === unit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate SchemaItem ${unitOverride[0]}.`);\r\n\r\n unitAndLabels.push([unit, unitOverride[1]]);\r\n }\r\n }\r\n\r\n const overrideFormat: OverrideFormat = this.createFormatOverride(format, presFormatOverride.precision, unitAndLabels);\r\n this.addPresentationFormat(overrideFormat);\r\n }\r\n }\r\n\r\n /**\r\n * Save this KindOfQuantity'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): KindOfQuantityProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.relativeError = this.relativeError;\r\n schemaJson.persistenceUnit = this.persistenceUnit!.fullName;\r\n if (undefined !== this.presentationFormats && 0 < this.presentationFormats.length)\r\n schemaJson.presentationUnits = this.presentationFormats.map((format: Format | OverrideFormat) => format.fullName);\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 persistenceUnit = await this.persistenceUnit;\r\n if (undefined !== persistenceUnit) {\r\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, persistenceUnit.schema, persistenceUnit.name);\r\n itemElement.setAttribute(\"persistenceUnit\", unitName);\r\n }\r\n\r\n if (undefined !== this.presentationFormats) {\r\n const presUnitStrings = this.presentationFormats.map((format: Format | OverrideFormat) => {\r\n if (!OverrideFormat.isOverrideFormat(format))\r\n return XmlSerializationUtils.createXmlTypedName(this.schema, format.schema, format.name);\r\n return format.fullNameXml(this.schema);\r\n });\r\n itemElement.setAttribute(\"presentationUnits\", presUnitStrings.join(\";\"));\r\n }\r\n itemElement.setAttribute(\"relativeError\", this.relativeError.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(kindOfQuantityProps: KindOfQuantityProps): void {\r\n super.fromJSONSync(kindOfQuantityProps);\r\n this._relativeError = kindOfQuantityProps.relativeError;\r\n\r\n const persistenceUnit = this.schema.lookupItemSync<Unit>(kindOfQuantityProps.persistenceUnit);\r\n if (undefined === persistenceUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\r\n\r\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\r\n\r\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n\r\n if (undefined !== kindOfQuantityProps.presentationUnits)\r\n this.processPresentationUnitsSync(kindOfQuantityProps.presentationUnits);\r\n }\r\n\r\n public override async fromJSON(kindOfQuantityProps: KindOfQuantityProps): Promise<void> {\r\n await super.fromJSON(kindOfQuantityProps);\r\n this._relativeError = kindOfQuantityProps.relativeError;\r\n\r\n const persistenceUnit = await this.schema.lookupItem<Unit>(kindOfQuantityProps.persistenceUnit);\r\n if (undefined === persistenceUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${kindOfQuantityProps.persistenceUnit} does not exist.`);\r\n\r\n if (persistenceUnit.schemaItemType !== SchemaItemType.Unit && persistenceUnit.schemaItemType !== SchemaItemType.InvertedUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The item ${kindOfQuantityProps.persistenceUnit} is not a Unit or InvertedUnit.`);\r\n\r\n this._persistenceUnit = new DelayedPromiseWithProps(persistenceUnit.key, async () => persistenceUnit);\r\n\r\n if (undefined !== kindOfQuantityProps.presentationUnits)\r\n await this.processPresentationUnits(kindOfQuantityProps.presentationUnits);\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected setRelativeError(relativeError: number): void {\r\n this._relativeError = relativeError;\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableKindOfQuantity extends KindOfQuantity {\r\n public abstract override addPresentationFormat(format: Format | OverrideFormat, isDefault: boolean): void;\r\n public abstract override createFormatOverride(parent: Format, precision?: number, unitLabelOverrides?: Array<[Unit | InvertedUnit, string | undefined]>): OverrideFormat;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Metadata
|
|
3
|
+
*/
|
|
4
|
+
import { MixinProps } from "../Deserialization/JsonProps";
|
|
5
|
+
import { SchemaItemType, StrengthDirection } from "../ECObjects";
|
|
6
|
+
import { LazyLoadedEntityClass } from "../Interfaces";
|
|
7
|
+
import { ECClass } from "./Class";
|
|
8
|
+
import { EntityClass } from "./EntityClass";
|
|
9
|
+
import { NavigationProperty } from "./Property";
|
|
10
|
+
import { RelationshipClass } from "./RelationshipClass";
|
|
11
|
+
import { Schema } from "./Schema";
|
|
12
|
+
/**
|
|
13
|
+
* A Typescript class representation of a Mixin.
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export declare class Mixin extends ECClass {
|
|
17
|
+
readonly schemaItemType: SchemaItemType.Mixin;
|
|
18
|
+
protected _appliesTo?: LazyLoadedEntityClass;
|
|
19
|
+
get appliesTo(): LazyLoadedEntityClass | undefined;
|
|
20
|
+
constructor(schema: Schema, name: string);
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param name
|
|
24
|
+
* @param relationship
|
|
25
|
+
* @param direction
|
|
26
|
+
*/
|
|
27
|
+
protected createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;
|
|
28
|
+
protected createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;
|
|
29
|
+
/**
|
|
30
|
+
* @alpha Used for schema editing.
|
|
31
|
+
*/
|
|
32
|
+
protected setAppliesTo(appliesTo: LazyLoadedEntityClass): void;
|
|
33
|
+
/**
|
|
34
|
+
* Save this Mixin's properties to an object for serializing to JSON.
|
|
35
|
+
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
36
|
+
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
37
|
+
*/
|
|
38
|
+
toJSON(standalone?: boolean, includeSchemaVersion?: boolean): MixinProps;
|
|
39
|
+
/** @internal */
|
|
40
|
+
toXml(schemaXml: Document): Promise<Element>;
|
|
41
|
+
fromJSONSync(mixinProps: MixinProps): void;
|
|
42
|
+
fromJSON(mixinProps: MixinProps): Promise<void>;
|
|
43
|
+
applicableTo(entityClass: EntityClass): Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
* An abstract class used for schema editing.
|
|
48
|
+
*/
|
|
49
|
+
export declare abstract class MutableMixin extends Mixin {
|
|
50
|
+
abstract setAppliesTo(entityClass: LazyLoadedEntityClass): void;
|
|
51
|
+
abstract createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;
|
|
52
|
+
abstract createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;
|
|
53
|
+
abstract setDisplayLabel(displayLabel: string): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=Mixin.d.ts.map
|
|
@@ -0,0 +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,qBAA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KAAK;aACrB,YAAY,CAAC,WAAW,EAAE,qBAAqB,GAAG,IAAI;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"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Metadata
|
|
7
|
+
*/
|
|
8
|
+
import { DelayedPromiseWithProps } from "../DelayedPromise";
|
|
9
|
+
import { XmlSerializationUtils } from "../Deserialization/XmlSerializationUtils";
|
|
10
|
+
import { ECClassModifier, SchemaItemType } from "../ECObjects";
|
|
11
|
+
import { ECObjectsError, ECObjectsStatus } from "../Exception";
|
|
12
|
+
import { ECClass } from "./Class";
|
|
13
|
+
import { createNavigationProperty, createNavigationPropertySync } from "./EntityClass";
|
|
14
|
+
/**
|
|
15
|
+
* A Typescript class representation of a Mixin.
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
export class Mixin extends ECClass {
|
|
19
|
+
get appliesTo() {
|
|
20
|
+
return this._appliesTo;
|
|
21
|
+
}
|
|
22
|
+
constructor(schema, name) {
|
|
23
|
+
super(schema, name, ECClassModifier.Abstract);
|
|
24
|
+
this.schemaItemType = SchemaItemType.Mixin;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param name
|
|
29
|
+
* @param relationship
|
|
30
|
+
* @param direction
|
|
31
|
+
*/
|
|
32
|
+
async createNavigationProperty(name, relationship, direction) {
|
|
33
|
+
return this.addProperty(await createNavigationProperty(this, name, relationship, direction));
|
|
34
|
+
}
|
|
35
|
+
createNavigationPropertySync(name, relationship, direction) {
|
|
36
|
+
return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @alpha Used for schema editing.
|
|
40
|
+
*/
|
|
41
|
+
setAppliesTo(appliesTo) {
|
|
42
|
+
this._appliesTo = appliesTo;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Save this Mixin's properties to an object for serializing to JSON.
|
|
46
|
+
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
47
|
+
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
48
|
+
*/
|
|
49
|
+
toJSON(standalone = false, includeSchemaVersion = false) {
|
|
50
|
+
const schemaJson = super.toJSON(standalone, includeSchemaVersion);
|
|
51
|
+
if (undefined !== this.appliesTo) {
|
|
52
|
+
schemaJson.appliesTo = this.appliesTo.fullName;
|
|
53
|
+
}
|
|
54
|
+
return schemaJson;
|
|
55
|
+
}
|
|
56
|
+
/** @internal */
|
|
57
|
+
async toXml(schemaXml) {
|
|
58
|
+
const itemElement = await super.toXml(schemaXml);
|
|
59
|
+
// When CustomAttributes are added, there must be a check to see if the ECCustomAttributes
|
|
60
|
+
// already exist for this item before creating a new one to apply IsMixin
|
|
61
|
+
const customAttributes = schemaXml.createElement("ECCustomAttributes");
|
|
62
|
+
const isMixinElement = schemaXml.createElement("IsMixin");
|
|
63
|
+
const coreCustomSchema = this.schema.getReferenceSync("CoreCustomAttributes");
|
|
64
|
+
if (undefined !== coreCustomSchema) {
|
|
65
|
+
const xmlns = `CoreCustomAttributes.${coreCustomSchema.schemaKey.version.toString()}`;
|
|
66
|
+
isMixinElement.setAttribute("xmlns", xmlns);
|
|
67
|
+
}
|
|
68
|
+
const appliesToElement = schemaXml.createElement("AppliesToEntityClass");
|
|
69
|
+
const appliesTo = await this.appliesTo;
|
|
70
|
+
if (undefined !== appliesTo) {
|
|
71
|
+
const appliesToName = XmlSerializationUtils.createXmlTypedName(this.schema, appliesTo.schema, appliesTo.name);
|
|
72
|
+
appliesToElement.textContent = appliesToName;
|
|
73
|
+
isMixinElement.appendChild(appliesToElement);
|
|
74
|
+
}
|
|
75
|
+
customAttributes.appendChild(isMixinElement);
|
|
76
|
+
itemElement.appendChild(customAttributes);
|
|
77
|
+
return itemElement;
|
|
78
|
+
}
|
|
79
|
+
fromJSONSync(mixinProps) {
|
|
80
|
+
super.fromJSONSync(mixinProps);
|
|
81
|
+
const entityClassSchemaItemKey = this.schema.getSchemaItemKey(mixinProps.appliesTo);
|
|
82
|
+
if (!entityClassSchemaItemKey)
|
|
83
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);
|
|
84
|
+
this._appliesTo = new DelayedPromiseWithProps(entityClassSchemaItemKey, async () => {
|
|
85
|
+
const appliesTo = await this.schema.lookupItem(entityClassSchemaItemKey);
|
|
86
|
+
if (undefined === appliesTo)
|
|
87
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);
|
|
88
|
+
return appliesTo;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async fromJSON(mixinProps) {
|
|
92
|
+
this.fromJSONSync(mixinProps);
|
|
93
|
+
}
|
|
94
|
+
async applicableTo(entityClass) {
|
|
95
|
+
if (!this.appliesTo)
|
|
96
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidType, `appliesTo is undefined in the class ${this.fullName}.`);
|
|
97
|
+
const appliesTo = await this.appliesTo;
|
|
98
|
+
if (appliesTo === undefined)
|
|
99
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidType, `Unable to locate the appliesTo ${this.appliesTo.fullName}.`);
|
|
100
|
+
return appliesTo.is(entityClass);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @internal
|
|
105
|
+
* An abstract class used for schema editing.
|
|
106
|
+
*/
|
|
107
|
+
export class MutableMixin extends Mixin {
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=Mixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mixin.js","sourceRoot":"","sources":["../../../src/Metadata/Mixin.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,cAAc,EAAqB,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,4BAA4B,EAAe,MAAM,eAAe,CAAC;AAKpG;;;GAGG;AACH,MAAM,OAAO,KAAM,SAAQ,OAAO;IAIhC,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC,KAAK,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,wBAAwB,CAAC,IAAY,EAAE,YAAwC,EAAE,SAAqC;QACpI,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAC/F,CAAC;IAES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C,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,WAAwB;QAChD,IAAI,CAAC,IAAI,CAAC,SAAS;YACjB,MAAM,IAAI,cAAc,CAAC,eAAe,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,cAAc,CAAC,eAAe,CAAC,WAAW,EAAE,kCAAkC,IAAI,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC;QAEtH,OAAO,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;CACF;AACD;;;GAGG;AACH,MAAM,OAAgB,YAAa,SAAQ,KAAK;CAK/C","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 { MixinProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { ECClassModifier, SchemaItemType, StrengthDirection } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedEntityClass } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { ECClass } from \"./Class\";\r\nimport { createNavigationProperty, createNavigationPropertySync, EntityClass } from \"./EntityClass\";\r\nimport { NavigationProperty } from \"./Property\";\r\nimport { RelationshipClass } from \"./RelationshipClass\";\r\nimport { Schema } from \"./Schema\";\r\n\r\n/**\r\n * A Typescript class representation of a Mixin.\r\n * @beta\r\n */\r\nexport class Mixin extends ECClass {\r\n public override readonly schemaItemType!: SchemaItemType.Mixin; // eslint-disable-line\r\n protected _appliesTo?: LazyLoadedEntityClass;\r\n\r\n public get appliesTo(): LazyLoadedEntityClass | undefined {\r\n return this._appliesTo;\r\n }\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name, ECClassModifier.Abstract);\r\n this.schemaItemType = SchemaItemType.Mixin;\r\n }\r\n\r\n /**\r\n *\r\n * @param name\r\n * @param relationship\r\n * @param direction\r\n */\r\n protected async createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\r\n return this.addProperty(await createNavigationProperty(this, name, relationship, direction));\r\n }\r\n\r\n protected createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\r\n return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));\r\n }\r\n\r\n /**\r\n * @alpha Used for schema editing.\r\n */\r\n protected setAppliesTo(appliesTo: LazyLoadedEntityClass) {\r\n this._appliesTo = appliesTo;\r\n }\r\n /**\r\n * Save this Mixin'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): MixinProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n if (undefined !== this.appliesTo) {\r\n schemaJson.appliesTo = this.appliesTo.fullName;\r\n }\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n // When CustomAttributes are added, there must be a check to see if the ECCustomAttributes\r\n // already exist for this item before creating a new one to apply IsMixin\r\n const customAttributes = schemaXml.createElement(\"ECCustomAttributes\");\r\n const isMixinElement = schemaXml.createElement(\"IsMixin\");\r\n const coreCustomSchema = this.schema.getReferenceSync(\"CoreCustomAttributes\");\r\n if (undefined !== coreCustomSchema) {\r\n const xmlns = `CoreCustomAttributes.${coreCustomSchema.schemaKey.version.toString()}`;\r\n isMixinElement.setAttribute(\"xmlns\", xmlns);\r\n }\r\n\r\n const appliesToElement = schemaXml.createElement(\"AppliesToEntityClass\");\r\n const appliesTo = await this.appliesTo;\r\n if (undefined !== appliesTo) {\r\n const appliesToName = XmlSerializationUtils.createXmlTypedName(this.schema, appliesTo.schema, appliesTo.name);\r\n appliesToElement.textContent = appliesToName;\r\n isMixinElement.appendChild(appliesToElement);\r\n }\r\n\r\n customAttributes.appendChild(isMixinElement);\r\n itemElement.appendChild(customAttributes);\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(mixinProps: MixinProps) {\r\n super.fromJSONSync(mixinProps);\r\n const entityClassSchemaItemKey = this.schema.getSchemaItemKey(mixinProps.appliesTo);\r\n if (!entityClassSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);\r\n this._appliesTo = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(entityClassSchemaItemKey,\r\n async () => {\r\n const appliesTo = await this.schema.lookupItem<EntityClass>(entityClassSchemaItemKey);\r\n if (undefined === appliesTo)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the appliesTo ${mixinProps.appliesTo}.`);\r\n return appliesTo;\r\n });\r\n }\r\n\r\n public override async fromJSON(mixinProps: MixinProps) {\r\n this.fromJSONSync(mixinProps);\r\n }\r\n\r\n public async applicableTo(entityClass: EntityClass) {\r\n if (!this.appliesTo)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `appliesTo is undefined in the class ${this.fullName}.`);\r\n\r\n const appliesTo = await this.appliesTo;\r\n if (appliesTo === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `Unable to locate the appliesTo ${this.appliesTo.fullName}.`);\r\n\r\n return appliesTo.is(entityClass);\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableMixin extends Mixin {\r\n public abstract override setAppliesTo(entityClass: LazyLoadedEntityClass): void;\r\n public abstract override createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;\r\n public abstract override createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Metadata
|
|
3
|
+
*/
|
|
4
|
+
import { DecimalPrecision, FormatProps, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from "@itwin/core-quantity";
|
|
5
|
+
import { Format } from "./Format";
|
|
6
|
+
import { InvertedUnit } from "./InvertedUnit";
|
|
7
|
+
import { Schema } from "./Schema";
|
|
8
|
+
import { SchemaItemOverrideFormatProps } from "../Deserialization/JsonProps";
|
|
9
|
+
import { Unit } from "./Unit";
|
|
10
|
+
/**
|
|
11
|
+
* Overrides of a Format, from a Schema, and is SchemaItem that is used specifically on KindOfQuantity.
|
|
12
|
+
* @beta
|
|
13
|
+
*/
|
|
14
|
+
export declare class OverrideFormat {
|
|
15
|
+
private _precision?;
|
|
16
|
+
private _units?;
|
|
17
|
+
/** The Format that this OverrideFormat is extending */
|
|
18
|
+
readonly parent: Format;
|
|
19
|
+
/** The name of this OverrideFormat.
|
|
20
|
+
*
|
|
21
|
+
* This should be set to the [FormatString]($docs/bis/ec/kindofquantity/#format-string) which represents the format override.
|
|
22
|
+
*/
|
|
23
|
+
readonly name: string;
|
|
24
|
+
constructor(parent: Format, precision?: DecimalPrecision | FractionalPrecision, unitAndLabels?: Array<[Unit | InvertedUnit, string | undefined]>);
|
|
25
|
+
get precision(): DecimalPrecision | FractionalPrecision;
|
|
26
|
+
get units(): [Unit | InvertedUnit, string | undefined][] | undefined;
|
|
27
|
+
get fullName(): string;
|
|
28
|
+
get roundFactor(): number;
|
|
29
|
+
get type(): FormatType;
|
|
30
|
+
get minWidth(): number | undefined;
|
|
31
|
+
get scientificType(): ScientificType | undefined;
|
|
32
|
+
get showSignOption(): ShowSignOption;
|
|
33
|
+
get decimalSeparator(): string;
|
|
34
|
+
get thousandSeparator(): string;
|
|
35
|
+
get uomSeparator(): string;
|
|
36
|
+
get stationSeparator(): string;
|
|
37
|
+
get stationOffsetSize(): number | undefined;
|
|
38
|
+
get formatTraits(): FormatTraits;
|
|
39
|
+
get spacer(): string | undefined;
|
|
40
|
+
get includeZero(): boolean | undefined;
|
|
41
|
+
hasFormatTrait(formatTrait: FormatTraits): boolean;
|
|
42
|
+
/** Returns the format string of this override in the Xml full name format.
|
|
43
|
+
* @alpha
|
|
44
|
+
*/
|
|
45
|
+
fullNameXml(koqSchema: Schema): string;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a valid OverrideFormat fullName from the parent Format and overridden units.
|
|
48
|
+
* @param parent The parent Format.
|
|
49
|
+
* @param unitAndLabels The overridden unit and labels collection.
|
|
50
|
+
*/
|
|
51
|
+
static createOverrideFormatFullName(parent: Format, precision?: DecimalPrecision | FractionalPrecision, unitAndLabels?: Array<[Unit | InvertedUnit, string | undefined]>): string;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
static isOverrideFormat(object: any): object is OverrideFormat;
|
|
56
|
+
/**
|
|
57
|
+
* Returns a JSON object that contains the specification for the OverrideFormat where the precision and units properties have been overriden.
|
|
58
|
+
* If the precision and/or units properties have been overriden, the returned object will contain a "name" and a "parent" property.
|
|
59
|
+
* The "name" property identifies the OverrideFormat object itself and the "parent" property identifies the Format that has been overriden.
|
|
60
|
+
* This method is not intended for complete serialization as it does not serialize any of the schema item properties.
|
|
61
|
+
*/
|
|
62
|
+
getFormatProps(): SchemaItemOverrideFormatProps;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export declare function getFormatProps(format: Format | OverrideFormat): FormatProps;
|
|
68
|
+
//# sourceMappingURL=OverrideFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OverrideFormat.d.ts","sourceRoot":"","sources":["../../../src/Metadata/OverrideFormat.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpJ,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAC,CAAyC;IAC5D,OAAO,CAAC,MAAM,CAAC,CAAmD;IAElE,uDAAuD;IACvD,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,gBAAgB,GAAG,mBAAmB,EAAE,aAAa,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,GAAG,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAQhJ,IAAW,SAAS,IAAI,gBAAgB,GAAG,mBAAmB,CAAsF;IACpJ,IAAW,KAAK,4DAA4E;IAG5F,IAAW,QAAQ,IAAI,MAAM,CAAsB;IACnD,IAAW,WAAW,IAAI,MAAM,CAAoC;IACpE,IAAW,IAAI,IAAI,UAAU,CAA6B;IAC1D,IAAW,QAAQ,IAAI,MAAM,GAAG,SAAS,CAAiC;IAC1E,IAAW,cAAc,IA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