@itwin/core-backend
Version:
iTwin.js backend components
104 lines • 4.22 kB
TypeScript
/** @packageDocumentation
* @module Schema
*/
import { SchemaKey } from "@itwin/ecschema-metadata";
/** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).
*
* When subclassing from Schema, it is good practice to follow this pattern:
*
* ```typescript
* class MyCustomSchema extends Schema {
* public static override get schemaName(): string { return "MyCustomSchema"; }
* public static get classes(): typeof Entity[] {
* return [MyOwnECClass, AnotherECClass];
* }
* public static registerSchema() {
* if (this !== Schemas.getRegisteredSchema(this.schemaName)) {
* Schemas.unregisterSchema(this.schemaName);
* Schemas.registerSchema(this);
* for (const ecClass of this.classes) {
* ClassRegistry.register(ecClass, this);
* }
* }
* }
*
* public static unregisterSchema() {
* Schemas.unregisterSchema(this.schemaName);
* }
* }
* ```
*
* @public
*/
export declare class Schema {
/** The name of the BIS schema handled by this Schema.
* @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.
* Failure to do so will ordinarily result in an error when the schema is registered, since there may only
* be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)
*/
static get schemaName(): string;
/** Unique identifier for this schema, typed variant of [[schemaName]].
* @internal
*/
static get schemaKey(): SchemaKey;
/** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.
* Classes generated for this Schema will disallow protected operations.
* @internal
*/
static get missingRequiredBehavior(): boolean;
/** Get a semver-compatible string from a padded version string.
* works on unpadded version strings as well
* if there is no write version, it will be added
* @example Schema.toSemverString("1.02.03") === "1.2.3"
* @example Schema.toSemverString("1.01") === "1.0.1" // write version was added
* @beta
*/
static toSemverString(paddedVersion: string): string;
/** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an
* error if it is ever called.
* @internal
*/
protected constructor();
}
/**
* Holds a map of registered schemas.
* @public
*/
export declare class SchemaMap {
private readonly _schemas;
/** @internal */
get(schemaName: string): typeof Schema | undefined;
/** @internal */
set(schemaName: string, schema: typeof Schema): void;
/** @internal */
delete(schemaName: string): boolean;
/** Register a schema prior to using it.
* @throws [[IModelError]] if a schema of the same name is already registered.
* @public
*/
registerSchema(schema: typeof Schema): void;
}
/** Manages registered schemas
* @public
*/
export declare class Schemas {
private static readonly _globalSchemas;
private constructor();
/** Register a schema prior to using it.
* This method registers the schema globally, to register a schema within the scope of a single iModel, use `IModelDb.schemaMap`.
* @throws [[IModelError]] if a schema of the same name is already registered.
*/
static registerSchema(schema: typeof Schema): void;
/** Unregister a schema, by name, if one is already registered.
* 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 schemaName Name of the schema to unregister
* @return true if the schema was unregistered
*/
static unregisterSchema(schemaName: string): boolean;
/** Look up a previously registered schema
* @param schemaName The name of the schema
* @returns the previously registered schema or undefined if not registered.
*/
static getRegisteredSchema(schemaName: string): typeof Schema | undefined;
}
//# sourceMappingURL=Schema.d.ts.map