@itwin/ecschema-metadata 4.8.0-dev.9 → 4.9.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -1
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/DelayedPromise.js.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.d.ts +4 -0
- package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
- package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/cjs/ECName.js.map +1 -1
- package/lib/cjs/ECObjects.js.map +1 -1
- package/lib/cjs/Exception.js.map +1 -1
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Metadata/Class.d.ts +0 -6
- package/lib/cjs/Metadata/Class.d.ts.map +1 -1
- package/lib/cjs/Metadata/Class.js +0 -8
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +7 -3
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js +16 -10
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.js.map +1 -1
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.js +3 -1
- package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +14 -0
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +21 -0
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +5 -0
- package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.js +7 -0
- package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
- package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
- package/lib/cjs/PropertyTypes.js.map +1 -1
- package/lib/cjs/SchemaJsonLocater.js.map +1 -1
- package/lib/cjs/SchemaKey.js.map +1 -1
- package/lib/cjs/SchemaLoader.js.map +1 -1
- package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
- package/lib/cjs/UnitConversion/Graph.js.map +1 -1
- package/lib/cjs/UnitConversion/Parser.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaGraph.js.map +1 -1
- package/lib/esm/Constants.d.ts +24 -0
- package/lib/esm/Constants.d.ts.map +1 -0
- package/lib/esm/Constants.js +30 -0
- package/lib/esm/Constants.js.map +1 -0
- package/lib/esm/Context.d.ts +219 -0
- package/lib/esm/Context.d.ts.map +1 -0
- package/lib/esm/Context.js +321 -0
- package/lib/esm/Context.js.map +1 -0
- package/lib/esm/DelayedPromise.d.ts +89 -0
- package/lib/esm/DelayedPromise.d.ts.map +1 -0
- package/lib/esm/DelayedPromise.js +88 -0
- package/lib/esm/DelayedPromise.js.map +1 -0
- package/lib/esm/Deserialization/AbstractParser.d.ts +46 -0
- package/lib/esm/Deserialization/AbstractParser.d.ts.map +1 -0
- package/lib/esm/Deserialization/AbstractParser.js +8 -0
- package/lib/esm/Deserialization/AbstractParser.js.map +1 -0
- package/lib/esm/Deserialization/Helper.d.ts +263 -0
- package/lib/esm/Deserialization/Helper.d.ts.map +1 -0
- package/lib/esm/Deserialization/Helper.js +871 -0
- package/lib/esm/Deserialization/Helper.js.map +1 -0
- package/lib/esm/Deserialization/JsonParser.d.ts +166 -0
- package/lib/esm/Deserialization/JsonParser.d.ts.map +1 -0
- package/lib/esm/Deserialization/JsonParser.js +677 -0
- package/lib/esm/Deserialization/JsonParser.js.map +1 -0
- package/lib/esm/Deserialization/JsonProps.d.ts +273 -0
- package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -0
- package/lib/esm/Deserialization/JsonProps.js +9 -0
- package/lib/esm/Deserialization/JsonProps.js.map +1 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.d.ts +35 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.d.ts.map +1 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.js +74 -0
- package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -0
- package/lib/esm/Deserialization/XmlParser.d.ts +86 -0
- package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -0
- package/lib/esm/Deserialization/XmlParser.js +970 -0
- package/lib/esm/Deserialization/XmlParser.js.map +1 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +55 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.js +172 -0
- package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -0
- package/lib/esm/ECName.d.ts +31 -0
- package/lib/esm/ECName.d.ts.map +1 -0
- package/lib/esm/ECName.js +82 -0
- package/lib/esm/ECName.js.map +1 -0
- package/lib/esm/ECObjects.d.ts +166 -0
- package/lib/esm/ECObjects.d.ts.map +1 -0
- package/lib/esm/ECObjects.js +422 -0
- package/lib/esm/ECObjects.js.map +1 -0
- package/lib/esm/Exception.d.ts +45 -0
- package/lib/esm/Exception.d.ts.map +1 -0
- package/lib/esm/Exception.js +82 -0
- package/lib/esm/Exception.js.map +1 -0
- package/lib/esm/Interfaces.d.ts +79 -0
- package/lib/esm/Interfaces.d.ts.map +1 -0
- package/lib/esm/Interfaces.js +9 -0
- package/lib/esm/Interfaces.js.map +1 -0
- package/lib/esm/Metadata/Class.d.ts +245 -0
- package/lib/esm/Metadata/Class.d.ts.map +1 -0
- package/lib/esm/Metadata/Class.js +552 -0
- package/lib/esm/Metadata/Class.js.map +1 -0
- package/lib/esm/Metadata/Constant.d.ts +65 -0
- package/lib/esm/Metadata/Constant.d.ts.map +1 -0
- package/lib/esm/Metadata/Constant.js +119 -0
- package/lib/esm/Metadata/Constant.js.map +1 -0
- package/lib/esm/Metadata/CustomAttribute.d.ts +24 -0
- package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -0
- package/lib/esm/Metadata/CustomAttribute.js +24 -0
- package/lib/esm/Metadata/CustomAttribute.js.map +1 -0
- package/lib/esm/Metadata/CustomAttributeClass.d.ts +44 -0
- package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -0
- package/lib/esm/Metadata/CustomAttributeClass.js +70 -0
- package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -0
- package/lib/esm/Metadata/EntityClass.d.ts +78 -0
- package/lib/esm/Metadata/EntityClass.d.ts.map +1 -0
- package/lib/esm/Metadata/EntityClass.js +224 -0
- package/lib/esm/Metadata/EntityClass.js.map +1 -0
- package/lib/esm/Metadata/Enumeration.d.ts +87 -0
- package/lib/esm/Metadata/Enumeration.d.ts.map +1 -0
- package/lib/esm/Metadata/Enumeration.js +155 -0
- package/lib/esm/Metadata/Enumeration.js.map +1 -0
- package/lib/esm/Metadata/Format.d.ts +99 -0
- package/lib/esm/Metadata/Format.d.ts.map +1 -0
- package/lib/esm/Metadata/Format.js +238 -0
- package/lib/esm/Metadata/Format.js.map +1 -0
- package/lib/esm/Metadata/InvertedUnit.d.ts +50 -0
- package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -0
- package/lib/esm/Metadata/InvertedUnit.js +93 -0
- package/lib/esm/Metadata/InvertedUnit.js.map +1 -0
- package/lib/esm/Metadata/KindOfQuantity.d.ts +72 -0
- package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -0
- package/lib/esm/Metadata/KindOfQuantity.js +229 -0
- package/lib/esm/Metadata/KindOfQuantity.js.map +1 -0
- package/lib/esm/Metadata/Mixin.d.ts +55 -0
- package/lib/esm/Metadata/Mixin.d.ts.map +1 -0
- package/lib/esm/Metadata/Mixin.js +109 -0
- package/lib/esm/Metadata/Mixin.js.map +1 -0
- package/lib/esm/Metadata/OverrideFormat.d.ts +68 -0
- package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -0
- package/lib/esm/Metadata/OverrideFormat.js +124 -0
- package/lib/esm/Metadata/OverrideFormat.js.map +1 -0
- package/lib/esm/Metadata/Phenomenon.d.ts +34 -0
- package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -0
- package/lib/esm/Metadata/Phenomenon.js +55 -0
- package/lib/esm/Metadata/Phenomenon.js.map +1 -0
- package/lib/esm/Metadata/Property.d.ts +247 -0
- package/lib/esm/Metadata/Property.d.ts.map +1 -0
- package/lib/esm/Metadata/Property.js +565 -0
- package/lib/esm/Metadata/Property.js.map +1 -0
- package/lib/esm/Metadata/PropertyCategory.d.ts +40 -0
- package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -0
- package/lib/esm/Metadata/PropertyCategory.js +57 -0
- package/lib/esm/Metadata/PropertyCategory.js.map +1 -0
- package/lib/esm/Metadata/RelationshipClass.d.ts +170 -0
- package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -0
- package/lib/esm/Metadata/RelationshipClass.js +380 -0
- package/lib/esm/Metadata/RelationshipClass.js.map +1 -0
- package/lib/esm/Metadata/Schema.d.ts +330 -0
- package/lib/esm/Metadata/Schema.d.ts.map +1 -0
- package/lib/esm/Metadata/Schema.js +570 -0
- package/lib/esm/Metadata/Schema.js.map +1 -0
- package/lib/esm/Metadata/SchemaItem.d.ts +67 -0
- package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -0
- package/lib/esm/Metadata/SchemaItem.js +140 -0
- package/lib/esm/Metadata/SchemaItem.js.map +1 -0
- package/lib/esm/Metadata/Unit.d.ts +77 -0
- package/lib/esm/Metadata/Unit.d.ts.map +1 -0
- package/lib/esm/Metadata/Unit.js +158 -0
- package/lib/esm/Metadata/Unit.js.map +1 -0
- package/lib/esm/Metadata/UnitSystem.d.ts +21 -0
- package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -0
- package/lib/esm/Metadata/UnitSystem.js +25 -0
- package/lib/esm/Metadata/UnitSystem.js.map +1 -0
- package/lib/esm/PropertyTypes.d.ts +50 -0
- package/lib/esm/PropertyTypes.d.ts.map +1 -0
- package/lib/esm/PropertyTypes.js +88 -0
- package/lib/esm/PropertyTypes.js.map +1 -0
- package/lib/esm/SchemaJsonLocater.d.ts +42 -0
- package/lib/esm/SchemaJsonLocater.d.ts.map +1 -0
- package/lib/esm/SchemaJsonLocater.js +54 -0
- package/lib/esm/SchemaJsonLocater.js.map +1 -0
- package/lib/esm/SchemaKey.d.ts +111 -0
- package/lib/esm/SchemaKey.d.ts.map +1 -0
- package/lib/esm/SchemaKey.js +214 -0
- package/lib/esm/SchemaKey.js.map +1 -0
- package/lib/esm/SchemaLoader.d.ts +32 -0
- package/lib/esm/SchemaLoader.d.ts.map +1 -0
- package/lib/esm/SchemaLoader.js +53 -0
- package/lib/esm/SchemaLoader.js.map +1 -0
- package/lib/esm/SchemaPartVisitorDelegate.d.ts +275 -0
- package/lib/esm/SchemaPartVisitorDelegate.d.ts.map +1 -0
- package/lib/esm/SchemaPartVisitorDelegate.js +209 -0
- package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -0
- package/lib/esm/UnitConversion/Graph.d.ts +35 -0
- package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
- package/lib/esm/UnitConversion/Graph.js +80 -0
- package/lib/esm/UnitConversion/Graph.js.map +1 -0
- package/lib/esm/UnitConversion/Parser.d.ts +9 -0
- package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
- package/lib/esm/UnitConversion/Parser.js +39 -0
- package/lib/esm/UnitConversion/Parser.js.map +1 -0
- package/lib/esm/UnitConversion/UnitConversion.d.ts +46 -0
- package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitConversion.js +74 -0
- package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
- package/lib/esm/UnitConversion/UnitConverter.d.ts +40 -0
- package/lib/esm/UnitConversion/UnitConverter.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitConverter.js +113 -0
- package/lib/esm/UnitConversion/UnitConverter.js.map +1 -0
- package/lib/esm/UnitConversion/UnitTree.d.ts +44 -0
- package/lib/esm/UnitConversion/UnitTree.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitTree.js +165 -0
- package/lib/esm/UnitConversion/UnitTree.js.map +1 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts +78 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts.map +1 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.js +231 -0
- package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -0
- package/lib/esm/Validation/SchemaWalker.d.ts +24 -0
- package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -0
- package/lib/esm/Validation/SchemaWalker.js +50 -0
- package/lib/esm/Validation/SchemaWalker.js.map +1 -0
- package/lib/esm/ecschema-metadata.d.ts +52 -0
- package/lib/esm/ecschema-metadata.d.ts.map +1 -0
- package/lib/esm/ecschema-metadata.js +55 -0
- package/lib/esm/ecschema-metadata.js.map +1 -0
- package/lib/esm/utils/SchemaGraph.d.ts +44 -0
- package/lib/esm/utils/SchemaGraph.d.ts.map +1 -0
- package/lib/esm/utils/SchemaGraph.js +111 -0
- package/lib/esm/utils/SchemaGraph.js.map +1 -0
- package/package.json +9 -7
|
@@ -0,0 +1,677 @@
|
|
|
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 { ECObjectsError, ECObjectsStatus } from "../Exception";
|
|
6
|
+
import { ECName } from "../ECName";
|
|
7
|
+
import { AbstractParser } from "./AbstractParser";
|
|
8
|
+
function isObject(x) {
|
|
9
|
+
return typeof (x) === "object";
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
export class JsonParser extends AbstractParser {
|
|
13
|
+
constructor(rawSchema) {
|
|
14
|
+
super();
|
|
15
|
+
if (!isObject(rawSchema))
|
|
16
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Invalid JSON object.`);
|
|
17
|
+
this._rawSchema = rawSchema;
|
|
18
|
+
this._schemaName = rawSchema.name;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Type checks Schema and returns SchemaProps interface
|
|
22
|
+
* @param this._rawSchema
|
|
23
|
+
* @returns SchemaProps
|
|
24
|
+
*/
|
|
25
|
+
parseSchema() {
|
|
26
|
+
if (undefined === this._rawSchema.name)
|
|
27
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `An ECSchema is missing the required 'name' attribute.`);
|
|
28
|
+
if (typeof (this._rawSchema.name) !== "string")
|
|
29
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `An ECSchema has an invalid 'name' attribute. It should be of type 'string'.`);
|
|
30
|
+
if (undefined === this._rawSchema.$schema)
|
|
31
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECSchema ${this._schemaName} is missing the required '$schema' attribute.`);
|
|
32
|
+
if (typeof (this._rawSchema.$schema) !== "string")
|
|
33
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECSchema ${this._schemaName} has an invalid '$schema' attribute. It should be of type 'string'.`);
|
|
34
|
+
if (undefined === this._rawSchema.version)
|
|
35
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECSchema ${this._schemaName} is missing the required 'version' attribute.`);
|
|
36
|
+
if (typeof (this._rawSchema.version) !== "string")
|
|
37
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECSchema ${this._schemaName} has an invalid 'version' attribute. It should be of type 'string'.`);
|
|
38
|
+
if (undefined !== this._rawSchema.alias) {
|
|
39
|
+
if (typeof (this._rawSchema.alias) !== "string")
|
|
40
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECSchema ${this._schemaName} has an invalid 'alias' attribute. It should be of type 'string'.`);
|
|
41
|
+
}
|
|
42
|
+
if (undefined !== this._rawSchema.label) {
|
|
43
|
+
if (typeof (this._rawSchema.label) !== "string")
|
|
44
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECSchema ${this._schemaName} has an invalid 'label' attribute. It should be of type 'string'.`);
|
|
45
|
+
}
|
|
46
|
+
if (undefined !== this._rawSchema.description) {
|
|
47
|
+
if (typeof (this._rawSchema.description) !== "string")
|
|
48
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECSchema ${this._schemaName} has an invalid 'description' attribute. It should be of type 'string'.`);
|
|
49
|
+
}
|
|
50
|
+
return this._rawSchema;
|
|
51
|
+
}
|
|
52
|
+
*getReferences() {
|
|
53
|
+
if (undefined !== this._rawSchema.references) {
|
|
54
|
+
if (!Array.isArray(this._rawSchema.references))
|
|
55
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._rawSchema.name} has an invalid 'references' attribute. It should be of type 'object[]'.`);
|
|
56
|
+
for (const ref of this._rawSchema.references) {
|
|
57
|
+
yield this.checkSchemaReference(ref);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
checkSchemaReference(jsonObj) {
|
|
62
|
+
if (!isObject(jsonObj))
|
|
63
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._schemaName} has an invalid 'references' attribute. It should be of type 'object[]'.`);
|
|
64
|
+
if (undefined === jsonObj.name)
|
|
65
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._schemaName} has an invalid 'references' attribute. One of the references is missing the required 'name' attribute.`);
|
|
66
|
+
if (typeof (jsonObj.name) !== "string")
|
|
67
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._schemaName} has an invalid 'references' attribute. One of the references has an invalid 'name' attribute. It should be of type 'string'.`);
|
|
68
|
+
if (undefined === jsonObj.version)
|
|
69
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._schemaName} has an invalid 'references' attribute. One of the references is missing the required 'version' attribute.`);
|
|
70
|
+
if (typeof (jsonObj.version) !== "string")
|
|
71
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._schemaName} has an invalid 'references' attribute. One of the references has an invalid 'version' attribute. It should be of type 'string'.`);
|
|
72
|
+
return jsonObj;
|
|
73
|
+
}
|
|
74
|
+
*getItems() {
|
|
75
|
+
const items = this._rawSchema.items;
|
|
76
|
+
if (undefined !== items) {
|
|
77
|
+
if (!isObject(items) || Array.isArray(items))
|
|
78
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._schemaName} has an invalid 'items' attribute. It should be of type 'object'.`);
|
|
79
|
+
// eslint-disable-next-line guard-for-in
|
|
80
|
+
for (const itemName in items) {
|
|
81
|
+
const item = items[itemName];
|
|
82
|
+
if (!isObject(item))
|
|
83
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `A SchemaItem in ${this._schemaName} is an invalid JSON object.`);
|
|
84
|
+
if (!ECName.validate(itemName))
|
|
85
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECName, `A SchemaItem in ${this._schemaName} has an invalid 'name' attribute. '${itemName}' is not a valid ECName.`);
|
|
86
|
+
if (undefined === item.schemaItemType)
|
|
87
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The SchemaItem ${this._schemaName}.${itemName} is missing the required 'schemaItemType' attribute.`);
|
|
88
|
+
if (typeof (item.schemaItemType) !== "string")
|
|
89
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The SchemaItem ${this._schemaName}.${itemName} has an invalid 'schemaItemType' attribute. It should be of type 'string'.`);
|
|
90
|
+
this._currentItemFullName = `${this._schemaName}.${itemName}`;
|
|
91
|
+
yield [itemName, item.schemaItemType, item];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
findItem(itemName) {
|
|
96
|
+
const items = this._rawSchema.items;
|
|
97
|
+
if (undefined !== items) {
|
|
98
|
+
if (!isObject(items) || Array.isArray(items))
|
|
99
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The schema ${this._schemaName} has an invalid 'items' attribute. It should be of type 'object'.`);
|
|
100
|
+
const item = items[itemName];
|
|
101
|
+
if (undefined !== item) {
|
|
102
|
+
if (!isObject(item))
|
|
103
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `A SchemaItem in ${this._schemaName} is an invalid JSON object.`);
|
|
104
|
+
if (!ECName.validate(itemName))
|
|
105
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECName, `A SchemaItem in ${this._schemaName} has an invalid 'name' attribute. '${itemName}' is not a valid ECName.`);
|
|
106
|
+
if (undefined === item.schemaItemType)
|
|
107
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The SchemaItem ${this._schemaName}.${itemName} is missing the required 'schemaItemType' attribute.`);
|
|
108
|
+
if (typeof (item.schemaItemType) !== "string")
|
|
109
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The SchemaItem ${this._schemaName}.${itemName} has an invalid 'schemaItemType' attribute. It should be of type 'string'.`);
|
|
110
|
+
this._currentItemFullName = `${this._schemaName}.${itemName}`;
|
|
111
|
+
return [itemName, item.schemaItemType, item];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Type checks all Schema Item attributes.
|
|
118
|
+
* @param jsonObj The JSON object to check if it represents a Schema Item.
|
|
119
|
+
*/
|
|
120
|
+
checkSchemaItemProps(jsonObj) {
|
|
121
|
+
if (undefined !== jsonObj.description) {
|
|
122
|
+
if (typeof (jsonObj.description) !== "string")
|
|
123
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The SchemaItem ${this._currentItemFullName} has an invalid 'description' attribute. It should be of type 'string'.`);
|
|
124
|
+
}
|
|
125
|
+
if (undefined !== jsonObj.label) {
|
|
126
|
+
if (typeof (jsonObj.label) !== "string")
|
|
127
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The SchemaItem ${this._currentItemFullName} has an invalid 'label' attribute. It should be of type 'string'.`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
*getProperties(jsonObj, itemName) {
|
|
131
|
+
const properties = jsonObj.properties;
|
|
132
|
+
if (undefined !== properties) {
|
|
133
|
+
if (!Array.isArray(properties))
|
|
134
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECClass ${itemName} has an invalid 'properties' attribute. It should be of type 'object[]'.`);
|
|
135
|
+
for (const property of properties) {
|
|
136
|
+
if (!isObject(property))
|
|
137
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `An ECProperty in ${itemName} is an invalid JSON object.`);
|
|
138
|
+
if (undefined === property.name)
|
|
139
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `An ECProperty in ${itemName} is missing the required 'name' attribute.`);
|
|
140
|
+
if (typeof (property.name) !== "string")
|
|
141
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `An ECProperty in ${itemName} has an invalid 'name' attribute. It should be of type 'string'.`);
|
|
142
|
+
if (undefined === property.type)
|
|
143
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${itemName}.${property.name} does not have the required 'type' attribute.`);
|
|
144
|
+
if (typeof (property.type) !== "string")
|
|
145
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${itemName}.${property.name} has an invalid 'type' attribute. It should be of type 'string'.`);
|
|
146
|
+
if (!this.isValidPropertyType(property.type))
|
|
147
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${itemName}.${property.name} has an invalid 'type' attribute. '${property.type}' is not a valid type.`);
|
|
148
|
+
yield [property.name, property.type, property];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Type checks Class and returns ClassProps interface
|
|
154
|
+
* @param jsonObj The JSON object to check if it represents a Class.
|
|
155
|
+
*/
|
|
156
|
+
checkClassProps(jsonObj) {
|
|
157
|
+
this.checkSchemaItemProps(jsonObj);
|
|
158
|
+
if (undefined !== jsonObj.modifier) {
|
|
159
|
+
if (typeof (jsonObj.modifier) !== "string")
|
|
160
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECClass ${this._currentItemFullName} has an invalid 'modifier' attribute. It should be of type 'string'.`);
|
|
161
|
+
}
|
|
162
|
+
if (undefined !== jsonObj.baseClass) {
|
|
163
|
+
if (typeof (jsonObj.baseClass) !== "string")
|
|
164
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECClass ${this._currentItemFullName} has an invalid 'baseClass' attribute. It should be of type 'string'.`);
|
|
165
|
+
}
|
|
166
|
+
if (undefined !== jsonObj.customAttributes) {
|
|
167
|
+
if (!Array.isArray(jsonObj.customAttributes)) {
|
|
168
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECClass ${this._currentItemFullName} has an invalid 'customAttributes' attribute. It should be of type 'array'.`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Type checks entity class and returns EntityClassProps interface
|
|
174
|
+
* @param jsonObj
|
|
175
|
+
* @returns EntityClassProps
|
|
176
|
+
*/
|
|
177
|
+
parseEntityClass(jsonObj) {
|
|
178
|
+
this.checkClassProps(jsonObj);
|
|
179
|
+
if (undefined !== jsonObj.mixins) {
|
|
180
|
+
if (!Array.isArray(jsonObj.mixins))
|
|
181
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this._currentItemFullName} has an invalid 'mixins' attribute. It should be of type 'string[]'.`);
|
|
182
|
+
for (const mixinName of jsonObj.mixins) {
|
|
183
|
+
if (typeof (mixinName) !== "string")
|
|
184
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this._currentItemFullName} has an invalid 'mixins' attribute. It should be of type 'string[]'.`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return jsonObj;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Type checks mixin and returns MixinProps interface
|
|
191
|
+
* @param jsonObj
|
|
192
|
+
* @returns MixinProps
|
|
193
|
+
*/
|
|
194
|
+
parseMixin(jsonObj) {
|
|
195
|
+
this.checkClassProps(jsonObj);
|
|
196
|
+
if (undefined === jsonObj.appliesTo)
|
|
197
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Mixin ${this._currentItemFullName} is missing the required 'appliesTo' attribute.`);
|
|
198
|
+
if (typeof (jsonObj.appliesTo) !== "string")
|
|
199
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Mixin ${this._currentItemFullName} has an invalid 'appliesTo' attribute. It should be of type 'string'.`);
|
|
200
|
+
return jsonObj;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Type checks custom attribute class and returns CustomAttributeClassProps interface
|
|
204
|
+
* @param jsonObj
|
|
205
|
+
* @returns CustomAttributeClassProps
|
|
206
|
+
*/
|
|
207
|
+
parseCustomAttributeClass(jsonObj) {
|
|
208
|
+
this.checkClassProps(jsonObj);
|
|
209
|
+
if (undefined === jsonObj.appliesTo)
|
|
210
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The CustomAttributeClass ${this._currentItemFullName} is missing the required 'appliesTo' attribute.`);
|
|
211
|
+
if (typeof (jsonObj.appliesTo) !== "string")
|
|
212
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The CustomAttributeClass ${this._currentItemFullName} has an invalid 'appliesTo' attribute. It should be of type 'string'.`);
|
|
213
|
+
return jsonObj;
|
|
214
|
+
}
|
|
215
|
+
parseStructClass(jsonObj) {
|
|
216
|
+
this.checkClassProps(jsonObj);
|
|
217
|
+
return jsonObj;
|
|
218
|
+
}
|
|
219
|
+
parseUnitSystem(jsonObj) {
|
|
220
|
+
this.checkSchemaItemProps(jsonObj);
|
|
221
|
+
return jsonObj;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Type checks Relationship Class and returns RelationshipClassProps interface
|
|
225
|
+
* @param jsonObj
|
|
226
|
+
* @returns RelationshipClassProps
|
|
227
|
+
*/
|
|
228
|
+
parseRelationshipClass(jsonObj) {
|
|
229
|
+
this.checkClassProps(jsonObj);
|
|
230
|
+
if (undefined === jsonObj.strength)
|
|
231
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} is missing the required 'strength' attribute.`);
|
|
232
|
+
if (typeof (jsonObj.strength) !== "string")
|
|
233
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} has an invalid 'strength' attribute. It should be of type 'string'.`);
|
|
234
|
+
if (undefined === jsonObj.strengthDirection)
|
|
235
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} is missing the required 'strengthDirection' attribute.`);
|
|
236
|
+
if (typeof (jsonObj.strengthDirection) !== "string")
|
|
237
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} has an invalid 'strengthDirection' attribute. It should be of type 'string'.`);
|
|
238
|
+
if (undefined === jsonObj.source)
|
|
239
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} is missing the required source constraint.`);
|
|
240
|
+
if (!isObject(jsonObj.source))
|
|
241
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} has an invalid source constraint. It should be of type 'object'.`);
|
|
242
|
+
this.checkRelationshipConstraintProps(jsonObj.source, true);
|
|
243
|
+
if (undefined === jsonObj.target)
|
|
244
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} is missing the required target constraint.`);
|
|
245
|
+
if (!isObject(jsonObj.target))
|
|
246
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The RelationshipClass ${this._currentItemFullName} has an invalid target constraint. It should be of type 'object'.`);
|
|
247
|
+
this.checkRelationshipConstraintProps(jsonObj.target, false);
|
|
248
|
+
return jsonObj;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Type checks Relationship Constraint and returns RelationshipConstraintProps interface.
|
|
252
|
+
* @param jsonObj
|
|
253
|
+
* @param isSource For sake of error message, is this relationship constraint a source or target
|
|
254
|
+
* @returns RelationshipConstraintProps
|
|
255
|
+
*/
|
|
256
|
+
checkRelationshipConstraintProps(jsonObj, isSource) {
|
|
257
|
+
const constraintName = `${(isSource) ? "Source" : "Target"} Constraint of ${this._currentItemFullName}`; // most specific name to call RelationshipConstraint
|
|
258
|
+
if (undefined === jsonObj.multiplicity)
|
|
259
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} is missing the required 'multiplicity' attribute.`);
|
|
260
|
+
if (typeof (jsonObj.multiplicity) !== "string")
|
|
261
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} has an invalid 'multiplicity' attribute. It should be of type 'string'.`);
|
|
262
|
+
if (undefined === jsonObj.roleLabel)
|
|
263
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} is missing the required 'roleLabel' attribute.`);
|
|
264
|
+
if (typeof (jsonObj.roleLabel) !== "string")
|
|
265
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} has an invalid 'roleLabel' attribute. It should be of type 'string'.`);
|
|
266
|
+
if (undefined === jsonObj.polymorphic)
|
|
267
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} is missing the required 'polymorphic' attribute.`);
|
|
268
|
+
if (typeof (jsonObj.polymorphic) !== "boolean")
|
|
269
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} has an invalid 'polymorphic' attribute. It should be of type 'boolean'.`);
|
|
270
|
+
if (undefined !== jsonObj.abstractConstraint && typeof (jsonObj.abstractConstraint) !== "string")
|
|
271
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} has an invalid 'abstractConstraint' attribute. It should be of type 'string'.`);
|
|
272
|
+
if (undefined === jsonObj.constraintClasses)
|
|
273
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} is missing the required 'constraintClasses' attribute.`);
|
|
274
|
+
if (!Array.isArray(jsonObj.constraintClasses))
|
|
275
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} has an invalid 'constraintClasses' attribute. It should be of type 'string[]'.`);
|
|
276
|
+
for (const constraintClassName of jsonObj.constraintClasses) {
|
|
277
|
+
if (typeof (constraintClassName) !== "string")
|
|
278
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} has an invalid 'constraintClasses' attribute. It should be of type 'string[]'.`);
|
|
279
|
+
}
|
|
280
|
+
if (undefined !== jsonObj.customAttributes && !Array.isArray(jsonObj.customAttributes))
|
|
281
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${constraintName} has an invalid 'customAttributes' attribute. It should be of type 'array'.`);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Type checks Enumeration and returns EnumerationProps interface
|
|
285
|
+
* @param jsonObj
|
|
286
|
+
* @returns EnumerationProps
|
|
287
|
+
*/
|
|
288
|
+
parseEnumeration(jsonObj) {
|
|
289
|
+
this.checkSchemaItemProps(jsonObj);
|
|
290
|
+
if (undefined === jsonObj.type)
|
|
291
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} is missing the required 'type' attribute.`);
|
|
292
|
+
if (typeof (jsonObj.type) !== "string")
|
|
293
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an invalid 'type' attribute. It should be of type 'string'.`);
|
|
294
|
+
const isValidEnumerationType = (type) => {
|
|
295
|
+
type = type.toLowerCase();
|
|
296
|
+
return (type === "int") ||
|
|
297
|
+
(type === "integer") ||
|
|
298
|
+
(type === "string");
|
|
299
|
+
};
|
|
300
|
+
if (!isValidEnumerationType(jsonObj.type))
|
|
301
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an invalid 'type' attribute. It should be either "int" or "string".`);
|
|
302
|
+
if (undefined !== jsonObj.isStrict) { // TODO: make required
|
|
303
|
+
if (typeof (jsonObj.isStrict) !== "boolean")
|
|
304
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an invalid 'isStrict' attribute. It should be of type 'boolean'.`);
|
|
305
|
+
}
|
|
306
|
+
if (undefined === jsonObj.enumerators)
|
|
307
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} is missing the required 'enumerators' attribute.`);
|
|
308
|
+
if (!Array.isArray(jsonObj.enumerators))
|
|
309
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an invalid 'enumerators' attribute. It should be of type 'object[]'.`);
|
|
310
|
+
for (const enumerator of jsonObj.enumerators) {
|
|
311
|
+
if (!isObject(enumerator))
|
|
312
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an invalid 'enumerators' attribute. It should be of type 'object[]'.`);
|
|
313
|
+
if (undefined === enumerator.value)
|
|
314
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an enumerator that is missing the required attribute 'value'.`);
|
|
315
|
+
// TODO: Should this really be handled here?
|
|
316
|
+
const expectedType = jsonObj.type;
|
|
317
|
+
const receivedType = (typeof (enumerator.value) === "number") ? "int" : typeof (enumerator.value);
|
|
318
|
+
if (!expectedType.includes(receivedType)) // is receivedType a substring of expectedType? - easiest way to check "int" === "int" | "integer" && "string" === "string"
|
|
319
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an incompatible type. It must be "${expectedType}", not "${receivedType}".`);
|
|
320
|
+
if (undefined === enumerator.name)
|
|
321
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an enumerator that is missing the required attribute 'name'.`);
|
|
322
|
+
if (typeof (enumerator.name) !== "string")
|
|
323
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an enumerator with an invalid 'name' attribute. It should be of type 'string'.`);
|
|
324
|
+
if (undefined !== enumerator.label) {
|
|
325
|
+
if (typeof (enumerator.label) !== "string")
|
|
326
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an enumerator with an invalid 'label' attribute. It should be of type 'string'.`);
|
|
327
|
+
}
|
|
328
|
+
if (undefined !== enumerator.description) {
|
|
329
|
+
if (typeof (enumerator.description) !== "string")
|
|
330
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an enumerator with an invalid 'description' attribute. It should be of type 'string'.`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return jsonObj;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Type checks KindOfQuantity and returns KindOfQuantityProps interface
|
|
337
|
+
* @param jsonObj
|
|
338
|
+
* @returns KindOfQuantityProps
|
|
339
|
+
*/
|
|
340
|
+
parseKindOfQuantity(jsonObj) {
|
|
341
|
+
this.checkSchemaItemProps(jsonObj);
|
|
342
|
+
if (undefined === jsonObj.relativeError)
|
|
343
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The KindOfQuantity ${this._currentItemFullName} is missing the required 'relativeError' attribute.`);
|
|
344
|
+
if (typeof (jsonObj.relativeError) !== "number")
|
|
345
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The KindOfQuantity ${this._currentItemFullName} has an invalid 'relativeError' attribute. It should be of type 'number'.`);
|
|
346
|
+
if (undefined !== jsonObj.presentationUnits) {
|
|
347
|
+
if (!Array.isArray(jsonObj.presentationUnits) && typeof (jsonObj.presentationUnits) !== "string")
|
|
348
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The KindOfQuantity ${this._currentItemFullName} has an invalid 'presentationUnits' attribute. It should be of type 'string' or 'string[]'.`);
|
|
349
|
+
}
|
|
350
|
+
if (undefined === jsonObj.persistenceUnit)
|
|
351
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The KindOfQuantity ${this._currentItemFullName} is missing the required 'persistenceUnit' attribute.`);
|
|
352
|
+
if (typeof (jsonObj.persistenceUnit) !== "string")
|
|
353
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The KindOfQuantity ${this._currentItemFullName} has an invalid 'persistenceUnit' attribute. It should be of type 'string'.`);
|
|
354
|
+
return jsonObj;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Type checks Property Category and returns PropertyCategoryProps interface
|
|
358
|
+
* @param jsonObj
|
|
359
|
+
* @returns PropertyCategoryProps
|
|
360
|
+
*/
|
|
361
|
+
parsePropertyCategory(jsonObj) {
|
|
362
|
+
this.checkSchemaItemProps(jsonObj);
|
|
363
|
+
if (undefined !== jsonObj.priority) { // TODO: make required
|
|
364
|
+
if (typeof (jsonObj.priority) !== "number")
|
|
365
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The PropertyCategory ${this._currentItemFullName} has an invalid 'priority' attribute. It should be of type 'number'.`);
|
|
366
|
+
}
|
|
367
|
+
return jsonObj;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Type checks unit and returns UnitProps interface
|
|
371
|
+
* @param jsonObj
|
|
372
|
+
* @returns UnitProps
|
|
373
|
+
*/
|
|
374
|
+
parseUnit(jsonObj) {
|
|
375
|
+
this.checkSchemaItemProps(jsonObj);
|
|
376
|
+
if (undefined === jsonObj.phenomenon)
|
|
377
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} does not have the required 'phenomenon' attribute.`);
|
|
378
|
+
if (typeof (jsonObj.phenomenon) !== "string")
|
|
379
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} has an invalid 'phenomenon' attribute. It should be of type 'string'.`);
|
|
380
|
+
if (undefined === jsonObj.unitSystem)
|
|
381
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} does not have the required 'unitSystem' attribute.`);
|
|
382
|
+
if (typeof (jsonObj.unitSystem) !== "string")
|
|
383
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} has an invalid 'unitSystem' attribute. It should be of type 'string'.`);
|
|
384
|
+
if (undefined === jsonObj.definition)
|
|
385
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} does not have the required 'definition' attribute.`);
|
|
386
|
+
if (typeof (jsonObj.definition) !== "string")
|
|
387
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} has an invalid 'definition' attribute. It should be of type 'string'.`);
|
|
388
|
+
if (undefined !== jsonObj.numerator) {
|
|
389
|
+
if (typeof (jsonObj.numerator) !== "number")
|
|
390
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} has an invalid 'numerator' attribute. It should be of type 'number'.`);
|
|
391
|
+
}
|
|
392
|
+
if (undefined !== jsonObj.denominator) {
|
|
393
|
+
if (typeof (jsonObj.denominator) !== "number")
|
|
394
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} has an invalid 'denominator' attribute. It should be of type 'number'.`);
|
|
395
|
+
}
|
|
396
|
+
if (undefined !== jsonObj.offset) {
|
|
397
|
+
if (typeof (jsonObj.offset) !== "number")
|
|
398
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this._currentItemFullName} has an invalid 'offset' attribute. It should be of type 'number'.`);
|
|
399
|
+
}
|
|
400
|
+
return jsonObj;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Type checks inverted unit and returns InvertedUnitProps interface
|
|
404
|
+
* @param jsonObj
|
|
405
|
+
* @returns InvertedUnitProps
|
|
406
|
+
*/
|
|
407
|
+
parseInvertedUnit(jsonObj) {
|
|
408
|
+
this.checkSchemaItemProps(jsonObj);
|
|
409
|
+
if (undefined === jsonObj.invertsUnit)
|
|
410
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The InvertedUnit ${this._currentItemFullName} does not have the required 'invertsUnit' attribute.`);
|
|
411
|
+
if (typeof (jsonObj.invertsUnit) !== "string")
|
|
412
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The InvertedUnit ${this._currentItemFullName} has an invalid 'invertsUnit' attribute. It should be of type 'string'.`);
|
|
413
|
+
if (undefined === jsonObj.unitSystem)
|
|
414
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The InvertedUnit ${this._currentItemFullName} does not have the required 'unitSystem' attribute.`);
|
|
415
|
+
if (typeof (jsonObj.unitSystem) !== "string")
|
|
416
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The InvertedUnit ${this._currentItemFullName} has an invalid 'unitSystem' attribute. It should be of type 'string'.`);
|
|
417
|
+
return jsonObj;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Type checks constant and returns ConstantProps interface
|
|
421
|
+
* @param jsonObj
|
|
422
|
+
* @returns ConstantProps
|
|
423
|
+
*/
|
|
424
|
+
parseConstant(jsonObj) {
|
|
425
|
+
this.checkSchemaItemProps(jsonObj);
|
|
426
|
+
if (undefined === jsonObj.phenomenon)
|
|
427
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Constant ${this._currentItemFullName} does not have the required 'phenomenon' attribute.`);
|
|
428
|
+
if (typeof (jsonObj.phenomenon) !== "string")
|
|
429
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Constant ${this._currentItemFullName} has an invalid 'phenomenon' attribute. It should be of type 'string'.`);
|
|
430
|
+
if (undefined === jsonObj.definition)
|
|
431
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Constant ${this._currentItemFullName} does not have the required 'definition' attribute.`);
|
|
432
|
+
if (typeof (jsonObj.definition) !== "string")
|
|
433
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Constant ${this._currentItemFullName} has an invalid 'definition' attribute. It should be of type 'string'.`);
|
|
434
|
+
if (undefined !== jsonObj.numerator) {
|
|
435
|
+
if (typeof (jsonObj.numerator) !== "number")
|
|
436
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Constant ${this._currentItemFullName} has an invalid 'numerator' attribute. It should be of type 'number'.`);
|
|
437
|
+
}
|
|
438
|
+
if (undefined !== jsonObj.denominator) {
|
|
439
|
+
if (typeof (jsonObj.denominator) !== "number")
|
|
440
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Constant ${this._currentItemFullName} has an invalid 'denominator' attribute. It should be of type 'number'.`);
|
|
441
|
+
}
|
|
442
|
+
return jsonObj;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Type checks phenomenon and returns PhenomenonProps interface
|
|
446
|
+
* @param jsonObj
|
|
447
|
+
* @returns PhenomenonProps
|
|
448
|
+
*/
|
|
449
|
+
parsePhenomenon(jsonObj) {
|
|
450
|
+
this.checkSchemaItemProps(jsonObj);
|
|
451
|
+
if (undefined === jsonObj.definition)
|
|
452
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Phenomenon ${this._currentItemFullName} does not have the required 'definition' attribute.`);
|
|
453
|
+
if (typeof (jsonObj.definition) !== "string")
|
|
454
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Phenomenon ${this._currentItemFullName} has an invalid 'definition' attribute. It should be of type 'string'.`);
|
|
455
|
+
return jsonObj;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Type checks format and returns SchemaItemFormatProps interface
|
|
459
|
+
* @param jsonObj
|
|
460
|
+
* @returns SchemaItemFormatProps
|
|
461
|
+
*/
|
|
462
|
+
parseFormat(jsonObj) {
|
|
463
|
+
this.checkSchemaItemProps(jsonObj);
|
|
464
|
+
if (undefined === jsonObj.type)
|
|
465
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} does not have the required 'type' attribute.`);
|
|
466
|
+
if (typeof (jsonObj.type) !== "string")
|
|
467
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'type' attribute. It should be of type 'string'.`);
|
|
468
|
+
if (undefined !== jsonObj.precision && typeof (jsonObj.precision) !== "number")
|
|
469
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'precision' attribute. It should be of type 'number'.`);
|
|
470
|
+
if (undefined !== jsonObj.roundFactor && typeof (jsonObj.roundFactor) !== "number")
|
|
471
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'roundFactor' attribute. It should be of type 'number'.`);
|
|
472
|
+
if (undefined !== jsonObj.minWidth && typeof (jsonObj.minWidth) !== "number")
|
|
473
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'minWidth' attribute. It should be of type 'number'.`);
|
|
474
|
+
if (undefined !== jsonObj.showSignOption && typeof (jsonObj.showSignOption) !== "string")
|
|
475
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'showSignOption' attribute. It should be of type 'string'.`);
|
|
476
|
+
if (undefined !== jsonObj.formatTraits) {
|
|
477
|
+
if (!Array.isArray(jsonObj.formatTraits) && typeof (jsonObj.formatTraits) !== "string") // must be either an array of strings or a string
|
|
478
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'formatTraits' attribute. It should be of type 'string' or 'string[]'.`);
|
|
479
|
+
}
|
|
480
|
+
if (undefined !== jsonObj.decimalSeparator && typeof (jsonObj.decimalSeparator) !== "string")
|
|
481
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'decimalSeparator' attribute. It should be of type 'string'.`);
|
|
482
|
+
if (undefined !== jsonObj.thousandSeparator && typeof (jsonObj.thousandSeparator) !== "string")
|
|
483
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'thousandSeparator' attribute. It should be of type 'string'.`);
|
|
484
|
+
if (undefined !== jsonObj.uomSeparator && typeof (jsonObj.uomSeparator) !== "string")
|
|
485
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'uomSeparator' attribute. It should be of type 'string'.`);
|
|
486
|
+
if (undefined !== jsonObj.scientificType && typeof (jsonObj.scientificType) !== "string")
|
|
487
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'scientificType' attribute. It should be of type 'string'.`);
|
|
488
|
+
if (undefined !== jsonObj.stationOffsetSize && typeof (jsonObj.stationOffsetSize) !== "number")
|
|
489
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'stationOffsetSize' attribute. It should be of type 'number'.`);
|
|
490
|
+
if (undefined !== jsonObj.stationSeparator && typeof (jsonObj.stationSeparator) !== "string")
|
|
491
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'stationSeparator' attribute. It should be of type 'string'.`);
|
|
492
|
+
if (undefined !== jsonObj.composite) { // optional
|
|
493
|
+
if (!isObject(jsonObj.composite))
|
|
494
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'composite' object.`);
|
|
495
|
+
if (undefined !== jsonObj.composite.includeZero && typeof (jsonObj.composite.includeZero) !== "boolean")
|
|
496
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has a Composite with an invalid 'includeZero' attribute. It should be of type 'boolean'.`);
|
|
497
|
+
if (undefined !== jsonObj.composite.spacer && typeof (jsonObj.composite.spacer) !== "string")
|
|
498
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has a Composite with an invalid 'spacer' attribute. It should be of type 'string'.`);
|
|
499
|
+
// if composite is defined
|
|
500
|
+
if (undefined === jsonObj.composite.units)
|
|
501
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);
|
|
502
|
+
if (!Array.isArray(jsonObj.composite.units))
|
|
503
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has a Composite with an invalid 'units' attribute. It should be of type 'object[]'.`);
|
|
504
|
+
for (let i = 0; i < jsonObj.composite.units.length; i++) {
|
|
505
|
+
if (!isObject(jsonObj.composite.units[i]))
|
|
506
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has a Composite with an invalid 'units' attribute. It should be of type 'object[]'.`);
|
|
507
|
+
if (undefined === jsonObj.composite.units[i].name) // required
|
|
508
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has a Composite with an invalid 'units' attribute. The object at position ${i} is missing the required 'name' attribute.`);
|
|
509
|
+
if (typeof (jsonObj.composite.units[i].name) !== "string")
|
|
510
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has a Composite with an invalid 'units' attribute. The object at position ${i} has an invalid 'name' attribute. It should be of type 'string'.`);
|
|
511
|
+
if (undefined !== jsonObj.composite.units[i].label && typeof (jsonObj.composite.units[i].label) !== "string")
|
|
512
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this._currentItemFullName} has a Composite with an invalid 'units' attribute. The object at position ${i} has an invalid 'label' attribute. It should be of type 'string'.`);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return jsonObj;
|
|
516
|
+
}
|
|
517
|
+
isValidPropertyType(type) {
|
|
518
|
+
type = type.toLowerCase();
|
|
519
|
+
return (type === "primitiveproperty") ||
|
|
520
|
+
(type === "structproperty") ||
|
|
521
|
+
(type === "primitivearrayproperty") ||
|
|
522
|
+
(type === "structarrayproperty") ||
|
|
523
|
+
(type === "navigationproperty");
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Type checks property and returns PropertyProps interface
|
|
527
|
+
* @param jsonObj
|
|
528
|
+
* @returns PropertyProps
|
|
529
|
+
*/
|
|
530
|
+
checkPropertyProps(jsonObj) {
|
|
531
|
+
const propName = jsonObj.name;
|
|
532
|
+
if (undefined !== jsonObj.label && typeof (jsonObj.label) !== "string")
|
|
533
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'label' attribute. It should be of type 'string'.`);
|
|
534
|
+
if (undefined !== jsonObj.description && typeof (jsonObj.description) !== "string")
|
|
535
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'description' attribute. It should be of type 'string'.`);
|
|
536
|
+
if (undefined !== jsonObj.priority && typeof (jsonObj.priority) !== "number")
|
|
537
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'priority' attribute. It should be of type 'number'.`);
|
|
538
|
+
if (undefined !== jsonObj.isReadOnly && typeof (jsonObj.isReadOnly) !== "boolean")
|
|
539
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'isReadOnly' attribute. It should be of type 'boolean'.`);
|
|
540
|
+
if (undefined !== jsonObj.category && typeof (jsonObj.category) !== "string")
|
|
541
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'category' attribute. It should be of type 'string'.`);
|
|
542
|
+
if (undefined !== jsonObj.kindOfQuantity && typeof (jsonObj.kindOfQuantity) !== "string")
|
|
543
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'kindOfQuantity' attribute. It should be of type 'string'.`);
|
|
544
|
+
if (undefined !== jsonObj.inherited && typeof (jsonObj.inherited) !== "boolean")
|
|
545
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'inherited' attribute. It should be of type 'boolean'.`);
|
|
546
|
+
if (undefined !== jsonObj.customAttributes && !Array.isArray(jsonObj.customAttributes))
|
|
547
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'customAttributes' attribute. It should be of type 'array'.`);
|
|
548
|
+
return jsonObj;
|
|
549
|
+
}
|
|
550
|
+
checkPropertyTypename(jsonObj) {
|
|
551
|
+
const propName = jsonObj.name;
|
|
552
|
+
if (undefined === jsonObj.typeName)
|
|
553
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} is missing the required 'typeName' attribute.`);
|
|
554
|
+
if (typeof (jsonObj.typeName) !== "string")
|
|
555
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'typeName' attribute. It should be of type 'string'.`);
|
|
556
|
+
}
|
|
557
|
+
checkPropertyMinAndMaxOccurs(jsonObj) {
|
|
558
|
+
const propName = jsonObj.name;
|
|
559
|
+
if (undefined !== jsonObj.minOccurs && typeof (jsonObj.minOccurs) !== "number")
|
|
560
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'minOccurs' attribute. It should be of type 'number'.`);
|
|
561
|
+
if (undefined !== jsonObj.maxOccurs && typeof (jsonObj.maxOccurs) !== "number")
|
|
562
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'maxOccurs' attribute. It should be of type 'number'.`);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Type checks PrimitiveOrEnumProperty and returns PrimitiveOrEnumPropertyBaseProps interface
|
|
566
|
+
* @param jsonObj
|
|
567
|
+
* @returns PrimitiveOrEnumPropertyBaseProps
|
|
568
|
+
*/
|
|
569
|
+
checkPrimitiveOrEnumPropertyBaseProps(jsonObj) {
|
|
570
|
+
this.checkPropertyProps(jsonObj);
|
|
571
|
+
this.checkPropertyTypename(jsonObj);
|
|
572
|
+
const propName = jsonObj.name;
|
|
573
|
+
if (undefined !== jsonObj.minLength && typeof (jsonObj.minLength) !== "number")
|
|
574
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'minLength' attribute. It should be of type 'number'.`);
|
|
575
|
+
if (undefined !== jsonObj.maxLength && typeof (jsonObj.maxLength) !== "number")
|
|
576
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'maxLength' attribute. It should be of type 'number'.`);
|
|
577
|
+
if (undefined !== jsonObj.minValue && typeof (jsonObj.minValue) !== "number")
|
|
578
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'minValue' attribute. It should be of type 'number'.`);
|
|
579
|
+
if (undefined !== jsonObj.maxValue && typeof (jsonObj.maxValue) !== "number")
|
|
580
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'maxValue' attribute. It should be of type 'number'.`);
|
|
581
|
+
if (undefined !== jsonObj.extendedTypeName && typeof (jsonObj.extendedTypeName) !== "string")
|
|
582
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'extendedTypeName' attribute. It should be of type 'string'.`);
|
|
583
|
+
return jsonObj;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Type checks PrimitiveProperty and returns PrimitivePropertyProps interface
|
|
587
|
+
* @param jsonObj
|
|
588
|
+
* @returns PrimitivePropertyProps
|
|
589
|
+
*/
|
|
590
|
+
parsePrimitiveProperty(jsonObj) {
|
|
591
|
+
this.checkPrimitiveOrEnumPropertyBaseProps(jsonObj);
|
|
592
|
+
return jsonObj;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Type checks StructProperty and returns StructPropertyProps interface
|
|
596
|
+
* @param jsonObj
|
|
597
|
+
* @returns StructPropertyProps
|
|
598
|
+
*/
|
|
599
|
+
parseStructProperty(jsonObj) {
|
|
600
|
+
this.checkPropertyProps(jsonObj);
|
|
601
|
+
this.checkPropertyTypename(jsonObj);
|
|
602
|
+
return jsonObj;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Type checks PrimitiveArrayProperty and returns PrimitiveArrayPropertyProps interface
|
|
606
|
+
* @param jsonObj
|
|
607
|
+
* @returns PrimitiveArrayPropertyProps
|
|
608
|
+
*/
|
|
609
|
+
parsePrimitiveArrayProperty(jsonObj) {
|
|
610
|
+
this.checkPrimitiveOrEnumPropertyBaseProps(jsonObj);
|
|
611
|
+
this.checkPropertyMinAndMaxOccurs(jsonObj);
|
|
612
|
+
return jsonObj;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Type checks StructArrayProperty and returns StructArrayPropertyProps interface
|
|
616
|
+
* @param jsonObj
|
|
617
|
+
* @returns StructArrayPropertyProps
|
|
618
|
+
*/
|
|
619
|
+
parseStructArrayProperty(jsonObj) {
|
|
620
|
+
this.checkPropertyProps(jsonObj);
|
|
621
|
+
this.checkPropertyTypename(jsonObj);
|
|
622
|
+
this.checkPropertyMinAndMaxOccurs(jsonObj);
|
|
623
|
+
return jsonObj;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Type checks NavigationProperty and returns NavigationPropertyProps interface
|
|
627
|
+
* @param jsonObj
|
|
628
|
+
* @returns NavigationPropertyProps
|
|
629
|
+
*/
|
|
630
|
+
parseNavigationProperty(jsonObj) {
|
|
631
|
+
this.checkPropertyProps(jsonObj);
|
|
632
|
+
const fullname = `${this._currentItemFullName}.${jsonObj.name}`;
|
|
633
|
+
if (undefined === jsonObj.relationshipName)
|
|
634
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Navigation Property ${fullname} is missing the required 'relationshipName' property.`);
|
|
635
|
+
if (typeof (jsonObj.relationshipName) !== "string")
|
|
636
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Navigation Property ${fullname} has an invalid 'relationshipName' property. It should be of type 'string'.`);
|
|
637
|
+
if (undefined === jsonObj.direction)
|
|
638
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Navigation Property ${fullname} is missing the required 'direction' property.`);
|
|
639
|
+
if (typeof (jsonObj.direction) !== "string")
|
|
640
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Navigation Property ${fullname} has an invalid 'direction' property. It should be of type 'string'.`);
|
|
641
|
+
return jsonObj;
|
|
642
|
+
}
|
|
643
|
+
getSchemaCustomAttributeProviders() {
|
|
644
|
+
return this.getCustomAttributeProviders(this._rawSchema, "Schema", this._schemaName);
|
|
645
|
+
}
|
|
646
|
+
getClassCustomAttributeProviders(jsonObj) {
|
|
647
|
+
return this.getCustomAttributeProviders(jsonObj, "ECClass", this._currentItemFullName);
|
|
648
|
+
}
|
|
649
|
+
getPropertyCustomAttributeProviders(jsonObj) {
|
|
650
|
+
return this.getCustomAttributeProviders(jsonObj, "ECProperty", `${this._currentItemFullName}.${jsonObj.name}`);
|
|
651
|
+
}
|
|
652
|
+
getRelationshipConstraintCustomAttributeProviders(jsonObj) {
|
|
653
|
+
const sourceCustomAttributes = this.getCustomAttributeProviders(jsonObj.source, "Source Constraint of", this._currentItemFullName);
|
|
654
|
+
const targetCustomAttributes = this.getCustomAttributeProviders(jsonObj.target, "Target Constraint of", this._currentItemFullName);
|
|
655
|
+
return [sourceCustomAttributes, targetCustomAttributes];
|
|
656
|
+
}
|
|
657
|
+
*getCustomAttributeProviders(jsonObj, type, name) {
|
|
658
|
+
if (undefined !== jsonObj.customAttributes) {
|
|
659
|
+
if (!Array.isArray(jsonObj.customAttributes))
|
|
660
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${type} ${name} has an invalid 'customAttributes' attribute. It should be of type 'object[]'.`);
|
|
661
|
+
for (const instance of jsonObj.customAttributes) {
|
|
662
|
+
if (!isObject(instance) || Array.isArray(instance))
|
|
663
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ${type} ${name} has an invalid 'customAttributes' attribute. It should be of type 'object[]'.`);
|
|
664
|
+
if (undefined === instance.className)
|
|
665
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `A CustomAttribute in ${name}.customAttributes is missing the required 'className' attribute.`);
|
|
666
|
+
if (typeof (instance.className) !== "string")
|
|
667
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `A CustomAttribute in ${name}.customAttributes has an invalid 'className' attribute. It should be of type 'string'.`);
|
|
668
|
+
const provider = (_caClass) => {
|
|
669
|
+
return instance;
|
|
670
|
+
};
|
|
671
|
+
const caTuple = [instance.className, provider];
|
|
672
|
+
yield caTuple;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
//# sourceMappingURL=JsonParser.js.map
|