UNPKG

@itwin/ecschema-metadata

Version:

ECObjects core concepts in typescript

84 lines 3.47 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 { SchemaItemType } from "../ECObjects"; import { ECSchemaError, ECSchemaStatus } from "../Exception"; import { SchemaItem } from "./SchemaItem"; /** @public @preview */ export class Phenomenon extends SchemaItem { schemaItemType = Phenomenon.schemaItemType; /** @internal */ static get schemaItemType() { return SchemaItemType.Phenomenon; } _definition; // Contains a combination of Phenomena names which form this Phenomenon. Each Phenomena name is separated by a * and may have an exponent, specified using parentheses /** @internal */ constructor(schema, name) { super(schema, name); this._definition = ""; } get definition() { return this._definition; } /** * Save this Phenomenon's 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 = false, includeSchemaVersion = false) { const schemaJson = super.toJSON(standalone, includeSchemaVersion); schemaJson.definition = this.definition; return schemaJson; } /** @internal */ async toXml(schemaXml) { const itemElement = await super.toXml(schemaXml); itemElement.setAttribute("definition", this.definition); return itemElement; } fromJSONSync(phenomenonProps) { super.fromJSONSync(phenomenonProps); if (this._definition !== "" && phenomenonProps.definition.toLowerCase() !== this._definition.toLowerCase()) throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Phenomenon ${this.name} has an invalid 'definition' attribute.`); else if (this._definition === "") this._definition = phenomenonProps.definition; } async fromJSON(phenomenonProps) { this.fromJSONSync(phenomenonProps); } /** * * @param definition * @internal */ async setDefinition(definition) { this._definition = definition; } /** * Type guard to check if the SchemaItem is of type Phenomenon. * @param item The SchemaItem to check. * @returns True if the item is a Phenomenon, false otherwise. */ static isPhenomenon(item) { if (item && item.schemaItemType === SchemaItemType.Phenomenon) return true; return false; } /** * Type assertion to check if the SchemaItem is of type Phenomenon. * @param item The SchemaItem to check. * @returns The item cast to Phenomenon if it is a Phenomenon, undefined otherwise. * @internal */ static assertIsPhenomenon(item) { if (!this.isPhenomenon(item)) throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Phenomenon}' (Phenomenon)`); } } /** * @internal * An abstract class used for schema editing. */ export class MutablePhenomenon extends Phenomenon { } //# sourceMappingURL=Phenomenon.js.map