@itwin/ecschema-metadata 4.0.0-dev.1 → 4.0.0-dev.100

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 (135) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/lib/cjs/Constants.d.ts +23 -23
  3. package/lib/cjs/Constants.js +33 -33
  4. package/lib/cjs/Constants.js.map +1 -1
  5. package/lib/cjs/Context.d.ts +139 -139
  6. package/lib/cjs/Context.js +204 -204
  7. package/lib/cjs/DelayedPromise.d.ts +88 -88
  8. package/lib/cjs/DelayedPromise.d.ts.map +1 -1
  9. package/lib/cjs/DelayedPromise.js +91 -91
  10. package/lib/cjs/DelayedPromise.js.map +1 -1
  11. package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
  12. package/lib/cjs/Deserialization/AbstractParser.d.ts.map +1 -1
  13. package/lib/cjs/Deserialization/AbstractParser.js +11 -11
  14. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  15. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  16. package/lib/cjs/Deserialization/Helper.js +843 -843
  17. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  18. package/lib/cjs/Deserialization/JsonParser.d.ts.map +1 -1
  19. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  20. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  21. package/lib/cjs/Deserialization/JsonProps.d.ts +268 -282
  22. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  23. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  24. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  25. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  26. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  27. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  28. package/lib/cjs/Deserialization/XmlParser.d.ts.map +1 -1
  29. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  30. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  31. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  32. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  33. package/lib/cjs/ECName.d.ts +30 -30
  34. package/lib/cjs/ECName.js +85 -85
  35. package/lib/cjs/ECObjects.d.ts +162 -162
  36. package/lib/cjs/ECObjects.js +453 -453
  37. package/lib/cjs/Exception.d.ts +43 -43
  38. package/lib/cjs/Exception.d.ts.map +1 -1
  39. package/lib/cjs/Exception.js +84 -86
  40. package/lib/cjs/Exception.js.map +1 -1
  41. package/lib/cjs/Interfaces.d.ts +66 -66
  42. package/lib/cjs/Interfaces.d.ts.map +1 -1
  43. package/lib/cjs/Interfaces.js +9 -9
  44. package/lib/cjs/Metadata/Class.d.ts +243 -243
  45. package/lib/cjs/Metadata/Class.js +558 -558
  46. package/lib/cjs/Metadata/Class.js.map +1 -1
  47. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  48. package/lib/cjs/Metadata/Constant.js +123 -123
  49. package/lib/cjs/Metadata/Constant.js.map +1 -1
  50. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  51. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  52. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  53. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  54. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  55. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  56. package/lib/cjs/Metadata/EntityClass.js +230 -230
  57. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  58. package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
  59. package/lib/cjs/Metadata/Enumeration.js +159 -159
  60. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  61. package/lib/cjs/Metadata/Format.d.ts +98 -98
  62. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  63. package/lib/cjs/Metadata/Format.js +242 -242
  64. package/lib/cjs/Metadata/Format.js.map +1 -1
  65. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  66. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  67. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  68. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  69. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  70. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  71. package/lib/cjs/Metadata/Mixin.js +113 -113
  72. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  73. package/lib/cjs/Metadata/OverrideFormat.d.ts +67 -55
  74. package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
  75. package/lib/cjs/Metadata/OverrideFormat.js +126 -88
  76. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  77. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  78. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  79. package/lib/cjs/Metadata/Property.d.ts +197 -197
  80. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  81. package/lib/cjs/Metadata/Property.js +491 -491
  82. package/lib/cjs/Metadata/Property.js.map +1 -1
  83. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  84. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  85. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  86. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  87. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  88. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  89. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  90. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  91. package/lib/cjs/Metadata/Schema.js +520 -520
  92. package/lib/cjs/Metadata/Schema.js.map +1 -1
  93. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  94. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  95. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  96. package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
  97. package/lib/cjs/Metadata/Unit.js +162 -162
  98. package/lib/cjs/Metadata/Unit.js.map +1 -1
  99. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  100. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  101. package/lib/cjs/PropertyTypes.d.ts +49 -49
  102. package/lib/cjs/PropertyTypes.js +91 -91
  103. package/lib/cjs/PropertyTypes.js.map +1 -1
  104. package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
  105. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
  106. package/lib/cjs/SchemaJsonLocater.js +42 -42
  107. package/lib/cjs/SchemaKey.d.ts +110 -110
  108. package/lib/cjs/SchemaKey.js +219 -219
  109. package/lib/cjs/SchemaLoader.d.ts +23 -23
  110. package/lib/cjs/SchemaLoader.js +47 -47
  111. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  112. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  113. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  114. package/lib/cjs/UnitConversion/Graph.js +83 -83
  115. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  116. package/lib/cjs/UnitConversion/Parser.js +42 -42
  117. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  118. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  119. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  120. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  121. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  122. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  123. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  124. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  125. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts.map +1 -1
  126. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +234 -236
  127. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  128. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  129. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  130. package/lib/cjs/ecschema-metadata.d.ts +51 -51
  131. package/lib/cjs/ecschema-metadata.js +100 -96
  132. package/lib/cjs/ecschema-metadata.js.map +1 -1
  133. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  134. package/lib/cjs/utils/SchemaGraph.js +65 -65
  135. package/package.json +13 -14
