@itwin/core-backend
Version:
iTwin.js backend components
142 lines • 6.77 kB
TypeScript
/** @packageDocumentation
* @module Schema
*/
import { Id64String } from "@itwin/core-bentley";
import { EntityMetaData, IModelError } from "@itwin/core-common";
import { Entity } from "./Entity";
import { IModelDb } from "./IModelDb";
import { Schema } from "./Schema";
/** Maintains the mapping between the name of a BIS [ECClass]($ecschema-metadata) (in "schema:class" format) and the JavaScript [[Entity]] class that implements it.
* @public
*/
export declare class EntityJsClassMap {
private readonly _classMap;
/** @internal */
has(classFullName: string): boolean;
/** @internal */
get(classFullName: string): typeof Entity | undefined;
/** @internal */
set(classFullName: string, entityClass: typeof Entity): void;
/** @internal */
delete(classFullName: string): boolean;
/** @internal */
clear(): void;
/** @internal */
[Symbol.iterator](): IterableIterator<[string, typeof Entity]>;
/**
* Registers a single `entityClass` defined in the specified `schema`.
* This method registers the class globally. To register a class for a specific iModel, use [[IModelDb.jsClassMap]].
*
* @param entityClass - The JavaScript class that implements the BIS [ECClass](@itwin/core-common) to be registered.
* @param schema - The schema that contains the `entityClass`.
*
* @throws Error if the class is already registered.
*
* @public
*/
register(entityClass: typeof Entity, schema: typeof Schema): void;
}
/** Maintains the mapping between the name of a BIS [ECClass]($ecschema-metadata) (in "schema:class" format) and the JavaScript [[Entity]] class that implements it.
* Applications or modules that supply their own Entity subclasses should use [[registerModule]] or [[register]] at startup
* to establish their mappings.
*
* When creating custom Entity subclasses for registration, you should:
* - Override the `className` property to match your ECClass name:
* ```typescript
* public static override get className() { return "TestElement"; }
* ```
* - Do NOT override `schemaName` or `schema` - these will be wired up automatically during registration
*
* @public
*/
export declare class ClassRegistry {
private static readonly _globalClassMap;
/** @internal */
static isNotFoundError(err: any): boolean;
/** @internal */
static makeMetaDataNotFoundError(className: string): IModelError;
/** Register a single `entityClass` defined in the specified `schema`.
* @see [[registerModule]] to register multiple classes.
* @public
*/
static register(entityClass: typeof Entity, schema: typeof Schema): void;
/** Generate a proxy Schema for a domain that has not been registered. */
private static generateProxySchema;
/** First, finds the root BisCore entity class for an entity, by traversing base classes and mixin targets (AppliesTo).
* Then, gets its metadata and returns that.
* @param iModel - iModel containing the metadata for this type
* @param ecTypeQualifier - a full name of an ECEntityClass to find the root of
* @returns the qualified full name of an ECEntityClass
* @internal public for testing only
*/
static getRootEntity(iModel: IModelDb, ecTypeQualifier: string): string;
/** Generate a JavaScript class from Entity metadata.
* @param entityMetaData The Entity metadata that defines the class
*/
private static generateClassForEntity;
/** Register all of the classes found in the given module that derive from [[Entity]].
* [[register]] will be invoked for each subclass of `Entity` exported by `moduleObj`.
* @param moduleObj The module to search for subclasses of Entity
* @param schema The schema that contains all of the [ECClass]($ecschema-metadata)es exported by `moduleObj`.
*/
static registerModule(moduleObj: any, schema: typeof Schema): void;
/**
* This function fetches the specified Entity from the imodel, generates a JavaScript class for it, and registers the generated
* class. This function also ensures that all of the base classes of the Entity exist and are registered.
*/
private static generateClass;
/** Find a registered class by classFullName.
* @param classFullName class to find
* @param iModel The IModel that contains the class definitions
* @returns The Entity class or undefined
*/
static findRegisteredClass(classFullName: string): typeof Entity | undefined;
/** Get the Entity class for the specified Entity className.
* @param classFullName The full BIS class name of the Entity
* @param iModel The IModel that contains the class definitions
* @returns The Entity class
*/
static getClass(classFullName: string, iModel: IModelDb): typeof Entity;
/** Unregister a class, by name, if one is already registered.
* This function is not normally needed, but is useful for cases where a generated *proxy* class needs to be replaced by the *real* class.
* @param classFullName Name of the class to unregister
* @return true if the class was unregistered
* @internal
*/
static unregisterClass(classFullName: string): boolean;
/** Unregister all classes from a schema.
* This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.
* @param schema Name of the schema to unregister
* @internal
*/
static unregisterClassesFrom(schema: typeof Schema): void;
}
/**
* A cache that records the mapping between class names and class metadata.
* @see [[IModelDb.classMetaDataRegistry]] to access the registry for a specific iModel.
* @internal
* @deprecated in 5.0 - will not be removed until after 2026-06-13. Please use `schemaContext` from the `iModel` instead.
*
* @example
* @
* Current Usage:
* ```ts
* const metaData: EntityMetaData | undefined = iModel.classMetaDataRegistry.find("SchemaName:ClassName");
* ```
*
* Replacement:
* ```ts
* const entityMetaData: EntityClass | undefined = iModel.schemaContext.getSchemaItemSync("SchemaName.ClassName", EntityClass);
* const relationshipMetaData: RelationshipClass | undefined = iModel.schemaContext.getSchemaItemSync("SchemaName", "ClassName", RelationshipClass);
* ```
*/
export declare class MetaDataRegistry {
private _registry;
private _classIdToName;
/** Get the specified Entity metadata */
find(classFullName: string): EntityMetaData | undefined;
findByClassId(classId: Id64String): EntityMetaData | undefined;
/** Add metadata to the cache */
add(classFullName: string, metaData: EntityMetaData): void;
}
//# sourceMappingURL=ClassRegistry.d.ts.map