@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
483 lines • 22 kB
TypeScript
/** @packageDocumentation
* @module Metadata
*/
import { SchemaContext } from "../Context";
import { SchemaProps } from "../Deserialization/JsonProps";
import { ECClassModifier, PrimitiveType } from "../ECObjects";
import { AnyClass, SchemaInfo } from "../Interfaces";
import { SchemaItemKey, SchemaKey } from "../SchemaKey";
import { StructClass } from "./Class";
import { Constant } from "./Constant";
import { CustomAttribute, CustomAttributeContainerProps, CustomAttributeSet } from "./CustomAttribute";
import { CustomAttributeClass } from "./CustomAttributeClass";
import { EntityClass } from "./EntityClass";
import { Enumeration } from "./Enumeration";
import { Format } from "./Format";
import { InvertedUnit } from "./InvertedUnit";
import { KindOfQuantity } from "./KindOfQuantity";
import { Mixin } from "./Mixin";
import { Phenomenon } from "./Phenomenon";
import { PropertyCategory } from "./PropertyCategory";
import { RelationshipClass } from "./RelationshipClass";
import { SchemaItem } from "./SchemaItem";
import { Unit } from "./Unit";
import { UnitSystem } from "./UnitSystem";
import { SchemaLoadingController } from "../utils/SchemaLoadingController";
/**
* @public @preview
*/
export declare class Schema implements CustomAttributeContainerProps {
private static _currentECSpecVersion;
private _context;
private _schemaKey?;
private _alias?;
private _label?;
private _description?;
readonly references: Schema[];
private readonly _items;
private _customAttributes?;
private _originalECSpecMajorVersion?;
private _originalECSpecMinorVersion?;
private _loadingController?;
/**
* Constructs an empty Schema with the given name and version in the provided context.
* @param context The SchemaContext that will control the lifetime of the schema
* @param name The schema's name
* @param readVersion The integer read (major) version of the schema
* @param writeVersion The integer write version of the schema
* @param minorVersion The integer minor version of the schema
*/
constructor(context: SchemaContext, name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number);
/**
* Constructs an empty Schema with the given key in the provided context.
* @param context The SchemaContext that will control the lifetime of the schema
* @param key A SchemaKey that uniquely identifies the schema
*/
constructor(context: SchemaContext, key: SchemaKey, alias: string);
/**
* Constructs an empty Schema (without a SchemaKey) in the provided context.
* This should only be used when the schema name and version will be deserialized (via `fromJson()`) immediately after this Schema is instantiated.
* @param context The SchemaContext that will control the lifetime of the schema
* @internal
*/
constructor(context: SchemaContext);
get schemaKey(): SchemaKey;
get name(): string;
get readVersion(): number;
get writeVersion(): number;
get minorVersion(): number;
get originalECSpecMajorVersion(): number | undefined;
get originalECSpecMinorVersion(): number | undefined;
static get currentECSpecMajorVersion(): number;
static get currentECSpecMinorVersion(): number;
private get _isECSpecVersionUnsupported();
get alias(): string;
get label(): string | undefined;
get description(): string | undefined;
get customAttributes(): CustomAttributeSet | undefined;
/** Returns the schema name. */
get fullName(): string;
/** Returns the schema. */
get schema(): Schema;
/** Returns the schema context this schema is within. */
get context(): SchemaContext;
/** Returns whether this schema is dynamic schema */
get isDynamic(): boolean;
/**
* Returns the SchemaLoadingController for this Schema. This would only be set if the schema is
* loaded incrementally.
* @internal
*/
get loadingController(): SchemaLoadingController | undefined;
/**
* Returns a SchemaItemKey given the item name and the schema it belongs to
* @param fullName fully qualified name {Schema name}.{Item Name}
*/
getSchemaItemKey(fullName: string): SchemaItemKey;
/** @internal */
protected addItem<T extends SchemaItem>(item: T): void;
/**
* @internal
*/
protected createClass<T extends AnyClass>(type: (new (_schema: Schema, _name: string, _modifier?: ECClassModifier) => T), name: string, modifier?: ECClassModifier): T;
/**
* Deletes a class from within this schema.
* @param name the local (unqualified) class name, lookup is case-insensitive
* @internal
*/
protected deleteClass(name: string): Promise<void>;
/**
* Deletes a class from within this schema.
* @param name the local (unqualified) class name, lookup is case-insensitive
* @internal
*/
protected deleteClassSync(name: string): void;
/**
* Deletes a SchemaItem from within this schema.
* @param name the local (unqualified) class name, lookup is case-insensitive
* @internal
*/
protected deleteSchemaItem(name: string): Promise<void>;
/**
* Deletes a SchemaItem from within this schema.
* @param name the local (unqualified) class name, lookup is case-insensitive
* @internal
*/
protected deleteSchemaItemSync(name: string): void;
/** @internal */
protected createItem<T extends SchemaItem>(type: (new (_schema: Schema, _name: string) => T), name: string): T;
/** @internal */
protected addCustomAttribute(customAttribute: CustomAttribute): void;
/**
* Creates a EntityClass with the provided name in this schema.
* @param name
* @param modifier
* @internal
*/
protected createEntityClass(name: string, modifier?: ECClassModifier): Promise<EntityClass>;
/** @internal */
protected createEntityClassSync(name: string, modifier?: ECClassModifier): EntityClass;
/**
* Creates a Mixin with the provided name in this schema.
* @param name
* @internal
*/
protected createMixinClass(name: string): Promise<Mixin>;
/** @internal */
protected createMixinClassSync(name: string): Mixin;
/**
* Creates a StructClass with the provided name in this schema.
* @param name
* @param modifier
* @internal
*/
protected createStructClass(name: string, modifier?: ECClassModifier): Promise<StructClass>;
/** @internal */
protected createStructClassSync(name: string, modifier?: ECClassModifier): StructClass;
/**
* Creates a CustomAttributeClass with the provided name in this schema.
* @param name
* @param modifier
* @internal
*/
protected createCustomAttributeClass(name: string, modifier?: ECClassModifier): Promise<CustomAttributeClass>;
/** @internal */
protected createCustomAttributeClassSync(name: string, modifier?: ECClassModifier): CustomAttributeClass;
/**
* Creates a RelationshipClass with the provided name in this schema.
* @param name
* @param modifier
* @internal
*/
protected createRelationshipClass(name: string, modifier?: ECClassModifier): Promise<RelationshipClass>;
/** @internal */
protected createRelationshipClassSync(name: string, modifier?: ECClassModifier): RelationshipClass;
/**
* Creates an Enumeration with the provided name in this schema.
* @param name
* @param primitiveType
*
* @internal
*/
protected createEnumeration(name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String): Promise<Enumeration>;
/** @internal */
protected createEnumerationSync(name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String): Enumeration;
/**
* Creates an KindOfQuantity with the provided name in this schema.
* @param name
* @internal
*/
protected createKindOfQuantity(name: string): Promise<KindOfQuantity>;
/** @internal */
protected createKindOfQuantitySync(name: string): KindOfQuantity;
/**
* Creates a Constant with the provided name in this schema.
* @param name
* @internal
*/
protected createConstant(name: string): Promise<Constant>;
/** @internal */
protected createConstantSync(name: string): Constant;
/**
* Creates a Inverted Unit with the provided name in this schema.
* @param name
* @internal
*/
protected createInvertedUnit(name: string): Promise<InvertedUnit>;
/** @internal */
protected createInvertedUnitSync(name: string): InvertedUnit;
/**
* Creates an Format with the provided name in this schema.
* @param name
* @internal
*/
protected createFormat(name: string): Promise<Format>;
/** @internal */
protected createFormatSync(name: string): Format;
/**
* Creates a UnitSystem with the provided name in this schema.
* @param name
* @internal
*/
protected createUnitSystem(name: string): Promise<UnitSystem>;
/** @internal */
protected createUnitSystemSync(name: string): UnitSystem;
/**
* Creates a Phenomenon with the provided name in this schema.
* @param name
* @internal
*/
protected createPhenomenon(name: string): Promise<Phenomenon>;
/** @internal */
protected createPhenomenonSync(name: string): Phenomenon;
/**
* Creates a Unit with the provided name in this schema.
* @param name
* @internal
*/
protected createUnit(name: string): Promise<Unit>;
/** @internal */
protected createUnitSync(name: string): Unit;
/**
* Creates an PropertyCategory with the provided name in this schema.
* @param name
* @internal
*/
protected createPropertyCategory(name: string): Promise<PropertyCategory>;
/** @internal */
protected createPropertyCategorySync(name: string): PropertyCategory;
/**
*
* @param refSchema
* @internal
*/
protected addReference(refSchema: Schema): Promise<void>;
/** @internal */
protected addReferenceSync(refSchema: Schema): void;
/** @internal */
protected setContext(context: SchemaContext): void;
/**
* Sets the version of the SchemaKey identifying the schema.
* @param readVersion The read version of the schema. If undefined, the value from the existing SchemaKey will be used.
* @param writeVersion The write version of the schema. If undefined, the value from the existing SchemaKey will be used.
* @param minorVersion The minor version of the schema. If undefined, the value from the existing SchemaKey will be used.
* @internal
*/
setVersion(readVersion?: number, writeVersion?: number, minorVersion?: number): void;
/**
* Shortcut for calling getItem with EntityClass.
* @param name The local (unqualified) name of the item to return.
* @returns The requested EntityClass or undefined if not found.
*/
getEntityClass(name: string): Promise<EntityClass | undefined>;
/**
* Shortcut for calling getItem with Mixin.
* @param name The local (unqualified) name of the item to return.
* @returns The requested Mixin or undefined if not found.
*/
getMixin(name: string): Promise<Mixin | undefined>;
/**
* Shortcut for calling getItem with StructClass.
* @param name The local (unqualified) name of the item to return.
* @returns The requested StructClass or undefined if not found.
*/
getStructClass(name: string): Promise<StructClass | undefined>;
/**
* Shortcut for calling getItem with CustomAttributeClass.
* @param name The local (unqualified) name of the item to return.
* @returns The requested CustomAttributeClass or undefined if not found.
*/
getCustomAttributeClass(name: string): Promise<CustomAttributeClass | undefined>;
/**
* Shortcut for calling getItem with RelationshipClass.
* @param name The local (unqualified) name of the item to return.
* @returns The requested RelationshipClass or undefined if not found.
*/
getRelationshipClass(name: string): Promise<RelationshipClass | undefined>;
/**
* Shortcut for calling getItem with Enumeration.
* @param name The local (unqualified) name of the item to return.
* @returns The requested Enumeration or undefined if not found.
*/
getEnumeration(name: string): Promise<Enumeration | undefined>;
/**
* Shortcut for calling getItem with KindOfQuantity.
* @param name The local (unqualified) name of the item to return.
* @returns The requested KindOfQuantity or undefined if not found.
*/
getKindOfQuantity(name: string): Promise<KindOfQuantity | undefined>;
/**
* Shortcut for calling getItem with PropertyCategory.
* @param name The local (unqualified) name of the item to return.
* @returns The requested PropertyCategory or undefined if not found.
*/
getPropertyCategory(name: string): Promise<PropertyCategory | undefined>;
/**
* Shortcut for calling getItem with Unit.
* @param name The local (unqualified) name of the item to return.
* @returns The requested Unit or undefined if not found.
*/
getUnit(name: string): Promise<Unit | undefined>;
/**
* Shortcut for calling getItem with InvertedUnit.
* @param name The local (unqualified) name of the item to return.
* @returns The requested InvertedUnit or undefined if not found.
*/
getInvertedUnit(name: string): Promise<InvertedUnit | undefined>;
/**
* Shortcut for calling getItem with Constant.
* @param name The local (unqualified) name of the item to return.
* @returns The requested Constant or undefined if not found.
*/
getConstant(name: string): Promise<Constant | undefined>;
/**
* Shortcut for calling getItem with Phenomenon.
* @param name The local (unqualified) name of the item to return.
* @returns The requested Phenomenon or undefined if not found.
*/
getPhenomenon(name: string): Promise<Phenomenon | undefined>;
/**
* Shortcut for calling getItem with UnitSystem.
* @param name The local (unqualified) name of the item to return.
* @returns The requested UnitSystem or undefined if not found.
*/
getUnitSystem(name: string): Promise<UnitSystem | undefined>;
/**
* Shortcut for calling getItem with Format.
* @param name The local (unqualified) name of the item to return.
* @returns The requested Format or undefined if not found.
*/
getFormat(name: string): Promise<Format | undefined>;
/**
* Gets an item from within this schema. To get by full name use lookupItem instead.
* @param key the local (unqualified) name, lookup is case-insensitive
*/
getItem(name: string): Promise<SchemaItem | undefined>;
getItem<T extends typeof SchemaItem>(name: string, itemConstructor: T): Promise<InstanceType<T> | undefined>;
/**
* Gets an item from within this schema. To get by full name use lookupItem instead.
* If an item of the name exists but does not match the requested type, undefined is returned
* @param key the local (unqualified) name, lookup is case-insensitive
* @param itemConstructor The constructor of the item to return.
*/
getItemSync(name: string): SchemaItem | undefined;
getItemSync<T extends typeof SchemaItem>(name: string, itemConstructor: T): InstanceType<T> | undefined;
/**
* Attempts to find a schema item within this schema or a (directly) referenced schema
* @param key The full name or a SchemaItemKey identifying the desired item.
*/
lookupItem(key: Readonly<SchemaItemKey> | string): Promise<SchemaItem | undefined>;
lookupItem<T extends typeof SchemaItem>(key: Readonly<SchemaItemKey> | string, itemConstructor: T): Promise<InstanceType<T> | undefined>;
/**
* Attempts to find a schema item within this schema or a (directly) referenced schema
* @param key The full name or a SchemaItemKey identifying the desired item.
*/
lookupItemSync(key: Readonly<SchemaItemKey> | string): SchemaItem | undefined;
lookupItemSync<T extends typeof SchemaItem>(key: Readonly<SchemaItemKey> | string, itemConstructor: T): InstanceType<T> | undefined;
/**
* Returns all of the loaded items in this schema.
*/
getItems(): Iterable<SchemaItem>;
getItems<T extends typeof SchemaItem>(itemConstructor: T): Iterable<InstanceType<T>>;
/**
* Gets a referenced schema by name
* @param refSchemaName schema name to find
*/
getReference(refSchemaName: string): Promise<Schema | undefined>;
/**
* Gets a referenced schema by alias
* @param alias alias to find
*/
getReferenceNameByAlias(alias: string): string | undefined;
/**
* Gets a referenced schema by name
* @param refSchemaName schema name to find
*/
getReferenceSync(refSchemaName: string): Schema | undefined;
/**
* Save this Schema's properties to an object for serializing to JSON.
*/
toJSON(): SchemaProps;
/**
* Converts the schema to a DOM XML Document.
* @param schemaXml An empty DOM document to which the schema will be written
*/
toXml(schemaXml: Document): Promise<Document>;
/**
* Loads the schema header (name, version alias, label and description) from the input SchemaProps
*/
fromJSONSync(schemaProps: SchemaProps): void;
/**
* Loads the schema header (name, version alias, label and description) from the input SchemaProps
*/
fromJSON(schemaProps: SchemaProps): Promise<void>;
/**
* Completely loads the SchemaInfo from the input json and starts loading the entire schema. The complete schema can be retrieved from the
* schema context using the getCachedSchema method
*/
static startLoadingFromJson(jsonObj: object | string, context: SchemaContext): Promise<SchemaInfo>;
static fromJson(jsonObj: object | string, context: SchemaContext): Promise<Schema>;
/**
* Completely loads the Schema from the input json. The schema is cached in the schema context.
*/
static fromJsonSync(jsonObj: object | string, context: SchemaContext): Schema;
/**
* @internal
*/
static isSchema(object: any): object is Schema;
/** @internal */
protected setDisplayLabel(displayLabel: string): void;
/** @internal */
protected setDescription(description: string): void;
/** @internal */
protected setAlias(alias: string): void;
/** @internal */
setLoadingController(controller: SchemaLoadingController): void;
}
/**
* Hackish approach that works like a "friend class" so we can access protected members without making them public.
* We cannot put this into Helper.ts and make it non-export, because we are importing Helper.ts from this file, and the circular import
* would prevent this class from extending Schema.
* @internal
*/
export declare abstract class MutableSchema extends Schema {
abstract addCustomAttribute(customAttribute: CustomAttribute): void;
abstract createEntityClass(name: string, modifier?: ECClassModifier): Promise<EntityClass>;
abstract createEntityClassSync(name: string, modifier?: ECClassModifier): EntityClass;
abstract createMixinClass(name: string): Promise<Mixin>;
abstract createMixinClassSync(name: string): Mixin;
abstract createStructClass(name: string, modifier?: ECClassModifier): Promise<StructClass>;
abstract createStructClassSync(name: string, modifier?: ECClassModifier): StructClass;
abstract createCustomAttributeClass(name: string, modifier?: ECClassModifier): Promise<CustomAttributeClass>;
abstract createCustomAttributeClassSync(name: string, modifier?: ECClassModifier): CustomAttributeClass;
abstract createRelationshipClass(name: string, modifier?: ECClassModifier): Promise<RelationshipClass>;
abstract createRelationshipClassSync(name: string, modifier?: ECClassModifier): RelationshipClass;
abstract createEnumeration(name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String): Promise<Enumeration>;
abstract createEnumerationSync(name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String): Enumeration;
abstract createKindOfQuantity(name: string): Promise<KindOfQuantity>;
abstract createKindOfQuantitySync(name: string): KindOfQuantity;
abstract createUnit(name: string): Promise<Unit>;
abstract createUnitSync(name: string): Unit;
abstract createConstant(name: string): Promise<Constant>;
abstract createConstantSync(name: string): Constant;
abstract createInvertedUnit(name: string): Promise<InvertedUnit>;
abstract createInvertedUnitSync(name: string): InvertedUnit;
abstract createPhenomenon(name: string): Promise<Phenomenon>;
abstract createPhenomenonSync(name: string): Phenomenon;
abstract createFormat(name: string): Promise<Format>;
abstract createFormatSync(name: string): Format;
abstract createUnitSystem(name: string): Promise<UnitSystem>;
abstract createUnitSystemSync(name: string): UnitSystem;
abstract createPropertyCategory(name: string): Promise<PropertyCategory>;
abstract createPropertyCategorySync(name: string): PropertyCategory;
abstract addItem<T extends SchemaItem>(item: T): void;
abstract addReference(refSchema: Schema): Promise<void>;
abstract addReferenceSync(refSchema: Schema): void;
abstract setContext(schemaContext: SchemaContext): void;
abstract deleteClass(name: string): Promise<void>;
abstract deleteClassSync(name: string): void;
abstract deleteSchemaItem(name: string): Promise<void>;
abstract deleteSchemaItemSync(name: string): void;
abstract setAlias(alias: string): void;
}
//# sourceMappingURL=Schema.d.ts.map