@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
366 lines • 16.2 kB
TypeScript
/** @packageDocumentation
* @module Metadata
*/
import { ClassProps } from "../Deserialization/JsonProps";
import { ECClassModifier, PrimitiveType, SchemaItemType, SupportedSchemaItemType } from "../ECObjects";
import { AnyClass, LazyLoadedECClass } from "../Interfaces";
import { CustomAttribute, CustomAttributeContainerProps, CustomAttributeSet } from "./CustomAttribute";
import { Enumeration } from "./Enumeration";
import { EnumerationArrayProperty, EnumerationProperty, PrimitiveArrayProperty, PrimitiveProperty, Property, StructArrayProperty, StructProperty } from "./Property";
import { Schema } from "./Schema";
import { SchemaItem } from "./SchemaItem";
/**
* A common abstract class for all of the ECClass types.
* @public @preview
*/
export declare abstract class ECClass extends SchemaItem implements CustomAttributeContainerProps {
/** @internal */
static get schemaItemType(): SupportedSchemaItemType;
private _modifier;
private _baseClass?;
private _properties?;
private _customAttributes?;
private _mergedPropertyCache?;
get modifier(): ECClassModifier;
get customAttributes(): CustomAttributeSet | undefined;
/** @internal */
constructor(schema: Schema, name: string, modifier?: ECClassModifier);
/**
* Gets the base class if it exists, otherwise returns undefined.
*/
get baseClass(): LazyLoadedECClass | undefined;
getBaseClassSync(): ECClass | undefined;
/**
* Sets the base class of the ECClass. Pass undefined to 'remove' the base class.
*
* @internal
*/
protected setBaseClass(baseClass: LazyLoadedECClass | undefined): Promise<void>;
/**
* Gets the derived classes belonging to this class.
* @returns An array of ECClasses or undefined if no derived classes exist.
*/
getDerivedClasses(): Promise<ECClass[] | undefined>;
/**
* Convenience method for adding an already loaded ECProperty used by create*Property methods.
* @param prop The property to add.
* @return The property that was added.
*
* @internal
*/
protected addProperty<T extends Property>(prop: T): T;
/**
* Deletes a property from within this class.
* @param name The property name to delete, lookup is case-insensitive
* @internal
*/
protected deleteProperty(name: string): Promise<void>;
/**
* Deletes a property from within this class.
* @param name The property name to delete, lookup is case-insensitive
* @internal
*/
protected deletePropertySync(name: string): void;
/**
* Searches, case-insensitive, for an ECProperty with given the name on this class and, by default, on
* all base classes. Set excludeInherited to 'true' to only search the local class.
* @param name The name of the property to retrieve.
* @param excludeInherited If true, excludes inherited properties from the results. Defaults to false.
*/
getProperty(name: string, excludeInherited?: boolean): Promise<Property | undefined>;
/**
* Searches, case-insensitive, for a local ECProperty with the name provided.
* @param name The name of the property to retrieve.
* @param excludeInherited If true, excludes inherited properties from the results. Defaults to false.
*/
getPropertySync(name: string, excludeInherited?: boolean): Property | undefined;
/**
* Searches the base class, if one exists, for the property with the name provided.
* @param name The name of the inherited property to find.
*/
getInheritedProperty(name: string): Promise<Property | undefined>;
/**
* Searches the base class, if one exists, for the property with the name provided.
* @param name The name of the inherited property to find.
*/
getInheritedPropertySync(name: string): Property | undefined;
/**
* Creates a PrimitiveECProperty.
* @param name The name of property to create.
* @param primitiveType The primitive type of property to create. If not provided the default is PrimitiveType.Integer
* @throws ECSchemaStatus DuplicateProperty: thrown if a property with the same name already exists in the class.
*
* @internal
*/
protected createPrimitiveProperty(name: string, primitiveType: PrimitiveType): Promise<PrimitiveProperty>;
protected createPrimitiveProperty(name: string, primitiveType: Enumeration): Promise<EnumerationProperty>;
/**
* Creates a PrimitiveECProperty.
* @param name The name of property to create.
* @param primitiveType The primitive type of property to create. If not provided the default is PrimitiveType.Integer
* @throws ECSchemaStatus DuplicateProperty: thrown if a property with the same name already exists in the class.
*
* @internal
*/
protected createPrimitivePropertySync(name: string, primitiveType: PrimitiveType): PrimitiveProperty;
protected createPrimitivePropertySync(name: string, primitiveType: Enumeration): EnumerationProperty;
/**
* Creates a PrimitiveArrayECProperty.
* @param name The name of property to create.
* @param primitiveType The primitive type of property to create. If not provided the default is PrimitiveType.Integer
*
* @internal
*/
protected createPrimitiveArrayProperty(name: string, primitiveType: PrimitiveType): Promise<PrimitiveArrayProperty>;
protected createPrimitiveArrayProperty(name: string, primitiveType: Enumeration): Promise<EnumerationArrayProperty>;
/**
* Creates a PrimitiveArrayECProperty.
* @param name The name of property to create.
* @param primitiveType The primitive type of property to create. If not provided the default is PrimitiveType.Integer
*
* @internal
*/
protected createPrimitiveArrayPropertySync(name: string, primitiveType: PrimitiveType): PrimitiveArrayProperty;
protected createPrimitiveArrayPropertySync(name: string, primitiveType: Enumeration): EnumerationArrayProperty;
/**
*
* @param name The name of property to create.
* @param structType The struct type of property to create.
*
* @internal
*/
protected createStructProperty(name: string, structType: string | StructClass): Promise<StructProperty>;
/**
*
* @param name The name of property to create.
* @param structType The struct type of property to create.
*
* @internal
*/
protected createStructPropertySync(name: string, structType: string | StructClass): StructProperty;
/**
*
* @param name
* @param type
*
* @internal
*/
protected createStructArrayProperty(name: string, structType: string | StructClass): Promise<StructArrayProperty>;
/**
*
* @param name
* @param type
*
* @internal
*/
protected createStructArrayPropertySync(name: string, structType: string | StructClass): StructArrayProperty;
/**
*
* @param structType
* @param schema
* @returns
*
* @internal
*/
protected loadStructType(structType: string | StructClass | undefined, schema: Schema): Promise<StructClass>;
/**
*
* @param structType
* @param schema
* @returns
*
* @internal
*/
protected loadStructTypeSync(structType: string | StructClass | undefined, schema: Schema): StructClass;
/**
*
* @param primitiveType
* @param schema
* @returns
*
* @internal
*/
protected loadPrimitiveType(primitiveType: string | PrimitiveType | Enumeration | undefined, schema: Schema): Promise<PrimitiveType | Enumeration>;
/**
*
* @param primitiveType
* @param schema
* @returns
*
* @internal
*/
protected loadPrimitiveTypeSync(primitiveType: string | PrimitiveType | Enumeration | undefined, schema: Schema): PrimitiveType | Enumeration;
/**
* Save this Classes properties to an object for serializing to JSON.
* @param standalone Serialization includes only this object (as opposed to the full schema).
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
*/
toJSON(standalone?: boolean, includeSchemaVersion?: boolean): ClassProps;
/** @internal */
toXml(schemaXml: Document): Promise<Element>;
fromJSONSync(classProps: ClassProps): void;
fromJSON(classProps: ClassProps): Promise<void>;
/**
*
* @param customAttribute
*
* @internal
*/
protected addCustomAttribute(customAttribute: CustomAttribute): void;
/**
* Iterates (recursively) over all base classes and mixins, in "property override" order.
* This is essentially a depth-first traversal through the inheritance tree.
*/
getAllBaseClasses(): AsyncIterable<ECClass>;
getAllBaseClassesSync(): Iterable<AnyClass>;
/**
*
* @param cache
* @returns
*
* @internal
*/
protected buildPropertyCache(): Promise<Map<string, Property>>;
/**
*
* @param cache
* @returns
*
* @internal
*/
protected buildPropertyCacheSync(): Map<string, Property>;
/**
* Clears all caches on this object. This is called implicitly for this class,
* but needs to be called if derived classes have changed.
* @internal
*/
cleanCache(): void;
/**
* Returns the properties on this class and its base classes.
* Since this is an expensive operation, results will be cached after first call.
* @param excludeInherited If true, only properties defined directly on this class will be returned. Defaults to false.
* @returns An array of properties, empty array if none exist.
*/
getPropertiesSync(excludeInherited?: boolean): Iterable<Property>;
/**
* Quick way to check whether this class has any local properties without having to use the iterable
*/
get hasLocalProperties(): boolean;
/**
* Returns the properties on this class and its base classes.
* Since this is an expensive operation, results will be cached after first call.
* @param excludeInherited If true, only properties defined directly on this class will be returned.
* @returns An array of properties, empty array if none exist.
*/
getProperties(excludeInherited?: boolean): Promise<Iterable<Property>>;
/**
* Retrieve all custom attributes in the current class and its bases
* This is the async version of getCustomAttributesSync()
*/
getCustomAttributes(): Promise<CustomAttributeSet>;
/**
* Retrieve all custom attributes in the current class and its bases.
*/
getCustomAttributesSync(): CustomAttributeSet;
/**
* Asynchronously traverses through the inheritance tree, using depth-first traversal, calling the given callback
* function for each base class encountered.
* @param callback The function to call for each base class in the hierarchy.
* @param arg An argument that will be passed as the second parameter to the callback function.
*/
traverseBaseClasses(callback: (ecClass: ECClass, arg?: any) => boolean, arg?: any): Promise<boolean>;
/**
* Synchronously traverses through the inheritance tree, using depth-first traversal, calling the given callback
* function for each base class encountered.
* @param callback The function to call for each base class in the hierarchy.
* @param arg An argument that will be passed as the second parameter to the callback function.
*/
traverseBaseClassesSync(callback: (ecClass: ECClass, arg?: any) => boolean, arg?: any): boolean;
/**
* Indicates if the targetClass is of this type.
* @param targetClass The ECClass or ECClass name to check.
* @param schemaName The schema name. Required if targetClass is the ECClass name.
*/
is(targetClass: string, schemaName: string): Promise<boolean>;
is(targetClass: ECClass): Promise<boolean>;
/**
* A synchronous version of the [[ECClass.is]], indicating if the targetClass is of this type.
* @param targetClass The class to check.
*/
isSync(targetClass: ECClass): boolean;
isSync(targetClass: string, schemaName: string): boolean;
/**
* @internal
*/
static isECClass(object: any): object is ECClass;
/**
* A setter method for the ECClass modifier, used specifically for schema editing.
* @param modifier
* @internal
*/
protected setModifier(modifier: ECClassModifier): void;
}
/**
* A Typescript class representation of an ECStructClass.
* @public @preview
*/
export declare class StructClass extends ECClass {
/**
* Get the type of item represented by this instance
*/
readonly schemaItemType: SchemaItemType;
/**
* Get the type of item represented by this class
* @internal
*/
static get schemaItemType(): SchemaItemType;
/**
* Type guard to check if the SchemaItem is of type StructClass.
* @param item The SchemaItem to check.
* @returns True if the item is a StructClass, false otherwise.
*/
static isStructClass(item?: SchemaItem): item is StructClass;
/**
* Type assertion to check if the SchemaItem is of type StructClass.
* @param item The SchemaItem to check.
* @returns The item cast to StructClass if it is a StructClass, undefined otherwise.
* @internal
*/
static assertIsStructClass(item?: SchemaItem): asserts item is StructClass;
}
/**
* @internal
* An abstract class used for schema editing.
*/
export declare abstract class MutableStructClass extends StructClass {
abstract setDisplayLabel(displayLabel: string): void;
}
/**
* Hackish approach that works like a "friend class" so we can access protected members without making them public.
* @internal
*/
export declare abstract class MutableClass extends ECClass {
abstract setBaseClass(baseClass: LazyLoadedECClass | undefined): Promise<void>;
abstract addCustomAttribute(customAttribute: CustomAttribute): void;
abstract setModifier(modifier: ECClassModifier): void;
abstract setName(name: string): void;
abstract createPrimitiveProperty(name: string, primitiveType: PrimitiveType): Promise<PrimitiveProperty>;
abstract createPrimitiveProperty(name: string, primitiveType: Enumeration): Promise<EnumerationProperty>;
abstract createPrimitiveProperty(name: string, primitiveType?: string | PrimitiveType | Enumeration): Promise<Property>;
abstract createPrimitivePropertySync(name: string, primitiveType: PrimitiveType): PrimitiveProperty;
abstract createPrimitivePropertySync(name: string, primitiveType: Enumeration): EnumerationProperty;
abstract createPrimitivePropertySync(name: string, primitiveType?: string | PrimitiveType | Enumeration): Property;
abstract createPrimitiveArrayProperty(name: string, primitiveType: PrimitiveType): Promise<PrimitiveArrayProperty>;
abstract createPrimitiveArrayProperty(name: string, primitiveType: Enumeration): Promise<EnumerationArrayProperty>;
abstract createPrimitiveArrayProperty(name: string, primitiveType?: string | PrimitiveType | Enumeration): Promise<Property>;
abstract createPrimitiveArrayPropertySync(name: string, primitiveType: PrimitiveType): PrimitiveArrayProperty;
abstract createPrimitiveArrayPropertySync(name: string, primitiveType: Enumeration): EnumerationArrayProperty;
abstract createPrimitiveArrayPropertySync(name: string, primitiveType?: string | PrimitiveType | Enumeration): Property;
abstract createStructProperty(name: string, structType: string | StructClass): Promise<StructProperty>;
abstract createStructPropertySync(name: string, structType: string | StructClass): StructProperty;
abstract createStructArrayProperty(name: string, structType: string | StructClass): Promise<StructArrayProperty>;
abstract createStructArrayPropertySync(name: string, structType: string | StructClass): StructArrayProperty;
abstract deleteProperty(name: string): Promise<void>;
abstract deletePropertySync(name: string): void;
}
//# sourceMappingURL=Class.d.ts.map