@itwin/ecschema-metadata 4.0.0-dev.103 → 4.0.0-dev.104

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 (69) hide show
  1. package/lib/cjs/Constants.js.map +1 -1
  2. package/lib/cjs/Context.d.ts +99 -23
  3. package/lib/cjs/Context.d.ts.map +1 -1
  4. package/lib/cjs/Context.js +151 -33
  5. package/lib/cjs/Context.js.map +1 -1
  6. package/lib/cjs/DelayedPromise.js.map +1 -1
  7. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  8. package/lib/cjs/Deserialization/Helper.d.ts +11 -0
  9. package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
  10. package/lib/cjs/Deserialization/Helper.js +43 -18
  11. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  12. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  13. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  14. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  15. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  16. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  17. package/lib/cjs/ECName.js.map +1 -1
  18. package/lib/cjs/ECObjects.js.map +1 -1
  19. package/lib/cjs/Exception.d.ts +2 -1
  20. package/lib/cjs/Exception.d.ts.map +1 -1
  21. package/lib/cjs/Exception.js +1 -0
  22. package/lib/cjs/Exception.js.map +1 -1
  23. package/lib/cjs/Interfaces.d.ts +12 -0
  24. package/lib/cjs/Interfaces.d.ts.map +1 -1
  25. package/lib/cjs/Interfaces.js.map +1 -1
  26. package/lib/cjs/Metadata/Class.js.map +1 -1
  27. package/lib/cjs/Metadata/Constant.js.map +1 -1
  28. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  29. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  30. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  31. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  32. package/lib/cjs/Metadata/Format.js.map +1 -1
  33. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  34. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  35. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  36. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  37. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  38. package/lib/cjs/Metadata/Property.js.map +1 -1
  39. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  40. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  41. package/lib/cjs/Metadata/Schema.d.ts +15 -1
  42. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  43. package/lib/cjs/Metadata/Schema.js +19 -0
  44. package/lib/cjs/Metadata/Schema.js.map +1 -1
  45. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  46. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  47. package/lib/cjs/PropertyTypes.js.map +1 -1
  48. package/lib/cjs/SchemaJsonLocater.d.ts +9 -2
  49. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
  50. package/lib/cjs/SchemaJsonLocater.js +8 -0
  51. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  52. package/lib/cjs/SchemaKey.d.ts +1 -1
  53. package/lib/cjs/SchemaKey.d.ts.map +1 -1
  54. package/lib/cjs/SchemaKey.js.map +1 -1
  55. package/lib/cjs/SchemaLoader.js.map +1 -1
  56. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  57. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  58. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  59. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  60. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  61. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  62. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  63. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  64. package/lib/cjs/ecschema-metadata.js.map +1 -1
  65. package/lib/cjs/utils/SchemaGraph.d.ts +27 -9
  66. package/lib/cjs/utils/SchemaGraph.d.ts.map +1 -1
  67. package/lib/cjs/utils/SchemaGraph.js +70 -21
  68. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  69. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Constants.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AACH,MAAa,iBAAiB;;AAC5B,mBAAmB;AACI,yCAAuB,GAAW,QAAQ,CAAC;AAC3C,yCAAuB,GAAW,QAAQ,CAAC;AAElE,iBAAiB;AACM,sCAAoB,GAAW,QAAQ,CAAC;AACxC,2CAAyB,GAAW,aAAa,CAAC;AAClD,oDAAkC,GAAW,sBAAsB,CAAC;AACpE,2CAAyB,GAAW,aAAa,CAAC;AAClD,iDAA+B,GAAW,mBAAmB,CAAC;AAC9D,wCAAsB,GAAW,UAAU,CAAC;AAE5C,iDAA+B,GAAW,mBAAmB,CAAC;AAC9D,8CAA4B,GAAW,gBAAgB,CAAC;AACxD,sDAAoC,GAAW,eAAe,CAAC;AAC/D,mDAAiC,GAAW,qBAAqB,CAAC;AAClE,kDAAgC,GAAW,oBAAoB,CAAC;AAChE,2CAAyB,GAAW,aAAa,CAAC;AAElD,4DAA0C,GAAW,8BAA8B,CAAC;AACpF,4DAA0C,GAAW,8BAA8B,CAAC;AACpF,yDAAuC,GAAW,2BAA2B,CAAC;AAE9E,mCAAiB,GAAW,KAAK,CAAC;AAxB9C,8CAAiB","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\n/**\r\n * @internal\r\n */\r\nexport class ECStringConstants {\r\n // Relationship End\r\n public static readonly RELATIONSHIP_END_SOURCE: string = \"Source\";\r\n public static readonly RELATIONSHIP_END_TARGET: string = \"Target\";\r\n\r\n // Container Type\r\n public static readonly CONTAINERTYPE_SCHEMA: string = \"Schema\";\r\n public static readonly CONTAINERTYPE_ENTITYCLASS: string = \"EntityClass\";\r\n public static readonly CONTAINERTYPE_CUSTOMATTRIBUTECLASS: string = \"CustomAttributeClass\";\r\n public static readonly CONTAINERTYPE_STRUCTCLASS: string = \"StructClass\";\r\n public static readonly CONTAINERTYPE_RELATIONSHIPCLASS: string = \"RelationshipClass\";\r\n public static readonly CONTAINERTYPE_ANYCLASS: string = \"AnyClass\";\r\n\r\n public static readonly CONTAINERTYPE_PRIMITIVEPROPERTY: string = \"PrimitiveProperty\";\r\n public static readonly CONTAINERTYPE_STRUCTPROPERTY: string = \"StructProperty\";\r\n public static readonly CONTAINERTYPE_PRIMITIVEARRAYPROPERTY: string = \"ArrayProperty\";\r\n public static readonly CONTAINERTYPE_STRUCTARRAYPROPERTY: string = \"StructArrayProperty\";\r\n public static readonly CONTAINERTYPE_NAVIGATIONPROPERTY: string = \"NavigationProperty\";\r\n public static readonly CONTAINERTYPE_ANYPROPERTY: string = \"AnyProperty\";\r\n\r\n public static readonly CONTAINERTYPE_SOURCERELATIONSHIPCONSTRAINT: string = \"SourceRelationshipConstraint\";\r\n public static readonly CONTAINERTYPE_TARGETRELATIONSHIPCONSTRAINT: string = \"TargetRelationshipConstraint\";\r\n public static readonly CONTAINERTYPE_ANYRELATIONSHIPCONSTRAINT: string = \"AnyRelationshipConstraint\";\r\n\r\n public static readonly CONTAINERTYPE_ANY: string = \"Any\";\r\n}\r\n"]}
1
+ {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Constants.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AACH,MAAa,iBAAiB;;AAC5B,mBAAmB;AACI,yCAAuB,GAAW,QAAQ,CAAC;AAC3C,yCAAuB,GAAW,QAAQ,CAAC;AAElE,iBAAiB;AACM,sCAAoB,GAAW,QAAQ,CAAC;AACxC,2CAAyB,GAAW,aAAa,CAAC;AAClD,oDAAkC,GAAW,sBAAsB,CAAC;AACpE,2CAAyB,GAAW,aAAa,CAAC;AAClD,iDAA+B,GAAW,mBAAmB,CAAC;AAC9D,wCAAsB,GAAW,UAAU,CAAC;AAE5C,iDAA+B,GAAW,mBAAmB,CAAC;AAC9D,8CAA4B,GAAW,gBAAgB,CAAC;AACxD,sDAAoC,GAAW,eAAe,CAAC;AAC/D,mDAAiC,GAAW,qBAAqB,CAAC;AAClE,kDAAgC,GAAW,oBAAoB,CAAC;AAChE,2CAAyB,GAAW,aAAa,CAAC;AAElD,4DAA0C,GAAW,8BAA8B,CAAC;AACpF,4DAA0C,GAAW,8BAA8B,CAAC;AACpF,yDAAuC,GAAW,2BAA2B,CAAC;AAE9E,mCAAiB,GAAW,KAAK,CAAC;AAxB9C,8CAAiB","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\n/**\n * @internal\n */\nexport class ECStringConstants {\n // Relationship End\n public static readonly RELATIONSHIP_END_SOURCE: string = \"Source\";\n public static readonly RELATIONSHIP_END_TARGET: string = \"Target\";\n\n // Container Type\n public static readonly CONTAINERTYPE_SCHEMA: string = \"Schema\";\n public static readonly CONTAINERTYPE_ENTITYCLASS: string = \"EntityClass\";\n public static readonly CONTAINERTYPE_CUSTOMATTRIBUTECLASS: string = \"CustomAttributeClass\";\n public static readonly CONTAINERTYPE_STRUCTCLASS: string = \"StructClass\";\n public static readonly CONTAINERTYPE_RELATIONSHIPCLASS: string = \"RelationshipClass\";\n public static readonly CONTAINERTYPE_ANYCLASS: string = \"AnyClass\";\n\n public static readonly CONTAINERTYPE_PRIMITIVEPROPERTY: string = \"PrimitiveProperty\";\n public static readonly CONTAINERTYPE_STRUCTPROPERTY: string = \"StructProperty\";\n public static readonly CONTAINERTYPE_PRIMITIVEARRAYPROPERTY: string = \"ArrayProperty\";\n public static readonly CONTAINERTYPE_STRUCTARRAYPROPERTY: string = \"StructArrayProperty\";\n public static readonly CONTAINERTYPE_NAVIGATIONPROPERTY: string = \"NavigationProperty\";\n public static readonly CONTAINERTYPE_ANYPROPERTY: string = \"AnyProperty\";\n\n public static readonly CONTAINERTYPE_SOURCERELATIONSHIPCONSTRAINT: string = \"SourceRelationshipConstraint\";\n public static readonly CONTAINERTYPE_TARGETRELATIONSHIPCONSTRAINT: string = \"TargetRelationshipConstraint\";\n public static readonly CONTAINERTYPE_ANYRELATIONSHIPCONSTRAINT: string = \"AnyRelationshipConstraint\";\n\n public static readonly CONTAINERTYPE_ANY: string = \"Any\";\n}\n"]}
@@ -1,14 +1,14 @@
1
1
  import { SchemaMatchType } from "./ECObjects";
2
+ import { SchemaInfo } from "./Interfaces";
2
3
  import { Schema } from "./Metadata/Schema";
3
4
  import { SchemaItem } from "./Metadata/SchemaItem";
4
5
  import { SchemaItemKey, SchemaKey } from "./SchemaKey";
5
6
  /**
6
- * @beta
7
- */
8
- export declare class SchemaMap extends Array<Schema> {
9
- }
10
- /**
11
- * The interface defines what is needed to be a ISchemaLocater, which are used in a SchemaContext.
7
+ * The interface defines what is needed to be an `ISchemaLocater`.
8
+ * A Schema Locater loads the requested schema if it can or returns undefined.
9
+ * Schema Locaters should always load the schema on each request and should not hold a cache of schemas.
10
+ * Schema locaters should never be used directly to load a schema, they should be added to a `SchemaContext`
11
+ * and the context should be used to load schemas. The `SchemaContext` caches schemas and manages schema life time.
12
12
  * @beta
13
13
  */
14
14
  export interface ISchemaLocater {
@@ -17,17 +17,24 @@ export interface ISchemaLocater {
17
17
  * For schemas that may have references, construct and call through a SchemaContext instead.
18
18
  * @param schemaKey key to look up
19
19
  * @param matchType how to match key against candidate schemas
20
- * @param context optional context for loading schema references
20
+ * @param context context for loading schema references
21
21
  */
22
- getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context?: SchemaContext): Promise<T | undefined>;
22
+ getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
23
+ /**
24
+ * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
25
+ * May return the entire Schema so long as it is completely loaded as it satisfies the SchemaInfo interface.
26
+ * @param schemaKey The SchemaKey describing the schema to get from the cache.
27
+ * @param matchType The match type to use when locating the schema
28
+ */
29
+ getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
23
30
  /**
24
31
  * Attempts to get a schema from the locater. Yields undefined if no matching schema is found.
25
32
  * For schemas that may have references, construct and call through a SchemaContext instead.
26
33
  * @param schemaKey key to look up
27
34
  * @param matchType how to match key against candidate schemas
28
- * @param context optional context for loading schema references
35
+ * @param context context for loading schema references
29
36
  */
30
- getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context?: SchemaContext): T | undefined;
37
+ getSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
31
38
  }
32
39
  /**
33
40
  * @beta
@@ -36,12 +43,30 @@ export interface ISchemaItemLocater {
36
43
  getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey): Promise<T | undefined>;
37
44
  }
38
45
  /**
39
- * @beta
46
+ * @internal
40
47
  */
41
48
  export declare class SchemaCache implements ISchemaLocater {
42
49
  private _schema;
43
50
  constructor();
44
51
  get count(): number;
52
+ private loadedSchemaExists;
53
+ private schemaPromiseExists;
54
+ private findEntry;
55
+ private removeSchemaPromise;
56
+ private removeEntry;
57
+ /**
58
+ * Returns true if the schema exists in either the schema cache or the promise cache. SchemaMatchType.Latest used.
59
+ * @param schemaKey The key to search for.
60
+ */
61
+ schemaExists(schemaKey: Readonly<SchemaKey>): boolean;
62
+ /**
63
+ * 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.
64
+ * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache
65
+ * @param schemaInfo An object with the schema key for the schema being loaded and it's references
66
+ * @param schema The partially loaded schema that the promise will fulfill
67
+ * @param schemaPromise The schema promise to add to the cache.
68
+ */
69
+ addSchemaPromise(schemaInfo: SchemaInfo, schema: Schema, schemaPromise: Promise<Schema>): Promise<void>;
45
70
  /**
46
71
  * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.
47
72
  * @param schema The schema to add to the cache.
@@ -57,19 +82,27 @@ export declare class SchemaCache implements ISchemaLocater {
57
82
  * @param schemaKey The SchemaKey describing the schema to get from the cache.
58
83
  * @param matchType The match type to use when locating the schema
59
84
  */
60
- getSchema<T extends Schema>(schemaKey: SchemaKey, matchType?: SchemaMatchType): Promise<T | undefined>;
85
+ getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<T | undefined>;
61
86
  /**
62
- *
63
- * @param schemaKey
64
- * @param matchType
87
+ * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
88
+ * @param schemaKey The SchemaKey describing the schema to get from the cache.
89
+ * @param matchType The match type to use when locating the schema
90
+ */
91
+ getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<SchemaInfo | undefined>;
92
+ /**
93
+ * Gets the schema which matches the provided SchemaKey. If the schema is partially loaded an exception will be thrown.
94
+ * @param schemaKey The SchemaKey describing the schema to get from the cache.
95
+ * @param matchType The match type to use when locating the schema
65
96
  */
66
- getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType?: SchemaMatchType): T | undefined;
97
+ getSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): T | undefined;
67
98
  /**
68
- * Generator function that can iterate through each schema in _schema SchemaMap and items for each Schema
99
+ * Generator function that can iterate through each schema in _schema SchemaMap and items for each Schema.
100
+ * Does not include schema items from schemas that are not completely loaded yet.
69
101
  */
70
102
  getSchemaItems(): IterableIterator<SchemaItem>;
71
103
  /**
72
104
  * Gets all the schemas from the schema cache.
105
+ * Does not include schemas from schemas that are not completely loaded yet.
73
106
  * @returns An array of Schema objects.
74
107
  */
75
108
  getAllSchemas(): Schema[];
@@ -82,13 +115,13 @@ export declare class SchemaCache implements ISchemaLocater {
82
115
  * The context is made up of a group of Schema Locators.
83
116
  * @beta
84
117
  */
85
- export declare class SchemaContext implements ISchemaLocater, ISchemaItemLocater {
118
+ export declare class SchemaContext implements ISchemaItemLocater {
86
119
  private _locaters;
87
120
  private _knownSchemas;
88
121
  constructor();
89
122
  addLocater(locater: ISchemaLocater): void;
90
123
  /**
91
- * Adds the schema to this context
124
+ * Adds the schema to this context. Use addSchemaPromise instead when asynchronously loading schemas.
92
125
  * @param schema The schema to add to this context
93
126
  */
94
127
  addSchema(schema: Schema): Promise<void>;
@@ -100,13 +133,35 @@ export declare class SchemaContext implements ISchemaLocater, ISchemaItemLocater
100
133
  /**
101
134
  * Adds the given SchemaItem to the the SchemaContext by locating the schema, with the best match of SchemaMatchType.Exact, and
102
135
  * @param schemaItem The SchemaItem to add
136
+ * @deprecated in 4.0 use ecschema-editing package
103
137
  */
104
138
  addSchemaItem(schemaItem: SchemaItem): Promise<void>;
139
+ /**
140
+ * Returns true if the schema is already in the context. SchemaMatchType.Latest is used to find a match.
141
+ * @param schemaKey
142
+ */
143
+ schemaExists(schemaKey: Readonly<SchemaKey>): boolean;
144
+ /**
145
+ * 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.
146
+ * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache.
147
+ * Use this method over addSchema when asynchronously loading schemas
148
+ * @param schemaInfo An object with the schema key for the schema being loaded and it's references
149
+ * @param schema The partially loaded schema that the promise will fulfill
150
+ * @param schemaPromise The schema promise to add to the cache.
151
+ */
152
+ addSchemaPromise(schemaInfo: SchemaInfo, schema: Schema, schemaPromise: Promise<Schema>): Promise<void>;
105
153
  /**
106
154
  *
107
155
  * @param schemaKey
108
156
  */
109
- getSchema<T extends Schema>(schemaKey: SchemaKey, matchType?: SchemaMatchType): Promise<T | undefined>;
157
+ getSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<T | undefined>;
158
+ /**
159
+ * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
160
+ * The fully loaded schema can be gotten later from the context using the getCachedSchema method.
161
+ * @param schemaKey The SchemaKey describing the schema to get from the cache.
162
+ * @param matchType The match type to use when locating the schema
163
+ */
164
+ getSchemaInfo(schemaKey: Readonly<SchemaKey>, matchType: SchemaMatchType): Promise<SchemaInfo | undefined>;
110
165
  /**
111
166
  *
112
167
  * @param schemaKey
@@ -114,25 +169,46 @@ export declare class SchemaContext implements ISchemaLocater, ISchemaItemLocater
114
169
  getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType?: SchemaMatchType): T | undefined;
115
170
  /**
116
171
  * Attempts to get a Schema from the context's cache.
172
+ * Will await a partially loaded schema then return when it is completely loaded.
117
173
  * @param schemaKey The SchemaKey to identify the Schema.
118
174
  * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.
119
175
  * @internal
120
176
  */
121
- getCachedSchema<T extends Schema>(schemaKey: SchemaKey, matchType?: SchemaMatchType): Promise<T | undefined>;
177
+ getCachedSchema<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): Promise<T | undefined>;
122
178
  /**
123
179
  * Attempts to get a Schema from the context's cache.
180
+ * Will return undefined if the cached schema is partially loaded. Use the async method to await partially loaded schemas.
124
181
  * @param schemaKey The SchemaKey to identify the Schema.
125
182
  * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.
126
183
  * @internal
127
184
  */
128
- getCachedSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType?: SchemaMatchType): Schema | undefined;
185
+ getCachedSchemaSync<T extends Schema>(schemaKey: Readonly<SchemaKey>, matchType?: SchemaMatchType): T | undefined;
186
+ /**
187
+ * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
188
+ * Will await a partially loaded schema then look in it for the requested item
189
+ * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
190
+ * @returns The requested schema item
191
+ */
129
192
  getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey): Promise<T | undefined>;
193
+ /**
194
+ * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
195
+ * 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.
196
+ * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
197
+ * @returns The requested schema item
198
+ */
130
199
  getSchemaItemSync<T extends SchemaItem>(schemaItemKey: SchemaItemKey): T | undefined;
200
+ /**
201
+ * Iterates through the items of each schema known to the context. This includes schemas added to the
202
+ * context using [[SchemaContext.addSchema]]. This does not include schemas that
203
+ * can be located by an ISchemaLocater instance added to the context.
204
+ * Does not include schema items from schemas that are not completely loaded yet.
205
+ */
131
206
  getSchemaItems(): IterableIterator<SchemaItem>;
132
207
  /**
133
208
  * Gets all the Schemas known by the context. This includes schemas added to the
134
209
  * context using [[SchemaContext.addSchema]]. This does not include schemas that
135
- * can be located by an ISchemaLocater instance added to the context.
210
+ * can be located by an ISchemaLocater instance added to the context. Does not
211
+ * include schemas that are partially loaded.
136
212
  * @returns An array of Schema objects.
137
213
  */
138
214
  getKnownSchemas(): Schema[];
@@ -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,EAAiB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,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AAS;IAO3F;;;;;OAKG;IACI,cAAc,IAAI,gBAAgB,CAAC,UAAU,CAAC;IAIrD;;;;;;OAMG;IACI,eAAe,IAAI,MAAM,EAAE;CAGnC"}
@@ -4,40 +4,82 @@
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SchemaContext = exports.SchemaCache = exports.SchemaMap = void 0;
7
+ exports.SchemaContext = exports.SchemaCache = void 0;
8
8
  const ECObjects_1 = require("./ECObjects");
9
9
  const Exception_1 = require("./Exception");
10
10
  /**
11
- * @beta
11
+ * @internal
12
12
  */
13
13
  class SchemaMap extends Array {
14
14
  }
15
- exports.SchemaMap = SchemaMap;
16
15
  /**
17
- * @beta
16
+ * @internal
18
17
  */
19
18
  class SchemaCache {
20
19
  constructor() {
21
20
  this._schema = new SchemaMap();
22
21
  }
23
22
  get count() { return this._schema.length; }
23
+ loadedSchemaExists(schemaKey) {
24
+ return undefined !== this._schema.find((entry) => entry.schemaInfo.schemaKey.matches(schemaKey, ECObjects_1.SchemaMatchType.Latest) && !entry.schemaPromise);
25
+ }
26
+ schemaPromiseExists(schemaKey) {
27
+ return undefined !== this._schema.find((entry) => entry.schemaInfo.schemaKey.matches(schemaKey, ECObjects_1.SchemaMatchType.Latest) && undefined !== entry.schemaPromise);
28
+ }
29
+ findEntry(schemaKey, matchType) {
30
+ return this._schema.find((entry) => entry.schemaInfo.schemaKey.matches(schemaKey, matchType));
31
+ }
32
+ removeSchemaPromise(schemaKey) {
33
+ const entry = this.findEntry(schemaKey, ECObjects_1.SchemaMatchType.Latest);
34
+ if (entry)
35
+ entry.schemaPromise = undefined;
36
+ }
37
+ removeEntry(schemaKey) {
38
+ this._schema = this._schema.filter((entry) => !entry.schemaInfo.schemaKey.matches(schemaKey));
39
+ }
40
+ /**
41
+ * Returns true if the schema exists in either the schema cache or the promise cache. SchemaMatchType.Latest used.
42
+ * @param schemaKey The key to search for.
43
+ */
44
+ schemaExists(schemaKey) {
45
+ return this.loadedSchemaExists(schemaKey) || this.schemaPromiseExists(schemaKey);
46
+ }
47
+ /**
48
+ * 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.
49
+ * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache
50
+ * @param schemaInfo An object with the schema key for the schema being loaded and it's references
51
+ * @param schema The partially loaded schema that the promise will fulfill
52
+ * @param schemaPromise The schema promise to add to the cache.
53
+ */
54
+ async addSchemaPromise(schemaInfo, schema, schemaPromise) {
55
+ if (this.schemaExists(schemaInfo.schemaKey))
56
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.DuplicateSchema, `The schema, ${schemaPromise.toString()}, already exists within this cache.`);
57
+ this._schema.push({ schemaInfo, schema, schemaPromise });
58
+ // This promise is cached and will be awaited when the user requests the full schema.
59
+ // If the promise competes successfully before the user requests the schema it will be removed from the cache
60
+ // If it fails it will remain in the cache until the user awaits it and handles the error
61
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
62
+ schemaPromise.then(() => {
63
+ this.removeSchemaPromise(schemaInfo.schemaKey);
64
+ });
65
+ }
24
66
  /**
25
67
  * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.
26
68
  * @param schema The schema to add to the cache.
27
69
  */
28
70
  async addSchema(schema) {
29
- if (await this.getSchema(schema.schemaKey))
71
+ if (this.schemaExists(schema.schemaKey))
30
72
  throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.DuplicateSchema, `The schema, ${schema.schemaKey.toString()}, already exists within this cache.`);
31
- this._schema.push(schema);
73
+ this._schema.push({ schemaInfo: schema, schema });
32
74
  }
