@itwin/ecschema-metadata 5.0.0-dev.59 → 5.0.0-dev.61

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 (209) hide show
  1. package/lib/cjs/Context.d.ts +36 -15
  2. package/lib/cjs/Context.d.ts.map +1 -1
  3. package/lib/cjs/Context.js +10 -18
  4. package/lib/cjs/Context.js.map +1 -1
  5. package/lib/cjs/Deserialization/Helper.d.ts +3 -3
  6. package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
  7. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  8. package/lib/cjs/Deserialization/XmlParser.js +2 -1
  9. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  10. package/lib/cjs/ECObjects.d.ts +21 -1
  11. package/lib/cjs/ECObjects.d.ts.map +1 -1
  12. package/lib/cjs/ECObjects.js +34 -2
  13. package/lib/cjs/ECObjects.js.map +1 -1
  14. package/lib/cjs/Interfaces.d.ts +7 -0
  15. package/lib/cjs/Interfaces.d.ts.map +1 -1
  16. package/lib/cjs/Interfaces.js.map +1 -1
  17. package/lib/cjs/Metadata/Class.d.ts +24 -2
  18. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  19. package/lib/cjs/Metadata/Class.js +40 -10
  20. package/lib/cjs/Metadata/Class.js.map +1 -1
  21. package/lib/cjs/Metadata/Constant.d.ts +14 -1
  22. package/lib/cjs/Metadata/Constant.d.ts.map +1 -1
  23. package/lib/cjs/Metadata/Constant.js +23 -2
  24. package/lib/cjs/Metadata/Constant.js.map +1 -1
  25. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +15 -1
  26. package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
  27. package/lib/cjs/Metadata/CustomAttributeClass.js +21 -1
  28. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  29. package/lib/cjs/Metadata/EntityClass.d.ts +17 -3
  30. package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
  31. package/lib/cjs/Metadata/EntityClass.js +28 -6
  32. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  33. package/lib/cjs/Metadata/Enumeration.d.ts +14 -1
  34. package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
  35. package/lib/cjs/Metadata/Enumeration.js +19 -1
  36. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  37. package/lib/cjs/Metadata/Format.d.ts +13 -1
  38. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  39. package/lib/cjs/Metadata/Format.js +24 -3
  40. package/lib/cjs/Metadata/Format.js.map +1 -1
  41. package/lib/cjs/Metadata/InvertedUnit.d.ts +8 -1
  42. package/lib/cjs/Metadata/InvertedUnit.d.ts.map +1 -1
  43. package/lib/cjs/Metadata/InvertedUnit.js +15 -3
  44. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  45. package/lib/cjs/Metadata/KindOfQuantity.d.ts +14 -1
  46. package/lib/cjs/Metadata/KindOfQuantity.d.ts.map +1 -1
  47. package/lib/cjs/Metadata/KindOfQuantity.js +40 -13
  48. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  49. package/lib/cjs/Metadata/Mixin.d.ts +15 -1
  50. package/lib/cjs/Metadata/Mixin.d.ts.map +1 -1
  51. package/lib/cjs/Metadata/Mixin.js +22 -2
  52. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  53. package/lib/cjs/Metadata/Phenomenon.d.ts +14 -1
  54. package/lib/cjs/Metadata/Phenomenon.d.ts.map +1 -1
  55. package/lib/cjs/Metadata/Phenomenon.js +21 -1
  56. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  57. package/lib/cjs/Metadata/Property.d.ts +1 -1
  58. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  59. package/lib/cjs/Metadata/Property.js +11 -6
  60. package/lib/cjs/Metadata/Property.js.map +1 -1
  61. package/lib/cjs/Metadata/PropertyCategory.d.ts +14 -1
  62. package/lib/cjs/Metadata/PropertyCategory.d.ts.map +1 -1
  63. package/lib/cjs/Metadata/PropertyCategory.js +20 -1
  64. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  65. package/lib/cjs/Metadata/RelationshipClass.d.ts +15 -1
  66. package/lib/cjs/Metadata/RelationshipClass.d.ts.map +1 -1
  67. package/lib/cjs/Metadata/RelationshipClass.js +29 -6
  68. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  69. package/lib/cjs/Metadata/Schema.d.ts +114 -6
  70. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  71. package/lib/cjs/Metadata/Schema.js +125 -24
  72. package/lib/cjs/Metadata/Schema.js.map +1 -1
  73. package/lib/cjs/Metadata/SchemaItem.d.ts +11 -2
  74. package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
  75. package/lib/cjs/Metadata/SchemaItem.js +6 -1
  76. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  77. package/lib/cjs/Metadata/Unit.d.ts +8 -1
  78. package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
  79. package/lib/cjs/Metadata/Unit.js +15 -3
  80. package/lib/cjs/Metadata/Unit.js.map +1 -1
  81. package/lib/cjs/Metadata/UnitSystem.d.ts +14 -1
  82. package/lib/cjs/Metadata/UnitSystem.d.ts.map +1 -1
  83. package/lib/cjs/Metadata/UnitSystem.js +22 -1
  84. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  85. package/lib/cjs/SchemaJsonLocater.d.ts +2 -2
  86. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
  87. package/lib/cjs/SchemaJsonLocater.js +1 -1
  88. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  89. package/lib/cjs/SchemaKey.d.ts +6 -0
  90. package/lib/cjs/SchemaKey.d.ts.map +1 -1
  91. package/lib/cjs/SchemaKey.js +6 -0
  92. package/lib/cjs/SchemaKey.js.map +1 -1
  93. package/lib/cjs/SchemaLoader.d.ts +2 -2
  94. package/lib/cjs/SchemaLoader.d.ts.map +1 -1
  95. package/lib/cjs/SchemaLoader.js.map +1 -1
  96. package/lib/cjs/UnitConversion/UnitConversion.d.ts +1 -1
  97. package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -1
  98. package/lib/cjs/UnitConversion/UnitConversion.js +5 -5
  99. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  100. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +3 -3
  101. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  102. package/lib/cjs/Validation/SchemaWalker.d.ts +1 -1
  103. package/lib/cjs/Validation/SchemaWalker.d.ts.map +1 -1
  104. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  105. package/lib/esm/Context.d.ts +36 -15
  106. package/lib/esm/Context.d.ts.map +1 -1
  107. package/lib/esm/Context.js +8 -16
  108. package/lib/esm/Context.js.map +1 -1
  109. package/lib/esm/Deserialization/Helper.d.ts +3 -3
  110. package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
  111. package/lib/esm/Deserialization/Helper.js.map +1 -1
  112. package/lib/esm/Deserialization/XmlParser.js +2 -1
  113. package/lib/esm/Deserialization/XmlParser.js.map +1 -1
  114. package/lib/esm/ECObjects.d.ts +21 -1
  115. package/lib/esm/ECObjects.d.ts.map +1 -1
  116. package/lib/esm/ECObjects.js +32 -1
  117. package/lib/esm/ECObjects.js.map +1 -1
  118. package/lib/esm/Interfaces.d.ts +7 -0
  119. package/lib/esm/Interfaces.d.ts.map +1 -1
  120. package/lib/esm/Interfaces.js.map +1 -1
  121. package/lib/esm/Metadata/Class.d.ts +24 -2
  122. package/lib/esm/Metadata/Class.d.ts.map +1 -1
  123. package/lib/esm/Metadata/Class.js +41 -11
  124. package/lib/esm/Metadata/Class.js.map +1 -1
  125. package/lib/esm/Metadata/Constant.d.ts +14 -1
  126. package/lib/esm/Metadata/Constant.d.ts.map +1 -1
  127. package/lib/esm/Metadata/Constant.js +23 -2
  128. package/lib/esm/Metadata/Constant.js.map +1 -1
  129. package/lib/esm/Metadata/CustomAttributeClass.d.ts +15 -1
  130. package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -1
  131. package/lib/esm/Metadata/CustomAttributeClass.js +21 -1
  132. package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
  133. package/lib/esm/Metadata/EntityClass.d.ts +17 -3
  134. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
  135. package/lib/esm/Metadata/EntityClass.js +28 -6
  136. package/lib/esm/Metadata/EntityClass.js.map +1 -1
  137. package/lib/esm/Metadata/Enumeration.d.ts +14 -1
  138. package/lib/esm/Metadata/Enumeration.d.ts.map +1 -1
  139. package/lib/esm/Metadata/Enumeration.js +19 -1
  140. package/lib/esm/Metadata/Enumeration.js.map +1 -1
  141. package/lib/esm/Metadata/Format.d.ts +13 -1
  142. package/lib/esm/Metadata/Format.d.ts.map +1 -1
  143. package/lib/esm/Metadata/Format.js +24 -3
  144. package/lib/esm/Metadata/Format.js.map +1 -1
  145. package/lib/esm/Metadata/InvertedUnit.d.ts +8 -1
  146. package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -1
  147. package/lib/esm/Metadata/InvertedUnit.js +15 -3
  148. package/lib/esm/Metadata/InvertedUnit.js.map +1 -1
  149. package/lib/esm/Metadata/KindOfQuantity.d.ts +14 -1
  150. package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -1
  151. package/lib/esm/Metadata/KindOfQuantity.js +40 -13
  152. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
  153. package/lib/esm/Metadata/Mixin.d.ts +15 -1
  154. package/lib/esm/Metadata/Mixin.d.ts.map +1 -1
  155. package/lib/esm/Metadata/Mixin.js +23 -3
  156. package/lib/esm/Metadata/Mixin.js.map +1 -1
  157. package/lib/esm/Metadata/Phenomenon.d.ts +14 -1
  158. package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -1
  159. package/lib/esm/Metadata/Phenomenon.js +21 -1
  160. package/lib/esm/Metadata/Phenomenon.js.map +1 -1
  161. package/lib/esm/Metadata/Property.d.ts +1 -1
  162. package/lib/esm/Metadata/Property.d.ts.map +1 -1
  163. package/lib/esm/Metadata/Property.js +12 -7
  164. package/lib/esm/Metadata/Property.js.map +1 -1
  165. package/lib/esm/Metadata/PropertyCategory.d.ts +14 -1
  166. package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -1
  167. package/lib/esm/Metadata/PropertyCategory.js +20 -1
  168. package/lib/esm/Metadata/PropertyCategory.js.map +1 -1
  169. package/lib/esm/Metadata/RelationshipClass.d.ts +15 -1
  170. package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -1
  171. package/lib/esm/Metadata/RelationshipClass.js +30 -7
  172. package/lib/esm/Metadata/RelationshipClass.js.map +1 -1
  173. package/lib/esm/Metadata/Schema.d.ts +114 -6
  174. package/lib/esm/Metadata/Schema.d.ts.map +1 -1
  175. package/lib/esm/Metadata/Schema.js +125 -24
  176. package/lib/esm/Metadata/Schema.js.map +1 -1
  177. package/lib/esm/Metadata/SchemaItem.d.ts +11 -2
  178. package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
  179. package/lib/esm/Metadata/SchemaItem.js +7 -2
  180. package/lib/esm/Metadata/SchemaItem.js.map +1 -1
  181. package/lib/esm/Metadata/Unit.d.ts +8 -1
  182. package/lib/esm/Metadata/Unit.d.ts.map +1 -1
  183. package/lib/esm/Metadata/Unit.js +15 -3
  184. package/lib/esm/Metadata/Unit.js.map +1 -1
  185. package/lib/esm/Metadata/UnitSystem.d.ts +14 -1
  186. package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -1
  187. package/lib/esm/Metadata/UnitSystem.js +22 -1
  188. package/lib/esm/Metadata/UnitSystem.js.map +1 -1
  189. package/lib/esm/SchemaJsonLocater.d.ts +2 -2
  190. package/lib/esm/SchemaJsonLocater.d.ts.map +1 -1
  191. package/lib/esm/SchemaJsonLocater.js +1 -1
  192. package/lib/esm/SchemaJsonLocater.js.map +1 -1
  193. package/lib/esm/SchemaKey.d.ts +6 -0
  194. package/lib/esm/SchemaKey.d.ts.map +1 -1
  195. package/lib/esm/SchemaKey.js +6 -0
  196. package/lib/esm/SchemaKey.js.map +1 -1
  197. package/lib/esm/SchemaLoader.d.ts +2 -2
  198. package/lib/esm/SchemaLoader.d.ts.map +1 -1
  199. package/lib/esm/SchemaLoader.js.map +1 -1
  200. package/lib/esm/UnitConversion/UnitConversion.d.ts +1 -1
  201. package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -1
  202. package/lib/esm/UnitConversion/UnitConversion.js +5 -5
  203. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -1
  204. package/lib/esm/UnitProvider/SchemaUnitProvider.js +3 -3
  205. package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -1
  206. package/lib/esm/Validation/SchemaWalker.d.ts +1 -1
  207. package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -1
  208. package/lib/esm/Validation/SchemaWalker.js.map +1 -1
  209. package/package.json +6 -6
