@itwin/ecschema-metadata 5.0.0-dev.11 → 5.0.0-dev.110
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 +61 -1
- package/lib/cjs/Constants.d.ts +8 -0
- package/lib/cjs/Constants.d.ts.map +1 -1
- package/lib/cjs/Constants.js +30 -21
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/Context.d.ts +85 -36
- package/lib/cjs/Context.d.ts.map +1 -1
- package/lib/cjs/Context.js +79 -29
- package/lib/cjs/Context.js.map +1 -1
- package/lib/cjs/DelayedPromise.d.ts +9 -8
- package/lib/cjs/DelayedPromise.d.ts.map +1 -1
- package/lib/cjs/DelayedPromise.js +8 -6
- package/lib/cjs/DelayedPromise.js.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.js +1 -0
- package/lib/cjs/Deserialization/AbstractParser.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 +35 -26
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Deserialization/JsonParser.js +153 -150
- package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.d.ts +47 -33
- package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.js +3 -3
- package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.d.ts.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.js +60 -52
- package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +0 -5
- package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.js +8 -17
- package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/cjs/ECName.d.ts +2 -2
- package/lib/cjs/ECName.js +5 -4
- package/lib/cjs/ECName.js.map +1 -1
- package/lib/cjs/ECObjects.d.ts +41 -9
- package/lib/cjs/ECObjects.d.ts.map +1 -1
- package/lib/cjs/ECObjects.js +78 -24
- package/lib/cjs/ECObjects.js.map +1 -1
- package/lib/cjs/Exception.d.ts +4 -4
- package/lib/cjs/Exception.d.ts.map +1 -1
- package/lib/cjs/Exception.js +61 -60
- package/lib/cjs/Exception.js.map +1 -1
- package/lib/cjs/Interfaces.d.ts +35 -32
- package/lib/cjs/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Metadata/Class.d.ts +179 -32
- package/lib/cjs/Metadata/Class.d.ts.map +1 -1
- package/lib/cjs/Metadata/Class.js +290 -88
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.d.ts +26 -10
- package/lib/cjs/Metadata/Constant.d.ts.map +1 -1
- package/lib/cjs/Metadata/Constant.js +38 -10
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.d.ts +2 -2
- package/lib/cjs/Metadata/CustomAttribute.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +21 -7
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js +28 -8
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.d.ts +40 -11
- package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/EntityClass.js +72 -34
- package/lib/cjs/Metadata/EntityClass.js.map +1 -1
- package/lib/cjs/Metadata/Enumeration.d.ts +30 -10
- package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/cjs/Metadata/Enumeration.js +41 -13
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +65 -17
- package/lib/cjs/Metadata/Format.d.ts.map +1 -1
- package/lib/cjs/Metadata/Format.js +107 -22
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.d.ts +19 -10
- package/lib/cjs/Metadata/InvertedUnit.d.ts.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.js +32 -15
- package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.d.ts +38 -18
- package/lib/cjs/Metadata/KindOfQuantity.d.ts.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.js +90 -40
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.d.ts +31 -4
- package/lib/cjs/Metadata/Mixin.d.ts.map +1 -1
- package/lib/cjs/Metadata/Mixin.js +42 -8
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts +12 -12
- package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.js +36 -19
- package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.d.ts +24 -3
- package/lib/cjs/Metadata/Phenomenon.d.ts.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.js +32 -3
- package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
- package/lib/cjs/Metadata/Property.d.ts +47 -25
- package/lib/cjs/Metadata/Property.d.ts.map +1 -1
- package/lib/cjs/Metadata/Property.js +128 -49
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.d.ts +20 -4
- package/lib/cjs/Metadata/PropertyCategory.d.ts.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.js +31 -4
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.d.ts +63 -27
- package/lib/cjs/Metadata/RelationshipClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.js +100 -43
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +167 -41
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +211 -111
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +19 -19
- package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.js +23 -21
- package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
- package/lib/cjs/Metadata/Unit.d.ts +24 -21
- package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
- package/lib/cjs/Metadata/Unit.js +40 -24
- package/lib/cjs/Metadata/Unit.js.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.d.ts +17 -4
- package/lib/cjs/Metadata/UnitSystem.d.ts.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.js +24 -4
- package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
- package/lib/cjs/PropertyTypes.d.ts +11 -11
- package/lib/cjs/PropertyTypes.d.ts.map +1 -1
- package/lib/cjs/PropertyTypes.js +28 -20
- package/lib/cjs/PropertyTypes.js.map +1 -1
- package/lib/cjs/SchemaFormatsProvider.d.ts +39 -0
- package/lib/cjs/SchemaFormatsProvider.d.ts.map +1 -0
- package/lib/cjs/SchemaFormatsProvider.js +146 -0
- package/lib/cjs/SchemaFormatsProvider.js.map +1 -0
- package/lib/cjs/SchemaJsonLocater.d.ts +8 -8
- package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaJsonLocater.js +7 -7
- package/lib/cjs/SchemaJsonLocater.js.map +1 -1
- package/lib/cjs/SchemaKey.d.ts +13 -7
- package/lib/cjs/SchemaKey.d.ts.map +1 -1
- package/lib/cjs/SchemaKey.js +22 -12
- package/lib/cjs/SchemaKey.js.map +1 -1
- package/lib/cjs/SchemaLoader.d.ts +5 -5
- package/lib/cjs/SchemaLoader.d.ts.map +1 -1
- package/lib/cjs/SchemaLoader.js +5 -4
- package/lib/cjs/SchemaLoader.js.map +1 -1
- package/lib/cjs/SchemaPartVisitorDelegate.d.ts +2 -2
- package/lib/cjs/SchemaPartVisitorDelegate.js +2 -1
- package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
- package/lib/cjs/UnitConversion/Graph.js +69 -65
- package/lib/cjs/UnitConversion/Graph.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 +9 -7
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.js +2 -0
- package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitTree.d.ts +2 -0
- package/lib/cjs/UnitConversion/UnitTree.d.ts.map +1 -1
- package/lib/cjs/UnitConversion/UnitTree.js +11 -1
- package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js +8 -9
- 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 +6 -4
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-metadata.d.ts +1 -0
- package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
- package/lib/cjs/ecschema-metadata.js +1 -0
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaGraph.js +5 -6
- package/lib/cjs/utils/SchemaGraph.js.map +1 -1
- package/lib/esm/Constants.d.ts +8 -0
- package/lib/esm/Constants.d.ts.map +1 -1
- package/lib/esm/Constants.js +29 -20
- package/lib/esm/Constants.js.map +1 -1
- package/lib/esm/Context.d.ts +85 -36
- package/lib/esm/Context.d.ts.map +1 -1
- package/lib/esm/Context.js +78 -28
- package/lib/esm/Context.js.map +1 -1
- package/lib/esm/DelayedPromise.d.ts +9 -8
- package/lib/esm/DelayedPromise.d.ts.map +1 -1
- package/lib/esm/DelayedPromise.js +8 -6
- package/lib/esm/DelayedPromise.js.map +1 -1
- package/lib/esm/Deserialization/AbstractParser.js +1 -0
- package/lib/esm/Deserialization/AbstractParser.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 +36 -27
- package/lib/esm/Deserialization/Helper.js.map +1 -1
- package/lib/esm/Deserialization/JsonParser.js +154 -151
- package/lib/esm/Deserialization/JsonParser.js.map +1 -1
- package/lib/esm/Deserialization/JsonProps.d.ts +47 -33
- package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/esm/Deserialization/JsonProps.js +3 -3
- package/lib/esm/Deserialization/JsonProps.js.map +1 -1
- package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -1
- package/lib/esm/Deserialization/XmlParser.js +61 -53
- package/lib/esm/Deserialization/XmlParser.js.map +1 -1
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +0 -5
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
- package/lib/esm/Deserialization/XmlSerializationUtils.js +9 -18
- package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/esm/ECName.d.ts +2 -2
- package/lib/esm/ECName.js +6 -5
- package/lib/esm/ECName.js.map +1 -1
- package/lib/esm/ECObjects.d.ts +41 -9
- package/lib/esm/ECObjects.d.ts.map +1 -1
- package/lib/esm/ECObjects.js +77 -24
- package/lib/esm/ECObjects.js.map +1 -1
- package/lib/esm/Exception.d.ts +4 -4
- package/lib/esm/Exception.d.ts.map +1 -1
- package/lib/esm/Exception.js +59 -58
- package/lib/esm/Exception.js.map +1 -1
- package/lib/esm/Interfaces.d.ts +35 -32
- package/lib/esm/Interfaces.d.ts.map +1 -1
- package/lib/esm/Interfaces.js.map +1 -1
- package/lib/esm/Metadata/Class.d.ts +179 -32
- package/lib/esm/Metadata/Class.d.ts.map +1 -1
- package/lib/esm/Metadata/Class.js +292 -90
- package/lib/esm/Metadata/Class.js.map +1 -1
- package/lib/esm/Metadata/Constant.d.ts +26 -10
- package/lib/esm/Metadata/Constant.d.ts.map +1 -1
- package/lib/esm/Metadata/Constant.js +39 -11
- package/lib/esm/Metadata/Constant.js.map +1 -1
- package/lib/esm/Metadata/CustomAttribute.d.ts +2 -2
- package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -1
- package/lib/esm/Metadata/CustomAttribute.js.map +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.d.ts +21 -7
- package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.js +29 -9
- package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/esm/Metadata/EntityClass.d.ts +40 -11
- package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/esm/Metadata/EntityClass.js +73 -35
- package/lib/esm/Metadata/EntityClass.js.map +1 -1
- package/lib/esm/Metadata/Enumeration.d.ts +30 -10
- package/lib/esm/Metadata/Enumeration.d.ts.map +1 -1
- package/lib/esm/Metadata/Enumeration.js +42 -14
- package/lib/esm/Metadata/Enumeration.js.map +1 -1
- package/lib/esm/Metadata/Format.d.ts +65 -17
- package/lib/esm/Metadata/Format.d.ts.map +1 -1
- package/lib/esm/Metadata/Format.js +108 -23
- package/lib/esm/Metadata/Format.js.map +1 -1
- package/lib/esm/Metadata/InvertedUnit.d.ts +19 -10
- package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -1
- package/lib/esm/Metadata/InvertedUnit.js +33 -16
- package/lib/esm/Metadata/InvertedUnit.js.map +1 -1
- package/lib/esm/Metadata/KindOfQuantity.d.ts +38 -18
- package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -1
- package/lib/esm/Metadata/KindOfQuantity.js +91 -41
- package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/esm/Metadata/Mixin.d.ts +31 -4
- package/lib/esm/Metadata/Mixin.d.ts.map +1 -1
- package/lib/esm/Metadata/Mixin.js +44 -10
- package/lib/esm/Metadata/Mixin.js.map +1 -1
- package/lib/esm/Metadata/OverrideFormat.d.ts +12 -12
- package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -1
- package/lib/esm/Metadata/OverrideFormat.js +37 -20
- package/lib/esm/Metadata/OverrideFormat.js.map +1 -1
- package/lib/esm/Metadata/Phenomenon.d.ts +24 -3
- package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -1
- package/lib/esm/Metadata/Phenomenon.js +33 -4
- package/lib/esm/Metadata/Phenomenon.js.map +1 -1
- package/lib/esm/Metadata/Property.d.ts +47 -25
- package/lib/esm/Metadata/Property.d.ts.map +1 -1
- package/lib/esm/Metadata/Property.js +130 -51
- package/lib/esm/Metadata/Property.js.map +1 -1
- package/lib/esm/Metadata/PropertyCategory.d.ts +20 -4
- package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -1
- package/lib/esm/Metadata/PropertyCategory.js +31 -4
- package/lib/esm/Metadata/PropertyCategory.js.map +1 -1
- package/lib/esm/Metadata/RelationshipClass.d.ts +63 -27
- package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -1
- package/lib/esm/Metadata/RelationshipClass.js +102 -45
- package/lib/esm/Metadata/RelationshipClass.js.map +1 -1
- package/lib/esm/Metadata/Schema.d.ts +167 -41
- package/lib/esm/Metadata/Schema.d.ts.map +1 -1
- package/lib/esm/Metadata/Schema.js +212 -112
- package/lib/esm/Metadata/Schema.js.map +1 -1
- package/lib/esm/Metadata/SchemaItem.d.ts +19 -19
- package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/esm/Metadata/SchemaItem.js +25 -23
- package/lib/esm/Metadata/SchemaItem.js.map +1 -1
- package/lib/esm/Metadata/Unit.d.ts +24 -21
- package/lib/esm/Metadata/Unit.d.ts.map +1 -1
- package/lib/esm/Metadata/Unit.js +41 -25
- package/lib/esm/Metadata/Unit.js.map +1 -1
- package/lib/esm/Metadata/UnitSystem.d.ts +17 -4
- package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -1
- package/lib/esm/Metadata/UnitSystem.js +24 -4
- package/lib/esm/Metadata/UnitSystem.js.map +1 -1
- package/lib/esm/PropertyTypes.d.ts +11 -11
- package/lib/esm/PropertyTypes.d.ts.map +1 -1
- package/lib/esm/PropertyTypes.js +29 -21
- package/lib/esm/PropertyTypes.js.map +1 -1
- package/lib/esm/SchemaFormatsProvider.d.ts +39 -0
- package/lib/esm/SchemaFormatsProvider.d.ts.map +1 -0
- package/lib/esm/SchemaFormatsProvider.js +142 -0
- package/lib/esm/SchemaFormatsProvider.js.map +1 -0
- package/lib/esm/SchemaJsonLocater.d.ts +8 -8
- package/lib/esm/SchemaJsonLocater.d.ts.map +1 -1
- package/lib/esm/SchemaJsonLocater.js +7 -7
- package/lib/esm/SchemaJsonLocater.js.map +1 -1
- package/lib/esm/SchemaKey.d.ts +13 -7
- package/lib/esm/SchemaKey.d.ts.map +1 -1
- package/lib/esm/SchemaKey.js +23 -13
- package/lib/esm/SchemaKey.js.map +1 -1
- package/lib/esm/SchemaLoader.d.ts +5 -5
- package/lib/esm/SchemaLoader.d.ts.map +1 -1
- package/lib/esm/SchemaLoader.js +6 -5
- package/lib/esm/SchemaLoader.js.map +1 -1
- package/lib/esm/SchemaPartVisitorDelegate.d.ts +2 -2
- package/lib/esm/SchemaPartVisitorDelegate.js +2 -1
- package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -1
- package/lib/esm/UnitConversion/Graph.js +69 -65
- package/lib/esm/UnitConversion/Graph.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 +9 -7
- package/lib/esm/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/esm/UnitConversion/UnitConverter.js +2 -0
- package/lib/esm/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/esm/UnitConversion/UnitTree.d.ts +2 -0
- package/lib/esm/UnitConversion/UnitTree.d.ts.map +1 -1
- package/lib/esm/UnitConversion/UnitTree.js +11 -1
- package/lib/esm/UnitConversion/UnitTree.js.map +1 -1
- package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts.map +1 -1
- package/lib/esm/UnitProvider/SchemaUnitProvider.js +8 -9
- 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 +6 -4
- package/lib/esm/Validation/SchemaWalker.js.map +1 -1
- package/lib/esm/ecschema-metadata.d.ts +1 -0
- package/lib/esm/ecschema-metadata.d.ts.map +1 -1
- package/lib/esm/ecschema-metadata.js +1 -0
- package/lib/esm/ecschema-metadata.js.map +1 -1
- package/lib/esm/utils/SchemaGraph.js +6 -7
- package/lib/esm/utils/SchemaGraph.js.map +1 -1
- package/package.json +16 -14
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Metadata
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SchemaFormatsProvider = void 0;
|
|
11
|
+
const Context_1 = require("./Context");
|
|
12
|
+
const SchemaKey_1 = require("./SchemaKey");
|
|
13
|
+
const SchemaItem_1 = require("./Metadata/SchemaItem");
|
|
14
|
+
const Format_1 = require("./Metadata/Format");
|
|
15
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
16
|
+
const KindOfQuantity_1 = require("./Metadata/KindOfQuantity");
|
|
17
|
+
const OverrideFormat_1 = require("./Metadata/OverrideFormat");
|
|
18
|
+
/**
|
|
19
|
+
* Provides default formats and kind of quantities from a given SchemaContext or SchemaLocater.
|
|
20
|
+
* @beta
|
|
21
|
+
*/
|
|
22
|
+
class SchemaFormatsProvider {
|
|
23
|
+
_context;
|
|
24
|
+
_unitSystem;
|
|
25
|
+
_formatsRetrieved = new Set();
|
|
26
|
+
onFormatsChanged = new core_bentley_1.BeEvent();
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext
|
|
30
|
+
* class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be
|
|
31
|
+
* created and the locater will be added.
|
|
32
|
+
* @param unitSystem Used to lookup a default format through a schema specific algorithm, when the format retrieved is associated with a KindOfQuantity.
|
|
33
|
+
*/
|
|
34
|
+
constructor(contextOrLocater, unitSystem) {
|
|
35
|
+
if (contextOrLocater instanceof Context_1.SchemaContext) {
|
|
36
|
+
this._context = contextOrLocater;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this._context = new Context_1.SchemaContext();
|
|
40
|
+
this._context.addLocater(contextOrLocater);
|
|
41
|
+
}
|
|
42
|
+
this._unitSystem = unitSystem;
|
|
43
|
+
}
|
|
44
|
+
get context() { return this._context; }
|
|
45
|
+
get unitSystem() { return this._unitSystem; }
|
|
46
|
+
set unitSystem(unitSystem) {
|
|
47
|
+
this._unitSystem = unitSystem;
|
|
48
|
+
this.clear();
|
|
49
|
+
}
|
|
50
|
+
clear() {
|
|
51
|
+
const formatsChanged = Array.from(this._formatsRetrieved);
|
|
52
|
+
this._formatsRetrieved.clear();
|
|
53
|
+
this.onFormatsChanged.raiseEvent({ formatsChanged });
|
|
54
|
+
}
|
|
55
|
+
async getKindOfQuantityFormatFromSchema(itemKey) {
|
|
56
|
+
const kindOfQuantity = await this._context.getSchemaItem(itemKey, KindOfQuantity_1.KindOfQuantity);
|
|
57
|
+
if (!kindOfQuantity) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
// Find the first presentation format that matches the provided unit system.
|
|
61
|
+
const unitSystemGroupNames = getUnitSystemGroupNames(this._unitSystem);
|
|
62
|
+
const presentationFormats = kindOfQuantity.presentationFormats;
|
|
63
|
+
for (const system of unitSystemGroupNames) {
|
|
64
|
+
for (const lazyFormat of presentationFormats) {
|
|
65
|
+
const format = await lazyFormat;
|
|
66
|
+
const unit = await (format.units && format.units[0][0]);
|
|
67
|
+
if (!unit) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const currentUnitSystem = unit.unitSystem;
|
|
71
|
+
if (currentUnitSystem && currentUnitSystem.name.toUpperCase() === system) {
|
|
72
|
+
this._formatsRetrieved.add(itemKey.fullName);
|
|
73
|
+
return (0, OverrideFormat_1.getFormatProps)(format);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// If no matching presentation format was found, use persistence unit format if it matches unit system.
|
|
78
|
+
const persistenceUnit = await kindOfQuantity.persistenceUnit;
|
|
79
|
+
const persistenceUnitSystem = await persistenceUnit?.unitSystem;
|
|
80
|
+
if (persistenceUnitSystem && unitSystemGroupNames.includes(persistenceUnitSystem.name.toUpperCase())) {
|
|
81
|
+
this._formatsRetrieved.add(itemKey.fullName);
|
|
82
|
+
return getPersistenceUnitFormatProps(persistenceUnit);
|
|
83
|
+
}
|
|
84
|
+
const defaultFormat = kindOfQuantity.defaultPresentationFormat;
|
|
85
|
+
if (!defaultFormat) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
this._formatsRetrieved.add(itemKey.fullName);
|
|
89
|
+
return (0, OverrideFormat_1.getFormatProps)(await defaultFormat);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Retrieves a Format from a SchemaContext. If the format is part of a KindOfQuantity, the first presentation format in the KindOfQuantity that matches the current unit system will be retrieved.
|
|
93
|
+
* If no presentation format matches the current unit system, the persistence unit format will be retrieved if it matches the current unit system.
|
|
94
|
+
* Else, the default presentation format will be retrieved.
|
|
95
|
+
* @param name The full name of the Format or KindOfQuantity.
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
async getFormat(name) {
|
|
99
|
+
const [schemaName, schemaItemName] = SchemaItem_1.SchemaItem.parseFullName(name);
|
|
100
|
+
const schemaKey = new SchemaKey_1.SchemaKey(schemaName);
|
|
101
|
+
const schema = await this._context.getSchema(schemaKey);
|
|
102
|
+
if (!schema) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const itemKey = new SchemaKey_1.SchemaItemKey(schemaItemName, schema.schemaKey);
|
|
106
|
+
if (schema.name === "Formats") {
|
|
107
|
+
const format = await this._context.getSchemaItem(itemKey, Format_1.Format);
|
|
108
|
+
if (!format) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
return format.toJSON(true);
|
|
112
|
+
}
|
|
113
|
+
return this.getKindOfQuantityFormatFromSchema(itemKey);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.SchemaFormatsProvider = SchemaFormatsProvider;
|
|
117
|
+
function getUnitSystemGroupNames(unitSystem) {
|
|
118
|
+
switch (unitSystem) {
|
|
119
|
+
case "imperial":
|
|
120
|
+
return ["IMPERIAL", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
|
|
121
|
+
case "metric":
|
|
122
|
+
return ["SI", "METRIC", "INTERNATIONAL", "FINANCE"];
|
|
123
|
+
case "usCustomary":
|
|
124
|
+
return ["USCUSTOM", "INTERNATIONAL", "FINANCE"];
|
|
125
|
+
case "usSurvey":
|
|
126
|
+
return ["USSURVEY", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
|
|
127
|
+
}
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
function getPersistenceUnitFormatProps(persistenceUnit) {
|
|
131
|
+
// Same as Format "DefaultRealU" in Formats ecschema
|
|
132
|
+
return {
|
|
133
|
+
formatTraits: ["keepSingleZero", "keepDecimalPoint", "showUnitLabel"],
|
|
134
|
+
precision: 6,
|
|
135
|
+
type: "Decimal",
|
|
136
|
+
composite: {
|
|
137
|
+
units: [
|
|
138
|
+
{
|
|
139
|
+
name: persistenceUnit.fullName,
|
|
140
|
+
label: persistenceUnit.label,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=SchemaFormatsProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaFormatsProvider.js","sourceRoot":"","sources":["../../src/SchemaFormatsProvider.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,uCAA0D;AAC1D,2CAAuD;AACvD,sDAAmD;AACnD,8CAA2C;AAE3C,sDAA8C;AAC9C,8DAA2D;AAC3D,8DAA2D;AAK3D;;;GAGG;AACH,MAAa,qBAAqB;IACxB,QAAQ,CAAgB;IACxB,WAAW,CAAgB;IAC3B,iBAAiB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAC5C,gBAAgB,GAAG,IAAI,sBAAO,EAAsC,CAAC;IAC5E;;;;;;OAMG;IACH,YAAY,gBAAgC,EAAE,UAAyB;QACrE,IAAI,gBAAgB,YAAY,uBAAa,EAAE,CAAC;YAC9C,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC;QACnC,CAAC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EAAE,kBAAkB,EAAE,eAAe,CAAC;QACrE,SAAS,EAAE,CAAC;QACZ,IAAI,EAAE,SAAS;QACf,SAAS,EAAE;YACT,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,eAAe,CAAC,QAAQ;oBAC9B,KAAK,EAAE,eAAe,CAAC,KAAK;iBAC7B;aACF;SACF;KACF,CAAC;AACJ,CAAC","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 { ISchemaLocater, SchemaContext } from \"./Context\";\r\nimport { SchemaItemKey, SchemaKey } from \"./SchemaKey\";\r\nimport { SchemaItem } from \"./Metadata/SchemaItem\";\r\nimport { Format } from \"./Metadata/Format\";\r\nimport { SchemaItemFormatProps } from \"./Deserialization/JsonProps\";\r\nimport { BeEvent } from \"@itwin/core-bentley\";\r\nimport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\r\nimport { getFormatProps } from \"./Metadata/OverrideFormat\";\r\nimport { FormatProps, FormatsChangedArgs, FormatsProvider, UnitSystemKey } from \"@itwin/core-quantity\";\r\nimport { Unit } from \"./Metadata/Unit\";\r\nimport { InvertedUnit } from \"./Metadata/InvertedUnit\";\r\n\r\n/**\r\n * Provides default formats and kind of quantities from a given SchemaContext or SchemaLocater.\r\n * @beta\r\n */\r\nexport class SchemaFormatsProvider implements FormatsProvider {\r\n private _context: SchemaContext;\r\n private _unitSystem: UnitSystemKey;\r\n private _formatsRetrieved: Set<string> = new Set();\r\n public onFormatsChanged = new BeEvent<(args: FormatsChangedArgs) => void>();\r\n /**\r\n *\r\n * @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext\r\n * class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be\r\n * created and the locater will be added.\r\n * @param unitSystem Used to lookup a default format through a schema specific algorithm, when the format retrieved is associated with a KindOfQuantity.\r\n */\r\n constructor(contextOrLocater: ISchemaLocater, unitSystem: UnitSystemKey) {\r\n if (contextOrLocater instanceof SchemaContext) {\r\n this._context = contextOrLocater;\r\n } else {\r\n this._context = new SchemaContext();\r\n this._context.addLocater(contextOrLocater);\r\n }\r\n this._unitSystem = unitSystem;\r\n }\r\n\r\n public get context() { return this._context; }\r\n public get unitSystem() { return this._unitSystem; }\r\n\r\n public set unitSystem(unitSystem: UnitSystemKey) {\r\n this._unitSystem = unitSystem;\r\n this.clear();\r\n }\r\n\r\n private clear(): void {\r\n const formatsChanged = Array.from(this._formatsRetrieved);\r\n this._formatsRetrieved.clear();\r\n this.onFormatsChanged.raiseEvent({ formatsChanged });\r\n }\r\n\r\n private async getKindOfQuantityFormatFromSchema(itemKey: SchemaItemKey): Promise<SchemaItemFormatProps | undefined> {\r\n const kindOfQuantity = await this._context.getSchemaItem(itemKey, KindOfQuantity);\r\n\r\n if (!kindOfQuantity) {\r\n return undefined;\r\n }\r\n\r\n // Find the first presentation format that matches the provided unit system.\r\n const unitSystemGroupNames = getUnitSystemGroupNames(this._unitSystem);\r\n const presentationFormats = kindOfQuantity.presentationFormats;\r\n for (const system of unitSystemGroupNames) {\r\n for (const lazyFormat of presentationFormats) {\r\n const format = await lazyFormat;\r\n const unit = await (format.units && format.units[0][0]);\r\n if (!unit) {\r\n continue;\r\n }\r\n const currentUnitSystem = unit.unitSystem;\r\n if (currentUnitSystem && currentUnitSystem.name.toUpperCase() === system) {\r\n this._formatsRetrieved.add(itemKey.fullName);\r\n return getFormatProps(format);\r\n }\r\n }\r\n }\r\n\r\n // If no matching presentation format was found, use persistence unit format if it matches unit system.\r\n const persistenceUnit = await kindOfQuantity.persistenceUnit;\r\n const persistenceUnitSystem = await persistenceUnit?.unitSystem;\r\n if (persistenceUnitSystem && unitSystemGroupNames.includes(persistenceUnitSystem.name.toUpperCase())) {\r\n this._formatsRetrieved.add(itemKey.fullName);\r\n return getPersistenceUnitFormatProps(persistenceUnit!);\r\n }\r\n\r\n const defaultFormat = kindOfQuantity.defaultPresentationFormat;\r\n if (!defaultFormat) {\r\n return undefined;\r\n }\r\n this._formatsRetrieved.add(itemKey.fullName);\r\n return getFormatProps(await defaultFormat);\r\n }\r\n\r\n\r\n /**\r\n * Retrieves a Format from a SchemaContext. If the format is part of a KindOfQuantity, the first presentation format in the KindOfQuantity that matches the current unit system will be retrieved.\r\n * If no presentation format matches the current unit system, the persistence unit format will be retrieved if it matches the current unit system.\r\n * Else, the default presentation format will be retrieved.\r\n * @param name The full name of the Format or KindOfQuantity.\r\n * @returns\r\n */\r\n public async getFormat(name: string): Promise<SchemaItemFormatProps | undefined> {\r\n const [schemaName, schemaItemName] = SchemaItem.parseFullName(name);\r\n const schemaKey = new SchemaKey(schemaName);\r\n const schema = await this._context.getSchema(schemaKey);\r\n if (!schema) {\r\n return undefined;\r\n }\r\n const itemKey = new SchemaItemKey(schemaItemName, schema.schemaKey);\r\n\r\n if (schema.name === \"Formats\") {\r\n const format = await this._context.getSchemaItem(itemKey, Format);\r\n if (!format) {\r\n return undefined;\r\n }\r\n return format.toJSON(true);\r\n }\r\n return this.getKindOfQuantityFormatFromSchema(itemKey);\r\n }\r\n}\r\n\r\nfunction getUnitSystemGroupNames(unitSystem?: UnitSystemKey) {\r\n switch (unitSystem) {\r\n case \"imperial\":\r\n return [\"IMPERIAL\", \"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"];\r\n case \"metric\":\r\n return [\"SI\", \"METRIC\", \"INTERNATIONAL\", \"FINANCE\"];\r\n case \"usCustomary\":\r\n return [\"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"];\r\n case \"usSurvey\":\r\n return [\"USSURVEY\", \"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"];\r\n }\r\n return [];\r\n}\r\n\r\nfunction getPersistenceUnitFormatProps(persistenceUnit: Unit | InvertedUnit): FormatProps {\r\n // Same as Format \"DefaultRealU\" in Formats ecschema\r\n return {\r\n formatTraits: [\"keepSingleZero\", \"keepDecimalPoint\", \"showUnitLabel\"],\r\n precision: 6,\r\n type: \"Decimal\",\r\n composite: {\r\n units: [\r\n {\r\n name: persistenceUnit.fullName,\r\n label: persistenceUnit.label,\r\n },\r\n ],\r\n },\r\n };\r\n}"]}
|
|
@@ -7,13 +7,13 @@ import { SchemaKey } from "./SchemaKey";
|
|
|
7
7
|
/**
|
|
8
8
|
* Gets the full schema Json for the input schema name or undefined if not found
|
|
9
9
|
* @throws [Error] if the schema is found but json cannot be returned
|
|
10
|
-
* @
|
|
10
|
+
* @public @preview
|
|
11
11
|
*/
|
|
12
12
|
export type SchemaPropsGetter = (schemaName: string) => SchemaProps | undefined;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* An ISchemaLocater implementation for locating and retrieving EC Schema objects using a function
|
|
15
15
|
* that returns the Schema Json for a given schema name
|
|
16
|
-
* @
|
|
16
|
+
* @public @preview
|
|
17
17
|
*/
|
|
18
18
|
export declare class SchemaJsonLocater implements ISchemaLocater {
|
|
19
19
|
private _getSchema;
|
|
@@ -22,21 +22,21 @@ export declare class SchemaJsonLocater implements ISchemaLocater {
|
|
|
22
22
|
* @param schemaKey The [SchemaKey] that identifies the schema.
|
|
23
23
|
* @param matchType The [SchemaMatchType] to used for comparing schema versions.
|
|
24
24
|
* @param context The [SchemaContext] used to facilitate schema location.
|
|
25
|
-
* @throws [
|
|
25
|
+
* @throws [ECSchemaError]($ecschema-metadata) if the schema exists, but cannot be loaded.
|
|
26
26
|
*/
|
|
27
|
-
getSchema
|
|
27
|
+
getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
28
28
|
/**
|
|
29
29
|
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
30
30
|
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
31
31
|
* @param matchType The match type to use when locating the schema
|
|
32
32
|
*/
|
|
33
|
-
getSchemaInfo(schemaKey:
|
|
33
|
+
getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
|
|
34
34
|
/** Get a schema by [SchemaKey] synchronously.
|
|
35
35
|
* @param schemaKey The [SchemaKey] that identifies the schema.
|
|
36
|
-
*
|
|
36
|
+
* @param matchType The [SchemaMatchType] to used for comparing schema versions.
|
|
37
37
|
* @param context The [SchemaContext] used to facilitate schema location.
|
|
38
38
|
* @throws [Error]($ecschema-metadata) if the schema exists, but cannot be loaded.
|
|
39
39
|
*/
|
|
40
|
-
getSchemaSync
|
|
40
|
+
getSchemaSync(schemaKey: SchemaKey, _matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;
|
|
41
41
|
}
|
|
42
42
|
//# sourceMappingURL=SchemaJsonLocater.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaJsonLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaJsonLocater.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;AAEhF;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACnC,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,iBAAiB;IAExD;;;;;OAKG;IACU,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"SchemaJsonLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaJsonLocater.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;AAEhF;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACnC,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,iBAAiB;IAExD;;;;;OAKG;IACU,SAAS,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAK7H;;;;OAIG;IACU,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAYrI;;;;;OAKG;IACI,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;CAOpH"}
|
|
@@ -8,11 +8,12 @@ exports.SchemaJsonLocater = void 0;
|
|
|
8
8
|
const Context_1 = require("./Context");
|
|
9
9
|
const Schema_1 = require("./Metadata/Schema");
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* An ISchemaLocater implementation for locating and retrieving EC Schema objects using a function
|
|
12
12
|
* that returns the Schema Json for a given schema name
|
|
13
|
-
* @
|
|
13
|
+
* @public @preview
|
|
14
14
|
*/
|
|
15
15
|
class SchemaJsonLocater {
|
|
16
|
+
_getSchema;
|
|
16
17
|
constructor(_getSchema) {
|
|
17
18
|
this._getSchema = _getSchema;
|
|
18
19
|
}
|
|
@@ -20,11 +21,11 @@ class SchemaJsonLocater {
|
|
|
20
21
|
* @param schemaKey The [SchemaKey] that identifies the schema.
|
|
21
22
|
* @param matchType The [SchemaMatchType] to used for comparing schema versions.
|
|
22
23
|
* @param context The [SchemaContext] used to facilitate schema location.
|
|
23
|
-
* @throws [
|
|
24
|
+
* @throws [ECSchemaError]($ecschema-metadata) if the schema exists, but cannot be loaded.
|
|
24
25
|
*/
|
|
25
26
|
async getSchema(schemaKey, matchType, context) {
|
|
26
27
|
await this.getSchemaInfo(schemaKey, matchType, context);
|
|
27
|
-
return
|
|
28
|
+
return context.getCachedSchema(schemaKey, matchType);
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
31
|
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
@@ -42,7 +43,7 @@ class SchemaJsonLocater {
|
|
|
42
43
|
}
|
|
43
44
|
/** Get a schema by [SchemaKey] synchronously.
|
|
44
45
|
* @param schemaKey The [SchemaKey] that identifies the schema.
|
|
45
|
-
*
|
|
46
|
+
* @param matchType The [SchemaMatchType] to used for comparing schema versions.
|
|
46
47
|
* @param context The [SchemaContext] used to facilitate schema location.
|
|
47
48
|
* @throws [Error]($ecschema-metadata) if the schema exists, but cannot be loaded.
|
|
48
49
|
*/
|
|
@@ -50,8 +51,7 @@ class SchemaJsonLocater {
|
|
|
50
51
|
const schemaProps = this._getSchema(schemaKey.name);
|
|
51
52
|
if (!schemaProps)
|
|
52
53
|
return undefined;
|
|
53
|
-
|
|
54
|
-
return Schema_1.Schema.fromJsonSync(schemaProps, context);
|
|
54
|
+
return Schema_1.Schema.fromJsonSync(schemaProps, context || new Context_1.SchemaContext());
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
exports.SchemaJsonLocater = SchemaJsonLocater;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaJsonLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,uCAA0D;AAI1D,8CAA2C;AAU3C;;;;GAIG;AACH,MAAa,iBAAiB;
|
|
1
|
+
{"version":3,"file":"SchemaJsonLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,uCAA0D;AAI1D,8CAA2C;AAU3C;;;;GAIG;AACH,MAAa,iBAAiB;IACD;IAA3B,YAA2B,UAA6B;QAA7B,eAAU,GAAV,UAAU,CAAmB;IAAI,CAAC;IAE7D;;;;;OAKG;IACI,KAAK,CAAC,SAAS,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QAC7F,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,OAAO,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,aAAa,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QACjG,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,WAAW;YACd,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,MAAM,eAAM,CAAC,oBAAoB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC3E,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;YAChF,OAAO,UAAU,CAAC;QAEpB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,aAAa,CAAC,SAAoB,EAAE,UAA2B,EAAE,OAAsB;QAC5F,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,WAAW;YACd,OAAO,SAAS,CAAC;QAEnB,OAAO,eAAM,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,IAAI,IAAI,uBAAa,EAAE,CAAC,CAAC;IAC1E,CAAC;CACF;AA5CD,8CA4CC","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\r\nimport { ISchemaLocater, SchemaContext } from \"./Context\";\r\nimport { SchemaProps } from \"./Deserialization/JsonProps\";\r\nimport { SchemaMatchType } from \"./ECObjects\";\r\nimport { SchemaInfo } from \"./Interfaces\";\r\nimport { Schema } from \"./Metadata/Schema\";\r\nimport { SchemaKey } from \"./SchemaKey\";\r\n\r\n/**\r\n * Gets the full schema Json for the input schema name or undefined if not found\r\n * @throws [Error] if the schema is found but json cannot be returned\r\n * @public @preview\r\n */\r\nexport type SchemaPropsGetter = (schemaName: string) => SchemaProps | undefined;\r\n\r\n/**\r\n * An ISchemaLocater implementation for locating and retrieving EC Schema objects using a function\r\n * that returns the Schema Json for a given schema name\r\n * @public @preview\r\n */\r\nexport class SchemaJsonLocater implements ISchemaLocater {\r\n public constructor(private _getSchema: SchemaPropsGetter) { }\r\n\r\n /** Get a schema by [SchemaKey]\r\n * @param schemaKey The [SchemaKey] that identifies the schema.\r\n * @param matchType The [SchemaMatchType] to used for comparing schema versions.\r\n * @param context The [SchemaContext] used to facilitate schema location.\r\n * @throws [ECSchemaError]($ecschema-metadata) if the schema exists, but cannot be loaded.\r\n */\r\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\r\n await this.getSchemaInfo(schemaKey, matchType, context);\r\n return context.getCachedSchema(schemaKey, matchType);\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n const schemaProps = this._getSchema(schemaKey.name);\r\n if (!schemaProps)\r\n return undefined;\r\n\r\n const schemaInfo = await Schema.startLoadingFromJson(schemaProps, context);\r\n if (schemaInfo !== undefined && schemaInfo.schemaKey.matches(schemaKey, matchType))\r\n return schemaInfo;\r\n\r\n return undefined;\r\n }\r\n\r\n /** Get a schema by [SchemaKey] synchronously.\r\n * @param schemaKey The [SchemaKey] that identifies the schema.\r\n * @param matchType The [SchemaMatchType] to used for comparing schema versions.\r\n * @param context The [SchemaContext] used to facilitate schema location.\r\n * @throws [Error]($ecschema-metadata) if the schema exists, but cannot be loaded.\r\n */\r\n public getSchemaSync(schemaKey: SchemaKey, _matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\r\n const schemaProps = this._getSchema(schemaKey.name);\r\n if (!schemaProps)\r\n return undefined;\r\n\r\n return Schema.fromJsonSync(schemaProps, context || new SchemaContext());\r\n }\r\n}\r\n"]}
|
package/lib/cjs/SchemaKey.d.ts
CHANGED
|
@@ -4,14 +4,20 @@
|
|
|
4
4
|
import { SchemaKeyProps } from "./Deserialization/JsonProps";
|
|
5
5
|
import { SchemaMatchType } from "./ECObjects";
|
|
6
6
|
/**
|
|
7
|
-
* @
|
|
7
|
+
* @public @preview
|
|
8
8
|
*/
|
|
9
9
|
export declare class ECVersion {
|
|
10
10
|
private _read;
|
|
11
11
|
private _write;
|
|
12
12
|
private _minor;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Using a version with all zero is invalid
|
|
15
|
+
* for a schema, but it can be used to indicate
|
|
16
|
+
* "no version has been specified" when locating things
|
|
17
|
+
*/
|
|
18
|
+
static readonly NO_VERSION: ECVersion;
|
|
19
|
+
/**
|
|
20
|
+
* The constructor will throw an ECSchemaError if any of the parameters below are above the threshold.
|
|
15
21
|
* @param read Can support up to 999.
|
|
16
22
|
* @param write Can support up to 999.
|
|
17
23
|
* @param minor Can support up to 9999999.
|
|
@@ -41,11 +47,11 @@ export declare class ECVersion {
|
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* The SchemaKey contains a Schemas name and version.
|
|
44
|
-
* @
|
|
50
|
+
* @public @preview
|
|
45
51
|
*/
|
|
46
52
|
export declare class SchemaKey {
|
|
47
53
|
private _name;
|
|
48
|
-
|
|
54
|
+
private _version;
|
|
49
55
|
constructor(name: string, version: ECVersion);
|
|
50
56
|
constructor(name: string, readVersion?: number, writeVersion?: number, minorVersion?: number);
|
|
51
57
|
get version(): ECVersion;
|
|
@@ -76,7 +82,7 @@ export declare class SchemaKey {
|
|
|
76
82
|
* @param rhs The SchemaKey to compare with
|
|
77
83
|
* @param matchType The match type to use for comparison.
|
|
78
84
|
*/
|
|
79
|
-
matches(rhs:
|
|
85
|
+
matches(rhs: SchemaKey, matchType?: SchemaMatchType): boolean;
|
|
80
86
|
/**
|
|
81
87
|
* Deserializes a SchemaKeyProps JSON object into a SchemaKey object.
|
|
82
88
|
* @param props SchemaKeyProps
|
|
@@ -90,11 +96,11 @@ export declare class SchemaKey {
|
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
98
|
* The SchemaItemKey contains a SchemaItem's name and SchemaKey.
|
|
93
|
-
* @
|
|
99
|
+
* @public @preview
|
|
94
100
|
*/
|
|
95
101
|
export declare class SchemaItemKey {
|
|
96
102
|
private _name;
|
|
97
|
-
|
|
103
|
+
private _schemaKey;
|
|
98
104
|
constructor(name: string, schema: SchemaKey);
|
|
99
105
|
get schemaKey(): SchemaKey;
|
|
100
106
|
get name(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaKey.d.ts","sourceRoot":"","sources":["../../src/SchemaKey.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,MAAM,CAAa;IAE3B;;;;;;OAMG;gBACS,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAYzD,IAAW,IAAI,WAAyB;IACxC,IAAW,KAAK,WAA0B;IAC1C,IAAW,KAAK,WAA0B;IAE1C;;;;OAIG;IACI,QAAQ,CAAC,SAAS,GAAE,OAAc,GAAG,MAAM;IAWlD;;;OAGG;WACW,UAAU,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS;IAc1D;;;;OAIG;IACI,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM;CASvC;AAED;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAS;IACtB,
|
|
1
|
+
{"version":3,"file":"SchemaKey.d.ts","sourceRoot":"","sources":["../../src/SchemaKey.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,MAAM,CAAa;IAE3B;;;;OAIG;IACH,gBAAuB,UAAU,YAA0B;IAE3D;;;;;;OAMG;gBACS,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAYzD,IAA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AAS;IAK3C,IAAW,SAAS,cAA8B;IAClD,IAAW,IAAI,WAA8B;IAE7C,IAAW,UAAU,WAAkC;IAEvD,2DAA2D;IAC3D,IAAW,QAAQ,WAAgD;IAEnE;;;OAGG;IAEI,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO;IAUpC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAK9C"}
|
package/lib/cjs/SchemaKey.js
CHANGED
|
@@ -12,20 +12,26 @@ const ECObjects_1 = require("./ECObjects");
|
|
|
12
12
|
const Exception_1 = require("./Exception");
|
|
13
13
|
const ECName_1 = require("./ECName");
|
|
14
14
|
/**
|
|
15
|
-
* @
|
|
15
|
+
* @public @preview
|
|
16
16
|
*/
|
|
17
17
|
class ECVersion {
|
|
18
|
+
_read = 0;
|
|
19
|
+
_write = 0;
|
|
20
|
+
_minor = 0;
|
|
18
21
|
/**
|
|
19
|
-
*
|
|
22
|
+
* Using a version with all zero is invalid
|
|
23
|
+
* for a schema, but it can be used to indicate
|
|
24
|
+
* "no version has been specified" when locating things
|
|
25
|
+
*/
|
|
26
|
+
static NO_VERSION = new ECVersion(0, 0, 0);
|
|
27
|
+
/**
|
|
28
|
+
* The constructor will throw an ECSchemaError if any of the parameters below are above the threshold.
|
|
20
29
|
* @param read Can support up to 999.
|
|
21
30
|
* @param write Can support up to 999.
|
|
22
31
|
* @param minor Can support up to 9999999.
|
|
23
32
|
*
|
|
24
33
|
*/
|
|
25
34
|
constructor(read, write, minor) {
|
|
26
|
-
this._read = 0;
|
|
27
|
-
this._write = 0;
|
|
28
|
-
this._minor = 0;
|
|
29
35
|
if (undefined !== read)
|
|
30
36
|
this._read = read;
|
|
31
37
|
if (undefined !== write)
|
|
@@ -33,7 +39,7 @@ class ECVersion {
|
|
|
33
39
|
if (undefined !== minor)
|
|
34
40
|
this._minor = minor;
|
|
35
41
|
if (this._read > 999 || this._read < 0 || this._write > 999 || this._write < 0 || this._minor > 9999999 || this._minor < 0)
|
|
36
|
-
throw new Exception_1.
|
|
42
|
+
throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECVersion);
|
|
37
43
|
}
|
|
38
44
|
get read() { return this._read; }
|
|
39
45
|
get write() { return this._write; }
|
|
@@ -58,11 +64,11 @@ class ECVersion {
|
|
|
58
64
|
static fromString(versionString) {
|
|
59
65
|
const [read, write, minor] = versionString.split(".");
|
|
60
66
|
if (!read)
|
|
61
|
-
throw new Exception_1.
|
|
67
|
+
throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
|
|
62
68
|
if (!write)
|
|
63
|
-
throw new Exception_1.
|
|
69
|
+
throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECVersion, `The write version is missing from version string, ${versionString}`);
|
|
64
70
|
if (!minor)
|
|
65
|
-
throw new Exception_1.
|
|
71
|
+
throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
|
|
66
72
|
return new ECVersion(+read, +write, +minor);
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
@@ -81,9 +87,11 @@ class ECVersion {
|
|
|
81
87
|
exports.ECVersion = ECVersion;
|
|
82
88
|
/**
|
|
83
89
|
* The SchemaKey contains a Schemas name and version.
|
|
84
|
-
* @
|
|
90
|
+
* @public @preview
|
|
85
91
|
*/
|
|
86
92
|
class SchemaKey {
|
|
93
|
+
_name;
|
|
94
|
+
_version;
|
|
87
95
|
constructor(name, readOrVersion, writeVersion, minorVersion) {
|
|
88
96
|
this._name = new ECName_1.ECName(name);
|
|
89
97
|
if (readOrVersion !== undefined && typeof (readOrVersion) !== "number")
|
|
@@ -105,7 +113,7 @@ class SchemaKey {
|
|
|
105
113
|
static parseString(fullName) {
|
|
106
114
|
const keyPieces = fullName.split(".");
|
|
107
115
|
if (keyPieces.length !== 4)
|
|
108
|
-
throw new Exception_1.
|
|
116
|
+
throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECName);
|
|
109
117
|
const schemaName = keyPieces[0];
|
|
110
118
|
const readVer = Number(keyPieces[1]);
|
|
111
119
|
const writeVer = Number(keyPieces[2]);
|
|
@@ -182,9 +190,11 @@ class SchemaKey {
|
|
|
182
190
|
exports.SchemaKey = SchemaKey;
|
|
183
191
|
/**
|
|
184
192
|
* The SchemaItemKey contains a SchemaItem's name and SchemaKey.
|
|
185
|
-
* @
|
|
193
|
+
* @public @preview
|
|
186
194
|
*/
|
|
187
195
|
class SchemaItemKey {
|
|
196
|
+
_name;
|
|
197
|
+
_schemaKey;
|
|
188
198
|
constructor(name, schema) {
|
|
189
199
|
this._name = new ECName_1.ECName(name);
|
|
190
200
|
this._schemaKey = schema;
|
package/lib/cjs/SchemaKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaKey.js","sourceRoot":"","sources":["../../src/SchemaKey.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,2CAA8C;AAC9C,2CAA8D;AAC9D,qCAAkC;AAElC;;GAEG;AACH,MAAa,SAAS;IAKpB;;;;;;OAMG;IACH,YAAY,IAAa,EAAE,KAAc,EAAE,KAAc;QAXjD,UAAK,GAAW,CAAC,CAAC;QAClB,WAAM,GAAW,CAAC,CAAC;QACnB,WAAM,GAAW,CAAC,CAAC;QAUzB,IAAI,SAAS,KAAK,IAAI;YACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACtB,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEtB,IAAI,IAAI,CAAC,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,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C,MAAM,CAAC;YAChE,OAAO,KAAK,CAAC;QAEf,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,eAAe,CAAC,IAAY;QACjC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9E,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,OAAO,aAAa,SAAS,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;QACpG,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AArCD,sCAqCC","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 { SchemaKeyProps } from \"./Deserialization/JsonProps\";\r\nimport { SchemaMatchType } from \"./ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"./Exception\";\r\nimport { ECName } from \"./ECName\";\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class ECVersion {\r\n private _read: number = 0;\r\n private _write: number = 0;\r\n private _minor: number = 0;\r\n\r\n /**\r\n * The constructor will throw an ECObjectsError if any of the parameters below are above the threshold.\r\n * @param read Can support up to 999.\r\n * @param write Can support up to 999.\r\n * @param minor Can support up to 9999999.\r\n *\r\n */\r\n constructor(read?: number, write?: number, minor?: number) {\r\n if (undefined !== read)\r\n this._read = read;\r\n if (undefined !== write)\r\n this._write = write;\r\n if (undefined !== minor)\r\n this._minor = minor;\r\n\r\n if (this._read > 999 || this._read < 0 || this._write > 999 || this._write < 0 || this._minor > 9999999 || this._minor < 0)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion);\r\n }\r\n\r\n public get read() { return this._read; }\r\n public get write() { return this._write; }\r\n public get minor() { return this._minor; }\r\n\r\n /**\r\n * Creates a string, in the format 'RR.ww.mm', representing this ECVersion.\r\n * @note The default is to pad with zeroes.\r\n * @param padZeroes If true, the returned string will strictly follow `RR.ww.mm` and add leading zeroes if necessary.\r\n */\r\n public toString(padZeroes: boolean = true): string {\r\n if (!padZeroes)\r\n return `${this.read}.${this.write}.${this.minor}`;\r\n\r\n const padWithZeroes = (num: number) => {\r\n return (num < 10 ? \"0\" : \"\") + num;\r\n };\r\n\r\n return `${padWithZeroes(this.read)}.${padWithZeroes(this.write)}.${padWithZeroes(this.minor)}`;\r\n }\r\n\r\n /**\r\n * Given a valid version string the\r\n * @param versionString A valid version string of the format, 'RR.ww.mm'.\r\n */\r\n public static fromString(versionString: string): ECVersion {\r\n const [read, write, minor] = versionString.split(\".\");\r\n if (!read)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!write)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The write version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, +write, +minor);\r\n }\r\n\r\n /**\r\n * Compares two schema versions.\r\n * @param rhs The schema to compare.\r\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\r\n */\r\n public compare(rhv: ECVersion): number {\r\n if (this.read !== rhv.read)\r\n return this.read - rhv.read;\r\n\r\n if (this.write !== rhv.write)\r\n return this.write - rhv.write;\r\n\r\n return this.minor - rhv.minor;\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaKey contains a Schemas name and version.\r\n * @beta\r\n */\r\nexport class SchemaKey {\r\n private _name: ECName;\r\n protected _version: ECVersion;\r\n // public checksum: number;\r\n // TODO: need to add a checksum\r\n\r\n constructor(name: string, version: ECVersion);\r\n constructor(name: string, readVersion?: number, writeVersion?: number, minorVersion?: number);\r\n constructor(name: string, readOrVersion?: number | ECVersion, writeVersion?: number, minorVersion?: number) {\r\n this._name = new ECName(name);\r\n if (readOrVersion !== undefined && typeof (readOrVersion) !== \"number\")\r\n this._version = readOrVersion;\r\n else\r\n this._version = new ECVersion(readOrVersion, writeVersion, minorVersion);\r\n }\r\n\r\n public get version() { return this._version; }\r\n public get name() { return this._name.name; }\r\n public get readVersion() { return this.version.read; }\r\n public get writeVersion() { return this.version.write; }\r\n public get minorVersion() { return this.version.minor; }\r\n\r\n /**\r\n * Creates a string, in the format 'RR.ww.mm', representing this SchemaKey.\r\n * @note The default is to pad the full name with zeroes.\r\n * @param padZeroes If true, the returned string will strictly follow `Name.RR.ww.mm` and add leading zeroes if necessary.\r\n */\r\n public toString(padZeroes: boolean = true) { return `${this.name}.${this.version.toString(padZeroes)}`; }\r\n\r\n public static parseString(fullName: string) {\r\n const keyPieces = fullName.split(\".\");\r\n if (keyPieces.length !== 4)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECName);\r\n\r\n const schemaName = keyPieces[0];\r\n const readVer = Number(keyPieces[1]);\r\n const writeVer = Number(keyPieces[2]);\r\n const minorVer = Number(keyPieces[3]);\r\n return new SchemaKey(schemaName, new ECVersion(readVer, writeVer, minorVer));\r\n }\r\n\r\n /**\r\n * Compares two schema names, case-insensitive.\r\n * @return True if they match; otherwise, false.\r\n */\r\n public compareByName(rhs: SchemaKey | string | undefined): boolean {\r\n if (undefined === rhs)\r\n return false;\r\n\r\n if (typeof (rhs) === \"string\")\r\n return rhs.toLowerCase() === this.name.toLowerCase();\r\n\r\n return rhs.name.toLowerCase() === this.name.toLowerCase();\r\n }\r\n\r\n /**\r\n * Compares two schema versions.\r\n * @param rhs The schema to compare.\r\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\r\n */\r\n public compareByVersion(rhs: SchemaKey): number {\r\n return this.version.compare(rhs.version);\r\n }\r\n\r\n /**\r\n *\r\n * @param rhs The SchemaKey to compare with\r\n * @param matchType The match type to use for comparison.\r\n */\r\n public matches(rhs: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Exact): boolean {\r\n switch (matchType) {\r\n case SchemaMatchType.Identical:\r\n case SchemaMatchType.Exact:\r\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\r\n this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;\r\n case SchemaMatchType.LatestReadCompatible:\r\n if (!this.compareByName(rhs.name))\r\n return false;\r\n\r\n if (rhs.readVersion !== this.readVersion)\r\n return false;\r\n\r\n if (this.writeVersion === rhs.writeVersion)\r\n return this.minorVersion >= rhs.minorVersion;\r\n\r\n return this.writeVersion > rhs.writeVersion;\r\n case SchemaMatchType.LatestWriteCompatible:\r\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\r\n this.writeVersion === rhs.writeVersion && this.minorVersion >= rhs.minorVersion;\r\n case SchemaMatchType.Latest:\r\n return this.compareByName(rhs.name);\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Deserializes a SchemaKeyProps JSON object into a SchemaKey object.\r\n * @param props SchemaKeyProps\r\n * @returns A SchemaKey object.\r\n */\r\n public static fromJSON(props: SchemaKeyProps): SchemaKey {\r\n return new SchemaKey(props.name, props.read, props.write, props.minor);\r\n }\r\n\r\n /**\r\n * Save this SchemaKey's properties to an object for serializing to JSON.\r\n */\r\n public toJSON(): SchemaKeyProps {\r\n return {\r\n name: this.name,\r\n read: this.readVersion,\r\n write: this.writeVersion,\r\n minor: this.minorVersion,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaItemKey contains a SchemaItem's name and SchemaKey.\r\n * @beta\r\n */\r\nexport class SchemaItemKey {\r\n private _name: ECName;\r\n protected _schemaKey: SchemaKey;\r\n\r\n constructor(name: string, schema: SchemaKey) {\r\n this._name = new ECName(name);\r\n this._schemaKey = schema;\r\n }\r\n\r\n public get schemaKey() { return this._schemaKey; }\r\n public get name() { return this._name.name; }\r\n\r\n public get schemaName() { return this.schemaKey.name; }\r\n\r\n /** Returns the name in the format, {schemaName}.{name}. */\r\n public get fullName() { return `${this.schemaName}.${this.name}`; }\r\n\r\n /**\r\n * Checks whether this SchemaItemKey matches the one provided.\r\n * @param rhs The SchemaItemKey to compare to this.\r\n */\r\n // TODO: Need to add a match type\r\n public matches(rhs: SchemaItemKey): boolean {\r\n if (rhs.name !== this.name)\r\n return false;\r\n\r\n if (!rhs.schemaKey.matches(this.schemaKey, SchemaMatchType.Latest))\r\n return false;\r\n\r\n return true;\r\n }\r\n\r\n public matchesFullName(name: string): boolean {\r\n const schemaVersion = this.schemaKey.version.toString().replace(/\\./g, \"\\\\.\");\r\n const fullNameRegex = new RegExp(`^${this.schemaName}(\\\\.${schemaVersion})?[.:]${this.name}$`, \"i\");\r\n return fullNameRegex.test(name);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaKey.js","sourceRoot":"","sources":["../../src/SchemaKey.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,2CAA8C;AAC9C,2CAA4D;AAC5D,qCAAkC;AAElC;;GAEG;AACH,MAAa,SAAS;IACZ,KAAK,GAAW,CAAC,CAAC;IAClB,MAAM,GAAW,CAAC,CAAC;IACnB,MAAM,GAAW,CAAC,CAAC;IAE3B;;;;OAIG;IACI,MAAM,CAAU,UAAU,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE3D;;;;;;OAMG;IACH,YAAY,IAAa,EAAE,KAAc,EAAE,KAAc;QACvD,IAAI,SAAS,KAAK,IAAI;YACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACtB,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEtB,IAA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IACH,iCAAiC;IAC1B,OAAO,CAAC,GAAkB;QAC/B,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;YACxB,OAAO,KAAK,CAAC;QAEf,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,2BAAe,CAAC,MAAM,CAAC;YAChE,OAAO,KAAK,CAAC;QAEf,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,eAAe,CAAC,IAAY;QACjC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9E,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,OAAO,aAAa,SAAS,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;QACpG,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AArCD,sCAqCC","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 { SchemaKeyProps } from \"./Deserialization/JsonProps\";\r\nimport { SchemaMatchType } from \"./ECObjects\";\r\nimport { ECSchemaError, ECSchemaStatus } from \"./Exception\";\r\nimport { ECName } from \"./ECName\";\r\n\r\n/**\r\n * @public @preview\r\n */\r\nexport class ECVersion {\r\n private _read: number = 0;\r\n private _write: number = 0;\r\n private _minor: number = 0;\r\n\r\n /**\r\n * Using a version with all zero is invalid\r\n * for a schema, but it can be used to indicate\r\n * \"no version has been specified\" when locating things\r\n */\r\n public static readonly NO_VERSION = new ECVersion(0, 0, 0);\r\n\r\n /**\r\n * The constructor will throw an ECSchemaError if any of the parameters below are above the threshold.\r\n * @param read Can support up to 999.\r\n * @param write Can support up to 999.\r\n * @param minor Can support up to 9999999.\r\n *\r\n */\r\n constructor(read?: number, write?: number, minor?: number) {\r\n if (undefined !== read)\r\n this._read = read;\r\n if (undefined !== write)\r\n this._write = write;\r\n if (undefined !== minor)\r\n this._minor = minor;\r\n\r\n if (this._read > 999 || this._read < 0 || this._write > 999 || this._write < 0 || this._minor > 9999999 || this._minor < 0)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion);\r\n }\r\n\r\n public get read() { return this._read; }\r\n public get write() { return this._write; }\r\n public get minor() { return this._minor; }\r\n\r\n /**\r\n * Creates a string, in the format 'RR.ww.mm', representing this ECVersion.\r\n * @note The default is to pad with zeroes.\r\n * @param padZeroes If true, the returned string will strictly follow `RR.ww.mm` and add leading zeroes if necessary.\r\n */\r\n public toString(padZeroes: boolean = true): string {\r\n if (!padZeroes)\r\n return `${this.read}.${this.write}.${this.minor}`;\r\n\r\n const padWithZeroes = (num: number) => {\r\n return (num < 10 ? \"0\" : \"\") + num;\r\n };\r\n\r\n return `${padWithZeroes(this.read)}.${padWithZeroes(this.write)}.${padWithZeroes(this.minor)}`;\r\n }\r\n\r\n /**\r\n * Given a valid version string the\r\n * @param versionString A valid version string of the format, 'RR.ww.mm'.\r\n */\r\n public static fromString(versionString: string): ECVersion {\r\n const [read, write, minor] = versionString.split(\".\");\r\n if (!read)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!write)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The write version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, +write, +minor);\r\n }\r\n\r\n /**\r\n * Compares two schema versions.\r\n * @param rhs The schema to compare.\r\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\r\n */\r\n public compare(rhv: ECVersion): number {\r\n if (this.read !== rhv.read)\r\n return this.read - rhv.read;\r\n\r\n if (this.write !== rhv.write)\r\n return this.write - rhv.write;\r\n\r\n return this.minor - rhv.minor;\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaKey contains a Schemas name and version.\r\n * @public @preview\r\n */\r\nexport class SchemaKey {\r\n private _name: ECName;\r\n private _version: ECVersion;\r\n // public checksum: number;\r\n // TODO: need to add a checksum\r\n\r\n constructor(name: string, version: ECVersion);\r\n constructor(name: string, readVersion?: number, writeVersion?: number, minorVersion?: number);\r\n constructor(name: string, readOrVersion?: number | ECVersion, writeVersion?: number, minorVersion?: number) {\r\n this._name = new ECName(name);\r\n if (readOrVersion !== undefined && typeof (readOrVersion) !== \"number\")\r\n this._version = readOrVersion;\r\n else\r\n this._version = new ECVersion(readOrVersion, writeVersion, minorVersion);\r\n }\r\n\r\n public get version() { return this._version; }\r\n public get name() { return this._name.name; }\r\n public get readVersion() { return this.version.read; }\r\n public get writeVersion() { return this.version.write; }\r\n public get minorVersion() { return this.version.minor; }\r\n\r\n /**\r\n * Creates a string, in the format 'RR.ww.mm', representing this SchemaKey.\r\n * @note The default is to pad the full name with zeroes.\r\n * @param padZeroes If true, the returned string will strictly follow `Name.RR.ww.mm` and add leading zeroes if necessary.\r\n */\r\n public toString(padZeroes: boolean = true) { return `${this.name}.${this.version.toString(padZeroes)}`; }\r\n\r\n public static parseString(fullName: string) {\r\n const keyPieces = fullName.split(\".\");\r\n if (keyPieces.length !== 4)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECName);\r\n\r\n const schemaName = keyPieces[0];\r\n const readVer = Number(keyPieces[1]);\r\n const writeVer = Number(keyPieces[2]);\r\n const minorVer = Number(keyPieces[3]);\r\n return new SchemaKey(schemaName, new ECVersion(readVer, writeVer, minorVer));\r\n }\r\n\r\n /**\r\n * Compares two schema names, case-insensitive.\r\n * @return True if they match; otherwise, false.\r\n */\r\n public compareByName(rhs: SchemaKey | string | undefined): boolean {\r\n if (undefined === rhs)\r\n return false;\r\n\r\n if (typeof (rhs) === \"string\")\r\n return rhs.toLowerCase() === this.name.toLowerCase();\r\n\r\n return rhs.name.toLowerCase() === this.name.toLowerCase();\r\n }\r\n\r\n /**\r\n * Compares two schema versions.\r\n * @param rhs The schema to compare.\r\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\r\n */\r\n public compareByVersion(rhs: SchemaKey): number {\r\n return this.version.compare(rhs.version);\r\n }\r\n\r\n /**\r\n *\r\n * @param rhs The SchemaKey to compare with\r\n * @param matchType The match type to use for comparison.\r\n */\r\n public matches(rhs: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Exact): boolean {\r\n switch (matchType) {\r\n case SchemaMatchType.Identical:\r\n case SchemaMatchType.Exact:\r\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\r\n this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;\r\n case SchemaMatchType.LatestReadCompatible:\r\n if (!this.compareByName(rhs.name))\r\n return false;\r\n\r\n if (rhs.readVersion !== this.readVersion)\r\n return false;\r\n\r\n if (this.writeVersion === rhs.writeVersion)\r\n return this.minorVersion >= rhs.minorVersion;\r\n\r\n return this.writeVersion > rhs.writeVersion;\r\n case SchemaMatchType.LatestWriteCompatible:\r\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\r\n this.writeVersion === rhs.writeVersion && this.minorVersion >= rhs.minorVersion;\r\n case SchemaMatchType.Latest:\r\n return this.compareByName(rhs.name);\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Deserializes a SchemaKeyProps JSON object into a SchemaKey object.\r\n * @param props SchemaKeyProps\r\n * @returns A SchemaKey object.\r\n */\r\n public static fromJSON(props: SchemaKeyProps): SchemaKey {\r\n return new SchemaKey(props.name, props.read, props.write, props.minor);\r\n }\r\n\r\n /**\r\n * Save this SchemaKey's properties to an object for serializing to JSON.\r\n */\r\n public toJSON(): SchemaKeyProps {\r\n return {\r\n name: this.name,\r\n read: this.readVersion,\r\n write: this.writeVersion,\r\n minor: this.minorVersion,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaItemKey contains a SchemaItem's name and SchemaKey.\r\n * @public @preview\r\n */\r\nexport class SchemaItemKey {\r\n private _name: ECName;\r\n private _schemaKey: SchemaKey;\r\n\r\n constructor(name: string, schema: SchemaKey) {\r\n this._name = new ECName(name);\r\n this._schemaKey = schema;\r\n }\r\n\r\n public get schemaKey() { return this._schemaKey; }\r\n public get name() { return this._name.name; }\r\n\r\n public get schemaName() { return this.schemaKey.name; }\r\n\r\n /** Returns the name in the format, {schemaName}.{name}. */\r\n public get fullName() { return `${this.schemaName}.${this.name}`; }\r\n\r\n /**\r\n * Checks whether this SchemaItemKey matches the one provided.\r\n * @param rhs The SchemaItemKey to compare to this.\r\n */\r\n // TODO: Need to add a match type\r\n public matches(rhs: SchemaItemKey): boolean {\r\n if (rhs.name !== this.name)\r\n return false;\r\n\r\n if (!rhs.schemaKey.matches(this.schemaKey, SchemaMatchType.Latest))\r\n return false;\r\n\r\n return true;\r\n }\r\n\r\n public matchesFullName(name: string): boolean {\r\n const schemaVersion = this.schemaKey.version.toString().replace(/\\./g, \"\\\\.\");\r\n const fullNameRegex = new RegExp(`^${this.schemaName}(\\\\.${schemaVersion})?[.:]${this.name}$`, \"i\");\r\n return fullNameRegex.test(name);\r\n }\r\n}\r\n"]}
|
|
@@ -11,21 +11,21 @@ import { SchemaPropsGetter } from "./SchemaJsonLocater";
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* [[include:IModelSchemas.loadFromDb]]
|
|
13
13
|
* ```
|
|
14
|
-
* @beta
|
|
14
|
+
* @beta Is this concept needed no that backend and frontend will have contexts cached on the iModel?
|
|
15
15
|
*/
|
|
16
16
|
export declare class SchemaLoader {
|
|
17
17
|
private _context;
|
|
18
18
|
constructor(getSchema: SchemaPropsGetter);
|
|
19
19
|
/** Get a schema by name
|
|
20
20
|
* @param schemaName a string with the name of the schema to load.
|
|
21
|
-
* @throws [
|
|
21
|
+
* @throws [ECSchemaError]($ecschema-metadata) if the schema is not found or cannot be loaded.
|
|
22
22
|
*/
|
|
23
|
-
getSchema
|
|
23
|
+
getSchema(schemaName: string): Schema;
|
|
24
24
|
/** Attempts to get a schema by name
|
|
25
25
|
* @param schemaName a string with the name of the schema to load.
|
|
26
|
-
* @throws [
|
|
26
|
+
* @throws [ECSchemaError]($ecschema-metadata) if the schema exists, but cannot be loaded.
|
|
27
27
|
*/
|
|
28
|
-
tryGetSchema
|
|
28
|
+
tryGetSchema(schemaName: string): Schema | undefined;
|
|
29
29
|
/** Gets the SchemaContext used by the loader. */
|
|
30
30
|
get context(): SchemaContext;
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaLoader.d.ts","sourceRoot":"","sources":["../../src/SchemaLoader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAqB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG3E;;;;;;;;;;;GAWG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAgB;gBAEb,SAAS,EAAE,iBAAiB;IAM/C;;;OAGG;IACI,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"SchemaLoader.d.ts","sourceRoot":"","sources":["../../src/SchemaLoader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAqB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG3E;;;;;;;;;;;GAWG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAgB;gBAEb,SAAS,EAAE,iBAAiB;IAM/C;;;OAGG;IACI,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAQ5C;;;OAGG;IACI,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAO3D,iDAAiD;IACjD,IAAW,OAAO,IAAI,aAAa,CAElC;CACF"}
|
package/lib/cjs/SchemaLoader.js
CHANGED
|
@@ -20,9 +20,10 @@ const SchemaKey_1 = require("./SchemaKey");
|
|
|
20
20
|
* ```ts
|
|
21
21
|
* [[include:IModelSchemas.loadFromDb]]
|
|
22
22
|
* ```
|
|
23
|
-
* @beta
|
|
23
|
+
* @beta Is this concept needed no that backend and frontend will have contexts cached on the iModel?
|
|
24
24
|
*/
|
|
25
25
|
class SchemaLoader {
|
|
26
|
+
_context;
|
|
26
27
|
constructor(getSchema) {
|
|
27
28
|
this._context = new Context_1.SchemaContext();
|
|
28
29
|
const locater = new SchemaJsonLocater_1.SchemaJsonLocater(getSchema);
|
|
@@ -30,17 +31,17 @@ class SchemaLoader {
|
|
|
30
31
|
}
|
|
31
32
|
/** Get a schema by name
|
|
32
33
|
* @param schemaName a string with the name of the schema to load.
|
|
33
|
-
* @throws [
|
|
34
|
+
* @throws [ECSchemaError]($ecschema-metadata) if the schema is not found or cannot be loaded.
|
|
34
35
|
*/
|
|
35
36
|
getSchema(schemaName) {
|
|
36
37
|
const schema = this.tryGetSchema(schemaName);
|
|
37
38
|
if (!schema)
|
|
38
|
-
throw new Exception_1.
|
|
39
|
+
throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.UnableToLocateSchema, `reading schema=${schemaName}`);
|
|
39
40
|
return schema;
|
|
40
41
|
}
|
|
41
42
|
/** Attempts to get a schema by name
|
|
42
43
|
* @param schemaName a string with the name of the schema to load.
|
|
43
|
-
* @throws [
|
|
44
|
+
* @throws [ECSchemaError]($ecschema-metadata) if the schema exists, but cannot be loaded.
|
|
44
45
|
*/
|
|
45
46
|
tryGetSchema(schemaName) {
|
|
46
47
|
// SchemaKey version is not used when locating schema in an iModel, so the version is arbitrary.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaLoader.js","sourceRoot":"","sources":["../../src/SchemaLoader.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,uCAA0C;AAC1C,2CAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"SchemaLoader.js","sourceRoot":"","sources":["../../src/SchemaLoader.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,uCAA0C;AAC1C,2CAA8C;AAC9C,2CAA4D;AAE5D,2DAA2E;AAC3E,2CAAmD;AAEnD;;;;;;;;;;;GAWG;AACH,MAAa,YAAY;IACf,QAAQ,CAAgB;IAEhC,YAAmB,SAA4B;QAC7C,IAAI,CAAC,QAAQ,GAAG,IAAI,uBAAa,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,IAAI,qCAAiB,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,UAAkB;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM;YACT,MAAM,IAAI,yBAAa,CAAC,0BAAc,CAAC,oBAAoB,EAAE,kBAAkB,UAAU,EAAE,CAAC,CAAC;QAE/F,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,UAAkB;QACpC,gGAAgG;QAChG,MAAM,GAAG,GAAG,IAAI,qBAAS,CAAC,UAAU,EAAE,IAAI,qBAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,2BAAe,CAAC,MAAM,CAAC,CAAC;QACxE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iDAAiD;IACjD,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AApCD,oCAoCC","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\r\nimport { SchemaContext } from \"./Context\";\r\nimport { SchemaMatchType } from \"./ECObjects\";\r\nimport { ECSchemaError, ECSchemaStatus } from \"./Exception\";\r\nimport { Schema } from \"./Metadata/Schema\";\r\nimport { SchemaJsonLocater, SchemaPropsGetter } from \"./SchemaJsonLocater\";\r\nimport { ECVersion, SchemaKey } from \"./SchemaKey\";\r\n\r\n/**\r\n * A utility class for loading EC Schema objects using a function that returns schema json for a given schema name.\r\n * Loaded schemas are held in memory within a schema context managed by SchemaLoader.\r\n * The SchemaLoader object should be held in memory if multiple calls to [[getSchema]] or [[tryGetSchema]]\r\n * is a possibility, thereby avoiding unnecessary schema retrievals from the function.\r\n *\r\n * ** Example **\r\n * ```ts\r\n * [[include:IModelSchemas.loadFromDb]]\r\n * ```\r\n * @beta Is this concept needed no that backend and frontend will have contexts cached on the iModel?\r\n */\r\nexport class SchemaLoader {\r\n private _context: SchemaContext;\r\n\r\n public constructor(getSchema: SchemaPropsGetter) {\r\n this._context = new SchemaContext();\r\n const locater = new SchemaJsonLocater(getSchema);\r\n this._context.addLocater(locater);\r\n }\r\n\r\n /** Get a schema by name\r\n * @param schemaName a string with the name of the schema to load.\r\n * @throws [ECSchemaError]($ecschema-metadata) if the schema is not found or cannot be loaded.\r\n */\r\n public getSchema(schemaName: string): Schema {\r\n const schema = this.tryGetSchema(schemaName);\r\n if (!schema)\r\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `reading schema=${schemaName}`);\r\n\r\n return schema;\r\n }\r\n\r\n /** Attempts to get a schema by name\r\n * @param schemaName a string with the name of the schema to load.\r\n * @throws [ECSchemaError]($ecschema-metadata) if the schema exists, but cannot be loaded.\r\n */\r\n public tryGetSchema(schemaName: string): Schema | undefined {\r\n // SchemaKey version is not used when locating schema in an iModel, so the version is arbitrary.\r\n const key = new SchemaKey(schemaName, new ECVersion(1, 0, 0));\r\n const schema = this._context.getSchemaSync(key, SchemaMatchType.Latest);\r\n return schema;\r\n }\r\n\r\n /** Gets the SchemaContext used by the loader. */\r\n public get context(): SchemaContext {\r\n return this._context;\r\n }\r\n}\r\n"]}
|