@itwin/ecschema-metadata 4.0.0-dev.52 → 4.0.0-dev.55

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.
Files changed (117) hide show
  1. package/lib/cjs/Constants.d.ts +23 -23
  2. package/lib/cjs/Constants.js +33 -33
  3. package/lib/cjs/Constants.js.map +1 -1
  4. package/lib/cjs/Context.d.ts +139 -139
  5. package/lib/cjs/Context.js +204 -204
  6. package/lib/cjs/DelayedPromise.d.ts +88 -88
  7. package/lib/cjs/DelayedPromise.d.ts.map +1 -1
  8. package/lib/cjs/DelayedPromise.js +91 -91
  9. package/lib/cjs/DelayedPromise.js.map +1 -1
  10. package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
  11. package/lib/cjs/Deserialization/AbstractParser.d.ts.map +1 -1
  12. package/lib/cjs/Deserialization/AbstractParser.js +11 -11
  13. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  14. package/lib/cjs/Deserialization/Helper.js +843 -843
  15. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  16. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  17. package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
  18. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  19. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  20. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  21. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  22. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  23. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  24. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  25. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  26. package/lib/cjs/ECName.d.ts +30 -30
  27. package/lib/cjs/ECName.js +85 -85
  28. package/lib/cjs/ECObjects.d.ts +162 -162
  29. package/lib/cjs/ECObjects.js +453 -453
  30. package/lib/cjs/Exception.d.ts +43 -43
  31. package/lib/cjs/Exception.js +84 -84
  32. package/lib/cjs/Interfaces.d.ts +66 -66
  33. package/lib/cjs/Interfaces.d.ts.map +1 -1
  34. package/lib/cjs/Interfaces.js +9 -9
  35. package/lib/cjs/Metadata/Class.d.ts +243 -243
  36. package/lib/cjs/Metadata/Class.js +558 -558
  37. package/lib/cjs/Metadata/Class.js.map +1 -1
  38. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  39. package/lib/cjs/Metadata/Constant.js +123 -123
  40. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  41. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  42. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  43. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  44. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  45. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  46. package/lib/cjs/Metadata/EntityClass.js +230 -230
  47. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  48. package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
  49. package/lib/cjs/Metadata/Enumeration.js +159 -159
  50. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  51. package/lib/cjs/Metadata/Format.d.ts +98 -98
  52. package/lib/cjs/Metadata/Format.js +242 -242
  53. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  54. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  55. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  56. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  57. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  58. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  59. package/lib/cjs/Metadata/Mixin.js +113 -113
  60. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  61. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  62. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  63. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  64. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  65. package/lib/cjs/Metadata/Property.d.ts +197 -197
  66. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  67. package/lib/cjs/Metadata/Property.js +491 -491
  68. package/lib/cjs/Metadata/Property.js.map +1 -1
  69. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  70. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  71. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  72. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  73. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  74. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  75. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  76. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  77. package/lib/cjs/Metadata/Schema.js +520 -520
  78. package/lib/cjs/Metadata/Schema.js.map +1 -1
  79. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  80. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  81. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  82. package/lib/cjs/Metadata/Unit.js +162 -162
  83. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  84. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  85. package/lib/cjs/PropertyTypes.d.ts +49 -49
  86. package/lib/cjs/PropertyTypes.js +91 -91
  87. package/lib/cjs/PropertyTypes.js.map +1 -1
  88. package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
  89. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
  90. package/lib/cjs/SchemaJsonLocater.js +42 -42
  91. package/lib/cjs/SchemaKey.d.ts +110 -110
  92. package/lib/cjs/SchemaKey.js +219 -219
  93. package/lib/cjs/SchemaLoader.d.ts +23 -23
  94. package/lib/cjs/SchemaLoader.js +47 -47
  95. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  96. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  97. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  98. package/lib/cjs/UnitConversion/Graph.js +83 -83
  99. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  100. package/lib/cjs/UnitConversion/Parser.js +42 -42
  101. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  102. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  103. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  104. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  105. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  106. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  107. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  108. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  109. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +234 -234
  110. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  111. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  112. package/lib/cjs/ecschema-metadata.d.ts +51 -51
  113. package/lib/cjs/ecschema-metadata.js +100 -96
  114. package/lib/cjs/ecschema-metadata.js.map +1 -1
  115. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  116. package/lib/cjs/utils/SchemaGraph.js +65 -65
  117. package/package.json +8 -8