@@ -19,7 +19,7 @@ export interface ISchemaLocater {
19
19
  * @param matchType how to match key against candidate schemas
20
20
  * @param context context for loading schema references
21
21
  */
22
- getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
22
+ getSchema(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
23
23
  /**
24
24
  * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
25
25
  * May return the entire Schema so long as it is completely loaded as it satisfies the SchemaInfo interface.
@@ -34,13 +34,30 @@ export interface ISchemaLocater {
34
34
  * @param matchType how to match key against candidate schemas
35
35
  * @param context context for loading schema references
36
36
  */
37
- getSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
37
+ getSchemaSync(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;
38
38
  }
39
39
  /**
40
+ * Base interface for types that allow location of items inside a schema
40
41
  * @beta
41
42
  */
42
43
  export interface ISchemaItemLocater {
43
- getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey): Promise<T | undefined>;
44
+ /**
45
+ * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
46
+ * Will await a partially loaded schema then look in it for the requested item.
47
+ * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
48
+ * @returns The requested schema item.
49
+ */
50
+ getSchemaItem(schemaItemKey: SchemaItemKey): Promise<SchemaItem | undefined>;
51
+ getSchemaItem<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): Promise<InstanceType<T> | undefined>;
52
+ /**
53
+ * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
54
+ * Will skip a partially loaded schema and return undefined if the item belongs to that schema. Use the async method to await partially loaded schemas.
55
+ * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
56
+ * @param itemConstructor The constructor of the item to return.
57
+ * @returns The requested schema item.
58
+ */
59
+ getSchemaItemSync(schemaItemKey: SchemaItemKey): SchemaItem | undefined;
60
+ getSchemaItemSync<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): InstanceType<T> | undefined;
44
61
  }
45
62
  /**
46
63
  * @internal
@@ -71,18 +88,18 @@ export declare class SchemaCache implements ISchemaLocater {
71
88
  * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.
72
89
  * @param schema The schema to add to the cache.
73
90
  */
74
- addSchema<T extends Schema>(schema: T): Promise<void>;
91
+ addSchema(schema: Schema): Promise<void>;
75
92
  /**
76
93
  * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.
77
94
  * @param schema The schema to add to the cache.
78
95
  */
79
- addSchemaSync<T extends Schema>(schema: T): void;
96
+ addSchemaSync(schema: Schema): void;
80
97
  /**
81
98
  * Gets the schema which matches the provided SchemaKey.
82
99
  * @param schemaKey The SchemaKey describing the schema to get from the cache.
83
100
  * @param matchType The match type to use when locating the schema
84
101
  */