33
75
  /**
34
76
  * Adds a schema to the cache. Does not allow for duplicate schemas, checks using SchemaMatchType.Latest.
35
77
  * @param schema The schema to add to the cache.
36
78
  */
37
79
  addSchemaSync(schema) {
38
- if (this.getSchemaSync(schema.schemaKey))
80
+ if (this.schemaExists(schema.schemaKey))
39
81
  throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.DuplicateSchema, `The schema, ${schema.schemaKey.toString()}, already exists within this cache.`);
40
- this._schema.push(schema);
82
+ this._schema.push({ schemaInfo: schema, schema });
41
83
  }
42
84
  /**
43
85
  * Gets the schema which matches the provided SchemaKey.
@@ -47,46 +89,69 @@ class SchemaCache {
47
89
  async getSchema(schemaKey, matchType = ECObjects_1.SchemaMatchType.Latest) {
48
90
  if (this.count === 0)
49
91
  return undefined;
50
- const findFunc = (schema) => {
51
- return schema.schemaKey.matches(schemaKey, matchType);
52
- };
53
- const foundSchema = this._schema.find(findFunc);
54
- if (!foundSchema)
92
+ const entry = this.findEntry(schemaKey, matchType);
93
+ if (!entry)
55
94
  return undefined;
56
- return foundSchema;
95
+ if (entry.schemaPromise) {
96
+ try {
97
+ const schema = await entry.schemaPromise;
98
+ return schema;
99
+ }
100
+ catch (e) {
101
+ this.removeEntry(schemaKey);
102
+ throw e;
103
+ }
104
+ }
105
+ return entry.schema;
57
106
  }
58
107
  /**
59
- *
60
- * @param schemaKey
61
- * @param matchType
108
+ * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
109
+ * @param schemaKey The SchemaKey describing the schema to get from the cache.
110
+ * @param matchType The match type to use when locating the schema
111
+ */
112
+ async getSchemaInfo(schemaKey, matchType = ECObjects_1.SchemaMatchType.Latest) {
113
+ if (this.count === 0)
114
+ return undefined;
115
+ const entry = this.findEntry(schemaKey, matchType);
116
+ if (entry)
117
+ return entry.schemaInfo;
118
+ return undefined;
119
+ }
120
+ /**
121
+ * Gets the schema which matches the provided SchemaKey. If the schema is partially loaded an exception will be thrown.
122
+ * @param schemaKey The SchemaKey describing the schema to get from the cache.
123
+ * @param matchType The match type to use when locating the schema
62
124
  */
