@itwin/ecschema-metadata 5.1.0-dev.9 → 5.2.0-dev.2
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.
- package/CHANGELOG.md +74 -1
- package/lib/cjs/Context.d.ts +1 -1
- package/lib/cjs/Context.js +1 -1
- package/lib/cjs/Context.js.map +1 -1
- package/lib/cjs/Deserialization/Helper.d.ts +30 -11
- package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
- package/lib/cjs/Deserialization/Helper.js +124 -96
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +12 -3
- package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts.map +1 -1
- package/lib/cjs/Deserialization/SchemaGraphUtil.js +36 -23
- package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.d.ts.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.js +14 -5
- package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.js +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/cjs/ECName.js +1 -1
- package/lib/cjs/ECName.js.map +1 -1
- package/lib/cjs/ECObjects.d.ts +1 -1
- package/lib/cjs/ECObjects.js +2 -2
- package/lib/cjs/ECObjects.js.map +1 -1
- package/lib/cjs/IncrementalLoading/ClassParsers.d.ts +60 -0
- package/lib/cjs/IncrementalLoading/ClassParsers.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/ClassParsers.js +111 -0
- package/lib/cjs/IncrementalLoading/ClassParsers.js.map +1 -0
- package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.d.ts +211 -0
- package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.js +387 -0
- package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.js.map +1 -0
- package/lib/cjs/IncrementalLoading/FullSchemaQueries.d.ts +14 -0
- package/lib/cjs/IncrementalLoading/FullSchemaQueries.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/FullSchemaQueries.js +609 -0
- package/lib/cjs/IncrementalLoading/FullSchemaQueries.js.map +1 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.d.ts +109 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.js +219 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.js.map +1 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.d.ts +36 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.js +77 -0
- package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.js.map +1 -0
- package/lib/cjs/IncrementalLoading/PerformanceLogger.d.ts +60 -0
- package/lib/cjs/IncrementalLoading/PerformanceLogger.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/PerformanceLogger.js +82 -0
- package/lib/cjs/IncrementalLoading/PerformanceLogger.js.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaItemParsers.d.ts +51 -0
- package/lib/cjs/IncrementalLoading/SchemaItemParsers.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaItemParsers.js +122 -0
- package/lib/cjs/IncrementalLoading/SchemaItemParsers.js.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaItemQueries.d.ts +16 -0
- package/lib/cjs/IncrementalLoading/SchemaItemQueries.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaItemQueries.js +308 -0
- package/lib/cjs/IncrementalLoading/SchemaItemQueries.js.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaParser.d.ts +42 -0
- package/lib/cjs/IncrementalLoading/SchemaParser.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaParser.js +109 -0
- package/lib/cjs/IncrementalLoading/SchemaParser.js.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaStubQueries.d.ts +12 -0
- package/lib/cjs/IncrementalLoading/SchemaStubQueries.d.ts.map +1 -0
- package/lib/cjs/IncrementalLoading/SchemaStubQueries.js +365 -0
- package/lib/cjs/IncrementalLoading/SchemaStubQueries.js.map +1 -0
- package/lib/cjs/Metadata/Class.d.ts +5 -16
- package/lib/cjs/Metadata/Class.d.ts.map +1 -1
- package/lib/cjs/Metadata/Class.js +68 -68
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.d.ts +7 -1
- package/lib/cjs/Metadata/CustomAttribute.d.ts.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.d.ts +6 -6
- package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/cjs/Metadata/EntityClass.js +48 -26
- package/lib/cjs/Metadata/EntityClass.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +5 -0
- package/lib/cjs/Metadata/Format.d.ts.map +1 -1
- package/lib/cjs/Metadata/Format.js +7 -0
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +10 -0
- package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
- package/lib/cjs/Metadata/Schema.js +13 -0
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +10 -0
- package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.js +13 -0
- package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
- package/lib/cjs/SchemaFormatsProvider.d.ts +4 -3
- package/lib/cjs/SchemaFormatsProvider.d.ts.map +1 -1
- package/lib/cjs/SchemaFormatsProvider.js +60 -17
- package/lib/cjs/SchemaFormatsProvider.js.map +1 -1
- package/lib/cjs/SchemaLoader.d.ts +4 -1
- package/lib/cjs/SchemaLoader.d.ts.map +1 -1
- package/lib/cjs/SchemaLoader.js +4 -1
- package/lib/cjs/SchemaLoader.js.map +1 -1
- package/lib/cjs/ecschema-metadata.d.ts +2 -0
- package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
- package/lib/cjs/ecschema-metadata.js +2 -0
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaLoadingController.d.ts +37 -0
- package/lib/cjs/utils/SchemaLoadingController.d.ts.map +1 -0
- package/lib/cjs/utils/SchemaLoadingController.js +65 -0
- package/lib/cjs/utils/SchemaLoadingController.js.map +1 -0
- package/lib/esm/Context.d.ts +1 -1
- package/lib/esm/Context.js +1 -1
- package/lib/esm/Context.js.map +1 -1
- package/lib/esm/Deserialization/Helper.d.ts +30 -11
- package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
- package/lib/esm/Deserialization/Helper.js +124 -96
- package/lib/esm/Deserialization/Helper.js.map +1 -1
- package/lib/esm/Deserialization/SchemaGraphUtil.d.ts +12 -3
- package/lib/esm/Deserialization/SchemaGraphUtil.d.ts.map +1 -1
- package/lib/esm/Deserialization/SchemaGraphUtil.js +36 -23
- package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -1
- package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -1
- package/lib/esm/Deserialization/XmlParser.js +14 -5
- package/lib/esm/Deserialization/XmlParser.js.map +1 -1
- package/lib/esm/Deserialization/XmlSerializationUtils.js +1 -1
- package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/esm/ECName.js +1 -1
- package/lib/esm/ECName.js.map +1 -1
- package/lib/esm/ECObjects.d.ts +1 -1
- package/lib/esm/ECObjects.js +2 -2
- package/lib/esm/ECObjects.js.map +1 -1
- package/lib/esm/IncrementalLoading/ClassParsers.d.ts +60 -0
- package/lib/esm/IncrementalLoading/ClassParsers.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/ClassParsers.js +104 -0
- package/lib/esm/IncrementalLoading/ClassParsers.js.map +1 -0
- package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.d.ts +211 -0
- package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.js +383 -0
- package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.js.map +1 -0
- package/lib/esm/IncrementalLoading/FullSchemaQueries.d.ts +14 -0
- package/lib/esm/IncrementalLoading/FullSchemaQueries.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/FullSchemaQueries.js +606 -0
- package/lib/esm/IncrementalLoading/FullSchemaQueries.js.map +1 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.d.ts +109 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.js +215 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.js.map +1 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaReader.d.ts +36 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaReader.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaReader.js +73 -0
- package/lib/esm/IncrementalLoading/IncrementalSchemaReader.js.map +1 -0
- package/lib/esm/IncrementalLoading/PerformanceLogger.d.ts +60 -0
- package/lib/esm/IncrementalLoading/PerformanceLogger.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/PerformanceLogger.js +78 -0
- package/lib/esm/IncrementalLoading/PerformanceLogger.js.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaItemParsers.d.ts +51 -0
- package/lib/esm/IncrementalLoading/SchemaItemParsers.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaItemParsers.js +117 -0
- package/lib/esm/IncrementalLoading/SchemaItemParsers.js.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaItemQueries.d.ts +16 -0
- package/lib/esm/IncrementalLoading/SchemaItemQueries.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaItemQueries.js +305 -0
- package/lib/esm/IncrementalLoading/SchemaItemQueries.js.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaParser.d.ts +42 -0
- package/lib/esm/IncrementalLoading/SchemaParser.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaParser.js +104 -0
- package/lib/esm/IncrementalLoading/SchemaParser.js.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaStubQueries.d.ts +12 -0
- package/lib/esm/IncrementalLoading/SchemaStubQueries.d.ts.map +1 -0
- package/lib/esm/IncrementalLoading/SchemaStubQueries.js +359 -0
- package/lib/esm/IncrementalLoading/SchemaStubQueries.js.map +1 -0
- package/lib/esm/Metadata/Class.d.ts +5 -16
- package/lib/esm/Metadata/Class.d.ts.map +1 -1
- package/lib/esm/Metadata/Class.js +68 -68
- package/lib/esm/Metadata/Class.js.map +1 -1
- package/lib/esm/Metadata/CustomAttribute.d.ts +7 -1
- package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -1
- package/lib/esm/Metadata/CustomAttribute.js.map +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.d.ts +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.js +1 -1
- package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/esm/Metadata/EntityClass.d.ts +6 -6
- package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
- package/lib/esm/Metadata/EntityClass.js +48 -26
- package/lib/esm/Metadata/EntityClass.js.map +1 -1
- package/lib/esm/Metadata/Format.d.ts +5 -0
- package/lib/esm/Metadata/Format.d.ts.map +1 -1
- package/lib/esm/Metadata/Format.js +7 -0
- package/lib/esm/Metadata/Format.js.map +1 -1
- package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/esm/Metadata/Schema.d.ts +10 -0
- package/lib/esm/Metadata/Schema.d.ts.map +1 -1
- package/lib/esm/Metadata/Schema.js +13 -0
- package/lib/esm/Metadata/Schema.js.map +1 -1
- package/lib/esm/Metadata/SchemaItem.d.ts +10 -0
- package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
- package/lib/esm/Metadata/SchemaItem.js +13 -0
- package/lib/esm/Metadata/SchemaItem.js.map +1 -1
- package/lib/esm/SchemaFormatsProvider.d.ts +4 -3
- package/lib/esm/SchemaFormatsProvider.d.ts.map +1 -1
- package/lib/esm/SchemaFormatsProvider.js +61 -18
- package/lib/esm/SchemaFormatsProvider.js.map +1 -1
- package/lib/esm/SchemaLoader.d.ts +4 -1
- package/lib/esm/SchemaLoader.d.ts.map +1 -1
- package/lib/esm/SchemaLoader.js +4 -1
- package/lib/esm/SchemaLoader.js.map +1 -1
- package/lib/esm/ecschema-metadata.d.ts +2 -0
- package/lib/esm/ecschema-metadata.d.ts.map +1 -1
- package/lib/esm/ecschema-metadata.js +2 -0
- package/lib/esm/ecschema-metadata.js.map +1 -1
- package/lib/esm/utils/SchemaLoadingController.d.ts +37 -0
- package/lib/esm/utils/SchemaLoadingController.d.ts.map +1 -0
- package/lib/esm/utils/SchemaLoadingController.js +61 -0
- package/lib/esm/utils/SchemaLoadingController.js.map +1 -0
- package/package.json +15 -10
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ISchemaLocater, SchemaContext } from "../Context";
|
|
2
|
+
import { SchemaProps } from "../Deserialization/JsonProps";
|
|
3
|
+
import { SchemaMatchType } from "../ECObjects";
|
|
4
|
+
import { SchemaInfo } from "../Interfaces";
|
|
5
|
+
import { Schema } from "../Metadata/Schema";
|
|
6
|
+
import { SchemaKey } from "../SchemaKey";
|
|
7
|
+
/**
|
|
8
|
+
* Defines the SchemaLocater Options which determine how each schema is to be loaded.
|
|
9
|
+
* All options are optional.
|
|
10
|
+
* @beta
|
|
11
|
+
*/
|
|
12
|
+
export interface SchemaLocaterOptions {
|
|
13
|
+
/** Only load partial schemas. Full schema information will not be retrieved. Defaults to false. */
|
|
14
|
+
readonly loadPartialSchemaOnly?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A [[ISchemaLocater]] implementation for locating and retrieving EC [[Schema]]
|
|
18
|
+
* objects incrementally instead of the full schema and it's references at once. This is useful for large schemas that
|
|
19
|
+
* take a long time to load, but clients need a rough skeleton of the schema as fast as possible.
|
|
20
|
+
*
|
|
21
|
+
* The IncrementalSchemaLocater is a locater around the [[IncrementalSchemaLocater]] to be used in a
|
|
22
|
+
* [[SchemaContext]].
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare abstract class IncrementalSchemaLocater implements ISchemaLocater {
|
|
26
|
+
private readonly _options;
|
|
27
|
+
private readonly _schemaInfoCache;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes a new instance of the IncrementalSchemaLocater class.
|
|
30
|
+
* @param options The [[SchemaLocaterOptions]] that control the loading of the schema.
|
|
31
|
+
*/
|
|
32
|
+
constructor(options?: SchemaLocaterOptions);
|
|
33
|
+
/** Gets the options how the schema locater load the schemas. */
|
|
34
|
+
protected get options(): SchemaLocaterOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the [[SchemaInfo]] which matches the provided SchemaKey. The SchemaInfo may be returned
|
|
37
|
+
* before the schema is fully loaded. May return the entire Schema so long as it is completely loaded as it satisfies
|
|
38
|
+
* the SchemaInfo interface.
|
|
39
|
+
* @param schemaKey The [[SchemaKey]] to look up.
|
|
40
|
+
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
|
|
41
|
+
* @param context The [[SchemaContext]] for loading schema references.
|
|
42
|
+
*/
|
|
43
|
+
getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.
|
|
46
|
+
* For schemas that may have references, construct and call through a SchemaContext instead.
|
|
47
|
+
* @param schemaKey The [[SchemaKey]] to look up.
|
|
48
|
+
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
|
|
49
|
+
* @param context The [[SchemaContext]] for loading schema references.
|
|
50
|
+
*/
|
|
51
|
+
getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.
|
|
54
|
+
* For schemas that may have references, construct and call through a SchemaContext instead.
|
|
55
|
+
* NOT IMPLEMENTED IN THIS LOCATER - ALWAYS RETURNS UNDEFINED.
|
|
56
|
+
* @param schemaKey The [[SchemaKey]] to look up.
|
|
57
|
+
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
|
|
58
|
+
* @param context The [[SchemaContext]] for loading schema references.
|
|
59
|
+
* @returns Incremental schema loading does not work synchronously, this will always return undefined.
|
|
60
|
+
*/
|
|
61
|
+
getSchemaSync(_schemaKey: Readonly<SchemaKey>, _matchType: SchemaMatchType, _context: SchemaContext): Schema | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the schema partials for the given schema key. The first item in the array is the
|
|
64
|
+
* actual schema props of the schema to load, the following items are partial schema props
|
|
65
|
+
* of referenced schemas.
|
|
66
|
+
* @param schemaKey The schema key of the requested schema.
|
|
67
|
+
* @param context The schema context.
|
|
68
|
+
*/
|
|
69
|
+
protected abstract getSchemaPartials(schemaKey: SchemaKey, context: SchemaContext): Promise<ReadonlyArray<SchemaProps> | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the full schema json for the requested schema key.
|
|
72
|
+
* @param schemaKey The schema key of the requested schema.
|
|
73
|
+
* @param context The schema context.
|
|
74
|
+
*/
|
|
75
|
+
protected abstract getSchemaJson(schemaKey: SchemaKey, context: SchemaContext): Promise<SchemaProps | undefined>;
|
|
76
|
+
/**
|
|
77
|
+
* Loads the schema info objects for the given context.
|
|
78
|
+
* @param context The schema context to load the schema infos for.
|
|
79
|
+
* @returns A promise that resolves to an iterable of schema infos.
|
|
80
|
+
*/
|
|
81
|
+
abstract loadSchemaInfos(context: SchemaContext): Promise<Iterable<SchemaInfo>>;
|
|
82
|
+
/**
|
|
83
|
+
* Checks if the context contains the right schemas to support incremental schema loading.
|
|
84
|
+
* @param context The schema context to check.
|
|
85
|
+
* @returns true if incremental schema loading is supported, false otherwise.
|
|
86
|
+
*/
|
|
87
|
+
protected abstract supportPartialSchemaLoading(context: SchemaContext): Promise<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* Start loading the schema for the given schema info incrementally. The schema is returned
|
|
90
|
+
* as soon as the schema stub is loaded while the schema fully resolves in the background. It should
|
|
91
|
+
* only be called by the IncrementalSchemaLocater if a schema has not been loaded or started to
|
|
92
|
+
* load yet.
|
|
93
|
+
* @param schemaInfo The schema info of the schema to load.
|
|
94
|
+
* @param schemaContext The schema context to load the schema into.
|
|
95
|
+
*/
|
|
96
|
+
loadSchema(schemaInfo: SchemaInfo, schemaContext: SchemaContext): Promise<Schema>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a SchemaProps object by loading the Schema information from the given SchemaContext.
|
|
99
|
+
* @param schemaKey The SchemaKey of the Schema whose props are to be retrieved.
|
|
100
|
+
* @param schemaContext The SchemaContext holding the Schema.
|
|
101
|
+
* @returns The SchemaProps object.
|
|
102
|
+
*/
|
|
103
|
+
protected createSchemaProps(schemaKey: SchemaKey, schemaContext: SchemaContext): Promise<SchemaProps>;
|
|
104
|
+
private startLoadingPartialSchema;
|
|
105
|
+
private loadFullSchema;
|
|
106
|
+
private startLoadingFullSchema;
|
|
107
|
+
private sortSchemaPartials;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=IncrementalSchemaLocater.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E,aAAa,GAAG,MAAM,GAAG,SAAS;IAI/H;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;IAEnI;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAEhH;;;;OAIG;aACa,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAEtF;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,2BAA2B,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAExF;;;;;;;OAOG;IACU,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IA+B9F;;;;;OAKG;cACa,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC;YAuB7F,yBAAyB;YAgBzB,cAAc;YAMd,sBAAsB;YAsBtB,kBAAkB;CAcjC"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IncrementalSchemaLocater = void 0;
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
const Constants_1 = require("../Constants");
|
|
9
|
+
const SchemaGraphUtil_1 = require("../Deserialization/SchemaGraphUtil");
|
|
10
|
+
const ECObjects_1 = require("../ECObjects");
|
|
11
|
+
const Exception_1 = require("../Exception");
|
|
12
|
+
const Schema_1 = require("../Metadata/Schema");
|
|
13
|
+
const SchemaKey_1 = require("../SchemaKey");
|
|
14
|
+
const SchemaLoadingController_1 = require("../utils/SchemaLoadingController");
|
|
15
|
+
const IncrementalSchemaReader_1 = require("./IncrementalSchemaReader");
|
|
16
|
+
/**
|
|
17
|
+
* A [[ISchemaLocater]] implementation for locating and retrieving EC [[Schema]]
|
|
18
|
+
* objects incrementally instead of the full schema and it's references at once. This is useful for large schemas that
|
|
19
|
+
* take a long time to load, but clients need a rough skeleton of the schema as fast as possible.
|
|
20
|
+
*
|
|
21
|
+
* The IncrementalSchemaLocater is a locater around the [[IncrementalSchemaLocater]] to be used in a
|
|
22
|
+
* [[SchemaContext]].
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
class IncrementalSchemaLocater {
|
|
26
|
+
_options;
|
|
27
|
+
_schemaInfoCache;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes a new instance of the IncrementalSchemaLocater class.
|
|
30
|
+
* @param options The [[SchemaLocaterOptions]] that control the loading of the schema.
|
|
31
|
+
*/
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this._options = options || {};
|
|
34
|
+
this._schemaInfoCache = new SchemaInfoCache(async (context) => {
|
|
35
|
+
return this.loadSchemaInfos(context);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Gets the options how the schema locater load the schemas. */
|
|
39
|
+
get options() {
|
|
40
|
+
return this._options;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets the [[SchemaInfo]] which matches the provided SchemaKey. The SchemaInfo may be returned
|
|
44
|
+
* before the schema is fully loaded. May return the entire Schema so long as it is completely loaded as it satisfies
|
|
45
|
+
* the SchemaInfo interface.
|
|
46
|
+
* @param schemaKey The [[SchemaKey]] to look up.
|
|
47
|
+
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
|
|
48
|
+
* @param context The [[SchemaContext]] for loading schema references.
|
|
49
|
+
*/
|
|
50
|
+
async getSchemaInfo(schemaKey, matchType, context) {
|
|
51
|
+
return this._schemaInfoCache.lookup(schemaKey, matchType, context);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.
|
|
55
|
+
* For schemas that may have references, construct and call through a SchemaContext instead.
|
|
56
|
+
* @param schemaKey The [[SchemaKey]] to look up.
|
|
57
|
+
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
|
|
58
|
+
* @param context The [[SchemaContext]] for loading schema references.
|
|
59
|
+
*/
|
|
60
|
+
async getSchema(schemaKey, matchType, context) {
|
|
61
|
+
const schemaInfo = await this.getSchemaInfo(schemaKey, matchType, context);
|
|
62
|
+
return schemaInfo
|
|
63
|
+
? this.loadSchema(schemaInfo, context)
|
|
64
|
+
: undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.
|
|
68
|
+
* For schemas that may have references, construct and call through a SchemaContext instead.
|
|
69
|
+
* NOT IMPLEMENTED IN THIS LOCATER - ALWAYS RETURNS UNDEFINED.
|
|
70
|
+
* @param schemaKey The [[SchemaKey]] to look up.
|
|
71
|
+
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
|
|
72
|
+
* @param context The [[SchemaContext]] for loading schema references.
|
|
73
|
+
* @returns Incremental schema loading does not work synchronously, this will always return undefined.
|
|
74
|
+
*/
|
|
75
|
+
getSchemaSync(_schemaKey, _matchType, _context) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Start loading the schema for the given schema info incrementally. The schema is returned
|
|
80
|
+
* as soon as the schema stub is loaded while the schema fully resolves in the background. It should
|
|
81
|
+
* only be called by the IncrementalSchemaLocater if a schema has not been loaded or started to
|
|
82
|
+
* load yet.
|
|
83
|
+
* @param schemaInfo The schema info of the schema to load.
|
|
84
|
+
* @param schemaContext The schema context to load the schema into.
|
|
85
|
+
*/
|
|
86
|
+
async loadSchema(schemaInfo, schemaContext) {
|
|
87
|
+
// If the meta schema is an earlier version than 4.0.3, we can't use the ECSql query interface to get the schema
|
|
88
|
+
// information required to load the schema entirely. In this case, we fallback to use the ECSchema RPC interface
|
|
89
|
+
// to fetch the whole schema json.
|
|
90
|
+
if (!await this.supportPartialSchemaLoading(schemaContext)) {
|
|
91
|
+
const schemaJson = await this.getSchemaJson(schemaInfo.schemaKey, schemaContext);
|
|
92
|
+
return Schema_1.Schema.fromJson(schemaJson, schemaContext);
|
|
93
|
+
}
|
|
94
|
+
// Fetches the schema partials for the given schema key. The first item in the array is the
|
|
95
|
+
// actual schema props of the schema to load, the following items are schema props of referenced
|
|
96
|
+
// schema items that are needed to resolve the schema properly.
|
|
97
|
+
const schemaPartials = await this.getSchemaPartials(schemaInfo.schemaKey, schemaContext);
|
|
98
|
+
if (schemaPartials === undefined)
|
|
99
|
+
throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.UnableToLocateSchema, `Could not locate the schema, ${schemaInfo.schemaKey.name}.${schemaInfo.schemaKey.version.toString()}`);
|
|
100
|
+
// Sort the partials in dependency order to ensure referenced schemas exist in the schema context
|
|
101
|
+
// when they get requested. Otherwise the context would call this method again and for referenced
|
|
102
|
+
// schemas, we would not want to request the whole schema props.
|
|
103
|
+
const sortedPartials = await this.sortSchemaPartials(schemaPartials, schemaContext);
|
|
104
|
+
for (const schemaProps of sortedPartials) {
|
|
105
|
+
await this.startLoadingPartialSchema(schemaProps, schemaContext);
|
|
106
|
+
}
|
|
107
|
+
const schema = await schemaContext.getCachedSchema(schemaInfo.schemaKey);
|
|
108
|
+
if (!schema)
|
|
109
|
+
throw new Error(`Schema ${schemaInfo.schemaKey.name} could not be found.`);
|
|
110
|
+
return schema;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Creates a SchemaProps object by loading the Schema information from the given SchemaContext.
|
|
114
|
+
* @param schemaKey The SchemaKey of the Schema whose props are to be retrieved.
|
|
115
|
+
* @param schemaContext The SchemaContext holding the Schema.
|
|
116
|
+
* @returns The SchemaProps object.
|
|
117
|
+
*/
|
|
118
|
+
async createSchemaProps(schemaKey, schemaContext) {
|
|
119
|
+
const schemaInfo = await schemaContext.getSchemaInfo(schemaKey, ECObjects_1.SchemaMatchType.Latest);
|
|
120
|
+
if (!schemaInfo)
|
|
121
|
+
throw new Error(`Schema ${schemaKey.name} could not be found.`);
|
|
122
|
+
const schemaProps = {
|
|
123
|
+
$schema: Constants_1.ECSchemaNamespaceUris.SCHEMAURL3_2_JSON,
|
|
124
|
+
name: schemaKey.name,
|
|
125
|
+
alias: schemaInfo.alias,
|
|
126
|
+
version: schemaInfo.schemaKey.version.toString(),
|
|
127
|
+
references: [],
|
|
128
|
+
items: {}
|
|
129
|
+
};
|
|
130
|
+
if (!schemaProps.references)
|
|
131
|
+
throw new Error(`Schema references is undefined for the Schema ${schemaInfo.schemaKey.name}`);
|
|
132
|
+
schemaInfo.references.forEach((ref) => {
|
|
133
|
+
schemaProps.references.push({ name: ref.schemaKey.name, version: ref.schemaKey.version.toString() });
|
|
134
|
+
});
|
|
135
|
+
return schemaProps;
|
|
136
|
+
}
|
|
137
|
+
async startLoadingPartialSchema(schemaProps, schemaContext) {
|
|
138
|
+
if (schemaContext.schemaExists(SchemaKey_1.SchemaKey.parseString(`${schemaProps.name}.${schemaProps.version}`))) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const controller = new SchemaLoadingController_1.SchemaLoadingController();
|
|
142
|
+
const schemaReader = new IncrementalSchemaReader_1.IncrementalSchemaReader(schemaContext, true);
|
|
143
|
+
const schema = new Schema_1.Schema(schemaContext);
|
|
144
|
+
schema.setLoadingController(controller);
|
|
145
|
+
await schemaReader.readSchema(schema, schemaProps);
|
|
146
|
+
if (!this._options.loadPartialSchemaOnly)
|
|
147
|
+
controller.start(this.startLoadingFullSchema(schema));
|
|
148
|
+
}
|
|
149
|
+
async loadFullSchema(schema) {
|
|
150
|
+
const fullSchemaProps = await this.getSchemaJson(schema.schemaKey, schema.context);
|
|
151
|
+
const reader = new IncrementalSchemaReader_1.IncrementalSchemaReader(schema.context, false);
|
|
152
|
+
await reader.readSchema(schema, fullSchemaProps, false);
|
|
153
|
+
}
|
|
154
|
+
async startLoadingFullSchema(schema) {
|
|
155
|
+
if (!schema.loadingController)
|
|
156
|
+
return;
|
|
157
|
+
// If the schema is already resolved, return it directly.
|
|
158
|
+
if (schema.loadingController.isComplete || schema.loadingController.inProgress) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// Since the schema relies on it's references, they get triggered to be resolved
|
|
162
|
+
// first by recursively calling this method. After all references has been resolved
|
|
163
|
+
// the schema itself gets resolved.
|
|
164
|
+
await Promise.all(schema.references.map(async (referenceSchema) => {
|
|
165
|
+
if (referenceSchema.loadingController && referenceSchema.loadingController.inProgress)
|
|
166
|
+
return referenceSchema.loadingController.wait();
|
|
167
|
+
else
|
|
168
|
+
return this.startLoadingFullSchema(referenceSchema);
|
|
169
|
+
}));
|
|
170
|
+
return this.loadFullSchema(schema);
|
|
171
|
+
}
|
|
172
|
+
async sortSchemaPartials(schemaPartials, schemaContext) {
|
|
173
|
+
const schemaInfos = [];
|
|
174
|
+
for (const schemaProps of schemaPartials) {
|
|
175
|
+
const schemaKey = SchemaKey_1.SchemaKey.parseString(`${schemaProps.name}.${schemaProps.version}`);
|
|
176
|
+
const schemaInfo = await schemaContext.getSchemaInfo(schemaKey, ECObjects_1.SchemaMatchType.Latest);
|
|
177
|
+
if (!schemaInfo)
|
|
178
|
+
throw new Error(`Schema ${schemaKey.name} could not be found.`);
|
|
179
|
+
schemaInfos.push({ ...schemaInfo, props: schemaProps });
|
|
180
|
+
}
|
|
181
|
+
const orderedSchemaInfos = SchemaGraphUtil_1.SchemaGraphUtil.buildDependencyOrderedSchemaInfoList(schemaInfos);
|
|
182
|
+
return orderedSchemaInfos.map((schemaInfo) => schemaInfo.props);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.IncrementalSchemaLocater = IncrementalSchemaLocater;
|
|
186
|
+
/**
|
|
187
|
+
* Helper class to manage schema infos for a schema context.
|
|
188
|
+
*/
|
|
189
|
+
class SchemaInfoCache {
|
|
190
|
+
_schemaInfoCache;
|
|
191
|
+
_schemaInfoLoader;
|
|
192
|
+
constructor(schemaInfoLoader) {
|
|
193
|
+
this._schemaInfoCache = new WeakMap();
|
|
194
|
+
this._schemaInfoLoader = schemaInfoLoader;
|
|
195
|
+
}
|
|
196
|
+
async getSchemasByContext(context) {
|
|
197
|
+
if (!this._schemaInfoCache.has(context)) {
|
|
198
|
+
const schemaInfos = await this._schemaInfoLoader(context);
|
|
199
|
+
this._schemaInfoCache.set(context, Array.from(schemaInfos));
|
|
200
|
+
}
|
|
201
|
+
return this._schemaInfoCache.get(context);
|
|
202
|
+
}
|
|
203
|
+
async lookup(schemaKey, matchType, context) {
|
|
204
|
+
const contextSchemaInfos = await this.getSchemasByContext(context);
|
|
205
|
+
return contextSchemaInfos
|
|
206
|
+
? contextSchemaInfos.find((schemaInfo) => schemaInfo.schemaKey.matches(schemaKey, matchType))
|
|
207
|
+
: undefined;
|
|
208
|
+
}
|
|
209
|
+
remove(schemaKey, context) {
|
|
210
|
+
const contextSchemaInfos = this._schemaInfoCache.get(context);
|
|
211
|
+
if (!contextSchemaInfos)
|
|
212
|
+
return;
|
|
213
|
+
const index = contextSchemaInfos.findIndex((schemaInfo) => schemaInfo.schemaKey.name === schemaKey.name);
|
|
214
|
+
if (index !== -1) {
|
|
215
|
+
contextSchemaInfos.splice(index, 1);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=IncrementalSchemaLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IncrementalSchemaLocater.js","sourceRoot":"","sources":["../../../src/IncrementalLo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1D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QAC1F,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACnE,OAAO,kBAAkB;YACvB,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAC7F,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,SAAoB,EAAE,OAAsB;QACxD,MAAM,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9D,IAAI,CAAC,kBAAkB;YACrB,OAAO;QAET,MAAM,KAAK,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC;QACzG,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,kBAAkB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;CACF","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 *--------------------------------------------------------------------------------------------*/\nimport { ECSchemaNamespaceUris } from \"../Constants\";\nimport { ISchemaLocater, SchemaContext } from \"../Context\";\nimport { SchemaProps } from \"../Deserialization/JsonProps\";\nimport { SchemaGraphUtil } from \"../Deserialization/SchemaGraphUtil\";\nimport { SchemaMatchType } from \"../ECObjects\";\nimport { ECSchemaError, ECSchemaStatus } from \"../Exception\";\nimport { SchemaInfo } from \"../Interfaces\";\nimport { Schema } from \"../Metadata/Schema\";\nimport { SchemaKey } from \"../SchemaKey\";\nimport { SchemaLoadingController } from \"../utils/SchemaLoadingController\";\nimport { IncrementalSchemaReader } from \"./IncrementalSchemaReader\";\n\ntype LoadSchemaInfoHandler = (context: SchemaContext) => Promise<Iterable<SchemaInfo>>;\n\n/**\n * Defines the SchemaLocater Options which determine how each schema is to be loaded.\n * All options are optional.\n * @beta\n */\nexport interface SchemaLocaterOptions {\n /** Only load partial schemas. Full schema information will not be retrieved. Defaults to false. */\n readonly loadPartialSchemaOnly?: boolean;\n}\n\n/**\n * A [[ISchemaLocater]] implementation for locating and retrieving EC [[Schema]]\n * objects incrementally instead of the full schema and it's references at once. This is useful for large schemas that\n * take a long time to load, but clients need a rough skeleton of the schema as fast as possible.\n *\n * The IncrementalSchemaLocater is a locater around the [[IncrementalSchemaLocater]] to be used in a\n * [[SchemaContext]].\n * @internal\n */\nexport abstract class IncrementalSchemaLocater implements ISchemaLocater {\n private readonly _options: SchemaLocaterOptions;\n private readonly _schemaInfoCache: SchemaInfoCache;\n\n /**\n * Initializes a new instance of the IncrementalSchemaLocater class.\n * @param options The [[SchemaLocaterOptions]] that control the loading of the schema.\n */\n constructor(options?: SchemaLocaterOptions) {\n this._options = options || {};\n\n this._schemaInfoCache = new SchemaInfoCache(async (context) => {\n return this.loadSchemaInfos(context);\n });\n }\n\n /** Gets the options how the schema locater load the schemas. */\n protected get options(): SchemaLocaterOptions {\n return this._options;\n }\n\n /**\n * Gets the [[SchemaInfo]] which matches the provided SchemaKey. The SchemaInfo may be returned\n * before the schema is fully loaded. May return the entire Schema so long as it is completely loaded as it satisfies\n * the SchemaInfo interface.\n * @param schemaKey The [[SchemaKey]] to look up.\n * @param matchType The [[SchemaMatchType]] to use against candidate schemas.\n * @param context The [[SchemaContext]] for loading schema references.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n return this._schemaInfoCache.lookup(schemaKey, matchType, context);\n }\n\n /**\n * Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.\n * For schemas that may have references, construct and call through a SchemaContext instead.\n * @param schemaKey The [[SchemaKey]] to look up.\n * @param matchType The [[SchemaMatchType]] to use against candidate schemas.\n * @param context The [[SchemaContext]] for loading schema references.\n */\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n const schemaInfo = await this.getSchemaInfo(schemaKey, matchType, context);\n return schemaInfo\n ? this.loadSchema(schemaInfo, context)\n : undefined;\n }\n\n /**\n * Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.\n * For schemas that may have references, construct and call through a SchemaContext instead.\n * NOT IMPLEMENTED IN THIS LOCATER - ALWAYS RETURNS UNDEFINED.\n * @param schemaKey The [[SchemaKey]] to look up.\n * @param matchType The [[SchemaMatchType]] to use against candidate schemas.\n * @param context The [[SchemaContext]] for loading schema references.\n * @returns Incremental schema loading does not work synchronously, this will always return undefined.\n */\n public getSchemaSync(_schemaKey: Readonly<SchemaKey>, _matchType: SchemaMatchType, _context: SchemaContext): Schema | undefined {\n return undefined;\n }\n\n /**\n * Gets the schema partials for the given schema key. The first item in the array is the\n * actual schema props of the schema to load, the following items are partial schema props\n * of referenced schemas.\n * @param schemaKey The schema key of the requested schema.\n * @param context The schema context.\n */\n protected abstract getSchemaPartials(schemaKey: SchemaKey, context: SchemaContext): Promise<ReadonlyArray<SchemaProps> | undefined>;\n\n /**\n * Gets the full schema json for the requested schema key.\n * @param schemaKey The schema key of the requested schema.\n * @param context The schema context.\n */\n protected abstract getSchemaJson(schemaKey: SchemaKey, context: SchemaContext): Promise<SchemaProps | undefined>;\n\n /**\n * Loads the schema info objects for the given context.\n * @param context The schema context to load the schema infos for.\n * @returns A promise that resolves to an iterable of schema infos.\n */\n public abstract loadSchemaInfos(context: SchemaContext): Promise<Iterable<SchemaInfo>>;\n\n /**\n * Checks if the context contains the right schemas to support incremental schema loading.\n * @param context The schema context to check.\n * @returns true if incremental schema loading is supported, false otherwise.\n */\n protected abstract supportPartialSchemaLoading(context: SchemaContext): Promise<boolean>;\n\n /**\n * Start loading the schema for the given schema info incrementally. The schema is returned\n * as soon as the schema stub is loaded while the schema fully resolves in the background. It should\n * only be called by the IncrementalSchemaLocater if a schema has not been loaded or started to\n * load yet.\n * @param schemaInfo The schema info of the schema to load.\n * @param schemaContext The schema context to load the schema into.\n */\n public async loadSchema(schemaInfo: SchemaInfo, schemaContext: SchemaContext): Promise<Schema> {\n // If the meta schema is an earlier version than 4.0.3, we can't use the ECSql query interface to get the schema\n // information required to load the schema entirely. In this case, we fallback to use the ECSchema RPC interface\n // to fetch the whole schema json.\n if (!await this.supportPartialSchemaLoading(schemaContext)) {\n const schemaJson = await this.getSchemaJson(schemaInfo.schemaKey, schemaContext);\n return Schema.fromJson(schemaJson!, schemaContext);\n }\n\n // Fetches the schema partials for the given schema key. The first item in the array is the\n // actual schema props of the schema to load, the following items are schema props of referenced\n // schema items that are needed to resolve the schema properly.\n const schemaPartials = await this.getSchemaPartials(schemaInfo.schemaKey, schemaContext);\n if (schemaPartials === undefined)\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Could not locate the schema, ${schemaInfo.schemaKey.name}.${schemaInfo.schemaKey.version.toString()}`);\n\n // Sort the partials in dependency order to ensure referenced schemas exist in the schema context\n // when they get requested. Otherwise the context would call this method again and for referenced\n // schemas, we would not want to request the whole schema props.\n const sortedPartials = await this.sortSchemaPartials(schemaPartials, schemaContext);\n for (const schemaProps of sortedPartials) {\n await this.startLoadingPartialSchema(schemaProps, schemaContext);\n }\n\n const schema = await schemaContext.getCachedSchema(schemaInfo.schemaKey);\n if (!schema)\n throw new Error(`Schema ${schemaInfo.schemaKey.name} could not be found.`);\n\n return schema;\n }\n\n /**\n * Creates a SchemaProps object by loading the Schema information from the given SchemaContext.\n * @param schemaKey The SchemaKey of the Schema whose props are to be retrieved.\n * @param schemaContext The SchemaContext holding the Schema.\n * @returns The SchemaProps object.\n */\n protected async createSchemaProps(schemaKey: SchemaKey, schemaContext: SchemaContext): Promise<SchemaProps> {\n const schemaInfo = await schemaContext.getSchemaInfo(schemaKey, SchemaMatchType.Latest);\n if (!schemaInfo)\n throw new Error(`Schema ${schemaKey.name} could not be found.`);\n const schemaProps: SchemaProps = {\n $schema: ECSchemaNamespaceUris.SCHEMAURL3_2_JSON,\n name: schemaKey.name,\n alias: schemaInfo.alias,\n version: schemaInfo.schemaKey.version.toString(),\n references: [],\n items: {}\n };\n\n if (!schemaProps.references)\n throw new Error(`Schema references is undefined for the Schema ${schemaInfo.schemaKey.name}`);\n\n schemaInfo.references.forEach((ref) => {\n schemaProps.references!.push({ name: ref.schemaKey.name, version: ref.schemaKey.version.toString() });\n });\n\n return schemaProps;\n }\n\n private async startLoadingPartialSchema(schemaProps: SchemaProps, schemaContext: SchemaContext): Promise<void> {\n if (schemaContext.schemaExists(SchemaKey.parseString(`${schemaProps.name}.${schemaProps.version}`))) {\n return;\n }\n\n const controller = new SchemaLoadingController();\n const schemaReader = new IncrementalSchemaReader(schemaContext, true);\n const schema = new Schema(schemaContext);\n schema.setLoadingController(controller);\n\n await schemaReader.readSchema(schema, schemaProps);\n\n if (!this._options.loadPartialSchemaOnly)\n controller.start(this.startLoadingFullSchema(schema));\n }\n\n private async loadFullSchema(schema: Schema): Promise<void> {\n const fullSchemaProps = await this.getSchemaJson(schema.schemaKey, schema.context)\n const reader = new IncrementalSchemaReader(schema.context, false);\n await reader.readSchema(schema, fullSchemaProps, false);\n }\n\n private async startLoadingFullSchema(schema: Schema): Promise<void> {\n if (!schema.loadingController)\n return;\n\n // If the schema is already resolved, return it directly.\n if (schema.loadingController.isComplete || schema.loadingController.inProgress) {\n return;\n }\n\n // Since the schema relies on it's references, they get triggered to be resolved\n // first by recursively calling this method. After all references has been resolved\n // the schema itself gets resolved.\n await Promise.all(schema.references.map(async (referenceSchema) => {\n if (referenceSchema.loadingController && referenceSchema.loadingController.inProgress)\n return referenceSchema.loadingController.wait();\n else\n return this.startLoadingFullSchema(referenceSchema);\n }));\n\n return this.loadFullSchema(schema);\n }\n\n private async sortSchemaPartials(schemaPartials: ReadonlyArray<SchemaProps>, schemaContext: SchemaContext): Promise<ReadonlyArray<SchemaProps>> {\n const schemaInfos: Array<SchemaInfo & { props: SchemaProps }> = [];\n for (const schemaProps of schemaPartials) {\n const schemaKey = SchemaKey.parseString(`${schemaProps.name}.${schemaProps.version}`);\n const schemaInfo = await schemaContext.getSchemaInfo(schemaKey, SchemaMatchType.Latest);\n if (!schemaInfo)\n throw new Error(`Schema ${schemaKey.name} could not be found.`);\n\n schemaInfos.push({ ...schemaInfo, props: schemaProps });\n }\n\n const orderedSchemaInfos = SchemaGraphUtil.buildDependencyOrderedSchemaInfoList(schemaInfos) as Array<SchemaInfo & { props: SchemaProps }>;\n return orderedSchemaInfos.map((schemaInfo) => schemaInfo.props);\n }\n}\n\n/**\n * Helper class to manage schema infos for a schema context.\n */\nclass SchemaInfoCache {\n private readonly _schemaInfoCache: WeakMap<SchemaContext, Array<SchemaInfo>>;\n private readonly _schemaInfoLoader: LoadSchemaInfoHandler;\n\n constructor(schemaInfoLoader: LoadSchemaInfoHandler) {\n this._schemaInfoCache = new WeakMap<SchemaContext, Array<SchemaInfo>>();\n this._schemaInfoLoader = schemaInfoLoader;\n }\n\n public async getSchemasByContext(context: SchemaContext): Promise<SchemaInfo[] | undefined> {\n if (!this._schemaInfoCache.has(context)) {\n const schemaInfos = await this._schemaInfoLoader(context);\n this._schemaInfoCache.set(context, Array.from(schemaInfos));\n }\n return this._schemaInfoCache.get(context);\n }\n\n public async lookup(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n const contextSchemaInfos = await this.getSchemasByContext(context);\n return contextSchemaInfos\n ? contextSchemaInfos.find((schemaInfo) => schemaInfo.schemaKey.matches(schemaKey, matchType))\n : undefined;\n }\n\n public remove(schemaKey: SchemaKey, context: SchemaContext): void {\n const contextSchemaInfos = this._schemaInfoCache.get(context);\n if (!contextSchemaInfos)\n return;\n\n const index = contextSchemaInfos.findIndex((schemaInfo) => schemaInfo.schemaKey.name === schemaKey.name);\n if (index !== -1) {\n contextSchemaInfos.splice(index, 1);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SchemaContext } from "../Context";
|
|
2
|
+
import { SchemaReadHelper } from "../Deserialization/Helper";
|
|
3
|
+
import { Schema } from "../Metadata/Schema";
|
|
4
|
+
import { SchemaItem } from "../Metadata/SchemaItem";
|
|
5
|
+
/**
|
|
6
|
+
* Internal helper class to read schema information incrementally. It's based on the [[SchemaReadHelper]]
|
|
7
|
+
* but overrides a few methods to support the incremental schema loading case.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class IncrementalSchemaReader extends SchemaReadHelper {
|
|
11
|
+
private readonly _incremental;
|
|
12
|
+
/**
|
|
13
|
+
* Initializes a new [[IncrementalSchemaReader]] instance.
|
|
14
|
+
* @param schemaContext The [[SchemaContext]] used to load the schemas.
|
|
15
|
+
* @param incremental Indicates that the Schema should be read incrementally.
|
|
16
|
+
* Pass false to load the full schema without an incremental/partial load.
|
|
17
|
+
*/
|
|
18
|
+
constructor(schemaContext: SchemaContext, incremental: boolean);
|
|
19
|
+
/**
|
|
20
|
+
* Indicates that a given [[SchemaItem]] has been fully loaded.
|
|
21
|
+
* @param schemaItem The SchemaItem to check.
|
|
22
|
+
* @returns True if the item has been loaded, false if still in progress.
|
|
23
|
+
*/
|
|
24
|
+
protected isSchemaItemLoaded(schemaItem: SchemaItem | undefined): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Starts loading the [[SchemaItem]] identified by the given name and itemType.
|
|
27
|
+
* @param schema The [[Schema]] that contains the SchemaItem.
|
|
28
|
+
* @param name The name of the SchemaItem to load.
|
|
29
|
+
* @param itemType The SchemaItem type name of the item to load.
|
|
30
|
+
* @param schemaItemObject The object accepting the SchemaItem data.
|
|
31
|
+
* @returns A promise that resolves to the loaded SchemaItem instance. Can be undefined.
|
|
32
|
+
*/
|
|
33
|
+
loadSchemaItem(schema: Schema, name: string, itemType: string, schemaItemObject: Readonly<unknown>): Promise<SchemaItem | undefined>;
|
|
34
|
+
private schemaItemLoading;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=IncrementalSchemaReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IncrementalSchemaReader.d.ts","sourceRoot":"","sources":["../../../src/IncrementalLoading/IncrementalSchemaReader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAI7D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,gBAAgB;IAC3D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IAEvC;;;;;OAKG;gBACS,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO;IAK9D;;;;OAIG;cACgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO;IAMlF;;;;;;;OAOG;IACmB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAkB1J,OAAO,CAAC,iBAAiB;CAgB1B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IncrementalSchemaReader = void 0;
|
|
4
|
+
const Helper_1 = require("../Deserialization/Helper");
|
|
5
|
+
const JsonParser_1 = require("../Deserialization/JsonParser");
|
|
6
|
+
const ECObjects_1 = require("../ECObjects");
|
|
7
|
+
const Class_1 = require("../Metadata/Class");
|
|
8
|
+
const SchemaItem_1 = require("../Metadata/SchemaItem");
|
|
9
|
+
const SchemaLoadingController_1 = require("../utils/SchemaLoadingController");
|
|
10
|
+
/**
|
|
11
|
+
* Internal helper class to read schema information incrementally. It's based on the [[SchemaReadHelper]]
|
|
12
|
+
* but overrides a few methods to support the incremental schema loading case.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
class IncrementalSchemaReader extends Helper_1.SchemaReadHelper {
|
|
16
|
+
_incremental;
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a new [[IncrementalSchemaReader]] instance.
|
|
19
|
+
* @param schemaContext The [[SchemaContext]] used to load the schemas.
|
|
20
|
+
* @param incremental Indicates that the Schema should be read incrementally.
|
|
21
|
+
* Pass false to load the full schema without an incremental/partial load.
|
|
22
|
+
*/
|
|
23
|
+
constructor(schemaContext, incremental) {
|
|
24
|
+
super(JsonParser_1.JsonParser, schemaContext);
|
|
25
|
+
this._incremental = incremental;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Indicates that a given [[SchemaItem]] has been fully loaded.
|
|
29
|
+
* @param schemaItem The SchemaItem to check.
|
|
30
|
+
* @returns True if the item has been loaded, false if still in progress.
|
|
31
|
+
*/
|
|
32
|
+
isSchemaItemLoaded(schemaItem) {
|
|
33
|
+
return schemaItem !== undefined
|
|
34
|
+
&& schemaItem.loadingController !== undefined
|
|
35
|
+
&& schemaItem.loadingController.isComplete;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Starts loading the [[SchemaItem]] identified by the given name and itemType.
|
|
39
|
+
* @param schema The [[Schema]] that contains the SchemaItem.
|
|
40
|
+
* @param name The name of the SchemaItem to load.
|
|
41
|
+
* @param itemType The SchemaItem type name of the item to load.
|
|
42
|
+
* @param schemaItemObject The object accepting the SchemaItem data.
|
|
43
|
+
* @returns A promise that resolves to the loaded SchemaItem instance. Can be undefined.
|
|
44
|
+
*/
|
|
45
|
+
async loadSchemaItem(schema, name, itemType, schemaItemObject) {
|
|
46
|
+
const schemaItem = await super.loadSchemaItem(schema, name, itemType, this._incremental ? undefined : schemaItemObject);
|
|
47
|
+
// In incremental mode, we only load the stubs of the classes. These include the modifier and base classes.
|
|
48
|
+
// The fromJSON method of the actual class instances may complain about missing properties in the props, so
|
|
49
|
+
// calling the fromJSON on the ECClass ensures only the bare minimum is loaded.
|
|
50
|
+
if (this._incremental && schemaItemObject && schemaItem) {
|
|
51
|
+
if (schemaItem.schemaItemType === ECObjects_1.SchemaItemType.KindOfQuantity) {
|
|
52
|
+
SchemaItem_1.SchemaItem.prototype.fromJSONSync.call(schemaItem, schemaItemObject);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
schemaItem.fromJSONSync(schemaItemObject);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
this.schemaItemLoading(schemaItem);
|
|
59
|
+
return schemaItem;
|
|
60
|
+
}
|
|
61
|
+
schemaItemLoading(schemaItem) {
|
|
62
|
+
if (schemaItem === undefined)
|
|
63
|
+
return;
|
|
64
|
+
if (schemaItem.loadingController === undefined) {
|
|
65
|
+
const controller = new SchemaLoadingController_1.SchemaLoadingController();
|
|
66
|
+
schemaItem.setLoadingController(controller);
|
|
67
|
+
}
|
|
68
|
+
if (Class_1.ECClass.isECClass(schemaItem)
|
|
69
|
+
|| schemaItem.schemaItemType === ECObjects_1.SchemaItemType.KindOfQuantity
|
|
70
|
+
|| schemaItem.schemaItemType === ECObjects_1.SchemaItemType.Format)
|
|
71
|
+
schemaItem.loadingController.isComplete = !this._incremental;
|
|
72
|
+
else
|
|
73
|
+
schemaItem.loadingController.isComplete = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.IncrementalSchemaReader = IncrementalSchemaReader;
|
|
77
|
+
//# sourceMappingURL=IncrementalSchemaReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IncrementalSchemaReader.js","sourceRoot":"","sources":["../../../src/IncrementalLoading/IncrementalSchemaReader.ts"],"names":[],"mappings":";;;AAKA,sDAA6D;AAC7D,8DAA2D;AAC3D,4CAA8C;AAC9C,6CAA4C;AAE5C,uDAAoD;AACpD,8EAA2E;AAE3E;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,yBAAgB;IAC1C,YAAY,CAAU;IAEvC;;;;;OAKG;IACH,YAAY,aAA4B,EAAE,WAAoB;QAC5D,KAAK,CAAC,uBAAU,EAAE,aAAa,CAAC,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACgB,kBAAkB,CAAC,UAAkC;QACtE,OAAO,UAAU,KAAK,SAAS;eAC1B,UAAU,CAAC,iBAAiB,KAAK,SAAS;eAC1C,UAAU,CAAC,iBAAiB,CAAC,UAAU,CAAC;IAC/C,CAAC;IAED;;;;;;;OAOG;IACa,KAAK,CAAC,cAAc,CAAC,MAAc,EAAE,IAAY,EAAE,QAAgB,EAAE,gBAAmC;QACtH,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;QAExH,2GAA2G;QAC3G,2GAA2G;QAC3G,+EAA+E;QAC/E,IAAI,IAAI,CAAC,YAAY,IAAI,gBAAgB,IAAI,UAAU,EAAE,CAAC;YACxD,IAAI,UAAU,CAAC,cAAc,KAAK,0BAAc,CAAC,cAAc,EAAE,CAAC;gBAChE,uBAAU,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;YACvE,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QAED,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACnC,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,iBAAiB,CAAC,UAAkC;QAC1D,IAAI,UAAU,KAAK,SAAS;YAC1B,OAAO;QAET,IAAI,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;YAC/C,MAAM,UAAU,GAAG,IAAI,iDAAuB,EAAE,CAAC;YACjD,UAAU,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,eAAO,CAAC,SAAS,CAAC,UAAU,CAAC;eAC5B,UAAU,CAAC,cAAc,KAAK,0BAAc,CAAC,cAAc;eAC3D,UAAU,CAAC,cAAc,KAAK,0BAAc,CAAC,MAAM;YACtD,UAAU,CAAC,iBAAkB,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC;;YAE9D,UAAU,CAAC,iBAAkB,CAAC,UAAU,GAAG,IAAI,CAAC;IACpD,CAAC;CACF;AAnED,0DAmEC","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 *--------------------------------------------------------------------------------------------*/\nimport { SchemaContext } from \"../Context\";\nimport { SchemaReadHelper } from \"../Deserialization/Helper\";\nimport { JsonParser } from \"../Deserialization/JsonParser\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECClass } from \"../Metadata/Class\";\nimport { Schema } from \"../Metadata/Schema\";\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\nimport { SchemaLoadingController } from \"../utils/SchemaLoadingController\";\n\n/**\n * Internal helper class to read schema information incrementally. It's based on the [[SchemaReadHelper]]\n * but overrides a few methods to support the incremental schema loading case.\n * @internal\n */\nexport class IncrementalSchemaReader extends SchemaReadHelper {\n private readonly _incremental: boolean;\n\n /**\n * Initializes a new [[IncrementalSchemaReader]] instance.\n * @param schemaContext The [[SchemaContext]] used to load the schemas.\n * @param incremental Indicates that the Schema should be read incrementally.\n * Pass false to load the full schema without an incremental/partial load.\n */\n constructor(schemaContext: SchemaContext, incremental: boolean) {\n super(JsonParser, schemaContext);\n this._incremental = incremental;\n }\n\n /**\n * Indicates that a given [[SchemaItem]] has been fully loaded.\n * @param schemaItem The SchemaItem to check.\n * @returns True if the item has been loaded, false if still in progress.\n */\n protected override isSchemaItemLoaded(schemaItem: SchemaItem | undefined): boolean {\n return schemaItem !== undefined\n && schemaItem.loadingController !== undefined\n && schemaItem.loadingController.isComplete;\n }\n\n /**\n * Starts loading the [[SchemaItem]] identified by the given name and itemType.\n * @param schema The [[Schema]] that contains the SchemaItem.\n * @param name The name of the SchemaItem to load.\n * @param itemType The SchemaItem type name of the item to load.\n * @param schemaItemObject The object accepting the SchemaItem data.\n * @returns A promise that resolves to the loaded SchemaItem instance. Can be undefined.\n */\n public override async loadSchemaItem(schema: Schema, name: string, itemType: string, schemaItemObject: Readonly<unknown>): Promise<SchemaItem | undefined> {\n const schemaItem = await super.loadSchemaItem(schema, name, itemType, this._incremental ? undefined : schemaItemObject);\n\n // In incremental mode, we only load the stubs of the classes. These include the modifier and base classes.\n // The fromJSON method of the actual class instances may complain about missing properties in the props, so\n // calling the fromJSON on the ECClass ensures only the bare minimum is loaded.\n if (this._incremental && schemaItemObject && schemaItem) {\n if (schemaItem.schemaItemType === SchemaItemType.KindOfQuantity) {\n SchemaItem.prototype.fromJSONSync.call(schemaItem, schemaItemObject);\n } else {\n schemaItem.fromJSONSync(schemaItemObject);\n }\n }\n\n this.schemaItemLoading(schemaItem);\n return schemaItem;\n }\n\n private schemaItemLoading(schemaItem: SchemaItem | undefined) {\n if (schemaItem === undefined)\n return;\n\n if (schemaItem.loadingController === undefined) {\n const controller = new SchemaLoadingController();\n schemaItem.setLoadingController(controller);\n }\n\n if (ECClass.isECClass(schemaItem)\n || schemaItem.schemaItemType === SchemaItemType.KindOfQuantity\n || schemaItem.schemaItemType === SchemaItemType.Format)\n schemaItem.loadingController!.isComplete = !this._incremental;\n else\n schemaItem.loadingController!.isComplete = true;\n }\n}"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains the properties needed to track load times
|
|
3
|
+
* for SchemaItem queries.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface SchemaItemLoadData {
|
|
7
|
+
loadTime: number;
|
|
8
|
+
itemCount: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Contains the properties needed to track load times
|
|
12
|
+
* for Schema queries.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export interface SchemaLoadData {
|
|
16
|
+
loadTime?: number;
|
|
17
|
+
schemaItemMap: Map<string, SchemaItemLoadData>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Utility class used to log query load times for Schema and
|
|
21
|
+
* SchemaItem queries.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare class PerformanceLogger {
|
|
25
|
+
private _iModelItems;
|
|
26
|
+
private _label;
|
|
27
|
+
disableLogging: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes a new PerformanceLogger instance.
|
|
30
|
+
* @param label Arbitrary label used to tag this logging session (ex. IModel name)
|
|
31
|
+
*/
|
|
32
|
+
constructor(label?: string);
|
|
33
|
+
/**
|
|
34
|
+
* Gets the Map of logged Schema entries. The Map key is the iModel name. The Map
|
|
35
|
+
* value is a second Map whose key is a Schema name and value is a SchemaLoadData
|
|
36
|
+
* object.
|
|
37
|
+
*/
|
|
38
|
+
get logItems(): Map<string, Map<string, SchemaLoadData>>;
|
|
39
|
+
/**
|
|
40
|
+
* Adds a new log entry to the Schema Map.
|
|
41
|
+
* @param startTime The start time of the entry to be logged (end time/duration is handled in this method).
|
|
42
|
+
* @param schemaName The Schema being queried.
|
|
43
|
+
*/
|
|
44
|
+
logSchema(startTime: number, schemaName: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Adds a new log entry to the SchemaItem Map.
|
|
47
|
+
* @param startTime The start time of the entry to be logged (end time/duration is handled in this method).
|
|
48
|
+
* @param schemaName The name of the Schema being queried.
|
|
49
|
+
* @param schemaItemType The SchemaItemType name of the type being queried.
|
|
50
|
+
* @param itemCount The number of items retrieved in the query.
|
|
51
|
+
*/
|
|
52
|
+
logSchemaItem(startTime: number, schemaName: string, schemaItemType: string, itemCount: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Clears all log entries from the Map.
|
|
55
|
+
*/
|
|
56
|
+
clearLogs(): void;
|
|
57
|
+
private getSchemaMap;
|
|
58
|
+
private getSchemaLoadData;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=PerformanceLogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerformanceLogger.d.ts","sourceRoot":"","sources":["../../../src/IncrementalLoading/PerformanceLogger.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CAChD;AAED;;;;GAIG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,YAAY,CAAuD;IAC3E,OAAO,CAAC,MAAM,CAAS;IAGhB,cAAc,UAAS;IAE9B;;;OAGG;gBACS,KAAK,CAAC,EAAE,MAAM;IAI1B;;;;OAIG;IACH,IAAW,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAE9D;IAED;;;;OAIG;IACI,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAYtD;;;;;;OAMG;IACI,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAerG;;OAEG;IACI,SAAS;IAIhB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,iBAAiB;CAM1B"}
|