85
- getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<T | undefined>;
102
+ getSchema(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<Schema | undefined>;
86
103
  /**
87
104
  * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
88
105
  * @param schemaKey The SchemaKey describing the schema to get from the cache.
@@ -94,7 +111,7 @@ export declare class SchemaCache implements ISchemaLocater {
94
111
  * @param schemaKey The SchemaKey describing the schema to get from the cache.
95
112
  * @param matchType The match type to use when locating the schema
96
113
  */
97
- getSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): T | undefined;
114
+ getSchemaSync(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Schema | undefined;
98
115
  /**
99
116
  * Generator function that can iterate through each schema in _schema SchemaMap and items for each Schema.
100
117
  * Does not include schema items from schemas that are not completely loaded yet.
@@ -174,7 +191,7 @@ export declare class SchemaContext implements ISchemaItemLocater {
174
191
  * @param matchType Criteria by which to identify potentially matching schemas.
175
192
  * @returns the schema matching the input criteria, or `undefined` if no such schema could be located.
176
193
  */
177
- getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<T | undefined>;
194
+ getSchema(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<Schema | undefined>;
178
195
  /**
179
196
  * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
180
197
  * The fully loaded schema can be gotten later from the context using [[getSchema]].
@@ -188,7 +205,7 @@ export declare class SchemaContext implements ISchemaItemLocater {
188
205
  * @param matchType Criteria by which to identify potentially matching schemas.
189
206
  * @returns the schema matching the input criteria, or `undefined` if no such schema could be located.
190
207
  */
191
- getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType?: SchemaMatchType): T | undefined;
208
+ getSchemaSync(schemaKey: SchemaKey, matchType?: SchemaMatchType): Schema | undefined;
192
209
  /**
193
210
  * Attempts to get a Schema from the context's cache.
194
211
  * Will await a partially loaded schema then return when it is completely loaded.
@@ -196,7 +213,7 @@ export declare class SchemaContext implements ISchemaItemLocater {
196
213
  * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.
197
214
  * @internal
198
215
  */
199
- getCachedSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<T | undefined>;
216
+ getCachedSchema(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<Schema | undefined>;
200
217
  /**
201
218
  * Attempts to get a Schema from the context's cache.
202
219
  * Will return undefined if the cached schema is partially loaded. Use [[getCachedSchema]] to await until the schema is completely loaded.
@@ -204,21 +221,25 @@ export declare class SchemaContext implements ISchemaItemLocater {
204
221
  * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.
205
222
  * @internal
206
223
  */
207
- getCachedSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): T | undefined;
224
+ getCachedSchemaSync(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Schema | undefined;
208
225
  /**
209
226
  * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
210
227
  * Will await a partially loaded schema then look in it for the requested item
211
228
  * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
229
+ * @param itemConstructor The constructor of the item to return.
212
230
  * @returns The requested schema item
213
231
  */
214
- getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey): Promise<T | undefined>;
232
+ getSchemaItem(schemaItemKey: SchemaItemKey): Promise<SchemaItem | undefined>;
233
+ getSchemaItem<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): Promise<InstanceType<T> | undefined>;
215
234
  /**
216
235
  * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
217
- * Will skip a partially loaded schema and return undefined if the item belongs to that schema. Use the async method to await partially loaded schemas.
218
- * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
236
+ * Will return undefined if the cached schema is partially loaded. Use [[getSchemaItem]] to await until the schema is completely loaded.
237
+ * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
238
+ * @param itemConstructor The constructor of the item to return.
219
239
  * @returns The requested schema item
220
240
  */