@@ -1,55 +1,55 @@
1
- import { CustomAttribute } from "../Metadata/CustomAttribute";
2
- import { ArrayProperty, PrimitiveOrEnumPropertyBase, Property, StructProperty } from "../Metadata/Property";
3
- import { Schema } from "../Metadata/Schema";
4
- /**
5
- * Namespace holding utility functions for serializing EC types to the EC XML format.
6
- * @internal
7
- */
8
- export declare namespace XmlSerializationUtils {
9
- /**
10
- * Serializes a CustomAttribute instance to the EC XML format.
11
- * @param fullName The full name of the CustomAttribute (qualified by schema name).
12
- * @param customAttribute The CustomAttribute instance to serialize.
13
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
14
- * @param schema The Schema object being serialized.
15
- * @beta
16
- */
17
- function writeCustomAttribute(fullName: string, customAttribute: CustomAttribute, schemaDoc: Document, schema: Schema): Promise<Element>;
18
- /**
19
- * Serializes an EC Property instance to the EC XML format.
20
- * @param propertyClass The Property metadata object.
21
- * @param instance The Property instance.
22
- * @param instanceElement The XML Element that will contain the serialized property instance.
23
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
24
- * @beta
25
- */
26
- function writeInstanceProperty(propertyClass: Property, instance: any, instanceElement: Element, schemaDoc: Document): Promise<void>;
27
- /**
28
- * Serializes an EC ArrayProperty instance to the EC XML format.
29
- * @param propertyClass The Property metadata object.
30
- * @param propertyValue An array holding the property values.
31
- * @param arrayElement The XML Element that will contain the serialized property instance.
32
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
33
- * @beta
34
- */
35
- function writeArrayProperty(propertyClass: ArrayProperty, propertyValue: any[], arrayElement: Element, schemaDoc: Document): Promise<void>;
36
- /**
37
- * Serializes an EC StructProperty instance to the EC XML format.
38
- * @param propertyClass The Property metadata object.
39
- * @param propertyValue The struct object holding the property values.
40
- * @param structElement The XML Element that will contain the serialized property instance.
41
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
42
- * @beta
43
- */
44
- function writeStructProperty(propertyClass: StructProperty, propertyValue: any, structElement: Element, schemaDoc: Document): Promise<void>;
45
- /**
46
- * Serializes an EC PrimitiveProperty instance to the EC XML format.
47
- * @param propertyClass The Property metadata object.
48
- * @param propertyValue The struct object holding the property values.
49
- * @param propertyElement The XML Element that will contain the serialized property instance.
50
- * @beta
51
- */
52
- function writePrimitiveProperty(propertyClass: PrimitiveOrEnumPropertyBase, propertyValue: any, propertyElement: Element): Promise<void>;
53
- function createXmlTypedName(currentSchema: Schema, typeSchema: Schema, typeName: string): string;
54
- }
1
+ import { CustomAttribute } from "../Metadata/CustomAttribute";
2
+ import { ArrayProperty, PrimitiveOrEnumPropertyBase, Property, StructProperty } from "../Metadata/Property";
3
+ import { Schema } from "../Metadata/Schema";
4
+ /**
5
+ * Namespace holding utility functions for serializing EC types to the EC XML format.
6
+ * @internal
7
+ */
8
+ export declare namespace XmlSerializationUtils {
9
+ /**
10
+ * Serializes a CustomAttribute instance to the EC XML format.
11
+ * @param fullName The full name of the CustomAttribute (qualified by schema name).
12
+ * @param customAttribute The CustomAttribute instance to serialize.
13
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
14
+ * @param schema The Schema object being serialized.
15
+ * @beta
16
+ */
17
+ function writeCustomAttribute(fullName: string, customAttribute: CustomAttribute, schemaDoc: Document, schema: Schema): Promise<Element>;
18
+ /**
19
+ * Serializes an EC Property instance to the EC XML format.
20
+ * @param propertyClass The Property metadata object.
21
+ * @param instance The Property instance.
22
+ * @param instanceElement The XML Element that will contain the serialized property instance.
23
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
24
+ * @beta
25
+ */
26
+ function writeInstanceProperty(propertyClass: Property, instance: any, instanceElement: Element, schemaDoc: Document): Promise<void>;
27
+ /**
28
+ * Serializes an EC ArrayProperty instance to the EC XML format.
29
+ * @param propertyClass The Property metadata object.
30
+ * @param propertyValue An array holding the property values.
31
+ * @param arrayElement The XML Element that will contain the serialized property instance.
32
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
33
+ * @beta
34
+ */
35
+ function writeArrayProperty(propertyClass: ArrayProperty, propertyValue: any[], arrayElement: Element, schemaDoc: Document): Promise<void>;
36
+ /**
37
+ * Serializes an EC StructProperty instance to the EC XML format.
38
+ * @param propertyClass The Property metadata object.
39
+ * @param propertyValue The struct object holding the property values.
40
+ * @param structElement The XML Element that will contain the serialized property instance.
41
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
42
+ * @beta
43
+ */
44
+ function writeStructProperty(propertyClass: StructProperty, propertyValue: any, structElement: Element, schemaDoc: Document): Promise<void>;
45
+ /**
46
+ * Serializes an EC PrimitiveProperty instance to the EC XML format.
47
+ * @param propertyClass The Property metadata object.
48
+ * @param propertyValue The struct object holding the property values.
49
+ * @param propertyElement The XML Element that will contain the serialized property instance.
50
+ * @beta
51
+ */
52
+ function writePrimitiveProperty(propertyClass: PrimitiveOrEnumPropertyBase, propertyValue: any, propertyElement: Element): Promise<void>;
53
+ function createXmlTypedName(currentSchema: Schema, typeSchema: Schema, typeName: string): string;
54
+ }
55
55
  //# sourceMappingURL=XmlSerializationUtils.d.ts.map
