@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
89 lines • 3.75 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MutablePhenomenon = exports.Phenomenon = void 0;
const ECObjects_1 = require("../ECObjects");
const Exception_1 = require("../Exception");
const SchemaItem_1 = require("./SchemaItem");
/** @public @preview */
class Phenomenon extends SchemaItem_1.SchemaItem {
schemaItemType = Phenomenon.schemaItemType;
/** @internal */
static get schemaItemType() { return ECObjects_1.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 Exception_1.ECSchemaError(Exception_1.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 === ECObjects_1.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 Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidSchemaItemType, `Expected '${ECObjects_1.SchemaItemType.Phenomenon}' (Phenomenon)`);
}
}
exports.Phenomenon = Phenomenon;
/**
* @internal
* An abstract class used for schema editing.
*/
class MutablePhenomenon extends Phenomenon {
}
exports.MutablePhenomenon = MutablePhenomenon;
//# sourceMappingURL=Phenomenon.js.map