@itwin/ecschema-metadata 3.4.0-dev.8 → 3.5.0-dev.4

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 (153) hide show
  1. package/CHANGELOG.md +25 -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.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.js +11 -11
  12. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  13. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  14. package/lib/cjs/Deserialization/Helper.js +843 -843
  15. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  16. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  17. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  18. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  19. package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
  20. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  21. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  22. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  23. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  24. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  25. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  26. package/lib/cjs/Deserialization/XmlParser.d.ts.map +1 -1
  27. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  28. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  29. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  30. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  31. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  32. package/lib/cjs/ECName.d.ts +30 -30
  33. package/lib/cjs/ECName.js +85 -85
  34. package/lib/cjs/ECName.js.map +1 -1
  35. package/lib/cjs/ECObjects.d.ts +162 -162
  36. package/lib/cjs/ECObjects.js +453 -453
  37. package/lib/cjs/ECObjects.js.map +1 -1
  38. package/lib/cjs/Exception.d.ts +43 -43
  39. package/lib/cjs/Exception.js +86 -86
  40. package/lib/cjs/Exception.js.map +1 -1
  41. package/lib/cjs/Interfaces.d.ts +66 -66
  42. package/lib/cjs/Interfaces.js +9 -9
  43. package/lib/cjs/Interfaces.js.map +1 -1
  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.d.ts.map +1 -1
  52. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  53. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  54. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  55. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  56. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  57. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  58. package/lib/cjs/Metadata/EntityClass.js +230 -230
  59. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  60. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  61. package/lib/cjs/Metadata/Enumeration.js +159 -159
  62. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  63. package/lib/cjs/Metadata/Format.d.ts +98 -98
  64. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  65. package/lib/cjs/Metadata/Format.js +242 -242
  66. package/lib/cjs/Metadata/Format.js.map +1 -1
  67. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  68. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  69. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  70. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  71. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  72. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  73. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  74. package/lib/cjs/Metadata/Mixin.js +113 -113
  75. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  76. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  77. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  78. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  79. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  80. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  81. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  82. package/lib/cjs/Metadata/Property.d.ts +197 -197
  83. package/lib/cjs/Metadata/Property.js +491 -491
  84. package/lib/cjs/Metadata/Property.js.map +1 -1
  85. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  86. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  87. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  88. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  89. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  90. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  91. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  92. package/lib/cjs/Metadata/Schema.js +520 -520
  93. package/lib/cjs/Metadata/Schema.js.map +1 -1
  94. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  95. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  96. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  97. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  98. package/lib/cjs/Metadata/Unit.js +162 -162
  99. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  100. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  101. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  102. package/lib/cjs/PropertyTypes.d.ts +49 -49
  103. package/lib/cjs/PropertyTypes.d.ts.map +1 -1
  104. package/lib/cjs/PropertyTypes.js +91 -75
  105. package/lib/cjs/PropertyTypes.js.map +1 -1
  106. package/lib/cjs/SchemaJsonLocater.d.ts +35 -0
  107. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -0
  108. package/lib/cjs/SchemaJsonLocater.js +43 -0
  109. package/lib/cjs/SchemaJsonLocater.js.map +1 -0
  110. package/lib/cjs/SchemaKey.d.ts +110 -110
  111. package/lib/cjs/SchemaKey.d.ts.map +1 -1
  112. package/lib/cjs/SchemaKey.js +219 -220
  113. package/lib/cjs/SchemaKey.js.map +1 -1
  114. package/lib/cjs/SchemaLoader.d.ts +24 -0
  115. package/lib/cjs/SchemaLoader.d.ts.map +1 -0
  116. package/lib/cjs/SchemaLoader.js +48 -0
  117. package/lib/cjs/SchemaLoader.js.map +1 -0
  118. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  119. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  120. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  121. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  122. package/lib/cjs/UnitConversion/Graph.js +83 -83
  123. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  124. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  125. package/lib/cjs/UnitConversion/Parser.d.ts.map +1 -1
  126. package/lib/cjs/UnitConversion/Parser.js +42 -41
  127. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  128. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  129. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  130. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  131. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  132. package/lib/cjs/UnitConversion/UnitConverter.d.ts.map +1 -1
  133. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  134. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  135. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  136. package/lib/cjs/UnitConversion/UnitTree.d.ts.map +1 -1
  137. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  138. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  139. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  140. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +236 -236
  141. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  142. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  143. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  144. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  145. package/lib/cjs/ecschema-metadata.d.ts +51 -49
  146. package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
  147. package/lib/cjs/ecschema-metadata.js +96 -94
  148. package/lib/cjs/ecschema-metadata.js.map +1 -1
  149. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  150. package/lib/cjs/utils/SchemaGraph.d.ts.map +1 -1
  151. package/lib/cjs/utils/SchemaGraph.js +65 -65
  152. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  153. package/package.json +8 -8