@@ -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
package/lib/cjs/ECName.js CHANGED
@@ -1,86 +1,86 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Metadata
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ECName = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const Exception_1 = require("./Exception");
13
- const validECNameRegex = /^([a-zA-Z_]+[a-zA-Z0-9_]*)$/i;
14
- const ecNameReplacerRegex = /__x([0-9a-fA-F]{4})__/g;
15
- const leadingDigits = ["0000", "000", "00", "0", ""];
16
- function isDigit(character) {
17
- (0, core_bentley_1.assert)(1 === character.length);
18
- return character >= "0" && character <= "9";
19
- }
20
- function isValidAlphaNumericCharacter(c) {
21
- (0, core_bentley_1.assert)(1 === c.length);
22
- return (((c >= "0" && c <= "9") || (c >= "A" && c <= "Z") || (c >= "a" && c <= "z") || c === "_"));
23
- }
24
- /** The name of an item in a [[Schema]], encoded to meet restrictions on the characters usable in such names.
25
- * An ECName meets the following criteria:
26
- * - Contains at least one character.
27
- * - Does not begin with a digit.
28
- * - Consists entirely of characters in the ASCII ranges A-Z, a-z, and 0-9; and the underscore ("_") character.
29
- *
30
- * All characters not meeting the above criteria are encoded as "__x####__" where "####" is the UTF-16 character code.
31
- * Such names are often automatically generated from the item's display label, which is unrestricted in the characters it may contain.
32
- * @public
33
- */
34
- class ECName {
35
- /** Construct a new ECName from a valid EC name.
36
- * throws ECObjectsError if `name` does not meet the criteria for a valid EC name.
37
- */
38
- constructor(name) {
39
- if (!ECName.validate(name))
40
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName);
41
- this._name = name;
42
- }
43
- /** Returns true if a string meets the criteria of a valid EC name. */
44
- static validate(name) {
45
- return validECNameRegex.test(name);
46
- }
47
- /** The underlying name as a string. */
48
- get name() {
49
- return this._name;
50
- }
51
- /** Create an ECName from an arbitrary string, encoding any special characters as "__x####__" where "####" is the UTF-16 character code.
52
- * @throws ECObjectsError if `input` is an empty string.
53
- */
54
- static encode(input) {
55
- if (0 === input.length)
56
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName);
57
- if (ECName.validate(input)) {
58
- // It's already a valid EC name.
59
- return new ECName(input);
60
- }
61
- let output = "";
62
- function appendEncodedCharacter(index) {
63
- const hex = input.charCodeAt(index).toString(16).toUpperCase();
64
- (0, core_bentley_1.assert)(hex.length > 0 && hex.length < 5);
65
- output += `__x${leadingDigits[hex.length]}${hex}__`;
66
- }
67
- // First character cannot be a digit.
68
- const firstCharIsDigit = isDigit(input[0]);
69
- if (firstCharIsDigit)
70
- appendEncodedCharacter(0);
71
- for (let i = firstCharIsDigit ? 1 : 0; i < input.length; i++) {
72
- const char = input[i];
73
- if (!isValidAlphaNumericCharacter(char))
74
- appendEncodedCharacter(i);
75
- else
76
- output += char;
77
- }
78
- return new ECName(output);
79
- }
80
- /** Decode this ECName, replacing encoded special characters with the characters they encode. */
81
- decode() {
82
- return this.name.replace(ecNameReplacerRegex, (_match, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
83
- }
84
- }
85
- exports.ECName = ECName;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Metadata
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ECName = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const Exception_1 = require("./Exception");
13
+ const validECNameRegex = /^([a-zA-Z_]+[a-zA-Z0-9_]*)$/i;
14
+ const ecNameReplacerRegex = /__x([0-9a-fA-F]{4})__/g;
15
+ const leadingDigits = ["0000", "000", "00", "0", ""];
16
+ function isDigit(character) {
17
+ (0, core_bentley_1.assert)(1 === character.length);
18
+ return character >= "0" && character <= "9";
19
+ }
20
+ function isValidAlphaNumericCharacter(c) {
21
+ (0, core_bentley_1.assert)(1 === c.length);
22
+ return (((c >= "0" && c <= "9") || (c >= "A" && c <= "Z") || (c >= "a" && c <= "z") || c === "_"));
23
+ }
24
+ /** The name of an item in a [[Schema]], encoded to meet restrictions on the characters usable in such names.
25
+ * An ECName meets the following criteria:
26
+ * - Contains at least one character.
27
+ * - Does not begin with a digit.
28
+ * - Consists entirely of characters in the ASCII ranges A-Z, a-z, and 0-9; and the underscore ("_") character.
29
+ *
30
+ * All characters not meeting the above criteria are encoded as "__x####__" where "####" is the UTF-16 character code.
31
+ * Such names are often automatically generated from the item's display label, which is unrestricted in the characters it may contain.
32
+ * @public
33
+ */
34
+ class ECName {
35
+ /** Construct a new ECName from a valid EC name.
36
+ * throws ECObjectsError if `name` does not meet the criteria for a valid EC name.
37
+ */
38
+ constructor(name) {
39
+ if (!ECName.validate(name))
40
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName);
41
+ this._name = name;
42
+ }
43
+ /** Returns true if a string meets the criteria of a valid EC name. */
44
+ static validate(name) {
45
+ return validECNameRegex.test(name);
46
+ }
47
+ /** The underlying name as a string. */
48
+ get name() {
49
+ return this._name;
50
+ }
51
+ /** Create an ECName from an arbitrary string, encoding any special characters as "__x####__" where "####" is the UTF-16 character code.
52
+ * @throws ECObjectsError if `input` is an empty string.
53
+ */
54
+ static encode(input) {
55
+ if (0 === input.length)
56
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName);
57
+ if (ECName.validate(input)) {
58
+ // It's already a valid EC name.
59
+ return new ECName(input);
60
+ }
61
+ let output = "";
62
+ function appendEncodedCharacter(index) {
63
+ const hex = input.charCodeAt(index).toString(16).toUpperCase();
64
+ (0, core_bentley_1.assert)(hex.length > 0 && hex.length < 5);
65
+ output += `__x${leadingDigits[hex.length]}${hex}__`;
66
+ }
67
+ // First character cannot be a digit.
68
+ const firstCharIsDigit = isDigit(input[0]);
69
+ if (firstCharIsDigit)
70
+ appendEncodedCharacter(0);
71
+ for (let i = firstCharIsDigit ? 1 : 0; i < input.length; i++) {
72
+ const char = input[i];
73
+ if (!isValidAlphaNumericCharacter(char))
74
+ appendEncodedCharacter(i);
75
+ else
76
+ output += char;
77
+ }
78
+ return new ECName(output);
79
+ }
80
+ /** Decode this ECName, replacing encoded special characters with the characters they encode. */
81
+ decode() {
82
+ return this.name.replace(ecNameReplacerRegex, (_match, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
83
+ }
84
+ }
85
+ exports.ECName = ECName;
86
86
  //# sourceMappingURL=ECName.js.map