UNPKG

@itwin/ecschema-metadata

Version:

ECObjects core concepts in typescript

764 lines • 31.8 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Metadata */ import { SchemaReadHelper } from "../Deserialization/Helper"; import { JsonParser } from "../Deserialization/JsonParser"; import { XmlParser } from "../Deserialization/XmlParser"; import { XmlSerializationUtils } from "../Deserialization/XmlSerializationUtils"; import { isSupportedSchemaItemType } from "../ECObjects"; import { ECSchemaError, ECSchemaStatus } from "../Exception"; import { ECVersion, SchemaItemKey, SchemaKey } from "../SchemaKey"; import { ECName } from "../ECName"; import { ECClass, StructClass } from "./Class"; import { Constant } from "./Constant"; import { serializeCustomAttributes } 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 { ECSchemaNamespaceUris } from "../Constants"; /** * @public @preview */ export class Schema { static _currentECSpecVersion = "3.2"; _context; _schemaKey; _alias; _label; _description; references; _items; _customAttributes; _originalECSpecMajorVersion; _originalECSpecMinorVersion; _loadingController; /** @internal */ constructor(context, nameOrKey, alias, readVer, writeVer, minorVer) { this._schemaKey = (typeof (nameOrKey) === "string") ? new SchemaKey(nameOrKey, new ECVersion(readVer, writeVer, minorVer)) : nameOrKey; this._context = context; this.references = []; this._items = new Map(); if (alias !== undefined && ECName.validate(alias)) { this._alias = alias; } else if (nameOrKey !== undefined) { throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Schema ${this.name} does not have the required 'alias' attribute.`); } this._originalECSpecMajorVersion = Schema.currentECSpecMajorVersion; this._originalECSpecMinorVersion = Schema.currentECSpecMinorVersion; } get schemaKey() { if (undefined === this._schemaKey) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The schema has an invalid or missing SchemaKey.`); return this._schemaKey; } get name() { if (this._schemaKey === undefined) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The schema has an invalid or missing SchemaKey.`); return this.schemaKey.name; } get readVersion() { if (this._schemaKey === undefined) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The schema has an invalid or missing SchemaKey.`); return this.schemaKey.readVersion; } get writeVersion() { if (this._schemaKey === undefined) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The schema has an invalid or missing SchemaKey.`); return this.schemaKey.writeVersion; } get minorVersion() { if (this._schemaKey === undefined) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The schema has an invalid or missing SchemaKey.`); return this.schemaKey.minorVersion; } get originalECSpecMajorVersion() { return this._originalECSpecMajorVersion; } get originalECSpecMinorVersion() { return this._originalECSpecMinorVersion; } static get currentECSpecMajorVersion() { return parseInt(Schema._currentECSpecVersion.split(".")[0], 10); } static get currentECSpecMinorVersion() { return parseInt(Schema._currentECSpecVersion.split(".")[1], 10); } get _isECSpecVersionUnsupported() { return (this.originalECSpecMajorVersion !== 3 || this.originalECSpecMinorVersion === undefined || (this.originalECSpecMinorVersion < 2 || this.originalECSpecMinorVersion > Schema.currentECSpecMinorVersion)); } get alias() { if (this._alias === undefined || this._alias === null) { throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Schema ${this.name} does not have the required 'alias' attribute.`); } else { return this._alias; } } get label() { return this._label; } get description() { return this._description; } get customAttributes() { return this._customAttributes; } /** Returns the schema name. */ get fullName() { return this.schemaKey.name; } /** Returns the schema. */ get schema() { return this; } /** Returns the schema context this schema is within. */ get context() { return this._context; } /** Returns whether this schema is dynamic schema */ get isDynamic() { return this.customAttributes !== undefined && this.customAttributes.has("CoreCustomAttributes.DynamicSchema"); } /** * Returns the SchemaLoadingController for this Schema. This would only be set if the schema is * loaded incrementally. * @internal */ get loadingController() { return this._loadingController; } /** * Returns a SchemaItemKey given the item name and the schema it belongs to * @param fullName fully qualified name {Schema name}.{Item Name} */ getSchemaItemKey(fullName) { const [schemaName, itemName] = SchemaItem.parseFullName(fullName); let schemaKey = this.schemaKey; if (this.name !== schemaName) { const newSchemaRef = this.getReferenceSync(schemaName); if (undefined === newSchemaRef) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Unable to find the referenced SchemaItem ${itemName}.`); schemaKey = newSchemaRef.schemaKey; } return new SchemaItemKey(itemName, schemaKey); } /** @internal */ addItem(item) { if (undefined !== this.getItemSync(item.name)) throw new ECSchemaError(ECSchemaStatus.DuplicateItem, `The SchemaItem ${item.name} cannot be added to the schema ${this.name} because it already exists`); this._items.set(item.name.toUpperCase(), item); } /** * @internal */ createClass(type, name, modifier) { const item = new type(this, name, modifier); this.addItem(item); return item; } /** * Deletes a class from within this schema. * @param name the local (unqualified) class name, lookup is case-insensitive * @internal */ async deleteClass(name) { const schemaItem = await this.getItem(name); if (ECClass.isECClass(schemaItem)) { this._items.delete(name.toUpperCase()); } } /** * Deletes a class from within this schema. * @param name the local (unqualified) class name, lookup is case-insensitive * @internal */ deleteClassSync(name) { const schemaItem = this.getItemSync(name); if (ECClass.isECClass(schemaItem)) this._items.delete(name.toUpperCase()); } /** * Deletes a SchemaItem from within this schema. * @param name the local (unqualified) class name, lookup is case-insensitive * @internal */ async deleteSchemaItem(name) { const schemaItem = await this.getItem(name); if (SchemaItem.isSchemaItem(schemaItem)) { this._items.delete(name.toUpperCase()); } } /** * Deletes a SchemaItem from within this schema. * @param name the local (unqualified) class name, lookup is case-insensitive * @internal */ deleteSchemaItemSync(name) { const schemaItem = this.getItemSync(name); if (SchemaItem.isSchemaItem(schemaItem)) this._items.delete(name.toUpperCase()); } /** @internal */ createItem(type, name) { const item = new type(this, name); this.addItem(item); return item; } /** @internal */ addCustomAttribute(customAttribute) { if (!this._customAttributes) this._customAttributes = new Map(); this._customAttributes.set(customAttribute.className, customAttribute); } /** * Creates a EntityClass with the provided name in this schema. * @param name * @param modifier * @internal */ async createEntityClass(name, modifier) { return this.createClass(EntityClass, name, modifier); } /** @internal */ createEntityClassSync(name, modifier) { return this.createClass(EntityClass, name, modifier); } /** * Creates a Mixin with the provided name in this schema. * @param name * @internal */ async createMixinClass(name) { return this.createClass(Mixin, name); } /** @internal */ createMixinClassSync(name) { return this.createClass(Mixin, name); } /** * Creates a StructClass with the provided name in this schema. * @param name * @param modifier * @internal */ async createStructClass(name, modifier) { return this.createClass(StructClass, name, modifier); } /** @internal */ createStructClassSync(name, modifier) { return this.createClass(StructClass, name, modifier); } /** * Creates a CustomAttributeClass with the provided name in this schema. * @param name * @param modifier * @internal */ async createCustomAttributeClass(name, modifier) { return this.createClass(CustomAttributeClass, name, modifier); } /** @internal */ createCustomAttributeClassSync(name, modifier) { return this.createClass(CustomAttributeClass, name, modifier); } /** * Creates a RelationshipClass with the provided name in this schema. * @param name * @param modifier * @internal */ async createRelationshipClass(name, modifier) { return this.createRelationshipClassSync(name, modifier); } /** @internal */ createRelationshipClassSync(name, modifier) { return this.createClass(RelationshipClass, name, modifier); } /** * Creates an Enumeration with the provided name in this schema. * @param name * @param primitiveType * * @internal */ async createEnumeration(name, primitiveType) { return this.createEnumerationSync(name, primitiveType); } /** @internal */ createEnumerationSync(name, primitiveType) { const item = new Enumeration(this, name, primitiveType); this.addItem(item); return item; } /** * Creates an KindOfQuantity with the provided name in this schema. * @param name * @internal */ async createKindOfQuantity(name) { return this.createKindOfQuantitySync(name); } /** @internal */ createKindOfQuantitySync(name) { return this.createItem(KindOfQuantity, name); } /** * Creates a Constant with the provided name in this schema. * @param name * @internal */ async createConstant(name) { return this.createItem(Constant, name); } /** @internal */ createConstantSync(name) { return this.createItem(Constant, name); } /** * Creates a Inverted Unit with the provided name in this schema. * @param name * @internal */ async createInvertedUnit(name) { return this.createItem(InvertedUnit, name); } /** @internal */ createInvertedUnitSync(name) { return this.createItem(InvertedUnit, name); } /** * Creates an Format with the provided name in this schema. * @param name * @internal */ async createFormat(name) { return this.createItem(Format, name); } /** @internal */ createFormatSync(name) { return this.createItem(Format, name); } /** * Creates a UnitSystem with the provided name in this schema. * @param name * @internal */ async createUnitSystem(name) { return this.createItem(UnitSystem, name); } /** @internal */ createUnitSystemSync(name) { return this.createItem(UnitSystem, name); } /** * Creates a Phenomenon with the provided name in this schema. * @param name * @internal */ async createPhenomenon(name) { return this.createItem(Phenomenon, name); } /** @internal */ createPhenomenonSync(name) { return this.createItem(Phenomenon, name); } /** * Creates a Unit with the provided name in this schema. * @param name * @internal */ async createUnit(name) { return this.createItem(Unit, name); } /** @internal */ createUnitSync(name) { return this.createItem(Unit, name); } /** * Creates an PropertyCategory with the provided name in this schema. * @param name * @internal */ async createPropertyCategory(name) { return this.createItem(PropertyCategory, name); } /** @internal */ createPropertyCategorySync(name) { return this.createItem(PropertyCategory, name); } /** * * @param refSchema * @internal */ async addReference(refSchema) { // TODO validation of reference schema. For now just adding this.addReferenceSync(refSchema); } /** @internal */ addReferenceSync(refSchema) { this.references.push(refSchema); } /** @internal */ setContext(context) { this._context = context; } /** * 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, writeVersion, minorVersion) { if (!this._schemaKey) throw new ECSchemaError(ECSchemaStatus.InvalidSchemaKey, `The schema '${this.name}' has an invalid SchemaKey.`); const newVersion = new ECVersion(readVersion ?? this._schemaKey.readVersion, writeVersion ?? this._schemaKey.writeVersion, minorVersion ?? this._schemaKey.minorVersion); this._schemaKey = new SchemaKey(this._schemaKey.name, newVersion); } /** * 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. */ async getEntityClass(name) { return this.getItem(name, EntityClass); } /** * 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. */ async getMixin(name) { return this.getItem(name, Mixin); } /** * 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. */ async getStructClass(name) { return this.getItem(name, StructClass); } /** * 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. */ async getCustomAttributeClass(name) { return this.getItem(name, CustomAttributeClass); } /** * 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. */ async getRelationshipClass(name) { return this.getItem(name, RelationshipClass); } /** * 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. */ async getEnumeration(name) { return this.getItem(name, Enumeration); } /** * 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. */ async getKindOfQuantity(name) { return this.getItem(name, KindOfQuantity); } /** * 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. */ async getPropertyCategory(name) { return this.getItem(name, PropertyCategory); } /** * 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. */ async getUnit(name) { return this.getItem(name, Unit); } /** * 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. */ async getInvertedUnit(name) { return this.getItem(name, InvertedUnit); } /** * 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. */ async getConstant(name) { return this.getItem(name, Constant); } /** * 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. */ async getPhenomenon(name) { return this.getItem(name, Phenomenon); } /** * 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. */ async getUnitSystem(name) { return this.getItem(name, UnitSystem); } /** * 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. */ async getFormat(name) { return this.getItem(name, Format); } async getItem(name, itemConstructor) { // this method exists so we can rewire it later when we load partial schemas, for now it is identical to the sync version if (itemConstructor === undefined) return this.getItemSync(name); return this.getItemSync(name, itemConstructor); } getItemSync(name, itemConstructor) { const value = this._items.get(name.toUpperCase()); if (value === undefined || itemConstructor === undefined) return value; if (isSupportedSchemaItemType(value.schemaItemType, itemConstructor.schemaItemType)) return value; return undefined; } async lookupItem(key, itemConstructor) { let schemaName, itemName; if (typeof (key) === "string") { [schemaName, itemName] = SchemaItem.parseFullName(key); } else { itemName = key.name; schemaName = key.schemaName; } if (!schemaName || schemaName.toUpperCase() === this.name.toUpperCase()) { return itemConstructor ? this.getItem(itemName, itemConstructor) : this.getItem(itemName); } const refSchema = await this.getReference(schemaName); if (!refSchema) return undefined; return itemConstructor ? refSchema.getItem(itemName, itemConstructor) : refSchema.getItem(itemName); } lookupItemSync(key, itemConstructor) { let schemaName, itemName; if (typeof (key) === "string") { [schemaName, itemName] = SchemaItem.parseFullName(key); } else { itemName = key.name; schemaName = key.schemaName; } if (!schemaName || schemaName.toUpperCase() === this.name.toUpperCase()) { return itemConstructor ? this.getItemSync(itemName, itemConstructor) : this.getItemSync(itemName); } const refSchema = this.getReferenceSync(schemaName); if (!refSchema) return undefined; return itemConstructor ? refSchema.getItemSync(itemName, itemConstructor) : refSchema.getItemSync(itemName); } *getItems(itemConstructor) { if (!this._items) return; for (const item of this._items.values()) { if (itemConstructor === undefined || isSupportedSchemaItemType(item.schemaItemType, itemConstructor.schemaItemType)) yield item; } } /** * Gets a referenced schema by name * @param refSchemaName schema name to find */ async getReference(refSchemaName) { if (this.references.length === 0) return undefined; return this.references.find((ref) => ref.name.toLowerCase() === refSchemaName.toLowerCase()); } /** * Gets a referenced schema by alias * @param alias alias to find */ getReferenceNameByAlias(alias) { if (this.references.length === 0) return undefined; const schema = this.references.find((ref) => ref.alias ? ref.alias.toLowerCase() === alias.toLowerCase() : false); return schema ? schema.name : undefined; } /** * Gets a referenced schema by name * @param refSchemaName schema name to find */ getReferenceSync(refSchemaName) { if (this.references.length === 0) return undefined; return this.references.find((ref) => ref.name.toLowerCase() === refSchemaName.toLowerCase()); } /** * Save this Schema's properties to an object for serializing to JSON. */ toJSON() { if (this._isECSpecVersionUnsupported) throw new ECSchemaError(ECSchemaStatus.NewerECSpecVersion, `The Schema '${this.name}' has an unsupported ECSpecVersion and cannot be serialized.`); const schemaJson = {}; schemaJson.$schema = ECSchemaNamespaceUris.SCHEMAURL3_2_JSON; // $schema is required schemaJson.name = this.name; // name is required schemaJson.version = this.schemaKey.version.toString(true); schemaJson.alias = this.alias; // alias is required if (undefined !== this.label) // label is optional schemaJson.label = this.label; if (undefined !== this.description) // description is optional schemaJson.description = this.description; if (undefined !== this.references && this.references.length > 0) // references is optional schemaJson.references = this.references.map(({ name, schemaKey }) => ({ name, version: schemaKey.version.toString() })); const customAttributes = serializeCustomAttributes(this.customAttributes); if (undefined !== customAttributes) schemaJson.customAttributes = customAttributes; if (this._items.size > 0) { schemaJson.items = {}; this._items.forEach((schemaItem) => { schemaJson.items[schemaItem.name] = schemaItem.toJSON(false, true); }); } return schemaJson; } /** * Converts the schema to a DOM XML Document. * @param schemaXml An empty DOM document to which the schema will be written */ async toXml(schemaXml) { if (this._isECSpecVersionUnsupported) throw new ECSchemaError(ECSchemaStatus.NewerECSpecVersion, `The Schema '${this.name}' has an unsupported ECSpecVersion and cannot be serialized.`); const schemaMetadata = schemaXml.createElement("ECSchema"); schemaMetadata.setAttribute("xmlns", ECSchemaNamespaceUris.SCHEMAURL3_2_XML); schemaMetadata.setAttribute("version", this.schemaKey.version.toString()); schemaMetadata.setAttribute("schemaName", this.name); schemaMetadata.setAttribute("alias", this.alias ? this.alias : ""); if (undefined !== this.label) schemaMetadata.setAttribute("displayLabel", this.label); if (undefined !== this.description) schemaMetadata.setAttribute("description", this.description); // Map used for CA serialization const refSchemaMap = new Map(); this.references.forEach(({ name, schemaKey, alias }) => { const schemaRef = schemaXml.createElement("ECSchemaReference"); schemaRef.setAttribute("name", name); schemaRef.setAttribute("version", schemaKey.version.toString()); schemaRef.setAttribute("alias", alias ? alias : ""); schemaMetadata.appendChild(schemaRef); refSchemaMap.set(name, schemaKey.version.toString()); }); if (this._customAttributes) { const parentElem = schemaXml.createElement("ECCustomAttributes"); for (const [name, attribute] of this._customAttributes) { const caElem = await XmlSerializationUtils.writeCustomAttribute(name, attribute, schemaXml, this); parentElem.appendChild(caElem); } schemaMetadata.appendChild(parentElem); } for (const [, item] of this._items) { const itemXml = await item.toXml(schemaXml); schemaMetadata.appendChild(itemXml); } schemaXml.appendChild(schemaMetadata); return schemaXml; } /** * Loads the schema header (name, version alias, label and description) from the input SchemaProps */ fromJSONSync(schemaProps) { if (undefined === this._schemaKey) { const schemaName = schemaProps.name; const version = ECVersion.fromString(schemaProps.version); this._schemaKey = new SchemaKey(schemaName, version); } else { if (schemaProps.name.toLowerCase() !== this.name.toLowerCase()) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Schema ${this.name} does not match the provided name, '${schemaProps.name}'.`); if (this.schemaKey.version.compare(ECVersion.fromString(schemaProps.version))) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Schema ${this.name} has the version '${this.schemaKey.version}' that does not match the provided version '${schemaProps.version}'.`); } if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null) throw new ECSchemaError(ECSchemaStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`); // The schema props have not been parsed. Parse the ECXml version from the $schema attribute let ecVersion; if (schemaProps.ecSpecMajorVersion === undefined || schemaProps.ecSpecMinorVersion === undefined) { ecVersion = ((schemaProps.$schema.search("ECXML") !== -1) ? XmlParser.parseXmlNamespace(schemaProps.$schema) : JsonParser.parseJSUri(schemaProps.$schema)); } else { ecVersion = { readVersion: schemaProps.ecSpecMajorVersion, writeVersion: schemaProps.ecSpecMinorVersion }; } this._originalECSpecMajorVersion = ecVersion.readVersion; this._originalECSpecMinorVersion = ecVersion.writeVersion; if (ecVersion.readVersion !== 3 || (ecVersion.readVersion === 3 && ecVersion.writeVersion < 2)) throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The Schema '${this.name}' has an unsupported ECVersion ${ecVersion.readVersion}.${ecVersion.writeVersion} and cannot be loaded.`); if (ECName.validate(schemaProps.alias)) { this._alias = schemaProps.alias; } else { throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Schema ${schemaProps.name} does not have the required 'alias' attribute.`); } if (undefined !== schemaProps.label) this._label = schemaProps.label; if (undefined !== schemaProps.description) this._description = schemaProps.description; } /** * Loads the schema header (name, version alias, label and description) from the input SchemaProps */ async fromJSON(schemaProps) { this.fromJSONSync(schemaProps); } /** * 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 async startLoadingFromJson(jsonObj, context) { const schema = new Schema(context); const reader = new SchemaReadHelper(JsonParser, context); const rawSchema = typeof jsonObj === "string" ? JSON.parse(jsonObj) : jsonObj; return reader.readSchemaInfo(schema, rawSchema); } static async fromJson(jsonObj, context) { let schema = new Schema(context); const reader = new SchemaReadHelper(JsonParser, context); const rawSchema = typeof jsonObj === "string" ? JSON.parse(jsonObj) : jsonObj; schema = await reader.readSchema(schema, rawSchema); return schema; } /** * Completely loads the Schema from the input json. The schema is cached in the schema context. */ static fromJsonSync(jsonObj, context) { let schema = new Schema(context); const reader = new SchemaReadHelper(JsonParser, context); const rawSchema = typeof jsonObj === "string" ? JSON.parse(jsonObj) : jsonObj; schema = reader.readSchemaSync(schema, rawSchema); return schema; } /** * @internal */ static isSchema(object) { const schema = object; return schema !== undefined && schema.schemaKey !== undefined && schema.context !== undefined; } /** @internal */ setDisplayLabel(displayLabel) { this._label = displayLabel; } /** @internal */ setDescription(description) { this._description = description; } /** @internal */ setAlias(alias) { if (!ECName.validate(alias)) { throw new ECSchemaError(ECSchemaStatus.InvalidECName, "The specified schema alias is invalid."); } this._alias = alias; } /** @internal */ setLoadingController(controller) { this._loadingController = controller; } } /** * 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 class MutableSchema extends Schema { } //# sourceMappingURL=Schema.js.map