@@ -1,221 +1,220 @@
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.SchemaItemKey = exports.SchemaKey = exports.ECVersion = void 0;
11
- const ECObjects_1 = require("./ECObjects");
12
- const Exception_1 = require("./Exception");
13
- const ECName_1 = require("./ECName");
14
- /**
15
- * @beta
16
- */
17
- class ECVersion {
18
- /**
19
- * The constructor will throw an ECObjectsError if any of the parameters below are above the threshold.
20
- * @param read Can support up to 999.
21
- * @param write Can support up to 999.
22
- * @param minor Can support up to 9999999.
23
- *
24
- */
25
- constructor(read, write, minor) {
26
- this._read = 0;
27
- this._write = 0;
28
- this._minor = 0;
29
- if (undefined !== read)
30
- this._read = read;
31
- if (undefined !== write)
32
- this._write = write;
33
- if (undefined !== minor)
34
- this._minor = minor;
35
- if (this._read > 999 || this._read < 0 || this._write > 999 || this._write < 0 || this._minor > 9999999 || this._minor < 0)
36
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion);
37
- }
38
- get read() { return this._read; }
39
- get write() { return this._write; }
40
- get minor() { return this._minor; }
41
- /**
42
- * Creates a string, in the format 'RR.ww.mm', representing this ECVersion.
43
- * @note The default is to pad with zeroes.
44
- * @param padZeroes If true, the returned string will strictly follow `RR.ww.mm` and add leading zeroes if necessary.
45
- */
46
- toString(padZeroes = true) {
47
- if (!padZeroes)
48
- return `${this.read}.${this.write}.${this.minor}`;
49
- const padWithZeroes = (num) => {
50
- return (num < 10 ? "0" : "") + num;
51
- };
52
- return `${padWithZeroes(this.read)}.${padWithZeroes(this.write)}.${padWithZeroes(this.minor)}`;
53
- }
54
- /**
55
- * Given a valid version string the
56
- * @param versionString A valid version string of the format, 'RR.ww.mm'.
57
- */
58
- static fromString(versionString) {
59
- const [read, write, minor] = versionString.split(".");
60
- if (!read)
61
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
62
- if (!write)
63
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion, `The write version is missing from version string, ${versionString}`);
64
- if (!minor)
65
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
66
- return new ECVersion(+read, +write, +minor);
67
- }
68
- /**
69
- * Compares two schema versions.
70
- * @param rhs The schema to compare.
71
- * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.
72
- */
73
- compare(rhv) {
74
- if (this.read !== rhv.read)
75
- return this.read - rhv.read;
76
- if (this.write !== rhv.write)
77
- return this.write - rhv.write;
78
- return this.minor - rhv.minor;
79
- }
80
- }
81
- exports.ECVersion = ECVersion;
82
- /**
83
- * The SchemaKey contains a Schemas name and version.
84
- * @beta
85
- */
86
- class SchemaKey {
87
- constructor(name, readOrVersion, writeVersion, minorVersion) {
88
- this._name = new ECName_1.ECName(name);
89
- if (readOrVersion !== undefined && typeof (readOrVersion) !== "number")
90
- this._version = readOrVersion;
91
- else
92
- this._version = new ECVersion(readOrVersion, writeVersion, minorVersion);
93
- }
94
- get version() { return this._version; }
95
- get name() { return this._name.name; }
96
- get readVersion() { return this.version.read; }
97
- get writeVersion() { return this.version.write; }
98
- get minorVersion() { return this.version.minor; }
99
- /**
100
- * Creates a string, in the format 'RR.ww.mm', representing this SchemaKey.
101
- * @note The default is to pad the full name with zeroes.
102
- * @param padZeroes If true, the returned string will strictly follow `Name.RR.ww.mm` and add leading zeroes if necessary.
103
- */
104
- toString(padZeroes = true) { return `${this.name}.${this.version.toString(padZeroes)}`; }
105
- static parseString(fullName) {
106
- const keyPieces = fullName.split(".");
107
- if (keyPieces.length !== 4)
108
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName);
109
- const schemaName = keyPieces[0];
110
- const readVer = Number(keyPieces[1]);
111
- const writeVer = Number(keyPieces[2]);
112
- const minorVer = Number(keyPieces[3]);
113
- return new SchemaKey(schemaName, new ECVersion(readVer, writeVer, minorVer));
114
- }
115
- /**
116
- * Compares two schema names, case-insensitive.
117
- * @return True if they match; otherwise, false.
118
- */
119
- compareByName(rhs) {
120
- if (undefined === rhs) {
121
- return false;
122
- }
123
- if (typeof (rhs) === "string")
124
- return rhs.toLowerCase() === this.name.toLowerCase();
125
- return rhs.name.toLowerCase() === this.name.toLowerCase();
126
- }
127
- /**
128
- * Compares two schema versions.
129
- * @param rhs The schema to compare.
130
- * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.
131
- */
132
- compareByVersion(rhs) {
133
- return this.version.compare(rhs.version);
134
- }
135
- /**
136
- *
137
- * @param rhs The SchemaKey to compare with
138
- * @param matchType The match type to use for comparison.
139
- */
140
- matches(rhs, matchType = ECObjects_1.SchemaMatchType.Identical) {
141
- switch (matchType) {
142
- case ECObjects_1.SchemaMatchType.Identical:
143
- // TODO: if (this.checksum && rhs.checksum)
144
- // TODO: return this.checksum === rhs.checksum;
145
- return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&
146
- this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;
147
- case ECObjects_1.SchemaMatchType.Exact:
148
- return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&
149
- this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;
150
- case ECObjects_1.SchemaMatchType.LatestReadCompatible:
151
- if (!this.compareByName(rhs.name))
152
- return false;
153
- if (rhs.readVersion !== this.readVersion)
154
- return false;
155
- if (this.writeVersion === rhs.writeVersion)
156
- return this.minorVersion >= rhs.minorVersion;
157
- return this.writeVersion > rhs.writeVersion;
158
- case ECObjects_1.SchemaMatchType.LatestWriteCompatible:
159
- return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&
160
- this.writeVersion === rhs.writeVersion && this.minorVersion >= rhs.minorVersion;
161
- case ECObjects_1.SchemaMatchType.Latest:
162
- return this.compareByName(rhs.name);
163
- default:
164
- return false;
165
- }
166
- }
167
- /**
168
- * Deserializes a SchemaKeyProps JSON object into a SchemaKey object.
169
- * @param props SchemaKeyProps
170
- * @returns A SchemaKey object.
171
- */
172
- static fromJSON(props) {
173
- return new SchemaKey(props.name, props.read, props.write, props.minor);
174
- }
175
- /**
176
- * Save this SchemaKey's properties to an object for serializing to JSON.
177
- */
178
- toJSON() {
179
- return {
180
- name: this.name,
181
- read: this.readVersion,
182
- write: this.writeVersion,
183
- minor: this.minorVersion,
184
- };
185
- }
186
- }
187
- exports.SchemaKey = SchemaKey;
188
- /**
189
- * The SchemaItemKey contains a SchemaItem's name and SchemaKey.
190
- * @beta
191
- */
192
- class SchemaItemKey {
193
- constructor(name, schema) {
194
- this._name = new ECName_1.ECName(name);
195
- this._schemaKey = schema;
196
- }
197
- get schemaKey() { return this._schemaKey; }
198
- get name() { return this._name.name; }
199
- get schemaName() { return this.schemaKey.name; }
200
- /** Returns the name in the format, {schemaName}.{name}. */
201
- get fullName() { return `${this.schemaName}.${this.name}`; }
202
- /**
203
- * Checks whether this SchemaItemKey matches the one provided.
204
- * @param rhs The SchemaItemKey to compare to this.
205
- */
206
- // TODO: Need to add a match type
207
- matches(rhs) {
208
- if (rhs.name !== this.name)
209
- return false;
210
- if (!rhs.schemaKey.matches(this.schemaKey, ECObjects_1.SchemaMatchType.Latest))
211
- return false;
212
- return true;
213
- }
214
- matchesFullName(name) {
215
- const schemaVersion = this.schemaKey.version.toString().replace(/\./g, "\\.");
216
- const fullNameRegex = new RegExp(`^${this.schemaName}(\\.${schemaVersion})?[.:]${this.name}$`, "i");
217
- return fullNameRegex.test(name);
218
- }
219
- }
220
- exports.SchemaItemKey = SchemaItemKey;
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.SchemaItemKey = exports.SchemaKey = exports.ECVersion = void 0;
11
+ const ECObjects_1 = require("./ECObjects");
12
+ const Exception_1 = require("./Exception");
13
+ const ECName_1 = require("./ECName");
14
+ /**
15
+ * @beta
16
+ */
17
+ class ECVersion {
18
+ /**
19
+ * The constructor will throw an ECObjectsError if any of the parameters below are above the threshold.
20
+ * @param read Can support up to 999.
21
+ * @param write Can support up to 999.
22
+ * @param minor Can support up to 9999999.
23
+ *
24
+ */
25
+ constructor(read, write, minor) {
26
+ this._read = 0;
27
+ this._write = 0;
28
+ this._minor = 0;
29
+ if (undefined !== read)
30
+ this._read = read;
31
+ if (undefined !== write)
32
+ this._write = write;
33
+ if (undefined !== minor)
34
+ this._minor = minor;
35
+ if (this._read > 999 || this._read < 0 || this._write > 999 || this._write < 0 || this._minor > 9999999 || this._minor < 0)
36
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion);
37
+ }
38
+ get read() { return this._read; }
39
+ get write() { return this._write; }
40
+ get minor() { return this._minor; }
41
+ /**
42
+ * Creates a string, in the format 'RR.ww.mm', representing this ECVersion.
43
+ * @note The default is to pad with zeroes.
44
+ * @param padZeroes If true, the returned string will strictly follow `RR.ww.mm` and add leading zeroes if necessary.
45
+ */
46
+ toString(padZeroes = true) {
47
+ if (!padZeroes)
48
+ return `${this.read}.${this.write}.${this.minor}`;
49
+ const padWithZeroes = (num) => {
50
+ return (num < 10 ? "0" : "") + num;
51
+ };
52
+ return `${padWithZeroes(this.read)}.${padWithZeroes(this.write)}.${padWithZeroes(this.minor)}`;
53
+ }
54
+ /**
55
+ * Given a valid version string the
56
+ * @param versionString A valid version string of the format, 'RR.ww.mm'.
57
+ */
58
+ static fromString(versionString) {
59
+ const [read, write, minor] = versionString.split(".");
60
+ if (!read)
61
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
62
+ if (!write)
63
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion, `The write version is missing from version string, ${versionString}`);
64
+ if (!minor)
65
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
66
+ return new ECVersion(+read, +write, +minor);
67
+ }
68
+ /**
69
+ * Compares two schema versions.
70
+ * @param rhs The schema to compare.
71
+ * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.
72
+ */
73
+ compare(rhv) {
74
+ if (this.read !== rhv.read)
75
+ return this.read - rhv.read;
76
+ if (this.write !== rhv.write)
77
+ return this.write - rhv.write;
78
+ return this.minor - rhv.minor;
79
+ }
80
+ }
81
+ exports.ECVersion = ECVersion;
82
+ /**
83
+ * The SchemaKey contains a Schemas name and version.
84
+ * @beta
85
+ */
86
+ class SchemaKey {
87
+ constructor(name, readOrVersion, writeVersion, minorVersion) {
88
+ this._name = new ECName_1.ECName(name);
89
+ if (readOrVersion !== undefined && typeof (readOrVersion) !== "number")
90
+ this._version = readOrVersion;
91
+ else
92
+ this._version = new ECVersion(readOrVersion, writeVersion, minorVersion);
93
+ }
94
+ get version() { return this._version; }
95
+ get name() { return this._name.name; }
96
+ get readVersion() { return this.version.read; }
97
+ get writeVersion() { return this.version.write; }
98
+ get minorVersion() { return this.version.minor; }
99
+ /**
100
+ * Creates a string, in the format 'RR.ww.mm', representing this SchemaKey.
101
+ * @note The default is to pad the full name with zeroes.
102
+ * @param padZeroes If true, the returned string will strictly follow `Name.RR.ww.mm` and add leading zeroes if necessary.
103
+ */
104
+ toString(padZeroes = true) { return `${this.name}.${this.version.toString(padZeroes)}`; }
105
+ static parseString(fullName) {
106
+ const keyPieces = fullName.split(".");
107
+ if (keyPieces.length !== 4)
108
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName);
109
+ const schemaName = keyPieces[0];
110
+ const readVer = Number(keyPieces[1]);
111
+ const writeVer = Number(keyPieces[2]);
112
+ const minorVer = Number(keyPieces[3]);
113
+ return new SchemaKey(schemaName, new ECVersion(readVer, writeVer, minorVer));
114
+ }
115
+ /**
116
+ * Compares two schema names, case-insensitive.
117
+ * @return True if they match; otherwise, false.
118
+ */
119
+ compareByName(rhs) {
120
+ if (undefined === rhs)
121
+ return false;
122
+ if (typeof (rhs) === "string")
123
+ return rhs.toLowerCase() === this.name.toLowerCase();
124
+ return rhs.name.toLowerCase() === this.name.toLowerCase();
125
+ }
126
+ /**
127
+ * Compares two schema versions.
128
+ * @param rhs The schema to compare.
129
+ * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.
130
+ */
131
+ compareByVersion(rhs) {
132
+ return this.version.compare(rhs.version);
133
+ }
134
+ /**
135
+ *
136
+ * @param rhs The SchemaKey to compare with
137
+ * @param matchType The match type to use for comparison.
138
+ */
139
+ matches(rhs, matchType = ECObjects_1.SchemaMatchType.Identical) {
140
+ switch (matchType) {
141
+ case ECObjects_1.SchemaMatchType.Identical:
142
+ // TODO: if (this.checksum && rhs.checksum)
143
+ // TODO: return this.checksum === rhs.checksum;
144
+ return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&
145
+ this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;
146
+ case ECObjects_1.SchemaMatchType.Exact:
147
+ return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&
148
+ this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;
149
+ case ECObjects_1.SchemaMatchType.LatestReadCompatible:
150
+ if (!this.compareByName(rhs.name))
151
+ return false;
152
+ if (rhs.readVersion !== this.readVersion)
153
+ return false;
154
+ if (this.writeVersion === rhs.writeVersion)
155
+ return this.minorVersion >= rhs.minorVersion;
156
+ return this.writeVersion > rhs.writeVersion;
157
+ case ECObjects_1.SchemaMatchType.LatestWriteCompatible:
158
+ return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&
159
+ this.writeVersion === rhs.writeVersion && this.minorVersion >= rhs.minorVersion;
160
+ case ECObjects_1.SchemaMatchType.Latest:
161
+ return this.compareByName(rhs.name);
162
+ default:
163
+ return false;
164
+ }
165
+ }
166
+ /**
167
+ * Deserializes a SchemaKeyProps JSON object into a SchemaKey object.
168
+ * @param props SchemaKeyProps
169
+ * @returns A SchemaKey object.
170
+ */
171
+ static fromJSON(props) {
172
+ return new SchemaKey(props.name, props.read, props.write, props.minor);
173
+ }
174
+ /**
175
+ * Save this SchemaKey's properties to an object for serializing to JSON.
176
+ */
177
+ toJSON() {
178
+ return {
179
+ name: this.name,
180
+ read: this.readVersion,
181
+ write: this.writeVersion,
182
+ minor: this.minorVersion,
183
+ };
184
+ }
185
+ }
186
+ exports.SchemaKey = SchemaKey;
187
+ /**
188
+ * The SchemaItemKey contains a SchemaItem's name and SchemaKey.
189
+ * @beta
190
+ */
191
+ class SchemaItemKey {
192
+ constructor(name, schema) {
193
+ this._name = new ECName_1.ECName(name);
194
+ this._schemaKey = schema;
195
+ }
196
+ get schemaKey() { return this._schemaKey; }
197
+ get name() { return this._name.name; }
198
+ get schemaName() { return this.schemaKey.name; }
199
+ /** Returns the name in the format, {schemaName}.{name}. */
200
+ get fullName() { return `${this.schemaName}.${this.name}`; }
201
+ /**
202
+ * Checks whether this SchemaItemKey matches the one provided.
203
+ * @param rhs The SchemaItemKey to compare to this.
204
+ */
205
+ // TODO: Need to add a match type
206
+ matches(rhs) {
207
+ if (rhs.name !== this.name)
208
+ return false;
209
+ if (!rhs.schemaKey.matches(this.schemaKey, ECObjects_1.SchemaMatchType.Latest))
210
+ return false;
211
+ return true;
212
+ }
213
+ matchesFullName(name) {
214
+ const schemaVersion = this.schemaKey.version.toString().replace(/\./g, "\\.");
215
+ const fullNameRegex = new RegExp(`^${this.schemaName}(\\.${schemaVersion})?[.:]${this.name}$`, "i");
216
+ return fullNameRegex.test(name);
217
+ }
218
+ }
219
+ exports.SchemaItemKey = SchemaItemKey;
221
220
  //# sourceMappingURL=SchemaKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaKey.js","sourceRoot":"","sources":["../../src/SchemaKey.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG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,CAAC,CAAC;IAClC,CAAC;CACF;AArCD,sCAqCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { SchemaKeyProps } from \"./Deserialization/JsonProps\";\r\nimport { SchemaMatchType } from \"./ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"./Exception\";\r\nimport { ECName } from \"./ECName\";\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class ECVersion {\r\n private _read: number = 0;\r\n private _write: number = 0;\r\n private _minor: number = 0;\r\n\r\n /**\r\n * The constructor will throw an ECObjectsError if any of the parameters below are above the threshold.\r\n * @param read Can support up to 999.\r\n * @param write Can support up to 999.\r\n * @param minor Can support up to 9999999.\r\n *\r\n */\r\n constructor(read?: number, write?: number, minor?: number) {\r\n if (undefined !== read) this._read = read;\r\n if (undefined !== write) this._write = write;\r\n if (undefined !== minor) this._minor = minor;\r\n\r\n if (this._read > 999 || this._read < 0 || this._write > 999 || this._write < 0 || this._minor > 9999999 || this._minor < 0)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion);\r\n }\r\n\r\n public get read() { return this._read; }\r\n public get write() { return this._write; }\r\n public get minor() { return this._minor; }\r\n\r\n /**\r\n * Creates a string, in the format 'RR.ww.mm', representing this ECVersion.\r\n * @note The default is to pad with zeroes.\r\n * @param padZeroes If true, the returned string will strictly follow `RR.ww.mm` and add leading zeroes if necessary.\r\n */\r\n public toString(padZeroes: boolean = true): string {\r\n if (!padZeroes)\r\n return `${this.read}.${this.write}.${this.minor}`;\r\n\r\n const padWithZeroes = (num: number) => {\r\n return (num < 10 ? \"0\" : \"\") + num;\r\n };\r\n\r\n return `${padWithZeroes(this.read)}.${padWithZeroes(this.write)}.${padWithZeroes(this.minor)}`;\r\n }\r\n\r\n /**\r\n * Given a valid version string the\r\n * @param versionString A valid version string of the format, 'RR.ww.mm'.\r\n */\r\n public static fromString(versionString: string): ECVersion {\r\n const [read, write, minor] = versionString.split(\".\");\r\n if (!read)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!write)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The write version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, +write, +minor);\r\n }\r\n\r\n /**\r\n * Compares two schema versions.\r\n * @param rhs The schema to compare.\r\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\r\n */\r\n public compare(rhv: ECVersion): number {\r\n if (this.read !== rhv.read)\r\n return this.read - rhv.read;\r\n\r\n if (this.write !== rhv.write)\r\n return this.write - rhv.write;\r\n\r\n return this.minor - rhv.minor;\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaKey contains a Schemas name and version.\r\n * @beta\r\n */\r\nexport class SchemaKey {\r\n private _name: ECName;\r\n protected _version: ECVersion;\r\n // public checksum: number;\r\n // TODO: need to add a checksum\r\n\r\n constructor(name: string, version: ECVersion);\r\n constructor(name: string, readVersion?: number, writeVersion?: number, minorVersion?: number);\r\n constructor(name: string, readOrVersion?: number | ECVersion, writeVersion?: number, minorVersion?: number) {\r\n this._name = new ECName(name);\r\n if (readOrVersion !== undefined && typeof(readOrVersion) !== \"number\")\r\n this._version = readOrVersion;\r\n else\r\n this._version = new ECVersion(readOrVersion, writeVersion, minorVersion);\r\n }\r\n\r\n public get version() { return this._version; }\r\n public get name() { return this._name.name; }\r\n public get readVersion() { return this.version.read; }\r\n public get writeVersion() { return this.version.write; }\r\n public get minorVersion() { return this.version.minor; }\r\n\r\n /**\r\n * Creates a string, in the format 'RR.ww.mm', representing this SchemaKey.\r\n * @note The default is to pad the full name with zeroes.\r\n * @param padZeroes If true, the returned string will strictly follow `Name.RR.ww.mm` and add leading zeroes if necessary.\r\n */\r\n public toString(padZeroes: boolean = true) { return `${this.name}.${this.version.toString(padZeroes)}`; }\r\n\r\n public static parseString(fullName: string) {\r\n const keyPieces = fullName.split(\".\");\r\n if (keyPieces.length !== 4)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECName);\r\n\r\n const schemaName = keyPieces[0];\r\n const readVer = Number(keyPieces[1]);\r\n const writeVer = Number(keyPieces[2]);\r\n const minorVer = Number(keyPieces[3]);\r\n return new SchemaKey(schemaName, new ECVersion(readVer, writeVer, minorVer));\r\n }\r\n\r\n /**\r\n * Compares two schema names, case-insensitive.\r\n * @return True if they match; otherwise, false.\r\n */\r\n public compareByName(rhs: SchemaKey | string | undefined): boolean {\r\n if (undefined === rhs) { return false; }\r\n if (typeof (rhs) === \"string\")\r\n return rhs.toLowerCase() === this.name.toLowerCase();\r\n return rhs.name.toLowerCase() === this.name.toLowerCase();\r\n }\r\n\r\n /**\r\n * Compares two schema versions.\r\n * @param rhs The schema to compare.\r\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\r\n */\r\n public compareByVersion(rhs: SchemaKey): number {\r\n return this.version.compare(rhs.version);\r\n }\r\n\r\n /**\r\n *\r\n * @param rhs The SchemaKey to compare with\r\n * @param matchType The match type to use for comparison.\r\n */\r\n public matches(rhs: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Identical): boolean {\r\n switch (matchType) {\r\n case SchemaMatchType.Identical:\r\n // TODO: if (this.checksum && rhs.checksum)\r\n // TODO: return this.checksum === rhs.checksum;\r\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\r\n this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;\r\n case SchemaMatchType.Exact:\r\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\r\n this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;\r\n case SchemaMatchType.LatestReadCompatible:\r\n if (!this.compareByName(rhs.name))\r\n return false;\r\n\r\n if (rhs.readVersion !== this.readVersion)\r\n return false;\r\n\r\n if (this.writeVersion === rhs.writeVersion)\r\n return this.minorVersion >= rhs.minorVersion;\r\n\r\n return this.writeVersion > rhs.writeVersion;\r\n case SchemaMatchType.LatestWriteCompatible:\r\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\r\n this.writeVersion === rhs.writeVersion && this.minorVersion >= rhs.minorVersion;\r\n case SchemaMatchType.Latest:\r\n return this.compareByName(rhs.name);\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Deserializes a SchemaKeyProps JSON object into a SchemaKey object.\r\n * @param props SchemaKeyProps\r\n * @returns A SchemaKey object.\r\n */\r\n public static fromJSON(props: SchemaKeyProps): SchemaKey {\r\n return new SchemaKey(props.name, props.read, props.write, props.minor);\r\n }\r\n\r\n /**\r\n * Save this SchemaKey's properties to an object for serializing to JSON.\r\n */\r\n public toJSON(): SchemaKeyProps {\r\n return {\r\n name: this.name,\r\n read: this.readVersion,\r\n write: this.writeVersion,\r\n minor: this.minorVersion,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaItemKey contains a SchemaItem's name and SchemaKey.\r\n * @beta\r\n */\r\nexport class SchemaItemKey {\r\n private _name: ECName;\r\n protected _schemaKey: SchemaKey;\r\n\r\n constructor(name: string, schema: SchemaKey) {\r\n this._name = new ECName(name);\r\n this._schemaKey = schema;\r\n }\r\n\r\n public get schemaKey() { return this._schemaKey; }\r\n public get name() { return this._name.name; }\r\n\r\n public get schemaName() { return this.schemaKey.name; }\r\n\r\n /** Returns the name in the format, {schemaName}.{name}. */\r\n public get fullName() { return `${this.schemaName}.${this.name}`; }\r\n\r\n /**\r\n * Checks whether this SchemaItemKey matches the one provided.\r\n * @param rhs The SchemaItemKey to compare to this.\r\n */\r\n // TODO: Need to add a match type\r\n public matches(rhs: SchemaItemKey): boolean {\r\n if (rhs.name !== this.name)\r\n return false;\r\n\r\n if (!rhs.schemaKey.matches(this.schemaKey, SchemaMatchType.Latest))\r\n return false;\r\n\r\n return true;\r\n }\r\n\r\n public matchesFullName(name: string): boolean {\r\n const schemaVersion = this.schemaKey.version.toString().replace(/\\./g, \"\\\\.\");\r\n const fullNameRegex = new RegExp(`^${this.schemaName}(\\\\.${schemaVersion})?[.:]${this.name}$`, \"i\");\r\n return fullNameRegex.test(name);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaKey.js","sourceRoot":"","sources":["../../src/SchemaKey.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,2CAA8C;AAC9C,2CAA8D;AAC9D,qCAAkC;AAElC;;GAEG;AACH,MAAa,SAAS;IAKpB;;;;;;OAMG;IACH,YAAY,IAAa,EAAE,KAAc,EAAE,KAAc;QAXjD,UAAK,GAAW,CAAC,CAAC;QAClB,WAAM,GAAW,CAAC,CAAC;QACnB,WAAM,GAAW,CAAC,CAAC;QAUzB,IAAI,SAAS,KAAK,IAAI;YACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACtB,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEtB,IAAI,IAAI,CAAC,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,OAAO,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YACxH,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,gBAAgB,CAAC,CAAC;IAC/D,CAAC;IAED,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,IAAW,KAAK,KAAK,OAAO,I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,OAAO,KAAK,CAAC;QAEf,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,eAAe,CAAC,IAAY;QACjC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9E,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,OAAO,aAAa,SAAS,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;QACpG,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AArCD,sCAqCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { SchemaKeyProps } from \"./Deserialization/JsonProps\";\nimport { SchemaMatchType } from \"./ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"./Exception\";\nimport { ECName } from \"./ECName\";\n\n/**\n * @beta\n */\nexport class ECVersion {\n private _read: number = 0;\n private _write: number = 0;\n private _minor: number = 0;\n\n /**\n * The constructor will throw an ECObjectsError if any of the parameters below are above the threshold.\n * @param read Can support up to 999.\n * @param write Can support up to 999.\n * @param minor Can support up to 9999999.\n *\n */\n constructor(read?: number, write?: number, minor?: number) {\n if (undefined !== read)\n this._read = read;\n if (undefined !== write)\n this._write = write;\n if (undefined !== minor)\n this._minor = minor;\n\n if (this._read > 999 || this._read < 0 || this._write > 999 || this._write < 0 || this._minor > 9999999 || this._minor < 0)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion);\n }\n\n public get read() { return this._read; }\n public get write() { return this._write; }\n public get minor() { return this._minor; }\n\n /**\n * Creates a string, in the format 'RR.ww.mm', representing this ECVersion.\n * @note The default is to pad with zeroes.\n * @param padZeroes If true, the returned string will strictly follow `RR.ww.mm` and add leading zeroes if necessary.\n */\n public toString(padZeroes: boolean = true): string {\n if (!padZeroes)\n return `${this.read}.${this.write}.${this.minor}`;\n\n const padWithZeroes = (num: number) => {\n return (num < 10 ? \"0\" : \"\") + num;\n };\n\n return `${padWithZeroes(this.read)}.${padWithZeroes(this.write)}.${padWithZeroes(this.minor)}`;\n }\n\n /**\n * Given a valid version string the\n * @param versionString A valid version string of the format, 'RR.ww.mm'.\n */\n public static fromString(versionString: string): ECVersion {\n const [read, write, minor] = versionString.split(\".\");\n if (!read)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\n\n if (!write)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The write version is missing from version string, ${versionString}`);\n\n if (!minor)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\n\n return new ECVersion(+read, +write, +minor);\n }\n\n /**\n * Compares two schema versions.\n * @param rhs The schema to compare.\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\n */\n public compare(rhv: ECVersion): number {\n if (this.read !== rhv.read)\n return this.read - rhv.read;\n\n if (this.write !== rhv.write)\n return this.write - rhv.write;\n\n return this.minor - rhv.minor;\n }\n}\n\n/**\n * The SchemaKey contains a Schemas name and version.\n * @beta\n */\nexport class SchemaKey {\n private _name: ECName;\n protected _version: ECVersion;\n // public checksum: number;\n // TODO: need to add a checksum\n\n constructor(name: string, version: ECVersion);\n constructor(name: string, readVersion?: number, writeVersion?: number, minorVersion?: number);\n constructor(name: string, readOrVersion?: number | ECVersion, writeVersion?: number, minorVersion?: number) {\n this._name = new ECName(name);\n if (readOrVersion !== undefined && typeof(readOrVersion) !== \"number\")\n this._version = readOrVersion;\n else\n this._version = new ECVersion(readOrVersion, writeVersion, minorVersion);\n }\n\n public get version() { return this._version; }\n public get name() { return this._name.name; }\n public get readVersion() { return this.version.read; }\n public get writeVersion() { return this.version.write; }\n public get minorVersion() { return this.version.minor; }\n\n /**\n * Creates a string, in the format 'RR.ww.mm', representing this SchemaKey.\n * @note The default is to pad the full name with zeroes.\n * @param padZeroes If true, the returned string will strictly follow `Name.RR.ww.mm` and add leading zeroes if necessary.\n */\n public toString(padZeroes: boolean = true) { return `${this.name}.${this.version.toString(padZeroes)}`; }\n\n public static parseString(fullName: string) {\n const keyPieces = fullName.split(\".\");\n if (keyPieces.length !== 4)\n throw new ECObjectsError(ECObjectsStatus.InvalidECName);\n\n const schemaName = keyPieces[0];\n const readVer = Number(keyPieces[1]);\n const writeVer = Number(keyPieces[2]);\n const minorVer = Number(keyPieces[3]);\n return new SchemaKey(schemaName, new ECVersion(readVer, writeVer, minorVer));\n }\n\n /**\n * Compares two schema names, case-insensitive.\n * @return True if they match; otherwise, false.\n */\n public compareByName(rhs: SchemaKey | string | undefined): boolean {\n if (undefined === rhs)\n return false;\n\n if (typeof (rhs) === \"string\")\n return rhs.toLowerCase() === this.name.toLowerCase();\n\n return rhs.name.toLowerCase() === this.name.toLowerCase();\n }\n\n /**\n * Compares two schema versions.\n * @param rhs The schema to compare.\n * @return A negative number if this schema version is less than the given version, a positive number if greater, and 0 if are equivalent.\n */\n public compareByVersion(rhs: SchemaKey): number {\n return this.version.compare(rhs.version);\n }\n\n /**\n *\n * @param rhs The SchemaKey to compare with\n * @param matchType The match type to use for comparison.\n */\n public matches(rhs: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Identical): boolean {\n switch (matchType) {\n case SchemaMatchType.Identical:\n // TODO: if (this.checksum && rhs.checksum)\n // TODO: return this.checksum === rhs.checksum;\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\n this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;\n case SchemaMatchType.Exact:\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\n this.writeVersion === rhs.writeVersion && this.minorVersion === rhs.minorVersion;\n case SchemaMatchType.LatestReadCompatible:\n if (!this.compareByName(rhs.name))\n return false;\n\n if (rhs.readVersion !== this.readVersion)\n return false;\n\n if (this.writeVersion === rhs.writeVersion)\n return this.minorVersion >= rhs.minorVersion;\n\n return this.writeVersion > rhs.writeVersion;\n case SchemaMatchType.LatestWriteCompatible:\n return this.compareByName(rhs.name) && this.readVersion === rhs.readVersion &&\n this.writeVersion === rhs.writeVersion && this.minorVersion >= rhs.minorVersion;\n case SchemaMatchType.Latest:\n return this.compareByName(rhs.name);\n default:\n return false;\n }\n }\n\n /**\n * Deserializes a SchemaKeyProps JSON object into a SchemaKey object.\n * @param props SchemaKeyProps\n * @returns A SchemaKey object.\n */\n public static fromJSON(props: SchemaKeyProps): SchemaKey {\n return new SchemaKey(props.name, props.read, props.write, props.minor);\n }\n\n /**\n * Save this SchemaKey's properties to an object for serializing to JSON.\n */\n public toJSON(): SchemaKeyProps {\n return {\n name: this.name,\n read: this.readVersion,\n write: this.writeVersion,\n minor: this.minorVersion,\n };\n }\n}\n\n/**\n * The SchemaItemKey contains a SchemaItem's name and SchemaKey.\n * @beta\n */\nexport class SchemaItemKey {\n private _name: ECName;\n protected _schemaKey: SchemaKey;\n\n constructor(name: string, schema: SchemaKey) {\n this._name = new ECName(name);\n this._schemaKey = schema;\n }\n\n public get schemaKey() { return this._schemaKey; }\n public get name() { return this._name.name; }\n\n public get schemaName() { return this.schemaKey.name; }\n\n /** Returns the name in the format, {schemaName}.{name}. */\n public get fullName() { return `${this.schemaName}.${this.name}`; }\n\n /**\n * Checks whether this SchemaItemKey matches the one provided.\n * @param rhs The SchemaItemKey to compare to this.\n */\n // TODO: Need to add a match type\n public matches(rhs: SchemaItemKey): boolean {\n if (rhs.name !== this.name)\n return false;\n\n if (!rhs.schemaKey.matches(this.schemaKey, SchemaMatchType.Latest))\n return false;\n\n return true;\n }\n\n public matchesFullName(name: string): boolean {\n const schemaVersion = this.schemaKey.version.toString().replace(/\\./g, \"\\\\.\");\n const fullNameRegex = new RegExp(`^${this.schemaName}(\\\\.${schemaVersion})?[.:]${this.name}$`, \"i\");\n return fullNameRegex.test(name);\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { Schema } from "./Metadata/Schema";