@@ -1,175 +1,175 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.XmlSerializationUtils = void 0;
8
- const ECObjects_1 = require("../ECObjects");
9
- const Exception_1 = require("../Exception");
10
- /**
11
- * Namespace holding utility functions for serializing EC types to the EC XML format.
12
- * @internal
13
- */
14
- var XmlSerializationUtils;
15
- (function (XmlSerializationUtils) {
16
- /**
17
- * Serializes a CustomAttribute instance to the EC XML format.
18
- * @param fullName The full name of the CustomAttribute (qualified by schema name).
19
- * @param customAttribute The CustomAttribute instance to serialize.
20
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
21
- * @param schema The Schema object being serialized.
22
- * @beta
23
- */
24
- async function writeCustomAttribute(fullName, customAttribute, schemaDoc, schema) {
25
- const caClass = await schema.lookupItem(fullName);
26
- if (!caClass)
27
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.ClassNotFound, `The class '${fullName}' could not be found in the current schema context.`);
28
- const nameAndNamespace = await resolveCustomAttributeNamespace(fullName, schema);
29
- const caElement = schemaDoc.createElement(nameAndNamespace[0]);
30
- if (nameAndNamespace[1])
31
- caElement.setAttribute("xmlns", nameAndNamespace[1]);
32
- if (!caClass.properties)
33
- return caElement;
34
- for (const property of caClass.properties)
35
- await writeInstanceProperty(property, customAttribute, caElement, schemaDoc);
36
- return caElement;
37
- }
38
- XmlSerializationUtils.writeCustomAttribute = writeCustomAttribute;
39
- /**
40
- * Serializes an EC Property instance to the EC XML format.
41
- * @param propertyClass The Property metadata object.
42
- * @param instance The Property instance.
43
- * @param instanceElement The XML Element that will contain the serialized property instance.
44
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
45
- * @beta
46
- */
47
- async function writeInstanceProperty(propertyClass, instance, instanceElement, schemaDoc) {
48
- const propertyValue = instance[propertyClass.name];
49
- if (propertyValue === undefined)
50
- return;
51
- const propertyElement = schemaDoc.createElement(propertyClass.name);
52
- instanceElement.appendChild(propertyElement);
53
- if (propertyClass.isArray()) {
54
- await writeArrayProperty(propertyClass, propertyValue, propertyElement, schemaDoc);
55
- }
56
- else if (propertyClass.isPrimitive()) {
57
- await writePrimitiveProperty(propertyClass, propertyValue, propertyElement);
58
- }
59
- else if (propertyClass.isStruct()) {
60
- await writeStructProperty(propertyClass, propertyValue, propertyElement, schemaDoc);
61
- }
62
- }
63
- XmlSerializationUtils.writeInstanceProperty = writeInstanceProperty;
64
- /**
65
- * Serializes an EC ArrayProperty instance to the EC XML format.
66
- * @param propertyClass The Property metadata object.
67
- * @param propertyValue An array holding the property values.
68
- * @param arrayElement The XML Element that will contain the serialized property instance.
69
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
70
- * @beta
71
- */
72
- async function writeArrayProperty(propertyClass, propertyValue, arrayElement, schemaDoc) {
73
- if (propertyClass.isPrimitive()) {
74
- const typeString = (0, ECObjects_1.primitiveTypeToString)(propertyClass.primitiveType);
75
- for (const value of propertyValue) {
76
- const entryElement = schemaDoc.createElement(typeString);
77
- await writePrimitiveProperty(propertyClass, value, entryElement);
78
- arrayElement.appendChild(entryElement);
79
- }
80
- }
81
- if (propertyClass.isStruct()) {
82
- for (const value of propertyValue) {
83
- const structElement = schemaDoc.createElement(propertyClass.structClass.name);
84
- arrayElement.appendChild(structElement);
85
- await writeStructProperty(propertyClass, value, structElement, schemaDoc);
86
- }
87
- }
88
- }
89
- XmlSerializationUtils.writeArrayProperty = writeArrayProperty;
90
- /**
91
- * Serializes an EC StructProperty instance to the EC XML format.
92
- * @param propertyClass The Property metadata object.
93
- * @param propertyValue The struct object holding the property values.
94
- * @param structElement The XML Element that will contain the serialized property instance.
95
- * @param schemaDoc The Xml Document object holding the serialized EC Schema.
96
- * @beta
97
- */
98
- async function writeStructProperty(propertyClass, propertyValue, structElement, schemaDoc) {
99
- const structClass = propertyClass.structClass;
100
- if (!structClass.properties)
101
- return;
102
- for (const propertyMetadata of structClass.properties)
103
- await writeInstanceProperty(propertyMetadata, propertyValue, structElement, schemaDoc);
104
- }
105
- XmlSerializationUtils.writeStructProperty = writeStructProperty;
106
- /**
107
- * Serializes an EC PrimitiveProperty instance to the EC XML format.
108
- * @param propertyClass The Property metadata object.
109
- * @param propertyValue The struct object holding the property values.
110
- * @param propertyElement The XML Element that will contain the serialized property instance.
111
- * @beta
112
- */
113
- async function writePrimitiveProperty(propertyClass, propertyValue, propertyElement) {
114
- let primitiveType;
115
- if (propertyClass.isEnumeration()) {
116
- const enumeration = await propertyClass.enumeration;
117
- if (!enumeration)
118
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.ClassNotFound, `The enumeration on property class '${propertyClass.fullName}' could not be found in the current schema context.`);
119
- if (enumeration.type === undefined)
120
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidType, `The enumeration on property class '${propertyClass.fullName}' has an invalid primitive type.`);
121
- primitiveType = enumeration.type;
122
- }
123
- else
124
- primitiveType = propertyClass.primitiveType;
125
- switch (primitiveType) {
126
- case ECObjects_1.PrimitiveType.String:
127
- propertyElement.textContent = propertyValue;
128
- return;
129
- case ECObjects_1.PrimitiveType.Boolean:
130
- propertyElement.textContent = propertyValue ? "True" : "False";
131
- return;
132
- case ECObjects_1.PrimitiveType.Integer:
133
- case ECObjects_1.PrimitiveType.Double:
134
- case ECObjects_1.PrimitiveType.Long:
135
- propertyElement.textContent = propertyValue.toString();
136
- return;
137
- case ECObjects_1.PrimitiveType.DateTime:
138
- propertyElement.textContent = propertyValue.getTime().toString();
139
- return;
140
- case ECObjects_1.PrimitiveType.Point2d:
141
- propertyElement.textContent = `${propertyValue.x},${propertyValue.y}`;
142
- return;
143
- case ECObjects_1.PrimitiveType.Point3d:
144
- propertyElement.textContent = `${propertyValue.x},${propertyValue.y},${propertyValue.z}`;
145
- return;
146
- case ECObjects_1.PrimitiveType.IGeometry:
147
- case ECObjects_1.PrimitiveType.Binary:
148
- propertyElement.textContent = propertyValue;
149
- return;
150
- default:
151
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidPrimitiveType, `The property '${propertyClass.fullName}' has an invalid primitive type.`);
152
- }
153
- }
154
- XmlSerializationUtils.writePrimitiveProperty = writePrimitiveProperty;
155
- function createXmlTypedName(currentSchema, typeSchema, typeName) {
156
- if (currentSchema.schemaKey.matches(typeSchema.schemaKey))
157
- return typeName;
158
- // Alias is required in Spec. It could be undefined (technically), so
159
- // throw until fixed.
160
- if (typeSchema.alias === undefined)
161
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidSchemaAlias, `The schema '${typeSchema.name}' has an invalid alias.`);
162
- return `${typeSchema.alias}:${typeName}`;
163
- }
164
- XmlSerializationUtils.createXmlTypedName = createXmlTypedName;
165
- async function resolveCustomAttributeNamespace(caName, schema) {
166
- const nameParts = caName.split(".");
167
- if (nameParts.length === 1)
168
- return [caName, undefined];
169
- const attributeSchema = nameParts[0].toUpperCase() === schema.name.toUpperCase() ? schema : await schema.getReference(nameParts[0]);
170
- if (!attributeSchema)
171
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.UnableToLocateSchema, `Unable to resolve the namespace for CustomAttribute '${caName}' because the referenced schema '${nameParts[0]}' could not be located.`);
172
- return [nameParts[1], `${nameParts[0]}.${attributeSchema.schemaKey.version.toString()}`];
173
- }
174
- })(XmlSerializationUtils = exports.XmlSerializationUtils || (exports.XmlSerializationUtils = {}));
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.XmlSerializationUtils = void 0;
8
+ const ECObjects_1 = require("../ECObjects");
9
+ const Exception_1 = require("../Exception");
10
+ /**
11
+ * Namespace holding utility functions for serializing EC types to the EC XML format.
12
+ * @internal
13
+ */
14
+ var XmlSerializationUtils;
15
+ (function (XmlSerializationUtils) {
16
+ /**
17
+ * Serializes a CustomAttribute instance to the EC XML format.
18
+ * @param fullName The full name of the CustomAttribute (qualified by schema name).
19
+ * @param customAttribute The CustomAttribute instance to serialize.
20
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
21
+ * @param schema The Schema object being serialized.
22
+ * @beta
23
+ */
24
+ async function writeCustomAttribute(fullName, customAttribute, schemaDoc, schema) {
25
+ const caClass = await schema.lookupItem(fullName);
26
+ if (!caClass)
27
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.ClassNotFound, `The class '${fullName}' could not be found in the current schema context.`);
28
+ const nameAndNamespace = await resolveCustomAttributeNamespace(fullName, schema);
29
+ const caElement = schemaDoc.createElement(nameAndNamespace[0]);
30
+ if (nameAndNamespace[1])
31
+ caElement.setAttribute("xmlns", nameAndNamespace[1]);
32
+ if (!caClass.properties)
33
+ return caElement;
34
+ for (const property of caClass.properties)
35
+ await writeInstanceProperty(property, customAttribute, caElement, schemaDoc);
36
+ return caElement;
37
+ }
38
+ XmlSerializationUtils.writeCustomAttribute = writeCustomAttribute;
39
+ /**
40
+ * Serializes an EC Property instance to the EC XML format.
41
+ * @param propertyClass The Property metadata object.
42
+ * @param instance The Property instance.
43
+ * @param instanceElement The XML Element that will contain the serialized property instance.
44
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
45
+ * @beta
46
+ */
47
+ async function writeInstanceProperty(propertyClass, instance, instanceElement, schemaDoc) {
48
+ const propertyValue = instance[propertyClass.name];
49
+ if (propertyValue === undefined)
50
+ return;
51
+ const propertyElement = schemaDoc.createElement(propertyClass.name);
52
+ instanceElement.appendChild(propertyElement);
53
+ if (propertyClass.isArray()) {
54
+ await writeArrayProperty(propertyClass, propertyValue, propertyElement, schemaDoc);
55
+ }
56
+ else if (propertyClass.isPrimitive()) {
57
+ await writePrimitiveProperty(propertyClass, propertyValue, propertyElement);
58
+ }
59
+ else if (propertyClass.isStruct()) {
60
+ await writeStructProperty(propertyClass, propertyValue, propertyElement, schemaDoc);
61
+ }
62
+ }
63
+ XmlSerializationUtils.writeInstanceProperty = writeInstanceProperty;
64
+ /**
65
+ * Serializes an EC ArrayProperty instance to the EC XML format.
66
+ * @param propertyClass The Property metadata object.
67
+ * @param propertyValue An array holding the property values.
68
+ * @param arrayElement The XML Element that will contain the serialized property instance.
69
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
70
+ * @beta
71
+ */
72
+ async function writeArrayProperty(propertyClass, propertyValue, arrayElement, schemaDoc) {
73
+ if (propertyClass.isPrimitive()) {
74
+ const typeString = (0, ECObjects_1.primitiveTypeToString)(propertyClass.primitiveType);
75
+ for (const value of propertyValue) {
76
+ const entryElement = schemaDoc.createElement(typeString);
77
+ await writePrimitiveProperty(propertyClass, value, entryElement);
78
+ arrayElement.appendChild(entryElement);
79
+ }
80
+ }
81
+ if (propertyClass.isStruct()) {
82
+ for (const value of propertyValue) {
83
+ const structElement = schemaDoc.createElement(propertyClass.structClass.name);
84
+ arrayElement.appendChild(structElement);
85
+ await writeStructProperty(propertyClass, value, structElement, schemaDoc);
86
+ }
87
+ }
88
+ }
89
+ XmlSerializationUtils.writeArrayProperty = writeArrayProperty;
90
+ /**
91
+ * Serializes an EC StructProperty instance to the EC XML format.
92
+ * @param propertyClass The Property metadata object.
93
+ * @param propertyValue The struct object holding the property values.
94
+ * @param structElement The XML Element that will contain the serialized property instance.
95
+ * @param schemaDoc The Xml Document object holding the serialized EC Schema.
96
+ * @beta
97
+ */
98
+ async function writeStructProperty(propertyClass, propertyValue, structElement, schemaDoc) {
99
+ const structClass = propertyClass.structClass;
100
+ if (!structClass.properties)
101
+ return;
102
+ for (const propertyMetadata of structClass.properties)
103
+ await writeInstanceProperty(propertyMetadata, propertyValue, structElement, schemaDoc);
104
+ }
105
+ XmlSerializationUtils.writeStructProperty = writeStructProperty;
106
+ /**
107
+ * Serializes an EC PrimitiveProperty instance to the EC XML format.
108
+ * @param propertyClass The Property metadata object.
109
+ * @param propertyValue The struct object holding the property values.
110
+ * @param propertyElement The XML Element that will contain the serialized property instance.
111
+ * @beta
112
+ */
113
+ async function writePrimitiveProperty(propertyClass, propertyValue, propertyElement) {
114
+ let primitiveType;
115
+ if (propertyClass.isEnumeration()) {
116
+ const enumeration = await propertyClass.enumeration;
117
+ if (!enumeration)
118
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.ClassNotFound, `The enumeration on property class '${propertyClass.fullName}' could not be found in the current schema context.`);
119
+ if (enumeration.type === undefined)
120
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidType, `The enumeration on property class '${propertyClass.fullName}' has an invalid primitive type.`);
121
+ primitiveType = enumeration.type;
122
+ }
123
+ else
124
+ primitiveType = propertyClass.primitiveType;
125
+ switch (primitiveType) {
126
+ case ECObjects_1.PrimitiveType.String:
127
+ propertyElement.textContent = propertyValue;
128
+ return;
129
+ case ECObjects_1.PrimitiveType.Boolean:
130
+ propertyElement.textContent = propertyValue ? "True" : "False";
131
+ return;
132
+ case ECObjects_1.PrimitiveType.Integer:
133
+ case ECObjects_1.PrimitiveType.Double:
134
+ case ECObjects_1.PrimitiveType.Long:
135
+ propertyElement.textContent = propertyValue.toString();
136
+ return;
137
+ case ECObjects_1.PrimitiveType.DateTime:
138
+ propertyElement.textContent = propertyValue.getTime().toString();
139
+ return;
140
+ case ECObjects_1.PrimitiveType.Point2d:
141
+ propertyElement.textContent = `${propertyValue.x},${propertyValue.y}`;
142
+ return;
143
+ case ECObjects_1.PrimitiveType.Point3d:
144
+ propertyElement.textContent = `${propertyValue.x},${propertyValue.y},${propertyValue.z}`;
145
+ return;
146
+ case ECObjects_1.PrimitiveType.IGeometry:
147
+ case ECObjects_1.PrimitiveType.Binary:
148
+ propertyElement.textContent = propertyValue;
149
+ return;
150
+ default:
151
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidPrimitiveType, `The property '${propertyClass.fullName}' has an invalid primitive type.`);
152
+ }
153
+ }
154
+ XmlSerializationUtils.writePrimitiveProperty = writePrimitiveProperty;
155
+ function createXmlTypedName(currentSchema, typeSchema, typeName) {
156
+ if (currentSchema.schemaKey.matches(typeSchema.schemaKey))
157
+ return typeName;
158
+ // Alias is required in Spec. It could be undefined (technically), so
159
+ // throw until fixed.
160
+ if (typeSchema.alias === undefined)
161
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidSchemaAlias, `The schema '${typeSchema.name}' has an invalid alias.`);
162
+ return `${typeSchema.alias}:${typeName}`;
163
+ }
164
+ XmlSerializationUtils.createXmlTypedName = createXmlTypedName;
165
+ async function resolveCustomAttributeNamespace(caName, schema) {
166
+ const nameParts = caName.split(".");
167
+ if (nameParts.length === 1)
168
+ return [caName, undefined];
169
+ const attributeSchema = nameParts[0].toUpperCase() === schema.name.toUpperCase() ? schema : await schema.getReference(nameParts[0]);
170
+ if (!attributeSchema)
171
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.UnableToLocateSchema, `Unable to resolve the namespace for CustomAttribute '${caName}' because the referenced schema '${nameParts[0]}' could not be located.`);
172
+ return [nameParts[1], `${nameParts[0]}.${attributeSchema.schemaKey.version.toString()}`];
173
+ }
174
+ })(XmlSerializationUtils = exports.XmlSerializationUtils || (exports.XmlSerializationUtils = {}));
175
175
  //# sourceMappingURL=XmlSerializationUtils.js.map
