@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
90 lines • 3.83 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
*/
import { containerTypeToString, parseCustomAttributeContainerType, SchemaItemType, } from "../ECObjects";
import { ECSchemaError, ECSchemaStatus } from "../Exception";
import { ECClass } from "./Class";
/**
* A Typescript class representation of an ECCustomAttributeClass.
* @public @preview
*/
export class CustomAttributeClass extends ECClass {
schemaItemType = CustomAttributeClass.schemaItemType;
/** @internal */
static get schemaItemType() { return 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 ECSchemaError(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 = containerTypeToString(this.appliesTo);
return schemaJson;
}
/** @internal */
async toXml(schemaXml) {
const itemElement = await super.toXml(schemaXml);
itemElement.setAttribute("appliesTo", containerTypeToString(this.appliesTo));
return itemElement;
}
fromJSONSync(customAttributeProps) {
super.fromJSONSync(customAttributeProps);
const appliesTo = parseCustomAttributeContainerType(customAttributeProps.appliesTo);
if (undefined === appliesTo)
throw new ECSchemaError(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 === 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 ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.CustomAttributeClass}' (CustomAttributeClass)`);
}
}
/**
* @internal
* An abstract class used for Schema editing.
*/
export class MutableCAClass extends CustomAttributeClass {
}
//# sourceMappingURL=CustomAttributeClass.js.map