@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
126 lines • 6.89 kB
TypeScript
import { ISchemaLocater, SchemaContext } from "../Context";
import { SchemaProps } from "../Deserialization/JsonProps";
import { SchemaMatchType } from "../ECObjects";
import { SchemaInfo } from "../Interfaces";
import { Schema } from "../Metadata/Schema";
import { SchemaKey } from "../SchemaKey";
interface IncrementalSchemaInfo extends SchemaInfo {
readonly description?: string;
readonly label?: string;
}
type LoadSchemaInfoHandler = (context: SchemaContext) => Promise<Iterable<SchemaInfo>>;
/**
* Defines the SchemaLocater Options which determine how each schema is to be loaded.
* All options are optional.
* @beta
*/
export interface SchemaLocaterOptions {
/** Only load partial schemas. Full schema information will not be retrieved. Defaults to false. */
readonly loadPartialSchemaOnly?: boolean;
}
/**
* A [[ISchemaLocater]] implementation for locating and retrieving EC [[Schema]]
* objects incrementally instead of the full schema and it's references at once. This is useful for large schemas that
* take a long time to load, but clients need a rough skeleton of the schema as fast as possible.
*
* The IncrementalSchemaLocater is a locater around the [[IncrementalSchemaLocater]] to be used in a
* [[SchemaContext]].
* @internal
*/
export declare abstract class IncrementalSchemaLocater implements ISchemaLocater {
private readonly _options;
protected readonly _schemaInfoCache: SchemaInfoCache;
/**
* Initializes a new instance of the IncrementalSchemaLocater class.
* @param options The [[SchemaLocaterOptions]] that control the loading of the schema.
*/
constructor(options?: SchemaLocaterOptions);
/** Gets the options how the schema locater load the schemas. */
protected get options(): SchemaLocaterOptions;
/**
* Gets the [[SchemaInfo]] which matches the provided SchemaKey. The SchemaInfo may be returned
* before the schema is fully loaded. May return the entire Schema so long as it is completely loaded as it satisfies
* the SchemaInfo interface.
* @param schemaKey The [[SchemaKey]] to look up.
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
* @param context The [[SchemaContext]] for loading schema references.
*/
getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
/**
* Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.
* For schemas that may have references, construct and call through a SchemaContext instead.
* @param schemaKey The [[SchemaKey]] to look up.
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
* @param context The [[SchemaContext]] for loading schema references.
*/
getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
/**
* Attempts to get a [[Schema]] from the locater. Yields undefined if no matching schema is found.
* For schemas that may have references, construct and call through a SchemaContext instead.
* NOT IMPLEMENTED IN THIS LOCATER - ALWAYS RETURNS UNDEFINED.
* @param schemaKey The [[SchemaKey]] to look up.
* @param matchType The [[SchemaMatchType]] to use against candidate schemas.
* @param context The [[SchemaContext]] for loading schema references.
* @returns Incremental schema loading does not work synchronously, this will always return undefined.
*/
getSchemaSync(_schemaKey: Readonly<SchemaKey>, _matchType: SchemaMatchType, _context: SchemaContext): Schema | undefined;
/**
* Gets the schema partials for the given schema key. The first item in the array is the
* actual schema props of the schema to load, the following items are partial schema props
* of referenced schemas.
* @param schemaKey The schema key of the requested schema.
* @param context The schema context.
*/
protected abstract getSchemaPartials(schemaKey: SchemaKey, context: SchemaContext): Promise<ReadonlyArray<SchemaProps> | undefined>;
/**
* Gets the full schema json for the requested schema key.
* @param schemaKey The schema key of the requested schema.
* @param context The schema context.
*/
protected abstract getSchemaJson(schemaKey: SchemaKey, context: SchemaContext): Promise<SchemaProps | undefined>;
/**
* Loads the schema info objects for the given context.
* @param context The schema context to load the schema infos for.
* @returns A promise that resolves to an iterable of schema infos.
*/
protected abstract loadSchemaInfos(context: SchemaContext): Promise<Iterable<SchemaInfo>>;
/**
* Checks if the context contains the right schemas to support incremental schema loading.
* @param context The schema context to check.
* @returns true if incremental schema loading is supported, false otherwise.
*/
protected abstract supportPartialSchemaLoading(context: SchemaContext): Promise<boolean>;
/**
* Start loading the schema for the given schema info incrementally. The schema is returned
* as soon as the schema stub is loaded while the schema fully resolves in the background. It should
* only be called by the IncrementalSchemaLocater if a schema has not been loaded or started to
* load yet.
* @param schemaInfo The schema info of the schema to load.
* @param schemaContext The schema context to load the schema into.
*/
protected loadSchema(schemaInfo: SchemaInfo, schemaContext: SchemaContext): Promise<Schema>;
/**
* Creates a SchemaProps object by loading the Schema information from the given SchemaContext.
* @param schemaKey The SchemaKey of the Schema whose props are to be retrieved.
* @param schemaContext The SchemaContext holding the Schema.
* @returns The SchemaProps object.
*/
protected createSchemaProps(schemaKey: SchemaKey, schemaContext: SchemaContext): Promise<SchemaProps>;
private startLoadingPartialSchema;
private loadFullSchema;
private startLoadingFullSchema;
private sortSchemaPartials;
}
/**
* Helper class to manage schema infos for a schema context.
*/
declare class SchemaInfoCache {
private readonly _schemaInfoCache;
private readonly _schemaInfoLoader;
constructor(schemaInfoLoader: LoadSchemaInfoHandler);
getSchemasByContext(context: SchemaContext): Promise<IncrementalSchemaInfo[] | undefined>;
lookup(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<IncrementalSchemaInfo | undefined>;
remove(schemaKey: SchemaKey, context: SchemaContext): void;
}
export {};
//# sourceMappingURL=IncrementalSchemaLocater.d.ts.map