221
- getSchemaItemSync<T extends SchemaItem>(schemaItemKey: SchemaItemKey): T | undefined;
241
+ getSchemaItemSync(schemaItemKey: SchemaItemKey): SchemaItem | undefined;
242
+ getSchemaItemSync<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): InstanceType<T> | undefined;
222
243
  /**
223
244
  * Iterates through the items of each schema known to the context. This includes schemas added to the
224
245
  * context using [[SchemaContext.addSchema]]. This does not include schemas that
@@ -1 +1 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/Context.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAiB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAgBvD;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAE7B;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAExI;;;;;MAKE;IACF,aAAa,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B,CAAC,aAAa,EAAE,aAAa,GAAG,UAAU,GAAG,SAAS;IACvE,iBAAiB,CAAC,CAAC,SAAS,OAAO,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;IAYpI;;;;;OAKG;IACI,cAAc,IAAI,gBAAgB,CAAC,UAAU,CAAC;IAIrD;;;;;;OAMG;IACI,eAAe,IAAI,MAAM,EAAE;CAGnC"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaContext = exports.SchemaCache = void 0;
2
4
  /*---------------------------------------------------------------------------------------------
3
5
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
6
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
7
  *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SchemaContext = exports.SchemaCache = void 0;
8
8
  const ECObjects_1 = require("./ECObjects");
9
9
  const Exception_1 = require("./Exception");
10
10
  /**
@@ -310,29 +310,21 @@ class SchemaContext {
310
310
  getCachedSchemaSync(schemaKey, matchType = ECObjects_1.SchemaMatchType.Latest) {
311
311
  return this._knownSchemas.getSchemaSync(schemaKey, matchType);
312
312
  }
313
- /**
314
- * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
315
- * Will await a partially loaded schema then look in it for the requested item
316
- * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
317
- * @returns The requested schema item
318
- */
319
- async getSchemaItem(schemaItemKey) {
313
+ async getSchemaItem(schemaItemKey, itemConstructor) {
320
314
  const schema = await this.getSchema(schemaItemKey.schemaKey, ECObjects_1.SchemaMatchType.Latest);
321
315
  if (undefined === schema)
322
316
  return undefined;
323
- return schema.getItem(schemaItemKey.name);
317
+ if (undefined === itemConstructor)
318
+ return schema.getItem(schemaItemKey.name);
319
+ return schema.getItem(schemaItemKey.name, itemConstructor);
324
320
  }
325
- /**
326
- * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
327
- * Will skip a partially loaded schema and return undefined if the item belongs to that schema. Use the async method to await partially loaded schemas.
328
- * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
329
- * @returns The requested schema item
330
- */
331
- getSchemaItemSync(schemaItemKey) {
321
+ getSchemaItemSync(schemaItemKey, itemConstructor) {
332
322
  const schema = this.getSchemaSync(schemaItemKey.schemaKey, ECObjects_1.SchemaMatchType.Latest);
333
323
  if (undefined === schema)
334
324
  return undefined;
335
- return schema.getItemSync(schemaItemKey.name);
325
+ if (undefined === itemConstructor)
326
+ return schema.getItemSync(schemaItemKey.name);
327
+ return schema.getItemSync(schemaItemKey.name, itemConstructor);
336
328
  }
337
329
  /**
338
330
  * Iterates through the items of each schema known to the context. This includes schemas added to the
@@ -1 +1 @@
1
- {"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/Context.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,2CAA8C;AAC9C,2CAA8D;AAM9D;;GAEG;AACH,MAAM,SAAU,SAAQ,KAAkB;CAAI;AAuD9C;;GAEG;AACH,MAAa,WAAW;IACd,OAAO,CAAY;IAE3B;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,EAAE,CAAC;IACjC,CAAC;IAED,IAAW,KAAK,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAE1C,kBAAkB,CAAC,SAA8B;QACvD,OAAO,SAAS,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAkB,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,2BAAe,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAChK,CAAC;IAEO,mBAAmB,CAAC,SAA8B;QACxD,OAAO,SA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a,CAAC,aAAa,CAAI,SAAS,EAAE,SAAS,CAAC,CAAC;IACnE,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAuB,aAA4B;QAC3E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,2BAAe,CAAC,MAAM,CAAC,CAAC;QACrF,IAAI,SAAS,KAAK,MAAM;YACtB,OAAO,SAAS,CAAC;QACnB,OAAO,MAAM,CAAC,OAAO,CAAI,aAAa,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,iBAAiB,CAAuB,aAA4B;QACzE,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,SAAS,EAAE,2BAAe,CAAC,MAAM,CAAC,CAAC;QACnF,IAAI,SAAS,KAAK,MAAM;YACtB,OAAO,SAAS,CAAC;QACnB,OAAO,MAAM,CAAC,WAAW,CAAI,aAAa,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACI,cAAc;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;IAC7C,CAAC;IAED;;;;;;OAMG;IACI,eAAe;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;IAC5C,CAAC;CACF;AApND,sCAoNC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { SchemaMatchType } from \"./ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"./Exception\";\r\nimport { SchemaInfo } from \"./Interfaces\";\r\nimport { MutableSchema, Schema } from \"./Metadata/Schema\";\r\nimport { SchemaItem } from \"./Metadata/SchemaItem\";\r\nimport { SchemaItemKey, SchemaKey } from \"./SchemaKey\";\r\n\r\n/**\r\n * @internal\r\n */\r\nclass SchemaMap extends Array<SchemaEntry> { }\r\n\r\n/**\r\n * @internal\r\n */\r\ninterface SchemaEntry {\r\n schemaInfo: SchemaInfo;\r\n schema: Schema;\r\n schemaPromise?: Promise<Schema>;\r\n}\r\n\r\n/**\r\n * The interface defines what is needed to be an `ISchemaLocater`.\r\n * A Schema Locater loads the requested schema if it can or returns undefined.\r\n * Schema Locaters should always load the schema on each request and should not hold a cache of schemas.\r\n * Schema locaters should never be used directly to load a schema, they should be added to a `SchemaContext`\r\n * and the context should be used to load schemas. The `SchemaContext` caches schemas and manages schema life time.\r\n * @beta\r\n */\r\nexport interface ISchemaLocater {\r\n\r\n /**\r\n * Attempts to get a schema from the locater. Yields undefined if no matching schema is found.\r\n * For schemas that may have references, construct and call through a SchemaContext instead.\r\n * @param schemaKey key to look up\r\n * @param matchType how to match key against candidate schemas\r\n * @param context context for loading schema references\r\n */\r\n getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * May return the entire Schema so long as it is completely loaded as it satisfies the SchemaInfo interface.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;\r\n\r\n /**\r\n * Attempts to get a schema from the locater. Yields undefined if no matching schema is found.\r\n * For schemas that may have references, construct and call through a SchemaContext instead.\r\n * @param schemaKey key to look up\r\n * @param matchType how to match key against candidate schemas\r\n * @param context context for loading schema references\r\n */\r\n getSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): T | undefined;\r\n}\r\n\r\n/**\r\n * @beta\r\n */\r\nexport interface ISchemaItemLocater {\r\n getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey): Promise<T | undefined>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class SchemaCache implements ISchemaLocater {\r\n private _schema: SchemaMap;\r\n\r\n constructor() {\r\n this._schema = new SchemaMap();\r\n }\r\n\r\n public get count() { return this._schema.length; }\r\n\r\n private loadedSchemaExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return undefined !== this._schema.find((entry: SchemaEntry) => entry.schemaInfo.schemaKey.matches(schemaKey, SchemaMatchType.Latest) && !entry.schemaPromise);\r\n }\r\n\r\n private schemaPromiseExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return undefined !== this._schema.find((entry: SchemaEntry) => entry.schemaInfo.schemaKey.matches(schemaKey, SchemaMatchType.Latest) && undefined !== entry.schemaPromise);\r\n }\r\n\r\n private findEntry(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType): SchemaEntry | undefined {\r\n return this._schema.find((entry: SchemaEntry) => entry.schemaInfo.schemaKey.matches(schemaKey, matchType));\r\n }\r\n\r\n private removeSchemaPromise(schemaKey: Readonly<SchemaKey>) {\r\n const entry = this.findEntry(schemaKey, SchemaMatchType.Latest);\r\n if (entry)\r\n entry.schemaPromise = undefined;\r\n }\r\n\r\n private removeEntry(schemaKey: Readonly<SchemaKey>) {\r\n this._schema = this._schema.filter((entry: SchemaEntry) => !entry.schemaInfo.schemaKey.matches(schemaKey));\r\n }\r\n\r\n /**\r\n * Returns true if the schema exists in either the schema cache or the promise cache. SchemaMatchType.Latest used.\r\n * @param schemaKey The key to search for.\r\n */\r\n public schemaExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return this.loadedSchemaExists(schemaKey) || this.schemaPromiseExists(schemaKey);\r\n }\r\n\r\n /**\r\n * Adds a promise to load the schema to the cache. Does not allow for duplicate schemas in the cache of schemas or cache of promises, checks using SchemaMatchType.Latest.\r\n * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache\r\n * @param schemaInfo An object with the schema key for the schema being loaded and it's references\r\n * @param schema The partially loaded schema that the promise will fulfill\r\n * @param schemaPromise The schema promise to add to the cache.\r\n */\r\n public async addSchemaPromise(schemaInfo: SchemaInfo, schema: Schema, schemaPromise: Promise<Schema>) {\r\n if (this.schemaExists(schemaInfo.schemaKey))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateSchema, `The schema, ${schemaInfo.schemaKey.toString()}, already exists within this cache.`);\r\n\r\n this._schema.push({ schemaInfo, schema, schemaPromise });\r\n\r\n // This promise is cached and will be awaited when the user requests the full schema.\r\n // If the promise competes successfully before the user requests the schema it will be removed from the cache\r\n // If it fails it will remain in the cache until the user awaits it and handles the error\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n schemaPromise.then(() => {\r\n this.removeSchemaPromise(schemaInfo.schemaKey);\r\n });\r\n }\r\n\r\n /**\r\n * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.\r\n * @param schema The schema to add to the cache.\r\n */\r\n public async addSchema<T extends Schema>(schema: T) {\r\n if (this.schemaExists(schema.schemaKey))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateSchema, `The schema, ${schema.schemaKey.toString()}, already exists within this cache.`);\r\n\r\n this._schema.push({ schemaInfo: schema, schema });\r\n }\r\n\r\n /**\r\n * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.\r\n * @param schema The schema to add to the cache.\r\n */\r\n public addSchemaSync<T extends Schema>(schema: T) {\r\n if (this.schemaExists(schema.schemaKey))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateSchema, `The schema, ${schema.schemaKey.toString()}, already exists within this cache.`);\r\n\r\n this._schema.push({ schemaInfo: schema, schema });\r\n }\r\n\r\n /**\r\n * Gets the schema which matches the provided SchemaKey.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public async getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<T | undefined> {\r\n if (this.count === 0)\r\n return undefined;\r\n\r\n const entry = this.findEntry(schemaKey, matchType);\r\n if (!entry)\r\n return undefined;\r\n\r\n if (entry.schemaPromise) {\r\n try {\r\n const schema = await entry.schemaPromise as T;\r\n return schema;\r\n } catch (e) {\r\n this.removeEntry(schemaKey);\r\n throw e;\r\n }\r\n }\r\n\r\n return entry.schema as T;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public async getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<SchemaInfo | undefined> {\r\n if (this.count === 0)\r\n return undefined;\r\n\r\n const entry = this.findEntry(schemaKey, matchType);\r\n if (entry)\r\n return entry.schemaInfo;\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Gets the schema which matches the provided SchemaKey. If the schema is partially loaded an exception will be thrown.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public getSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): T | undefined {\r\n if (this.count === 0)\r\n return undefined;\r\n\r\n const entry = this.findEntry(schemaKey, matchType);\r\n if (entry) {\r\n if (entry.schemaPromise) {\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLoadSchema, `The Schema ${schemaKey.toString()} is partially loaded so cannot be loaded synchronously.`);\r\n }\r\n return entry.schema as T;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Generator function that can iterate through each schema in _schema SchemaMap and items for each Schema.\r\n * Does not include schema items from schemas that are not completely loaded yet.\r\n */\r\n public * getSchemaItems(): IterableIterator<SchemaItem> {\r\n for (const entry of this._schema) {\r\n for (const schemaItem of entry.schema.getItems()) {\r\n yield schemaItem;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets all the schemas from the schema cache.\r\n * Does not include schemas from schemas that are not completely loaded yet.\r\n * @returns An array of Schema objects.\r\n */\r\n public getAllSchemas(): Schema[] {\r\n return this._schema.map((entry: SchemaEntry) => entry.schema);\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaContext, context object is used to facilitate schema and schema item location.\r\n *\r\n * The context controls the lifetime of each schema that it knows about. It has to be explicitly removed from the context to delete a schema object.\r\n *\r\n * The context is made up of a group of Schema Locators.\r\n * @beta\r\n */\r\nexport class SchemaContext implements ISchemaItemLocater {\r\n private _locaters: ISchemaLocater[];\r\n\r\n private _knownSchemas: SchemaCache;\r\n private _fallbackLocaterDefined: boolean;\r\n\r\n constructor() {\r\n this._locaters = [];\r\n\r\n this._knownSchemas = new SchemaCache();\r\n this._locaters.push(this._knownSchemas);\r\n this._fallbackLocaterDefined = false;\r\n }\r\n\r\n public get locaters(): ISchemaLocater[] { return this._locaters; }\r\n\r\n /**\r\n * Adds a locater to the context.\r\n *\r\n * If no locaters are defined or a fallback locater is not defined, the new locater is added at the end of the locaters array.\r\n * If a fallback locater is already defined, the new locater is inserted before the fallback locater.\r\n *\r\n * @param locater - The locater to be added.\r\n */\r\n public addLocater(locater: ISchemaLocater) {\r\n const insertIndex = (this._locaters.length === 0 || !this._fallbackLocaterDefined) ? this._locaters.length : this._locaters.length - 1;\r\n this._locaters.splice(insertIndex, 0, locater);\r\n }\r\n\r\n /**\r\n * Adds a fallback locater to the context.\r\n *\r\n * If a fallback locater is already defined, it replaces the existing one.\r\n * Otherwise, it adds the new locater to the end of the locaters array and marks the fallback locater as defined.\r\n *\r\n * @param locater - The locater to be added as a fallback.\r\n */\r\n public addFallbackLocater(locater: ISchemaLocater) {\r\n if (this._fallbackLocaterDefined) {\r\n this._locaters[this._locaters.length - 1] = locater;\r\n } else {\r\n this._locaters.push(locater);\r\n this._fallbackLocaterDefined = true;\r\n }\r\n }\r\n\r\n /**\r\n * Adds the schema to this context. Use addSchemaPromise instead when asynchronously loading schemas.\r\n * @param schema The schema to add to this context\r\n */\r\n public async addSchema(schema: Schema) {\r\n this.addSchemaSync(schema);\r\n }\r\n\r\n /**\r\n * Adds the schema to this context\r\n * @param schema The schema to add to this context\r\n */\r\n public addSchemaSync(schema: Schema) {\r\n this._knownSchemas.addSchemaSync(schema);\r\n }\r\n\r\n /**\r\n * Adds the given SchemaItem to the the SchemaContext by locating the schema, with the best match of SchemaMatchType.Exact, and\r\n * @param schemaItem The SchemaItem to add\r\n * @deprecated in 4.0 use ecschema-editing package\r\n */\r\n public async addSchemaItem(schemaItem: SchemaItem) {\r\n const schema = await this.getSchema(schemaItem.key.schemaKey, SchemaMatchType.Exact);\r\n if (!schema)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to add the schema item ${schemaItem.name} to the schema ${schemaItem.key.schemaKey.toString()} because the schema could not be located.`);\r\n\r\n (schema as MutableSchema).addItem(schemaItem);\r\n }\r\n\r\n /**\r\n * Returns true if the schema is already in the context. SchemaMatchType.Latest is used to find a match.\r\n * @param schemaKey\r\n */\r\n public schemaExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return this._knownSchemas.schemaExists(schemaKey);\r\n }\r\n\r\n /**\r\n * Adds a promise to load the schema to the cache. Does not allow for duplicate schemas in the cache of schemas or cache of promises, checks using SchemaMatchType.Latest.\r\n * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache.\r\n * Use this method over addSchema when asynchronously loading schemas\r\n * @param schemaInfo An object with the schema key for the schema being loaded and it's references\r\n * @param schema The partially loaded schema that the promise will fulfill\r\n * @param schemaPromise The schema promise to add to the cache.\r\n */\r\n public async addSchemaPromise(schemaInfo: SchemaInfo, schema: Schema, schemaPromise: Promise<Schema>) {\r\n return this._knownSchemas.addSchemaPromise(schemaInfo, schema, schemaPromise);\r\n }\r\n\r\n /** Attempts to obtain a schema from this context that matches the specified criteria.\r\n * @param schemaKey Identifies the schema to obtain.\r\n * @param matchType Criteria by which to identify potentially matching schemas.\r\n * @returns the schema matching the input criteria, or `undefined` if no such schema could be located.\r\n */\r\n public async getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<T | undefined> {\r\n // the first locater is _knownSchemas, so we don't have to check the cache explicitly here\r\n for (const locater of this._locaters) {\r\n const schema = await locater.getSchema<T>(schemaKey, matchType, this);\r\n if (undefined !== schema)\r\n return schema;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using [[getSchema]].\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public async getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType): Promise<SchemaInfo | undefined> {\r\n for (const locater of this._locaters) {\r\n const schemaInfo = await locater.getSchemaInfo(schemaKey, matchType, this);\r\n if (undefined !== schemaInfo)\r\n return schemaInfo;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /** Attempts to obtain a schema from this context that matches the specified criteria.\r\n * Will return undefined if the schema is partially loaded. Use [[getSchema]] to await until the schema is completely loaded.\r\n * @param schemaKey Identifies the schema to obtain.\r\n * @param matchType Criteria by which to identify potentially matching schemas.\r\n * @returns the schema matching the input criteria, or `undefined` if no such schema could be located.\r\n */\r\n public getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Latest): T | undefined {\r\n // the first locater is _knownSchemas, so we don't have to check the cache explicitly here\r\n for (const locater of this._locaters) {\r\n const schema = locater.getSchemaSync<T>(schemaKey, matchType, this);\r\n if (undefined !== schema)\r\n return schema;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Attempts to get a Schema from the context's cache.\r\n * Will await a partially loaded schema then return when it is completely loaded.\r\n * @param schemaKey The SchemaKey to identify the Schema.\r\n * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.\r\n * @internal\r\n */\r\n public async getCachedSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<T | undefined> {\r\n return this._knownSchemas.getSchema<T>(schemaKey, matchType);\r\n }\r\n\r\n /**\r\n * Attempts to get a Schema from the context's cache.\r\n * Will return undefined if the cached schema is partially loaded. Use [[getCachedSchema]] to await until the schema is completely loaded.\r\n * @param schemaKey The SchemaKey to identify the Schema.\r\n * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.\r\n * @internal\r\n */\r\n public getCachedSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): T | undefined {\r\n return this._knownSchemas.getSchemaSync<T>(schemaKey, matchType);\r\n }\r\n\r\n /**\r\n * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].\r\n * Will await a partially loaded schema then look in it for the requested item\r\n * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.\r\n * @returns The requested schema item\r\n */\r\n public async getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey): Promise<T | undefined> {\r\n const schema = await this.getSchema(schemaItemKey.schemaKey, SchemaMatchType.Latest);\r\n if (undefined === schema)\r\n return undefined;\r\n return schema.getItem<T>(schemaItemKey.name);\r\n }\r\n\r\n /**\r\n * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].\r\n * Will skip a partially loaded schema and return undefined if the item belongs to that schema. Use the async method to await partially loaded schemas.\r\n * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.\r\n * @returns The requested schema item\r\n */\r\n public getSchemaItemSync<T extends SchemaItem>(schemaItemKey: SchemaItemKey): T | undefined {\r\n const schema = this.getSchemaSync(schemaItemKey.schemaKey, SchemaMatchType.Latest);\r\n if (undefined === schema)\r\n return undefined;\r\n return schema.getItemSync<T>(schemaItemKey.name);\r\n }\r\n\r\n /**\r\n * Iterates through the items of each schema known to the context. This includes schemas added to the\r\n * context using [[SchemaContext.addSchema]]. This does not include schemas that\r\n * can be located by an ISchemaLocater instance added to the context.\r\n * Does not include schema items from schemas that are not completely loaded yet.\r\n */\r\n public getSchemaItems(): IterableIterator<SchemaItem> {\r\n return this._knownSchemas.getSchemaItems();\r\n }\r\n\r\n /**\r\n * Gets all the Schemas known by the context. This includes schemas added to the\r\n * context using [[SchemaContext.addSchema]]. This does not include schemas that\r\n * can be located by an ISchemaLocater instance added to the context. Does not\r\n * include schemas that are partially loaded.\r\n * @returns An array of Schema objects.\r\n */\r\n public getKnownSchemas(): Schema[] {\r\n return this._knownSchemas.getAllSchemas();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/Context.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,2CAA8C;AAC9C,2CAA8D;AAM9D;;GAEG;AACH,MAAM,SAAU,SAAQ,KAAkB;CAAI;AAyE9C;;GAEG;AACH,MAAa,WAAW;IACd,OAAO,CAAY;IAE3B;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,EAAE,CAAC;IACjC,CAAC;IAED,IAAW,KAAK,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAE1C,kBAAkB,CAAC,SAA8B;QACvD,OAAO,SAAS,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAkB,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,2BAAe,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAChK,CAAC;IAEO,mBAAmB,CAAC,SAA8B;QACxD,OAAO,SAAS,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAkB,EAAE,EAAE,CAAC,KAAK,C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EAAE,eAAmB;QACvG,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,2BAAe,CAAC,MAAM,CAAC,CAAC;QACrF,IAAI,SAAS,KAAK,MAAM;YACtB,OAAO,SAAS,CAAC;QAEnB,IAAG,SAAS,KAAK,eAAe;YAC9B,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAE5C,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAC7D,CAAC;IAWM,iBAAiB,CAA8B,aAA4B,EAAE,eAAmB;QACrG,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,SAAS,EAAE,2BAAe,CAAC,MAAM,CAAC,CAAC;QACnF,IAAI,SAAS,KAAK,MAAM;YACtB,OAAO,SAAS,CAAC;QAEnB,IAAG,SAAS,KAAK,eAAe;YAC9B,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACI,cAAc;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;IAC7C,CAAC;IAED;;;;;;OAMG;IACI,eAAe;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;IAC5C,CAAC;CACF;AAlOD,sCAkOC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { SchemaMatchType } from \"./ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"./Exception\";\r\nimport { SchemaInfo } from \"./Interfaces\";\r\nimport { MutableSchema, Schema } from \"./Metadata/Schema\";\r\nimport { SchemaItem } from \"./Metadata/SchemaItem\";\r\nimport { SchemaItemKey, SchemaKey } from \"./SchemaKey\";\r\n\r\n/**\r\n * @internal\r\n */\r\nclass SchemaMap extends Array<SchemaEntry> { }\r\n\r\n/**\r\n * @internal\r\n */\r\ninterface SchemaEntry {\r\n schemaInfo: SchemaInfo;\r\n schema: Schema;\r\n schemaPromise?: Promise<Schema>;\r\n}\r\n\r\n/**\r\n * The interface defines what is needed to be an `ISchemaLocater`.\r\n * A Schema Locater loads the requested schema if it can or returns undefined.\r\n * Schema Locaters should always load the schema on each request and should not hold a cache of schemas.\r\n * Schema locaters should never be used directly to load a schema, they should be added to a `SchemaContext`\r\n * and the context should be used to load schemas. The `SchemaContext` caches schemas and manages schema life time.\r\n * @beta\r\n */\r\nexport interface ISchemaLocater {\r\n\r\n /**\r\n * Attempts to get a schema from the locater. Yields undefined if no matching schema is found.\r\n * For schemas that may have references, construct and call through a SchemaContext instead.\r\n * @param schemaKey key to look up\r\n * @param matchType how to match key against candidate schemas\r\n * @param context context for loading schema references\r\n */\r\n getSchema(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * May return the entire Schema so long as it is completely loaded as it satisfies the SchemaInfo interface.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;\r\n\r\n /**\r\n * Attempts to get a schema from the locater. Yields undefined if no matching schema is found.\r\n * For schemas that may have references, construct and call through a SchemaContext instead.\r\n * @param schemaKey key to look up\r\n * @param matchType how to match key against candidate schemas\r\n * @param context context for loading schema references\r\n */\r\n getSchemaSync(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;\r\n}\r\n\r\n/**\r\n * Base interface for types that allow location of items inside a schema\r\n * @beta\r\n */\r\nexport interface ISchemaItemLocater {\r\n /**\r\n * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].\r\n * Will await a partially loaded schema then look in it for the requested item.\r\n * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.\r\n * @returns The requested schema item.\r\n */\r\n getSchemaItem(schemaItemKey: SchemaItemKey): Promise<SchemaItem | undefined>;\r\n getSchemaItem<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): Promise<InstanceType<T> | undefined>;\r\n\r\n /**\r\n * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].\r\n * Will skip a partially loaded schema and return undefined if the item belongs to that schema. Use the async method to await partially loaded schemas.\r\n * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.\r\n * @param itemConstructor The constructor of the item to return.\r\n * @returns The requested schema item.\r\n */\r\n getSchemaItemSync(schemaItemKey: SchemaItemKey): SchemaItem | undefined;\r\n getSchemaItemSync<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): InstanceType<T> | undefined;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class SchemaCache implements ISchemaLocater {\r\n private _schema: SchemaMap;\r\n\r\n constructor() {\r\n this._schema = new SchemaMap();\r\n }\r\n\r\n public get count() { return this._schema.length; }\r\n\r\n private loadedSchemaExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return undefined !== this._schema.find((entry: SchemaEntry) => entry.schemaInfo.schemaKey.matches(schemaKey, SchemaMatchType.Latest) && !entry.schemaPromise);\r\n }\r\n\r\n private schemaPromiseExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return undefined !== this._schema.find((entry: SchemaEntry) => entry.schemaInfo.schemaKey.matches(schemaKey, SchemaMatchType.Latest) && undefined !== entry.schemaPromise);\r\n }\r\n\r\n private findEntry(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType): SchemaEntry | undefined {\r\n return this._schema.find((entry: SchemaEntry) => entry.schemaInfo.schemaKey.matches(schemaKey, matchType));\r\n }\r\n\r\n private removeSchemaPromise(schemaKey: Readonly<SchemaKey>) {\r\n const entry = this.findEntry(schemaKey, SchemaMatchType.Latest);\r\n if (entry)\r\n entry.schemaPromise = undefined;\r\n }\r\n\r\n private removeEntry(schemaKey: Readonly<SchemaKey>) {\r\n this._schema = this._schema.filter((entry: SchemaEntry) => !entry.schemaInfo.schemaKey.matches(schemaKey));\r\n }\r\n\r\n /**\r\n * Returns true if the schema exists in either the schema cache or the promise cache. SchemaMatchType.Latest used.\r\n * @param schemaKey The key to search for.\r\n */\r\n public schemaExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return this.loadedSchemaExists(schemaKey) || this.schemaPromiseExists(schemaKey);\r\n }\r\n\r\n /**\r\n * Adds a promise to load the schema to the cache. Does not allow for duplicate schemas in the cache of schemas or cache of promises, checks using SchemaMatchType.Latest.\r\n * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache\r\n * @param schemaInfo An object with the schema key for the schema being loaded and it's references\r\n * @param schema The partially loaded schema that the promise will fulfill\r\n * @param schemaPromise The schema promise to add to the cache.\r\n */\r\n public async addSchemaPromise(schemaInfo: SchemaInfo, schema: Schema, schemaPromise: Promise<Schema>) {\r\n if (this.schemaExists(schemaInfo.schemaKey))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateSchema, `The schema, ${schemaInfo.schemaKey.toString()}, already exists within this cache.`);\r\n\r\n this._schema.push({ schemaInfo, schema, schemaPromise });\r\n\r\n // This promise is cached and will be awaited when the user requests the full schema.\r\n // If the promise competes successfully before the user requests the schema it will be removed from the cache\r\n // If it fails it will remain in the cache until the user awaits it and handles the error\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n schemaPromise.then(() => {\r\n this.removeSchemaPromise(schemaInfo.schemaKey);\r\n });\r\n }\r\n\r\n /**\r\n * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.\r\n * @param schema The schema to add to the cache.\r\n */\r\n public async addSchema(schema: Schema) {\r\n if (this.schemaExists(schema.schemaKey))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateSchema, `The schema, ${schema.schemaKey.toString()}, already exists within this cache.`);\r\n\r\n this._schema.push({ schemaInfo: schema, schema });\r\n }\r\n\r\n /**\r\n * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.\r\n * @param schema The schema to add to the cache.\r\n */\r\n public addSchemaSync(schema: Schema) {\r\n if (this.schemaExists(schema.schemaKey))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateSchema, `The schema, ${schema.schemaKey.toString()}, already exists within this cache.`);\r\n\r\n this._schema.push({ schemaInfo: schema, schema });\r\n }\r\n\r\n /**\r\n * Gets the schema which matches the provided SchemaKey.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public async getSchema(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<Schema | undefined> {\r\n if (this.count === 0)\r\n return undefined;\r\n\r\n const entry = this.findEntry(schemaKey, matchType);\r\n if (!entry)\r\n return undefined;\r\n\r\n if (entry.schemaPromise) {\r\n try {\r\n const schema = await entry.schemaPromise;\r\n return schema;\r\n } catch (e) {\r\n this.removeEntry(schemaKey);\r\n throw e;\r\n }\r\n }\r\n\r\n return entry.schema;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public async getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<SchemaInfo | undefined> {\r\n if (this.count === 0)\r\n return undefined;\r\n\r\n const entry = this.findEntry(schemaKey, matchType);\r\n if (entry)\r\n return entry.schemaInfo;\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Gets the schema which matches the provided SchemaKey. If the schema is partially loaded an exception will be thrown.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public getSchemaSync(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Schema | undefined {\r\n if (this.count === 0)\r\n return undefined;\r\n\r\n const entry = this.findEntry(schemaKey, matchType);\r\n if (entry) {\r\n if (entry.schemaPromise) {\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLoadSchema, `The Schema ${schemaKey.toString()} is partially loaded so cannot be loaded synchronously.`);\r\n }\r\n return entry.schema;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Generator function that can iterate through each schema in _schema SchemaMap and items for each Schema.\r\n * Does not include schema items from schemas that are not completely loaded yet.\r\n */\r\n public * getSchemaItems(): IterableIterator<SchemaItem> {\r\n for (const entry of this._schema) {\r\n for (const schemaItem of entry.schema.getItems()) {\r\n yield schemaItem;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets all the schemas from the schema cache.\r\n * Does not include schemas from schemas that are not completely loaded yet.\r\n * @returns An array of Schema objects.\r\n */\r\n public getAllSchemas(): Schema[] {\r\n return this._schema.map((entry: SchemaEntry) => entry.schema);\r\n }\r\n}\r\n\r\n/**\r\n * The SchemaContext, context object is used to facilitate schema and schema item location.\r\n *\r\n * The context controls the lifetime of each schema that it knows about. It has to be explicitly removed from the context to delete a schema object.\r\n *\r\n * The context is made up of a group of Schema Locators.\r\n * @beta\r\n */\r\nexport class SchemaContext implements ISchemaItemLocater {\r\n private _locaters: ISchemaLocater[];\r\n\r\n private _knownSchemas: SchemaCache;\r\n private _fallbackLocaterDefined: boolean;\r\n\r\n constructor() {\r\n this._locaters = [];\r\n\r\n this._knownSchemas = new SchemaCache();\r\n this._locaters.push(this._knownSchemas);\r\n this._fallbackLocaterDefined = false;\r\n }\r\n\r\n public get locaters(): ISchemaLocater[] { return this._locaters; }\r\n\r\n /**\r\n * Adds a locater to the context.\r\n *\r\n * If no locaters are defined or a fallback locater is not defined, the new locater is added at the end of the locaters array.\r\n * If a fallback locater is already defined, the new locater is inserted before the fallback locater.\r\n *\r\n * @param locater - The locater to be added.\r\n */\r\n public addLocater(locater: ISchemaLocater) {\r\n const insertIndex = (this._locaters.length === 0 || !this._fallbackLocaterDefined) ? this._locaters.length : this._locaters.length - 1;\r\n this._locaters.splice(insertIndex, 0, locater);\r\n }\r\n\r\n /**\r\n * Adds a fallback locater to the context.\r\n *\r\n * If a fallback locater is already defined, it replaces the existing one.\r\n * Otherwise, it adds the new locater to the end of the locaters array and marks the fallback locater as defined.\r\n *\r\n * @param locater - The locater to be added as a fallback.\r\n */\r\n public addFallbackLocater(locater: ISchemaLocater) {\r\n if (this._fallbackLocaterDefined) {\r\n this._locaters[this._locaters.length - 1] = locater;\r\n } else {\r\n this._locaters.push(locater);\r\n this._fallbackLocaterDefined = true;\r\n }\r\n }\r\n\r\n /**\r\n * Adds the schema to this context. Use addSchemaPromise instead when asynchronously loading schemas.\r\n * @param schema The schema to add to this context\r\n */\r\n public async addSchema(schema: Schema) {\r\n this.addSchemaSync(schema);\r\n }\r\n\r\n /**\r\n * Adds the schema to this context\r\n * @param schema The schema to add to this context\r\n */\r\n public addSchemaSync(schema: Schema) {\r\n this._knownSchemas.addSchemaSync(schema);\r\n }\r\n\r\n /**\r\n * Adds the given SchemaItem to the the SchemaContext by locating the schema, with the best match of SchemaMatchType.Exact, and\r\n * @param schemaItem The SchemaItem to add\r\n * @deprecated in 4.0 use ecschema-editing package\r\n */\r\n public async addSchemaItem(schemaItem: SchemaItem) {\r\n const schema = await this.getSchema(schemaItem.key.schemaKey, SchemaMatchType.Exact);\r\n if (!schema)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to add the schema item ${schemaItem.name} to the schema ${schemaItem.key.schemaKey.toString()} because the schema could not be located.`);\r\n\r\n (schema as MutableSchema).addItem(schemaItem);\r\n }\r\n\r\n /**\r\n * Returns true if the schema is already in the context. SchemaMatchType.Latest is used to find a match.\r\n * @param schemaKey\r\n */\r\n public schemaExists(schemaKey: Readonly<SchemaKey>): boolean {\r\n return this._knownSchemas.schemaExists(schemaKey);\r\n }\r\n\r\n /**\r\n * Adds a promise to load the schema to the cache. Does not allow for duplicate schemas in the cache of schemas or cache of promises, checks using SchemaMatchType.Latest.\r\n * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache.\r\n * Use this method over addSchema when asynchronously loading schemas\r\n * @param schemaInfo An object with the schema key for the schema being loaded and it's references\r\n * @param schema The partially loaded schema that the promise will fulfill\r\n * @param schemaPromise The schema promise to add to the cache.\r\n */\r\n public async addSchemaPromise(schemaInfo: SchemaInfo, schema: Schema, schemaPromise: Promise<Schema>) {\r\n return this._knownSchemas.addSchemaPromise(schemaInfo, schema, schemaPromise);\r\n }\r\n\r\n /** Attempts to obtain a schema from this context that matches the specified criteria.\r\n * @param schemaKey Identifies the schema to obtain.\r\n * @param matchType Criteria by which to identify potentially matching schemas.\r\n * @returns the schema matching the input criteria, or `undefined` if no such schema could be located.\r\n */\r\n public async getSchema(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<Schema | undefined> {\r\n // the first locater is _knownSchemas, so we don't have to check the cache explicitly here\r\n for (const locater of this._locaters) {\r\n const schema = await locater.getSchema(schemaKey, matchType, this);\r\n if (undefined !== schema)\r\n return schema;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using [[getSchema]].\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n */\r\n public async getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType): Promise<SchemaInfo | undefined> {\r\n for (const locater of this._locaters) {\r\n const schemaInfo = await locater.getSchemaInfo(schemaKey, matchType, this);\r\n if (undefined !== schemaInfo)\r\n return schemaInfo;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /** Attempts to obtain a schema from this context that matches the specified criteria.\r\n * Will return undefined if the schema is partially loaded. Use [[getSchema]] to await until the schema is completely loaded.\r\n * @param schemaKey Identifies the schema to obtain.\r\n * @param matchType Criteria by which to identify potentially matching schemas.\r\n * @returns the schema matching the input criteria, or `undefined` if no such schema could be located.\r\n */\r\n public getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Latest): Schema | undefined {\r\n // the first locater is _knownSchemas, so we don't have to check the cache explicitly here\r\n for (const locater of this._locaters) {\r\n const schema = locater.getSchemaSync(schemaKey, matchType, this);\r\n if (undefined !== schema)\r\n return schema;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Attempts to get a Schema from the context's cache.\r\n * Will await a partially loaded schema then return when it is completely loaded.\r\n * @param schemaKey The SchemaKey to identify the Schema.\r\n * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.\r\n * @internal\r\n */\r\n public async getCachedSchema(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<Schema | undefined> {\r\n return this._knownSchemas.getSchema(schemaKey, matchType);\r\n }\r\n\r\n /**\r\n * Attempts to get a Schema from the context's cache.\r\n * Will return undefined if the cached schema is partially loaded. Use [[getCachedSchema]] to await until the schema is completely loaded.\r\n * @param schemaKey The SchemaKey to identify the Schema.\r\n * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.\r\n * @internal\r\n */\r\n public getCachedSchemaSync(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType = SchemaMatchType.Latest): Schema | undefined {\r\n return this._knownSchemas.getSchemaSync(schemaKey, matchType);\r\n }\r\n\r\n /**\r\n * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].\r\n * Will await a partially loaded schema then look in it for the requested item\r\n * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.\r\n * @param itemConstructor The constructor of the item to return.\r\n * @returns The requested schema item\r\n */\r\n public async getSchemaItem(schemaItemKey: SchemaItemKey): Promise<SchemaItem | undefined>\r\n public async getSchemaItem<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): Promise<InstanceType<T> | undefined>\r\n public async getSchemaItem<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor?: T): Promise<SchemaItem | InstanceType<T> | undefined> {\r\n const schema = await this.getSchema(schemaItemKey.schemaKey, SchemaMatchType.Latest);\r\n if (undefined === schema)\r\n return undefined;\r\n\r\n if(undefined === itemConstructor)\r\n return schema.getItem(schemaItemKey.name);\r\n\r\n return schema.getItem(schemaItemKey.name, itemConstructor);\r\n }\r\n\r\n /**\r\n * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].\r\n * Will return undefined if the cached schema is partially loaded. Use [[getSchemaItem]] to await until the schema is completely loaded.\r\n * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.\r\n * @param itemConstructor The constructor of the item to return.\r\n * @returns The requested schema item\r\n */\r\n public getSchemaItemSync(schemaItemKey: SchemaItemKey): SchemaItem | undefined\r\n public getSchemaItemSync<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): InstanceType<T> | undefined\r\n public getSchemaItemSync<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor?: T): SchemaItem | InstanceType<T> | undefined {\r\n const schema = this.getSchemaSync(schemaItemKey.schemaKey, SchemaMatchType.Latest);\r\n if (undefined === schema)\r\n return undefined;\r\n\r\n if(undefined === itemConstructor)\r\n return schema.getItemSync(schemaItemKey.name);\r\n\r\n return schema.getItemSync(schemaItemKey.name, itemConstructor);\r\n }\r\n\r\n /**\r\n * Iterates through the items of each schema known to the context. This includes schemas added to the\r\n * context using [[SchemaContext.addSchema]]. This does not include schemas that\r\n * can be located by an ISchemaLocater instance added to the context.\r\n * Does not include schema items from schemas that are not completely loaded yet.\r\n */\r\n public getSchemaItems(): IterableIterator<SchemaItem> {\r\n return this._knownSchemas.getSchemaItems();\r\n }\r\n\r\n /**\r\n * Gets all the Schemas known by the context. This includes schemas added to the\r\n * context using [[SchemaContext.addSchema]]. This does not include schemas that\r\n * can be located by an ISchemaLocater instance added to the context. Does not\r\n * include schemas that are partially loaded.\r\n * @returns An array of Schema objects.\r\n */\r\n public getKnownSchemas(): Schema[] {\r\n return this._knownSchemas.getAllSchemas();\r\n }\r\n}\r\n"]}
@@ -31,20 +31,20 @@ export declare class SchemaReadHelper<T = unknown> {
31
31
  * @param schema The Schema to populate
32
32
  * @param rawSchema The serialized data to use to populate the Schema.
33
33
  */
34
- readSchemaInfo<U extends Schema>(schema: U, rawSchema: T): Promise<SchemaInfo>;
34
+ readSchemaInfo(schema: Schema, rawSchema: T): Promise<SchemaInfo>;
35
35
  /**
36
36
  * Populates the given Schema from a serialized representation.
37
37
  * @param schema The Schema to populate
38
38
  * @param rawSchema The serialized data to use to populate the Schema.
39
39
  */
40
- readSchema<U extends Schema>(schema: U, rawSchema: T): Promise<U>;
40
+ readSchema(schema: Schema, rawSchema: T): Promise<Schema>;
41
41
  private loadSchema;
42
42
  /**
43
43
  * Populates the given Schema from a serialized representation.
44
44
  * @param schema The Schema to populate
45
45
  * @param rawSchema The serialized data to use to populate the Schema.
46
46
  */
47
- readSchemaSync<U extends Schema>(schema: U, rawSchema: T): U;
47
+ readSchemaSync(schema: Schema, rawSchema: T): Schema;
48
48
  /**
49
49
  * Ensures that the schema references can be located and adds them to the schema.
50
50
  * @param ref The object to read the SchemaReference's props from.
@@ -1 +1 @@
1
- {"version":3,"file":"Helper.d.ts","sourceRoot":"","sources":["../../../src/Deserialization/Helper.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC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