@@ -1,31 +1,31 @@
1
- /** @packageDocumentation
2
- * @module Metadata
3
- */
4
- /** The name of an item in a [[Schema]], encoded to meet restrictions on the characters usable in such names.
5
- * An ECName meets the following criteria:
6
- * - Contains at least one character.
7
- * - Does not begin with a digit.
8
- * - Consists entirely of characters in the ASCII ranges A-Z, a-z, and 0-9; and the underscore ("_") character.
9
- *
10
- * All characters not meeting the above criteria are encoded as "__x####__" where "####" is the UTF-16 character code.
11
- * Such names are often automatically generated from the item's display label, which is unrestricted in the characters it may contain.
12
- * @public
13
- */
14
- export declare class ECName {
15
- private _name;
16
- /** Construct a new ECName from a valid EC name.
17
- * throws ECObjectsError if `name` does not meet the criteria for a valid EC name.
18
- */
19
- constructor(name: string);
20
- /** Returns true if a string meets the criteria of a valid EC name. */
21
- static validate(name: string): boolean;
22
- /** The underlying name as a string. */
23
- get name(): string;
24
- /** Create an ECName from an arbitrary string, encoding any special characters as "__x####__" where "####" is the UTF-16 character code.
25
- * @throws ECObjectsError if `input` is an empty string.
26
- */
27
- static encode(input: string): ECName;
28
- /** Decode this ECName, replacing encoded special characters with the characters they encode. */
29
- decode(): string;
30
- }
1
+ /** @packageDocumentation
2
+ * @module Metadata
3
+ */
4
+ /** The name of an item in a [[Schema]], encoded to meet restrictions on the characters usable in such names.
5
+ * An ECName meets the following criteria:
6
+ * - Contains at least one character.
7
+ * - Does not begin with a digit.
8
+ * - Consists entirely of characters in the ASCII ranges A-Z, a-z, and 0-9; and the underscore ("_") character.
9
+ *
10
+ * All characters not meeting the above criteria are encoded as "__x####__" where "####" is the UTF-16 character code.
11
+ * Such names are often automatically generated from the item's display label, which is unrestricted in the characters it may contain.
12
+ * @public
13
+ */
14
+ export declare class ECName {
15
+ private _name;
16
+ /** Construct a new ECName from a valid EC name.
17
+ * throws ECObjectsError if `name` does not meet the criteria for a valid EC name.
18
+ */
19
+ constructor(name: string);
20
+ /** Returns true if a string meets the criteria of a valid EC name. */
21
+ static validate(name: string): boolean;
22
+ /** The underlying name as a string. */
23
+ get name(): string;
24
+ /** Create an ECName from an arbitrary string, encoding any special characters as "__x####__" where "####" is the UTF-16 character code.
25
+ * @throws ECObjectsError if `input` is an empty string.
26
+ */
27
+ static encode(input: string): ECName;
28
+ /** Decode this ECName, replacing encoded special characters with the characters they encode. */
29
+ decode(): string;
30
+ }
31
31
  //# sourceMappingURL=ECName.d.ts.map