@itwin/ecschema-metadata 4.8.0-dev.4 → 4.8.0-dev.41
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 +46 -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/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/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/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/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/UnitProvider/SchemaUnitProvider.d.ts +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.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,231 @@
|
|
|
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
|
+
import { BentleyError, BentleyStatus } from "@itwin/core-bentley";
|
|
6
|
+
import { SchemaContext } from "../Context";
|
|
7
|
+
import { SchemaItem } from "../Metadata/SchemaItem";
|
|
8
|
+
import { SchemaItemKey, SchemaKey } from "../SchemaKey";
|
|
9
|
+
import { Unit } from "../Metadata/Unit";
|
|
10
|
+
import { SchemaItemType } from "../ECObjects";
|
|
11
|
+
import { UnitConverter } from "../UnitConversion/UnitConverter";
|
|
12
|
+
/**
|
|
13
|
+
* Class used to find Units in SchemaContext by attributes such as Phenomenon and DisplayLabel.
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export class SchemaUnitProvider {
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext
|
|
20
|
+
* class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be
|
|
21
|
+
* created and the locater will be added.
|
|
22
|
+
* @param _unitExtraData Additional data like alternate display label not found in Units Schema to match with Units; Defaults to empty array.
|
|
23
|
+
*/
|
|
24
|
+
constructor(contextOrLocater, _unitExtraData = []) {
|
|
25
|
+
this._unitExtraData = _unitExtraData;
|
|
26
|
+
if (contextOrLocater instanceof SchemaContext) {
|
|
27
|
+
this._context = contextOrLocater;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this._context = new SchemaContext();
|
|
31
|
+
this._context.addLocater(contextOrLocater);
|
|
32
|
+
}
|
|
33
|
+
this._unitConverter = new UnitConverter(this._context);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Find unit in a schema that has unitName.
|
|
37
|
+
* @param unitName Full name of unit.
|
|
38
|
+
* @returns UnitProps interface from @itwin/core-quantity whose name matches unitName.
|
|
39
|
+
*/
|
|
40
|
+
async findUnitByName(unitName) {
|
|
41
|
+
const unit = await this.findECUnitByName(unitName);
|
|
42
|
+
return this.getUnitsProps(unit);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Find all units in context that belongs to given phenomenon.
|
|
46
|
+
* @param phenomenon Full name of phenomenon.
|
|
47
|
+
* @returns Array of UnitProps (from @itwin/core-quantity) interface objects whose name matches phenomenon param.
|
|
48
|
+
*/
|
|
49
|
+
async getUnitsByFamily(phenomenon) {
|
|
50
|
+
// Check if schema exists and phenomenon exists in schema
|
|
51
|
+
const [schemaName, schemaItemName] = SchemaItem.parseFullName(phenomenon);
|
|
52
|
+
const schemaKey = new SchemaKey(schemaName);
|
|
53
|
+
const schema = await this._context.getSchema(schemaKey);
|
|
54
|
+
if (!schema) {
|
|
55
|
+
throw new BentleyError(BentleyStatus.ERROR, "Cannot find schema for phenomenon", () => {
|
|
56
|
+
return { phenomenon, schema: schemaName };
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const itemKey = new SchemaItemKey(schemaItemName, schema.schemaKey);
|
|
60
|
+
const phenom = await this._context.getSchemaItem(itemKey);
|
|
61
|
+
if (!phenom)
|
|
62
|
+
throw new BentleyError(BentleyStatus.ERROR, "Cannot find schema item/phenomenon", () => {
|
|
63
|
+
return { item: schemaItemName, schema: schemaName };
|
|
64
|
+
});
|
|
65
|
+
if (phenom.schemaItemType !== SchemaItemType.Phenomenon)
|
|
66
|
+
throw new BentleyError(BentleyStatus.ERROR, "Item is not a phenomenon", () => {
|
|
67
|
+
return { itemType: phenom.key.fullName };
|
|
68
|
+
});
|
|
69
|
+
// Find units' full name that match given phenomenon param.
|
|
70
|
+
const filteredUnits = [];
|
|
71
|
+
const schemaItems = this._context.getSchemaItems();
|
|
72
|
+
let { value, done } = schemaItems.next();
|
|
73
|
+
while (!done) {
|
|
74
|
+
if (Unit.isUnit(value)) {
|
|
75
|
+
const foundPhenomenon = await value.phenomenon;
|
|
76
|
+
if (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)) {
|
|
77
|
+
const unitProps = this.getUnitsProps(value);
|
|
78
|
+
filteredUnits.push(unitProps);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
({ value, done } = schemaItems.next());
|
|
82
|
+
}
|
|
83
|
+
return filteredUnits;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Find alternate display labels associated with unitName, if any.
|
|
87
|
+
* @param unitName Full name of Unit.
|
|
88
|
+
*/
|
|
89
|
+
getAlternateDisplayLabels(unitName) {
|
|
90
|
+
let alternateLabels = [];
|
|
91
|
+
for (const entry of this._unitExtraData) {
|
|
92
|
+
if (entry.name.toLowerCase() === unitName.toLowerCase()) {
|
|
93
|
+
alternateLabels = entry.altDisplayLabels;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return alternateLabels;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Finds Unit by unitLabel, which could be a display label in the schema or alternate an display label defined in
|
|
100
|
+
* this._unitExtraData. If there are duplicates of the same display label in the context or teh same alternate display
|
|
101
|
+
* labels, specify schemaName, phenomenon, or unitSystem to get a specific unit.
|
|
102
|
+
*
|
|
103
|
+
* @param unitLabel Display label or alternate display label to query unit by.
|
|
104
|
+
* @param schemaName Ensure Unit with unitLabel belongs to Schema with schemaName.
|
|
105
|
+
* @param phenomenon Full name of phenomenon that Unit belongs to.
|
|
106
|
+
* @param unitSystem Full name of unitSystem that Unit belongs to.
|
|
107
|
+
* @returns The UnitProps interface from the @itwin/core-quantity package.
|
|
108
|
+
*/
|
|
109
|
+
async findUnit(unitLabel, schemaName, phenomenon, unitSystem) {
|
|
110
|
+
const findLabel = unitLabel.toLowerCase();
|
|
111
|
+
const findSchema = schemaName ? schemaName.toLowerCase() : undefined;
|
|
112
|
+
const findPhenomenon = phenomenon ? phenomenon.toLowerCase() : undefined;
|
|
113
|
+
const findUnitSystem = unitSystem ? unitSystem.toLowerCase() : undefined;
|
|
114
|
+
let foundUnit;
|
|
115
|
+
try {
|
|
116
|
+
try {
|
|
117
|
+
foundUnit = await this.findUnitByDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
// If there is no Unit with display label that matches label, then check for alternate display labels that may match
|
|
121
|
+
foundUnit = await this.findUnitByAltDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw new BentleyError(BentleyStatus.ERROR, "Cannot find unit with label", () => {
|
|
126
|
+
return { unitLabel };
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return this.getUnitsProps(foundUnit);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the @itwin/core-quantity UnitConversionProps for the given fromUnit and toUnit.
|
|
133
|
+
* @param fromUnit The UnitProps of the 'from' unit.
|
|
134
|
+
* @param toUnit The UnitProps of the 'to' unit.
|
|
135
|
+
* @returns The UnitConversionProps interface from the @itwin/core-quantity package.
|
|
136
|
+
*/
|
|
137
|
+
async getConversion(fromUnit, toUnit) {
|
|
138
|
+
const conversion = await this._unitConverter.calculateConversion(fromUnit.name, toUnit.name);
|
|
139
|
+
return {
|
|
140
|
+
factor: conversion.factor,
|
|
141
|
+
offset: conversion.offset,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Find unit in a schema that has unitName.
|
|
146
|
+
* @param unitName Full name of unit.
|
|
147
|
+
* @returns Unit whose full name matches unitName.
|
|
148
|
+
*/
|
|
149
|
+
async findECUnitByName(unitName) {
|
|
150
|
+
// Check if schema exists and unit exists in schema
|
|
151
|
+
const [schemaName, schemaItemName] = SchemaItem.parseFullName(unitName);
|
|
152
|
+
const schemaKey = new SchemaKey(schemaName);
|
|
153
|
+
const schema = await this._context.getSchema(schemaKey);
|
|
154
|
+
if (!schema) {
|
|
155
|
+
throw new BentleyError(BentleyStatus.ERROR, "Cannot find schema for unit", () => {
|
|
156
|
+
return { schema: schemaName, unit: unitName };
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const itemKey = new SchemaItemKey(schemaItemName, schema.schemaKey);
|
|
160
|
+
const item = await this._context.getSchemaItem(itemKey);
|
|
161
|
+
if (!item)
|
|
162
|
+
throw new BentleyError(BentleyStatus.ERROR, "Cannot find schema item/unit", () => {
|
|
163
|
+
return { item: schemaItemName, schema: schemaName };
|
|
164
|
+
});
|
|
165
|
+
if (item.schemaItemType === SchemaItemType.Unit)
|
|
166
|
+
return item;
|
|
167
|
+
throw new BentleyError(BentleyStatus.ERROR, "Item is not a unit", () => {
|
|
168
|
+
return { itemType: item.key.fullName };
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Gets the @itwin/core UnitProps for the given Unit.
|
|
173
|
+
* @param unit The Unit to convert.
|
|
174
|
+
* @returns UnitProps interface from @itwin/core.
|
|
175
|
+
*/
|
|
176
|
+
getUnitsProps(unit) {
|
|
177
|
+
return {
|
|
178
|
+
name: unit.fullName,
|
|
179
|
+
label: unit.label ?? "",
|
|
180
|
+
phenomenon: unit.phenomenon ? unit.phenomenon.fullName : "",
|
|
181
|
+
isValid: true,
|
|
182
|
+
system: unit.unitSystem === undefined ? "" : unit.unitSystem.fullName,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Finds Unit by displayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
async findUnitByDisplayLabel(displayLabel, schemaName, phenomenon, unitSystem) {
|
|
190
|
+
const schemaItems = this._context.getSchemaItems();
|
|
191
|
+
let { value, done } = schemaItems.next();
|
|
192
|
+
while (!done) {
|
|
193
|
+
if (Unit.isUnit(value) && value.label?.toLowerCase() === displayLabel) {
|
|
194
|
+
const currPhenomenon = await value.phenomenon;
|
|
195
|
+
const currUnitSystem = await value.unitSystem;
|
|
196
|
+
if (!schemaName || value.schema.name.toLowerCase() === schemaName)
|
|
197
|
+
if (!phenomenon || (currPhenomenon && currPhenomenon.key.matchesFullName(phenomenon)))
|
|
198
|
+
if (!unitSystem || (currUnitSystem && currUnitSystem.key.matchesFullName(unitSystem)))
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
({ value, done } = schemaItems.next());
|
|
202
|
+
}
|
|
203
|
+
throw new BentleyError(BentleyStatus.ERROR, "Cannot find unit with display label", () => {
|
|
204
|
+
return { displayLabel };
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Finds Unit by altDisplayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
async findUnitByAltDisplayLabel(altDisplayLabel, schemaName, phenomenon, unitSystem) {
|
|
212
|
+
for (const entry of this._unitExtraData) {
|
|
213
|
+
if (entry.altDisplayLabels && entry.altDisplayLabels.length > 0) {
|
|
214
|
+
if (entry.altDisplayLabels.findIndex((ref) => ref.toLowerCase() === altDisplayLabel) !== -1) {
|
|
215
|
+
// Found altDisplayLabel that matches label to find
|
|
216
|
+
const unit = await this.findECUnitByName(entry.name);
|
|
217
|
+
const foundPhenomenon = await unit.phenomenon;
|
|
218
|
+
const foundUnitSystem = await unit.unitSystem;
|
|
219
|
+
if (!schemaName || unit.schema.name.toLowerCase() === schemaName)
|
|
220
|
+
if (!phenomenon || (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)))
|
|
221
|
+
if (!unitSystem || (foundUnitSystem && foundUnitSystem.key.matchesFullName(unitSystem)))
|
|
222
|
+
return unit;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
throw new BentleyError(BentleyStatus.ERROR, "Cannot find unit with alternate display label", () => {
|
|
227
|
+
return { altDisplayLabel };
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=SchemaUnitProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaUnitProvider.js","sourceRoot":"","sources":["../../../src/UnitProvider/SchemaUnitProvider.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAElE,OAAO,EAAkB,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAI7B;;;;;;OAMG;IACH,YAAY,gBAAgC,EAAU,iBAAkC,EAAE;QAApC,mBAAc,GAAd,cAAc,CAAsB;QACxF,IAAI,gBAAgB,YAAY,aAAa,EAAE,CAAC;YAC9C,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC;QACnC,CAAC;aAA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e,CAAC,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;4BACrF,IAAI,CAAC,UAAU,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;gCACrF,OAAO,IAAI,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,IAAI,YAAY,CAAC,aAAa,CAAC,KAAK,EAAE,+CAA+C,EAAE,GAAG,EAAE;YAChG,OAAO,EAAE,eAAe,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CACF","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\nimport { BentleyError, BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { UnitConversionProps, UnitExtraData, UnitProps, UnitsProvider } from \"@itwin/core-quantity\";\r\nimport { ISchemaLocater, SchemaContext } from \"../Context\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { SchemaItemKey, SchemaKey } from \"../SchemaKey\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { UnitConverter } from \"../UnitConversion/UnitConverter\";\r\n\r\n/**\r\n * Class used to find Units in SchemaContext by attributes such as Phenomenon and DisplayLabel.\r\n * @beta\r\n */\r\nexport class SchemaUnitProvider implements UnitsProvider {\r\n private _unitConverter: UnitConverter;\r\n private _context: SchemaContext;\r\n\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 _unitExtraData Additional data like alternate display label not found in Units Schema to match with Units; Defaults to empty array.\r\n */\r\n constructor(contextOrLocater: ISchemaLocater, private _unitExtraData: UnitExtraData[] = []){\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._unitConverter = new UnitConverter(this._context);\r\n }\r\n\r\n /**\r\n * Find unit in a schema that has unitName.\r\n * @param unitName Full name of unit.\r\n * @returns UnitProps interface from @itwin/core-quantity whose name matches unitName.\r\n */\r\n public async findUnitByName(unitName: string): Promise<UnitProps> {\r\n const unit = await this.findECUnitByName(unitName);\r\n return this.getUnitsProps(unit);\r\n }\r\n\r\n /**\r\n * Find all units in context that belongs to given phenomenon.\r\n * @param phenomenon Full name of phenomenon.\r\n * @returns Array of UnitProps (from @itwin/core-quantity) interface objects whose name matches phenomenon param.\r\n */\r\n public async getUnitsByFamily(phenomenon: string): Promise<Array<UnitProps>> {\r\n // Check if schema exists and phenomenon exists in schema\r\n const [schemaName, schemaItemName] = SchemaItem.parseFullName(phenomenon);\r\n const schemaKey = new SchemaKey(schemaName);\r\n const schema = await this._context.getSchema(schemaKey);\r\n\r\n if (!schema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema for phenomenon\", () => {\r\n return { phenomenon, schema: schemaName };\r\n });\r\n }\r\n\r\n const itemKey = new SchemaItemKey(schemaItemName, schema.schemaKey);\r\n const phenom = await this._context.getSchemaItem(itemKey);\r\n if (!phenom)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item/phenomenon\", () => {\r\n return { item: schemaItemName, schema: schemaName };\r\n });\r\n\r\n if (phenom.schemaItemType !== SchemaItemType.Phenomenon)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Item is not a phenomenon\", () => {\r\n return { itemType: phenom.key.fullName };\r\n });\r\n\r\n // Find units' full name that match given phenomenon param.\r\n const filteredUnits: Array<UnitProps> = [];\r\n const schemaItems = this._context.getSchemaItems();\r\n let { value, done } = schemaItems.next();\r\n while (!done) {\r\n if (Unit.isUnit(value)) {\r\n const foundPhenomenon = await value.phenomenon;\r\n if (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)) {\r\n const unitProps = this.getUnitsProps(value);\r\n filteredUnits.push(unitProps);\r\n }\r\n }\r\n ({ value, done } = schemaItems.next());\r\n }\r\n\r\n return filteredUnits;\r\n }\r\n\r\n /**\r\n * Find alternate display labels associated with unitName, if any.\r\n * @param unitName Full name of Unit.\r\n */\r\n public getAlternateDisplayLabels(unitName: string): Array<string> {\r\n let alternateLabels: Array<string> = [];\r\n for (const entry of this._unitExtraData) {\r\n if (entry.name.toLowerCase() === unitName.toLowerCase()) {\r\n alternateLabels = entry.altDisplayLabels;\r\n }\r\n }\r\n\r\n return alternateLabels;\r\n }\r\n\r\n /**\r\n * Finds Unit by unitLabel, which could be a display label in the schema or alternate an display label defined in\r\n * this._unitExtraData. If there are duplicates of the same display label in the context or teh same alternate display\r\n * labels, specify schemaName, phenomenon, or unitSystem to get a specific unit.\r\n *\r\n * @param unitLabel Display label or alternate display label to query unit by.\r\n * @param schemaName Ensure Unit with unitLabel belongs to Schema with schemaName.\r\n * @param phenomenon Full name of phenomenon that Unit belongs to.\r\n * @param unitSystem Full name of unitSystem that Unit belongs to.\r\n * @returns The UnitProps interface from the @itwin/core-quantity package.\r\n */\r\n public async findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps> {\r\n const findLabel = unitLabel.toLowerCase();\r\n const findSchema = schemaName ? schemaName.toLowerCase() : undefined;\r\n const findPhenomenon = phenomenon ? phenomenon.toLowerCase() : undefined;\r\n const findUnitSystem = unitSystem ? unitSystem.toLowerCase() : undefined;\r\n let foundUnit: Unit | undefined;\r\n\r\n try {\r\n try {\r\n foundUnit = await this.findUnitByDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);\r\n } catch (err) {\r\n // If there is no Unit with display label that matches label, then check for alternate display labels that may match\r\n foundUnit = await this.findUnitByAltDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);\r\n }\r\n } catch (err) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find unit with label\", () => {\r\n return { unitLabel };\r\n });\r\n }\r\n\r\n return this.getUnitsProps(foundUnit);\r\n }\r\n\r\n /**\r\n * Gets the @itwin/core-quantity UnitConversionProps for the given fromUnit and toUnit.\r\n * @param fromUnit The UnitProps of the 'from' unit.\r\n * @param toUnit The UnitProps of the 'to' unit.\r\n * @returns The UnitConversionProps interface from the @itwin/core-quantity package.\r\n */\r\n public async getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps> {\r\n const conversion = await this._unitConverter.calculateConversion(fromUnit.name, toUnit.name);\r\n return {\r\n factor: conversion.factor,\r\n offset: conversion.offset,\r\n };\r\n }\r\n\r\n /**\r\n * Find unit in a schema that has unitName.\r\n * @param unitName Full name of unit.\r\n * @returns Unit whose full name matches unitName.\r\n */\r\n private async findECUnitByName(unitName: string): Promise<Unit> {\r\n // Check if schema exists and unit exists in schema\r\n const [schemaName, schemaItemName] = SchemaItem.parseFullName(unitName);\r\n const schemaKey = new SchemaKey(schemaName);\r\n const schema = await this._context.getSchema(schemaKey);\r\n\r\n if (!schema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema for unit\", () => {\r\n return { schema: schemaName, unit: unitName };\r\n });\r\n }\r\n\r\n const itemKey = new SchemaItemKey(schemaItemName, schema.schemaKey);\r\n const item = await this._context.getSchemaItem<Unit>(itemKey);\r\n if (!item)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item/unit\", () => {\r\n return { item: schemaItemName, schema: schemaName };\r\n });\r\n\r\n if (item.schemaItemType === SchemaItemType.Unit)\r\n return item;\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Item is not a unit\", () => {\r\n return { itemType: item.key.fullName };\r\n });\r\n }\r\n\r\n /**\r\n * Gets the @itwin/core UnitProps for the given Unit.\r\n * @param unit The Unit to convert.\r\n * @returns UnitProps interface from @itwin/core.\r\n */\r\n private getUnitsProps(unit: Unit): UnitProps {\r\n return {\r\n name: unit.fullName,\r\n label: unit.label ?? \"\",\r\n phenomenon: unit.phenomenon ? unit.phenomenon.fullName : \"\",\r\n isValid: true,\r\n system: unit.unitSystem === undefined ? \"\" : unit.unitSystem.fullName,\r\n };\r\n }\r\n\r\n /**\r\n * Finds Unit by displayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.\r\n * @internal\r\n */\r\n private async findUnitByDisplayLabel(displayLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<Unit> {\r\n const schemaItems = this._context.getSchemaItems();\r\n let { value, done } = schemaItems.next();\r\n while (!done) {\r\n if (Unit.isUnit(value) && value.label?.toLowerCase() === displayLabel) {\r\n const currPhenomenon = await value.phenomenon;\r\n const currUnitSystem = await value.unitSystem;\r\n if (!schemaName || value.schema.name.toLowerCase() === schemaName)\r\n if (!phenomenon || (currPhenomenon && currPhenomenon.key.matchesFullName(phenomenon)))\r\n if (!unitSystem || (currUnitSystem && currUnitSystem.key.matchesFullName(unitSystem)))\r\n return value;\r\n }\r\n ({ value, done } = schemaItems.next());\r\n }\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find unit with display label\", () => {\r\n return { displayLabel };\r\n });\r\n }\r\n\r\n /**\r\n * Finds Unit by altDisplayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.\r\n * @internal\r\n */\r\n private async findUnitByAltDisplayLabel(altDisplayLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<Unit> {\r\n for (const entry of this._unitExtraData) {\r\n if (entry.altDisplayLabels && entry.altDisplayLabels.length > 0) {\r\n if (entry.altDisplayLabels.findIndex((ref: string) => ref.toLowerCase() === altDisplayLabel) !== -1) {\r\n // Found altDisplayLabel that matches label to find\r\n const unit = await this.findECUnitByName(entry.name);\r\n const foundPhenomenon = await unit.phenomenon;\r\n const foundUnitSystem = await unit.unitSystem;\r\n if (!schemaName || unit.schema.name.toLowerCase() === schemaName)\r\n if (!phenomenon || (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)))\r\n if (!unitSystem || (foundUnitSystem && foundUnitSystem.key.matchesFullName(unitSystem)))\r\n return unit;\r\n }\r\n }\r\n }\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find unit with alternate display label\", () => {\r\n return { altDisplayLabel };\r\n });\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Schema } from "../Metadata/Schema";
|
|
2
|
+
import { ISchemaPartVisitor } from "../SchemaPartVisitorDelegate";
|
|
3
|
+
/**
|
|
4
|
+
* The purpose of this class is to traverse a given schema, allowing clients to hook into
|
|
5
|
+
* the traversal process via Visitors to allow for custom processing of the schema elements.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class SchemaWalker {
|
|
9
|
+
private _visitorHelper;
|
|
10
|
+
private _schema?;
|
|
11
|
+
/**
|
|
12
|
+
* Initializes a new SchemaWalker instance.
|
|
13
|
+
* @param visitor An ISchemaWalkerVisitor implementation whose methods will be called during schema traversal.
|
|
14
|
+
*/
|
|
15
|
+
constructor(visitor: ISchemaPartVisitor);
|
|
16
|
+
/**
|
|
17
|
+
* Traverses the given Schema, calling ISchemaWalkerVisitor methods along the way.
|
|
18
|
+
* @param schema The Schema to traverse.
|
|
19
|
+
*/
|
|
20
|
+
traverseSchema<T extends Schema>(schema: T): Promise<T>;
|
|
21
|
+
private traverseSchemaItem;
|
|
22
|
+
private traverseClass;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=SchemaWalker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaWalker.d.ts","sourceRoot":"","sources":["../../../src/Validation/SchemaWalker.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAA6B,MAAM,8BAA8B,CAAC;AAE7F;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,cAAc,CAA4B;IAIlD,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB;;;OAGG;gBACS,OAAO,EAAE,kBAAkB;IAIvC;;;OAGG;IACU,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;YAWtD,kBAAkB;YAOlB,aAAa;CAY5B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
import { SchemaItemType } from "../ECObjects";
|
|
6
|
+
import { ECClass } from "../Metadata/Class";
|
|
7
|
+
import { SchemaPartVisitorDelegate } from "../SchemaPartVisitorDelegate";
|
|
8
|
+
/**
|
|
9
|
+
* The purpose of this class is to traverse a given schema, allowing clients to hook into
|
|
10
|
+
* the traversal process via Visitors to allow for custom processing of the schema elements.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export class SchemaWalker {
|
|
14
|
+
/**
|
|
15
|
+
* Initializes a new SchemaWalker instance.
|
|
16
|
+
* @param visitor An ISchemaWalkerVisitor implementation whose methods will be called during schema traversal.
|
|
17
|
+
*/
|
|
18
|
+
constructor(visitor) {
|
|
19
|
+
this._visitorHelper = new SchemaPartVisitorDelegate(visitor);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Traverses the given Schema, calling ISchemaWalkerVisitor methods along the way.
|
|
23
|
+
* @param schema The Schema to traverse.
|
|
24
|
+
*/
|
|
25
|
+
async traverseSchema(schema) {
|
|
26
|
+
this._schema = schema;
|
|
27
|
+
await this._visitorHelper.visitSchema(schema);
|
|
28
|
+
await this._visitorHelper.visitSchemaPart(schema);
|
|
29
|
+
for (const item of this._schema.getItems())
|
|
30
|
+
await this.traverseSchemaItem(item);
|
|
31
|
+
return schema;
|
|
32
|
+
}
|
|
33
|
+
async traverseSchemaItem(schemaItem) {
|
|
34
|
+
await this._visitorHelper.visitSchemaPart(schemaItem);
|
|
35
|
+
if (ECClass.isECClass(schemaItem))
|
|
36
|
+
await this.traverseClass(schemaItem);
|
|
37
|
+
}
|
|
38
|
+
async traverseClass(ecClass) {
|
|
39
|
+
if (ecClass.properties) {
|
|
40
|
+
for (const property of ecClass.properties) {
|
|
41
|
+
await this._visitorHelper.visitSchemaPart(property);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (ecClass.schemaItemType === SchemaItemType.RelationshipClass) {
|
|
45
|
+
await this._visitorHelper.visitSchemaPart(ecClass.source);
|
|
46
|
+
await this._visitorHelper.visitSchemaPart(ecClass.target);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=SchemaWalker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaWalker.js","sourceRoot":"","sources":["../../../src/Validation/SchemaWalker.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAsB,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAE7F;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAOvB;;;OAGG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,cAAc,GAAG,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,cAAc,CAAmB,MAAS;QACrD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAEtB,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAElD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACxC,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,UAAsB;QACrD,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAEtD,IAAI,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC;YAC/B,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,OAAgB;QAC1C,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBAC1C,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,cAAc,KAAK,cAAc,CAAC,iBAAiB,EAAE,CAAC;YAChE,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAE,OAA6B,CAAC,MAAM,CAAC,CAAC;YACjF,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAE,OAA6B,CAAC,MAAM,CAAC,CAAC;QACnF,CAAC;IACH,CAAC;CACF","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 { SchemaItemType } from \"../ECObjects\";\r\nimport { ECClass } from \"../Metadata/Class\";\r\nimport { RelationshipClass } from \"../Metadata/RelationshipClass\";\r\nimport { Schema } from \"../Metadata/Schema\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { ISchemaPartVisitor, SchemaPartVisitorDelegate } from \"../SchemaPartVisitorDelegate\";\r\n\r\n/**\r\n * The purpose of this class is to traverse a given schema, allowing clients to hook into\r\n * the traversal process via Visitors to allow for custom processing of the schema elements.\r\n * @internal\r\n */\r\nexport class SchemaWalker {\r\n private _visitorHelper: SchemaPartVisitorDelegate;\r\n\r\n // This is a cache of the schema we are traversing. The schema also exists within the _context but in order\r\n // to not have to go back to the context every time we use this cache.\r\n private _schema?: Schema;\r\n\r\n /**\r\n * Initializes a new SchemaWalker instance.\r\n * @param visitor An ISchemaWalkerVisitor implementation whose methods will be called during schema traversal.\r\n */\r\n constructor(visitor: ISchemaPartVisitor) {\r\n this._visitorHelper = new SchemaPartVisitorDelegate(visitor);\r\n }\r\n\r\n /**\r\n * Traverses the given Schema, calling ISchemaWalkerVisitor methods along the way.\r\n * @param schema The Schema to traverse.\r\n */\r\n public async traverseSchema<T extends Schema>(schema: T): Promise<T> {\r\n this._schema = schema;\r\n\r\n await this._visitorHelper.visitSchema(schema);\r\n await this._visitorHelper.visitSchemaPart(schema);\r\n\r\n for (const item of this._schema.getItems())\r\n await this.traverseSchemaItem(item);\r\n return schema;\r\n }\r\n\r\n private async traverseSchemaItem(schemaItem: SchemaItem): Promise<void> {\r\n await this._visitorHelper.visitSchemaPart(schemaItem);\r\n\r\n if (ECClass.isECClass(schemaItem))\r\n await this.traverseClass(schemaItem);\r\n }\r\n\r\n private async traverseClass(ecClass: ECClass): Promise<void> {\r\n if (ecClass.properties) {\r\n for (const property of ecClass.properties) {\r\n await this._visitorHelper.visitSchemaPart(property);\r\n }\r\n }\r\n\r\n if (ecClass.schemaItemType === SchemaItemType.RelationshipClass) {\r\n await this._visitorHelper.visitSchemaPart((ecClass as RelationshipClass).source);\r\n await this._visitorHelper.visitSchemaPart((ecClass as RelationshipClass).target);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export * from "./Constants";
|
|
2
|
+
export * from "./Context";
|
|
3
|
+
export * from "./DelayedPromise";
|
|
4
|
+
export * from "./Deserialization/SchemaGraphUtil";
|
|
5
|
+
export * from "./Deserialization/JsonProps";
|
|
6
|
+
export * from "./Deserialization/Helper";
|
|
7
|
+
export * from "./Deserialization/XmlParser";
|
|
8
|
+
export * from "./ECName";
|
|
9
|
+
export * from "./ECObjects";
|
|
10
|
+
export * from "./Exception";
|
|
11
|
+
export * from "./Interfaces";
|
|
12
|
+
export { ECClass, StructClass } from "./Metadata/Class";
|
|
13
|
+
export { Constant } from "./Metadata/Constant";
|
|
14
|
+
export { CustomAttributeClass } from "./Metadata/CustomAttributeClass";
|
|
15
|
+
export { EntityClass } from "./Metadata/EntityClass";
|
|
16
|
+
export { AnyEnumerator, Enumeration, Enumerator } from "./Metadata/Enumeration";
|
|
17
|
+
export { Format } from "./Metadata/Format";
|
|
18
|
+
export { InvertedUnit } from "./Metadata/InvertedUnit";
|
|
19
|
+
export { KindOfQuantity } from "./Metadata/KindOfQuantity";
|
|
20
|
+
export { Mixin } from "./Metadata/Mixin";
|
|
21
|
+
export * from "./Metadata/OverrideFormat";
|
|
22
|
+
export { Phenomenon } from "./Metadata/Phenomenon";
|
|
23
|
+
export { Property, PrimitiveProperty, PrimitiveArrayProperty, EnumerationProperty, StructProperty, StructArrayProperty, EnumerationArrayProperty, NavigationProperty, AnyArrayProperty, AnyEnumerationProperty, AnyPrimitiveProperty, AnyProperty, AnyStructProperty, ArrayProperty, PrimitiveOrEnumPropertyBase, } from "./Metadata/Property";
|
|
24
|
+
export { PropertyCategory } from "./Metadata/PropertyCategory";
|
|
25
|
+
export { RelationshipClass, RelationshipConstraint, RelationshipMultiplicity } from "./Metadata/RelationshipClass";
|
|
26
|
+
export { Schema } from "./Metadata/Schema";
|
|
27
|
+
export * from "./Metadata/SchemaItem";
|
|
28
|
+
export { Unit } from "./Metadata/Unit";
|
|
29
|
+
export { UnitSystem } from "./Metadata/UnitSystem";
|
|
30
|
+
export * from "./PropertyTypes";
|
|
31
|
+
export * from "./SchemaJsonLocater";
|
|
32
|
+
export * from "./SchemaKey";
|
|
33
|
+
export * from "./SchemaLoader";
|
|
34
|
+
export * from "./UnitConversion/UnitConversion";
|
|
35
|
+
export * from "./UnitConversion/UnitConverter";
|
|
36
|
+
export * from "./UnitProvider/SchemaUnitProvider";
|
|
37
|
+
export * from "./Validation/SchemaWalker";
|
|
38
|
+
export * from "./SchemaPartVisitorDelegate";
|
|
39
|
+
export { CustomAttribute, CustomAttributeContainerProps } from "./Metadata/CustomAttribute";
|
|
40
|
+
export { SchemaGraph } from "./utils/SchemaGraph";
|
|
41
|
+
/** @docs-package-description
|
|
42
|
+
* The ecschema-metadata package contains classes for working with ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* @docs-group-description Metadata
|
|
46
|
+
* Definitions of classes and interfaces that represent all [EC elements]($docs/bis/ec/index.md).
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* @docs-group-description Utils
|
|
50
|
+
* A set of utility classes used throughout the package.
|
|
51
|
+
*/
|
|
52
|
+
//# sourceMappingURL=ecschema-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecschema-metadata.d.ts","sourceRoot":"","sources":["../../src/ecschema-metadata.ts"],"names":[],"mappings":"AAKA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,Q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AAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,6BAA6B,EAAC,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH;;;GAGG;AACH;;;GAGG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
export * from "./Constants";
|
|
6
|
+
export * from "./Context";
|
|
7
|
+
export * from "./DelayedPromise";
|
|
8
|
+
export * from "./Deserialization/SchemaGraphUtil";
|
|
9
|
+
export * from "./Deserialization/JsonProps";
|
|
10
|
+
export * from "./Deserialization/Helper";
|
|
11
|
+
export * from "./Deserialization/XmlParser";
|
|
12
|
+
export * from "./ECName";
|
|
13
|
+
export * from "./ECObjects";
|
|
14
|
+
export * from "./Exception";
|
|
15
|
+
export * from "./Interfaces";
|
|
16
|
+
export { ECClass, StructClass } from "./Metadata/Class";
|
|
17
|
+
export { Constant } from "./Metadata/Constant";
|
|
18
|
+
export { CustomAttributeClass } from "./Metadata/CustomAttributeClass";
|
|
19
|
+
export { EntityClass } from "./Metadata/EntityClass";
|
|
20
|
+
export { Enumeration } from "./Metadata/Enumeration";
|
|
21
|
+
export { Format } from "./Metadata/Format";
|
|
22
|
+
export { InvertedUnit } from "./Metadata/InvertedUnit";
|
|
23
|
+
export { KindOfQuantity } from "./Metadata/KindOfQuantity";
|
|
24
|
+
export { Mixin } from "./Metadata/Mixin";
|
|
25
|
+
export * from "./Metadata/OverrideFormat";
|
|
26
|
+
export { Phenomenon } from "./Metadata/Phenomenon";
|
|
27
|
+
export { Property, PrimitiveProperty, PrimitiveArrayProperty, EnumerationProperty, StructProperty, StructArrayProperty, EnumerationArrayProperty, NavigationProperty, ArrayProperty, PrimitiveOrEnumPropertyBase, } from "./Metadata/Property";
|
|
28
|
+
export { PropertyCategory } from "./Metadata/PropertyCategory";
|
|
29
|
+
export { RelationshipClass, RelationshipConstraint, RelationshipMultiplicity } from "./Metadata/RelationshipClass";
|
|
30
|
+
export { Schema } from "./Metadata/Schema";
|
|
31
|
+
export * from "./Metadata/SchemaItem";
|
|
32
|
+
export { Unit } from "./Metadata/Unit";
|
|
33
|
+
export { UnitSystem } from "./Metadata/UnitSystem";
|
|
34
|
+
export * from "./PropertyTypes";
|
|
35
|
+
export * from "./SchemaJsonLocater";
|
|
36
|
+
export * from "./SchemaKey";
|
|
37
|
+
export * from "./SchemaLoader";
|
|
38
|
+
export * from "./UnitConversion/UnitConversion";
|
|
39
|
+
export * from "./UnitConversion/UnitConverter";
|
|
40
|
+
export * from "./UnitProvider/SchemaUnitProvider";
|
|
41
|
+
export * from "./Validation/SchemaWalker";
|
|
42
|
+
export * from "./SchemaPartVisitorDelegate";
|
|
43
|
+
export { SchemaGraph } from "./utils/SchemaGraph";
|
|
44
|
+
/** @docs-package-description
|
|
45
|
+
* The ecschema-metadata package contains classes for working with ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* @docs-group-description Metadata
|
|
49
|
+
* Definitions of classes and interfaces that represent all [EC elements]($docs/bis/ec/index.md).
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* @docs-group-description Utils
|
|
53
|
+
* A set of utility classes used throughout the package.
|
|
54
|
+
*/
|
|
55
|
+
//# sourceMappingURL=ecschema-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecschema-metadata.js","sourceRoot":"","sources":["../../src/ecschema-metadata.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,aAAa,CAAC;AAC5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AM,iBAAiB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./Constants\";\r\nexport * from \"./Context\";\r\nexport * from \"./DelayedPromise\";\r\nexport * from \"./Deserialization/SchemaGraphUtil\";\r\nexport * from \"./Deserialization/JsonProps\";\r\nexport * from \"./Deserialization/Helper\";\r\nexport * from \"./Deserialization/XmlParser\";\r\nexport * from \"./ECName\";\r\nexport * from \"./ECObjects\";\r\nexport * from \"./Exception\";\r\nexport * from \"./Interfaces\";\r\nexport { ECClass, StructClass } from \"./Metadata/Class\";\r\nexport { Constant } from \"./Metadata/Constant\";\r\nexport { CustomAttributeClass } from \"./Metadata/CustomAttributeClass\";\r\nexport { EntityClass } from \"./Metadata/EntityClass\";\r\nexport { AnyEnumerator, Enumeration, Enumerator } from \"./Metadata/Enumeration\";\r\nexport { Format } from \"./Metadata/Format\";\r\nexport { InvertedUnit } from \"./Metadata/InvertedUnit\";\r\nexport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\r\nexport { Mixin } from \"./Metadata/Mixin\";\r\nexport * from \"./Metadata/OverrideFormat\";\r\nexport { Phenomenon } from \"./Metadata/Phenomenon\";\r\nexport {\r\n Property, PrimitiveProperty, PrimitiveArrayProperty, EnumerationProperty, StructProperty,\r\n StructArrayProperty, EnumerationArrayProperty, NavigationProperty, AnyArrayProperty, AnyEnumerationProperty,\r\n AnyPrimitiveProperty, AnyProperty, AnyStructProperty, ArrayProperty, PrimitiveOrEnumPropertyBase,\r\n} from \"./Metadata/Property\";\r\nexport { PropertyCategory } from \"./Metadata/PropertyCategory\";\r\nexport { RelationshipClass, RelationshipConstraint, RelationshipMultiplicity } from \"./Metadata/RelationshipClass\";\r\nexport { Schema } from \"./Metadata/Schema\";\r\nexport * from \"./Metadata/SchemaItem\";\r\nexport { Unit } from \"./Metadata/Unit\";\r\nexport { UnitSystem } from \"./Metadata/UnitSystem\";\r\nexport * from \"./PropertyTypes\";\r\nexport * from \"./SchemaJsonLocater\";\r\nexport * from \"./SchemaKey\";\r\nexport * from \"./SchemaLoader\";\r\nexport * from \"./UnitConversion/UnitConversion\";\r\nexport * from \"./UnitConversion/UnitConverter\";\r\nexport * from \"./UnitProvider/SchemaUnitProvider\";\r\nexport * from \"./Validation/SchemaWalker\";\r\nexport * from \"./SchemaPartVisitorDelegate\";\r\nexport { CustomAttribute, CustomAttributeContainerProps} from \"./Metadata/CustomAttribute\";\r\nexport { SchemaGraph } from \"./utils/SchemaGraph\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-metadata package contains classes for working with ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).\r\n */\r\n/**\r\n * @docs-group-description Metadata\r\n * Definitions of classes and interfaces that represent all [EC elements]($docs/bis/ec/index.md).\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * A set of utility classes used throughout the package.\r\n */\r\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SchemaContext } from "../Context";
|
|
2
|
+
import { SchemaInfo } from "../Interfaces";
|
|
3
|
+
import { Schema } from "../Metadata/Schema";
|
|
4
|
+
/**
|
|
5
|
+
* A schema and it's reference that make up part of a schema cycle
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface ReferenceCycle {
|
|
9
|
+
schema: SchemaInfo;
|
|
10
|
+
refSchema: SchemaInfo;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Utility class for detecting cyclic references in a Schema graph.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare class SchemaGraph {
|
|
17
|
+
private _schemas;
|
|
18
|
+
private constructor();
|
|
19
|
+
private find;
|
|
20
|
+
/**
|
|
21
|
+
* Detected cyclic references in a schema and throw an exception if a cycle is found.
|
|
22
|
+
*/
|
|
23
|
+
throwIfCycles(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Detected cyclic references in a schema.
|
|
26
|
+
* @returns An array describing the cycle if there is a cycle or undefined if no cycles found.
|
|
27
|
+
*/
|
|
28
|
+
detectCycles(): ReferenceCycle[] | undefined;
|
|
29
|
+
private detectCycleUtil;
|
|
30
|
+
/**
|
|
31
|
+
* Generates a SchemaGraph for the input schema using the context to find info on referenced schemas. Use the generateGraphSync if you have the fully loaded Schema.
|
|
32
|
+
* @param schema The SchemaInfo to build the graph from
|
|
33
|
+
* @param context The SchemaContext used to locate info on the referenced schemas
|
|
34
|
+
* @returns A SchemaGraph that can be used to detect schema cycles
|
|
35
|
+
*/
|
|
36
|
+
static generateGraph(schema: SchemaInfo, context: SchemaContext): Promise<SchemaGraph>;
|
|
37
|
+
/**
|
|
38
|
+
* Generates a SchemaGraph for the input schema. Use the generateGraph if you just have schema info.
|
|
39
|
+
* @param schema The Schema to build the graph from.
|
|
40
|
+
* @returns A SchemaGraph that can be used to detect schema cycles
|
|
41
|
+
*/
|
|
42
|
+
static generateGraphSync(schema: Schema): SchemaGraph;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=SchemaGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaGraph.d.ts","sourceRoot":"","sources":["../../../src/utils/SchemaGraph.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAoB;IAEpC,OAAO;IAEP,OAAO,CAAC,IAAI;IAIZ;;OAEG;IACI,aAAa;IAQpB;;;OAGG;IACI,YAAY,IAAI,cAAc,EAAE,GAAG,SAAS;IAcnD,OAAO,CAAC,eAAe;IA0BvB;;;;;OAKG;WACiB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC;IAyBnG;;;;OAIG;WACW,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW;CAmB7D"}
|