UNPKG

@itwin/ecschema-metadata

Version:

ECObjects core concepts in typescript

95 lines 4.14 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * 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.MutableCAClass = exports.CustomAttributeClass = void 0; const ECObjects_1 = require("../ECObjects"); const Exception_1 = require("../Exception"); const Class_1 = require("./Class"); /** * A Typescript class representation of an ECCustomAttributeClass. * @public @preview */ class CustomAttributeClass extends Class_1.ECClass { schemaItemType = CustomAttributeClass.schemaItemType; /** @internal */ static get schemaItemType() { return ECObjects_1.SchemaItemType.CustomAttributeClass; } _appliesTo; /** * @deprecated in 4.8 - will not be removed until after 2026-06-13. Use [[appliesTo]] * */ get containerType() { return this.appliesTo; } get appliesTo() { if (undefined === this._appliesTo) throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidContainerType, `The CustomAttributeClass ${this.name} does not have a CustomAttributeContainerType.`); return this._appliesTo; } /** * Save this CustomAttributeClasses 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.appliesTo = (0, ECObjects_1.containerTypeToString)(this.appliesTo); return schemaJson; } /** @internal */ async toXml(schemaXml) { const itemElement = await super.toXml(schemaXml); itemElement.setAttribute("appliesTo", (0, ECObjects_1.containerTypeToString)(this.appliesTo)); return itemElement; } fromJSONSync(customAttributeProps) { super.fromJSONSync(customAttributeProps); const appliesTo = (0, ECObjects_1.parseCustomAttributeContainerType)(customAttributeProps.appliesTo); if (undefined === appliesTo) throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidContainerType, `${appliesTo} is not a valid CustomAttributeContainerType.`); this._appliesTo = appliesTo; } async fromJSON(customAttributeProps) { this.fromJSONSync(customAttributeProps); } /** * @internal */ setAppliesTo(containerType) { this._appliesTo = containerType; } /** * Type guard to check if the SchemaItem is of type CustomAttributeClass. * @param item The SchemaItem to check. * @returns True if the item is a CustomAttributeClass, false otherwise. */ static isCustomAttributeClass(item) { if (item && item.schemaItemType === ECObjects_1.SchemaItemType.CustomAttributeClass) return true; return false; } /** * Type assertion to check if the SchemaItem is of type CustomAttributeClass. * @param item The SchemaItem to check. * @returns The item cast to CustomAttributeClass if it is a CustomAttributeClass, undefined otherwise. * @internal */ static assertIsCustomAttributeClass(item) { if (!this.isCustomAttributeClass(item)) throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidSchemaItemType, `Expected '${ECObjects_1.SchemaItemType.CustomAttributeClass}' (CustomAttributeClass)`); } } exports.CustomAttributeClass = CustomAttributeClass; /** * @internal * An abstract class used for Schema editing. */ class MutableCAClass extends CustomAttributeClass { } exports.MutableCAClass = MutableCAClass; //# sourceMappingURL=CustomAttributeClass.js.map