2
+ import { SchemaPropsGetter } from "./SchemaJsonLocater";
3
+ /**
4
+ * A utility class for loading EC Schema objects using a function that returns schema json for a given schema name.
5
+ * Loaded schemas are held in memory within a schema context managed by SchemaLoader.
6
+ * The SchemaLoader object should be held in memory if multiple calls to [[getSchema]] or [[tryGetSchema]]
7
+ * is a possibility, thereby avoiding unnecessary schema retrievals from the function.
8
+ * @alpha
9
+ */
10
+ export declare class SchemaLoader {
11
+ private _context;
12
+ constructor(getSchema: SchemaPropsGetter);
13
+ /** Get a schema by name
14
+ * @param schemaName a string with the name of the schema to load.
15
+ * @throws [ECObjectsError]($ecschema-metadata) if the schema is not found or cannot be loaded.
16
+ */
17
+ getSchema<T extends Schema>(schemaName: string): T;
18
+ /** Attempts to get a schema by name
19
+ * @param schemaName a string with the name of the schema to load.
20
+ * @throws [ECObjectsError]($ecschema-metadata) if the schema exists, but cannot be loaded.
21
+ */
22
+ tryGetSchema<T extends Schema>(schemaName: string): T | undefined;
23
+ }
24
+ //# sourceMappingURL=SchemaLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaLoader.d.ts","sourceRoot":"","sources":["../../src/SchemaLoader.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAqB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG3E;;;;;;GAMG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAgB;gBAEb,SAAS,EAAE,iBAAiB;IAM/C;;;OAGG;IACI,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;IAQzD;;;OAGG;IACI,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;CAMzE"}
@@ -0,0 +1,48 @@
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.SchemaLoader = void 0;
8
+ const Context_1 = require("./Context");
9
+ const ECObjects_1 = require("./ECObjects");
10
+ const Exception_1 = require("./Exception");
11
+ const SchemaJsonLocater_1 = require("./SchemaJsonLocater");
12
+ const SchemaKey_1 = require("./SchemaKey");
13
+ /**
14
+ * A utility class for loading EC Schema objects using a function that returns schema json for a given schema name.
15
+ * Loaded schemas are held in memory within a schema context managed by SchemaLoader.
16
+ * The SchemaLoader object should be held in memory if multiple calls to [[getSchema]] or [[tryGetSchema]]
17
+ * is a possibility, thereby avoiding unnecessary schema retrievals from the function.
18
+ * @alpha
19
+ */
20
+ class SchemaLoader {
21
+ constructor(getSchema) {
22
+ this._context = new Context_1.SchemaContext();
23
+ const locater = new SchemaJsonLocater_1.SchemaJsonLocater(getSchema);
24
+ this._context.addLocater(locater);
25
+ }
26
+ /** Get a schema by name
27
+ * @param schemaName a string with the name of the schema to load.
28
+ * @throws [ECObjectsError]($ecschema-metadata) if the schema is not found or cannot be loaded.
29
+ */
30
+ getSchema(schemaName) {
31
+ const schema = this.tryGetSchema(schemaName);
32
+ if (!schema)
33
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.UnableToLocateSchema, `reading schema=${schemaName}`);
34
+ return schema;
35
+ }
36
+ /** Attempts to get a schema by name
37
+ * @param schemaName a string with the name of the schema to load.
38
+ * @throws [ECObjectsError]($ecschema-metadata) if the schema exists, but cannot be loaded.
39
+ */
40
+ tryGetSchema(schemaName) {
41
+ // SchemaKey version is not used when locating schema in an iModel, so the version is arbitrary.
42
+ const key = new SchemaKey_1.SchemaKey(schemaName, new SchemaKey_1.ECVersion(1, 0, 0));
43
+ const schema = this._context.getSchemaSync(key, ECObjects_1.SchemaMatchType.Latest);
44
+ return schema;
45
+ }
46
+ }
47
+ exports.SchemaLoader = SchemaLoader;
48
+ //# sourceMappingURL=SchemaLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaLoader.js","sourceRoot":"","sources":["../../src/SchemaLoader.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,uCAA0C;AAC1C,2CAA8C;AAC9C,2CAA8D;AAE9D,2DAA2E;AAC3E,2CAAmD;AAEnD;;;;;;GAMG;AACH,MAAa,YAAY;IAGvB,YAAmB,SAA4B;QAC7C,IAAI,CAAC,QAAQ,GAAG,IAAI,uBAAa,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,IAAI,qCAAiB,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,SAAS,CAAmB,UAAkB;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM;YACT,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,oBAAoB,EAAE,kBAAkB,UAAU,EAAE,CAAC,CAAC;QAEjG,OAAO,MAAW,CAAC;IACrB,CAAC;IAED;;;OAGG;IACI,YAAY,CAAmB,UAAkB;QACtD,gGAAgG;QAChG,MAAM,GAAG,GAAG,IAAI,qBAAS,CAAC,UAAU,EAAE,IAAI,qBAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,2BAAe,CAAC,MAAM,CAAC,CAAC;QACxE,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AA/BD,oCA+BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { SchemaContext } from \"./Context\";\nimport { SchemaMatchType } from \"./ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"./Exception\";\nimport { Schema } from \"./Metadata/Schema\";\nimport { SchemaJsonLocater, SchemaPropsGetter } from \"./SchemaJsonLocater\";\nimport { ECVersion, SchemaKey } from \"./SchemaKey\";\n\n/**\n * A utility class for loading EC Schema objects using a function that returns schema json for a given schema name.\n * Loaded schemas are held in memory within a schema context managed by SchemaLoader.\n * The SchemaLoader object should be held in memory if multiple calls to [[getSchema]] or [[tryGetSchema]]\n * is a possibility, thereby avoiding unnecessary schema retrievals from the function.\n * @alpha\n */\nexport class SchemaLoader {\n private _context: SchemaContext;\n\n public constructor(getSchema: SchemaPropsGetter) {\n this._context = new SchemaContext();\n const locater = new SchemaJsonLocater(getSchema);\n this._context.addLocater(locater);\n }\n\n /** Get a schema by name\n * @param schemaName a string with the name of the schema to load.\n * @throws [ECObjectsError]($ecschema-metadata) if the schema is not found or cannot be loaded.\n */\n public getSchema<T extends Schema>(schemaName: string): T {\n const schema = this.tryGetSchema(schemaName);\n if (!schema)\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `reading schema=${schemaName}`);\n\n return schema as T;\n }\n\n /** Attempts to get a schema by name\n * @param schemaName a string with the name of the schema to load.\n * @throws [ECObjectsError]($ecschema-metadata) if the schema exists, but cannot be loaded.\n */\n public tryGetSchema<T extends Schema>(schemaName: string): T | undefined {\n // SchemaKey version is not used when locating schema in an iModel, so the version is arbitrary.\n const key = new SchemaKey(schemaName, new ECVersion(1, 0, 0));\n const schema = this._context.getSchemaSync(key, SchemaMatchType.Latest);\n return schema as T;\n }\n}\n"]}