63
125
  getSchemaSync(schemaKey, matchType = ECObjects_1.SchemaMatchType.Latest) {
64
126
  if (this.count === 0)
65
127
  return undefined;
66
- const findFunc = (schema) => {
67
- return schema.schemaKey.matches(schemaKey, matchType);
68
- };
69
- const foundSchema = this._schema.find(findFunc);
70
- if (!foundSchema)
71
- return foundSchema;
72
- return foundSchema;
128
+ const entry = this.findEntry(schemaKey, matchType);
129
+ if (entry) {
130
+ if (entry.schemaPromise) {
131
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.UnableToLoadSchema, `The Schema ${schemaKey.toString()} is partially loaded so cannot be loaded synchronously.`);
132
+ }
133
+ return entry.schema;
134
+ }
135
+ return undefined;
73
136
  }
74
137
  /**
75
- * Generator function that can iterate through each schema in _schema SchemaMap and items for each Schema
138
+ * Generator function that can iterate through each schema in _schema SchemaMap and items for each Schema.
139
+ * Does not include schema items from schemas that are not completely loaded yet.
76
140
  */
77
141
  *getSchemaItems() {
78
- for (const schema of this._schema) {
79
- for (const schemaItem of schema.getItems()) {
142
+ for (const entry of this._schema) {
143
+ for (const schemaItem of entry.schema.getItems()) {
80
144
  yield schemaItem;
81
145
  }
82
146
  }
83
147
  }
84
148
  /**
85
149
  * Gets all the schemas from the schema cache.
150
+ * Does not include schemas from schemas that are not completely loaded yet.
86
151
  * @returns An array of Schema objects.
87
152
  */
88
153
  getAllSchemas() {
89
- return this._schema;
154
+ return this._schema.map((entry) => entry.schema);
90
155
  }
91
156
  }
92
157
  exports.SchemaCache = SchemaCache;
@@ -108,7 +173,7 @@ class SchemaContext {
108
173
  this._locaters.push(locater);
109
174
  }
110
175
  /**
111
- * Adds the schema to this context
176
+ * Adds the schema to this context. Use addSchemaPromise instead when asynchronously loading schemas.
112
177
  * @param schema The schema to add to this context
113
178
  */
114
179
  async addSchema(schema) {
@@ -124,6 +189,7 @@ class SchemaContext {
124
189
  /**
125
190
  * Adds the given SchemaItem to the the SchemaContext by locating the schema, with the best match of SchemaMatchType.Exact, and
126
191
  * @param schemaItem The SchemaItem to add
192
+ * @deprecated in 4.0 use ecschema-editing package
127
193
  */
128
194
  async addSchemaItem(schemaItem) {
129
195
  const schema = await this.getSchema(schemaItem.key.schemaKey, ECObjects_1.SchemaMatchType.Exact);
@@ -131,6 +197,24 @@ class SchemaContext {
131
197
  throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.UnableToLocateSchema, `Unable to add the schema item ${schemaItem.name} to the schema ${schemaItem.key.schemaKey.toString()} because the schema could not be located.`);
132
198
  schema.addItem(schemaItem);
133
199
  }
200
+ /**
201
+ * Returns true if the schema is already in the context. SchemaMatchType.Latest is used to find a match.
202
+ * @param schemaKey
203
+ */
204
+ schemaExists(schemaKey) {
205
+ return this._knownSchemas.schemaExists(schemaKey);
206
+ }
207
+ /**
208
+ * 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.
209
+ * When the promise completes the schema will be added to the schema cache and the promise will be removed from the promise cache.
210
+ * Use this method over addSchema when asynchronously loading schemas
211
+ * @param schemaInfo An object with the schema key for the schema being loaded and it's references
212
+ * @param schema The partially loaded schema that the promise will fulfill
213
+ * @param schemaPromise The schema promise to add to the cache.
214
+ */
215
+ async addSchemaPromise(schemaInfo, schema, schemaPromise) {
216
+ return this._knownSchemas.addSchemaPromise(schemaInfo, schema, schemaPromise);
217
+ }
134
218
  /**
135
219
  *
136
220
  * @param schemaKey
@@ -144,6 +228,20 @@ class SchemaContext {
144
228
  }
145
229
  return undefined;
146
230
  }
231
+ /**
232
+ * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
233
+ * The fully loaded schema can be gotten later from the context using the getCachedSchema method.
234
+ * @param schemaKey The SchemaKey describing the schema to get from the cache.
235
+ * @param matchType The match type to use when locating the schema
236
+ */
237
+ async getSchemaInfo(schemaKey, matchType) {
238
+ for (const locater of this._locaters) {
239
+ const schemaInfo = await locater.getSchemaInfo(schemaKey, matchType, this);
240
+ if (undefined !== schemaInfo)
241
+ return schemaInfo;
242
+ }
243
+ return undefined;
244
+ }
147
245
  /**
148
246
  *
149
247
  * @param schemaKey
@@ -159,42 +257,62 @@ class SchemaContext {
159
257
  }
160
258
  /**
161
259
  * Attempts to get a Schema from the context's cache.
260
+ * Will await a partially loaded schema then return when it is completely loaded.
162
261
  * @param schemaKey The SchemaKey to identify the Schema.
163
262
  * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.
164
263
  * @internal
165
264
  */
166
265
  async getCachedSchema(schemaKey, matchType = ECObjects_1.SchemaMatchType.Latest) {
167
- return this.getCachedSchemaSync(schemaKey, matchType);
266
+ return this._knownSchemas.getSchema(schemaKey, matchType);
168
267
  }
169
268
  /**
170
269
  * Attempts to get a Schema from the context's cache.
270
+ * Will return undefined if the cached schema is partially loaded. Use the async method to await partially loaded schemas.
171
271
  * @param schemaKey The SchemaKey to identify the Schema.
172
272
  * @param matchType The SchemaMatch type to use. Default is SchemaMatchType.Latest.
173
273
  * @internal
174
274
  */
175
275
  getCachedSchemaSync(schemaKey, matchType = ECObjects_1.SchemaMatchType.Latest) {
176
- const schema = this._knownSchemas.getSchemaSync(schemaKey, matchType);
177
- return schema;
276
+ return this._knownSchemas.getSchemaSync(schemaKey, matchType);
178
277
  }
278
+ /**
279
+ * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
280
+ * Will await a partially loaded schema then look in it for the requested item
281
+ * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
282
+ * @returns The requested schema item
283
+ */
179
284
  async getSchemaItem(schemaItemKey) {
180
285
  const schema = await this.getSchema(schemaItemKey.schemaKey, ECObjects_1.SchemaMatchType.Latest);
181
286
  if (undefined === schema)
182
287
  return undefined;
183
288
  return schema.getItem(schemaItemKey.name);
184
289
  }
290
+ /**
291
+ * Gets the schema item from the specified schema if it exists in this [[SchemaContext]].
292
+ * 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.
293
+ * @param schemaItemKey The SchemaItemKey identifying the item to return. SchemaMatchType.Latest is used to match the schema.
294
+ * @returns The requested schema item
295
+ */
185
296
  getSchemaItemSync(schemaItemKey) {
186
297
  const schema = this.getSchemaSync(schemaItemKey.schemaKey, ECObjects_1.SchemaMatchType.Latest);
187
298
  if (undefined === schema)
188
299
  return undefined;
189
300
  return schema.getItemSync(schemaItemKey.name);
190
301
  }
302
+ /**
303
+ * Iterates through the items of each schema known to the context. This includes schemas added to the
304
+ * context using [[SchemaContext.addSchema]]. This does not include schemas that
305
+ * can be located by an ISchemaLocater instance added to the context.
306
+ * Does not include schema items from schemas that are not completely loaded yet.
307
+ */
191
308
  getSchemaItems() {
192
309
  return this._knownSchemas.getSchemaItems();
193
310
  }
194
311
  /**
195
312
  * Gets all the Schemas known by the context. This includes schemas added to the
196
313
  * context using [[SchemaContext.addSchema]]. This does not include schemas that
197
- * can be located by an ISchemaLocater instance added to the context.
314
+ * can be located by an ISchemaLocater instance added to the context. Does not
315
+ * include schemas that are partially loaded.
198
316
  * @returns An array of Schema objects.
199
317
  */
200
318
  getKnownSchemas() {