UNPKG

@itwin/ecschema-metadata

Version:

ECObjects core concepts in typescript

498 lines • 24.7 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.StrengthDirection = exports.StrengthType = exports.RelationshipEnd = exports.SchemaMatchType = exports.CustomAttributeContainerType = exports.PrimitiveType = exports.AbstractSchemaItemType = exports.SchemaItemType = exports.ECClassModifier = exports.PropertyType = void 0; exports.parseClassModifier = parseClassModifier; exports.classModifierToString = classModifierToString; exports.parseSchemaItemType = parseSchemaItemType; exports.schemaItemTypeToString = schemaItemTypeToString; exports.schemaItemTypeToXmlString = schemaItemTypeToXmlString; exports.parsePrimitiveType = parsePrimitiveType; exports.primitiveTypeToString = primitiveTypeToString; exports.parseCustomAttributeContainerType = parseCustomAttributeContainerType; exports.containerTypeToString = containerTypeToString; exports.parseRelationshipEnd = parseRelationshipEnd; exports.relationshipEndToString = relationshipEndToString; exports.parseStrength = parseStrength; exports.strengthToString = strengthToString; exports.parseStrengthDirection = parseStrengthDirection; exports.strengthDirectionToString = strengthDirectionToString; exports.isSupportedSchemaItemType = isSupportedSchemaItemType; const Constants_1 = require("./Constants"); const Exception_1 = require("./Exception"); var PropertyTypes_1 = require("./PropertyTypes"); Object.defineProperty(exports, "PropertyType", { enumerable: true, get: function () { return PropertyTypes_1.PropertyType; } }); // NEEDSWORK: This shim is currently required to use async iterators. See https://github.com/Microsoft/TypeScript/issues/14151 if (!Symbol.asyncIterator) { Symbol.asyncIterator = Symbol.for("Symbol.asyncIterator"); } /** * Identifies a class as abstract or sealed * * @public @preview */ var ECClassModifier; (function (ECClassModifier) { /* normal, instantiable class, can be subclassed */ ECClassModifier[ECClassModifier["None"] = 0] = "None"; /* abstract class, cannot be instantiated, can be subclassed */ ECClassModifier[ECClassModifier["Abstract"] = 1] = "Abstract"; /* sealed class, instantiable class, cannot be subclassed */ ECClassModifier[ECClassModifier["Sealed"] = 2] = "Sealed"; })(ECClassModifier || (exports.ECClassModifier = ECClassModifier = {})); /** * An enumeration that has all the schema item type names as values * * @enum {string} * @public @preview */ var SchemaItemType; (function (SchemaItemType) { SchemaItemType["EntityClass"] = "EntityClass"; SchemaItemType["Mixin"] = "Mixin"; SchemaItemType["StructClass"] = "StructClass"; SchemaItemType["CustomAttributeClass"] = "CustomAttributeClass"; SchemaItemType["RelationshipClass"] = "RelationshipClass"; SchemaItemType["Enumeration"] = "Enumeration"; SchemaItemType["KindOfQuantity"] = "KindOfQuantity"; SchemaItemType["PropertyCategory"] = "PropertyCategory"; SchemaItemType["Unit"] = "Unit"; SchemaItemType["InvertedUnit"] = "InvertedUnit"; SchemaItemType["Constant"] = "Constant"; SchemaItemType["Phenomenon"] = "Phenomenon"; SchemaItemType["UnitSystem"] = "UnitSystem"; SchemaItemType["Format"] = "Format"; })(SchemaItemType || (exports.SchemaItemType = SchemaItemType = {})); /** * Additional Schema Item Types which define classes of item types * @public @preview */ var AbstractSchemaItemType; (function (AbstractSchemaItemType) { /* Item is EntityClass, Mixin, StructClass, CustomAttributeClass, or RelationshipClass */ AbstractSchemaItemType["Class"] = "Class"; /* Any item type including the Class types */ AbstractSchemaItemType["SchemaItem"] = "SchemaItem"; })(AbstractSchemaItemType || (exports.AbstractSchemaItemType = AbstractSchemaItemType = {})); /** * Primitive data types for ECProperties. * @public @preview */ var PrimitiveType; (function (PrimitiveType) { PrimitiveType[PrimitiveType["Uninitialized"] = 0] = "Uninitialized"; PrimitiveType[PrimitiveType["Binary"] = 257] = "Binary"; PrimitiveType[PrimitiveType["Boolean"] = 513] = "Boolean"; PrimitiveType[PrimitiveType["DateTime"] = 769] = "DateTime"; PrimitiveType[PrimitiveType["Double"] = 1025] = "Double"; PrimitiveType[PrimitiveType["Integer"] = 1281] = "Integer"; PrimitiveType[PrimitiveType["Long"] = 1537] = "Long"; PrimitiveType[PrimitiveType["Point2d"] = 1793] = "Point2d"; PrimitiveType[PrimitiveType["Point3d"] = 2049] = "Point3d"; PrimitiveType[PrimitiveType["String"] = 2305] = "String"; PrimitiveType[PrimitiveType["IGeometry"] = 2561] = "IGeometry"; })(PrimitiveType || (exports.PrimitiveType = PrimitiveType = {})); /** * Defines the valid CustomAttribute container types. * @public @preview */ var CustomAttributeContainerType; (function (CustomAttributeContainerType) { CustomAttributeContainerType[CustomAttributeContainerType["Schema"] = 1] = "Schema"; CustomAttributeContainerType[CustomAttributeContainerType["EntityClass"] = 2] = "EntityClass"; CustomAttributeContainerType[CustomAttributeContainerType["CustomAttributeClass"] = 4] = "CustomAttributeClass"; CustomAttributeContainerType[CustomAttributeContainerType["StructClass"] = 8] = "StructClass"; CustomAttributeContainerType[CustomAttributeContainerType["RelationshipClass"] = 16] = "RelationshipClass"; CustomAttributeContainerType[CustomAttributeContainerType["AnyClass"] = 30] = "AnyClass"; CustomAttributeContainerType[CustomAttributeContainerType["PrimitiveProperty"] = 32] = "PrimitiveProperty"; CustomAttributeContainerType[CustomAttributeContainerType["StructProperty"] = 64] = "StructProperty"; CustomAttributeContainerType[CustomAttributeContainerType["PrimitiveArrayProperty"] = 128] = "PrimitiveArrayProperty"; CustomAttributeContainerType[CustomAttributeContainerType["StructArrayProperty"] = 256] = "StructArrayProperty"; CustomAttributeContainerType[CustomAttributeContainerType["NavigationProperty"] = 512] = "NavigationProperty"; CustomAttributeContainerType[CustomAttributeContainerType["AnyProperty"] = 992] = "AnyProperty"; CustomAttributeContainerType[CustomAttributeContainerType["SourceRelationshipConstraint"] = 1024] = "SourceRelationshipConstraint"; CustomAttributeContainerType[CustomAttributeContainerType["TargetRelationshipConstraint"] = 2048] = "TargetRelationshipConstraint"; CustomAttributeContainerType[CustomAttributeContainerType["AnyRelationshipConstraint"] = 3072] = "AnyRelationshipConstraint"; CustomAttributeContainerType[CustomAttributeContainerType["Any"] = 4095] = "Any"; })(CustomAttributeContainerType || (exports.CustomAttributeContainerType = CustomAttributeContainerType = {})); /** * Defines what sort of match should be used when locating a schema. * @public @preview */ var SchemaMatchType; (function (SchemaMatchType) { /* * Find exact VersionRead, VersionWrite, VersionMinor match as well as Data. NOTE data is not yet matched * @deprecated in 4.10 - will not be removed until after 2026-06-13. Use Exact instead. */ SchemaMatchType[SchemaMatchType["Identical"] = 0] = "Identical"; /* Find exact VersionRead, VersionWrite, VersionMinor match. */ SchemaMatchType[SchemaMatchType["Exact"] = 1] = "Exact"; /* Find latest version with matching VersionRead and VersionWrite */ SchemaMatchType[SchemaMatchType["LatestWriteCompatible"] = 2] = "LatestWriteCompatible"; /* Find latest version. */ SchemaMatchType[SchemaMatchType["Latest"] = 3] = "Latest"; /* Find latest version with matching VersionRead */ SchemaMatchType[SchemaMatchType["LatestReadCompatible"] = 4] = "LatestReadCompatible"; })(SchemaMatchType || (exports.SchemaMatchType = SchemaMatchType = {})); /** * Identifer for an ECRelationshipConstraint. Used to determine the side of the relationship the constraint is representing. * @public @preview */ var RelationshipEnd; (function (RelationshipEnd) { RelationshipEnd[RelationshipEnd["Source"] = 0] = "Source"; RelationshipEnd[RelationshipEnd["Target"] = 1] = "Target"; })(RelationshipEnd || (exports.RelationshipEnd = RelationshipEnd = {})); /** * Defines the how the lifetime of the source and target are related. * * @public @preview */ var StrengthType; (function (StrengthType) { StrengthType[StrengthType["Referencing"] = 0] = "Referencing"; StrengthType[StrengthType["Holding"] = 1] = "Holding"; StrengthType[StrengthType["Embedding"] = 2] = "Embedding"; })(StrengthType || (exports.StrengthType = StrengthType = {})); /** * Defines the which side of the relationship is the starting point of the relationship. This impacts how relationship strength is applied. * * @public @preview */ var StrengthDirection; (function (StrengthDirection) { /** The source is the starting point of the relationship. */ StrengthDirection[StrengthDirection["Forward"] = 1] = "Forward"; /** The target is the starting point of the relationship. */ StrengthDirection[StrengthDirection["Backward"] = 2] = "Backward"; })(StrengthDirection || (exports.StrengthDirection = StrengthDirection = {})); // Helper methods for going to/from string for the above Enumerations. /** * Parses the provided string into an ECClassModifier if the string is a valid modifier. * @param modifier The modifier string to parse. * @beta */ function parseClassModifier(modifier) { const lowerModifier = modifier.toLowerCase(); switch (lowerModifier) { case "abstract": return ECClassModifier.Abstract; case "none": return ECClassModifier.None; case "sealed": return ECClassModifier.Sealed; } return undefined; } /** * @return A string representing the provided ECClassModifier. If the modifier is not valid, an empty string is returned. * @beta */ function classModifierToString(modifier) { switch (modifier) { case ECClassModifier.Abstract: return "Abstract"; case ECClassModifier.None: return "None"; case ECClassModifier.Sealed: return "Sealed"; default: throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidModifier, "An invalid ECClassModifier has been provided."); } } /** * Tries to parse the given string as one of the 8 schema item types. * @param type The schema item type string to parse. * @returns A valid SchemaItemType if successfully parsed. Otherwise, undefined if the provided string is not a valid SchemaItemType. * @beta */ function parseSchemaItemType(type) { switch (type.toLowerCase()) { case "entityclass": return SchemaItemType.EntityClass; case "mixin": return SchemaItemType.Mixin; case "structclass": return SchemaItemType.StructClass; case "customattributeclass": return SchemaItemType.CustomAttributeClass; case "relationshipclass": return SchemaItemType.RelationshipClass; case "enumeration": return SchemaItemType.Enumeration; case "kindofquantity": return SchemaItemType.KindOfQuantity; case "propertycategory": return SchemaItemType.PropertyCategory; case "unit": return SchemaItemType.Unit; case "invertedunit": return SchemaItemType.InvertedUnit; case "constant": return SchemaItemType.Constant; case "phenomenon": return SchemaItemType.Phenomenon; case "unitsystem": return SchemaItemType.UnitSystem; case "format": return SchemaItemType.Format; } return undefined; } /** * Converts a valid SchemaItemType to a display string. * @param value The SchemaItemType to stringify. * @return A string representing the provided SchemaItemType. If the type is not valid, an empty string is returned. * @beta * @deprecated in 4.6.0 - will not be removed until after 2026-06-13. SchemaItemType is a string enum so just use it directly */ function schemaItemTypeToString(value) { return value; // TODO: Remove } /** @internal */ function schemaItemTypeToXmlString(value) { switch (value) { case SchemaItemType.EntityClass: return "ECEntityClass"; case SchemaItemType.Mixin: return "ECEntityClass"; case SchemaItemType.StructClass: return "ECStructClass"; case SchemaItemType.CustomAttributeClass: return "ECCustomAttributeClass"; case SchemaItemType.RelationshipClass: return "ECRelationshipClass"; case SchemaItemType.Enumeration: return "ECEnumeration"; case SchemaItemType.KindOfQuantity: return "KindOfQuantity"; case SchemaItemType.PropertyCategory: return "PropertyCategory"; case SchemaItemType.Unit: return "Unit"; case SchemaItemType.InvertedUnit: return "InvertedUnit"; case SchemaItemType.Constant: return "Constant"; case SchemaItemType.Phenomenon: return "Phenomenon"; case SchemaItemType.UnitSystem: return "UnitSystem"; case SchemaItemType.Format: return "Format"; default: throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidSchemaItemType, "An invalid SchemaItemType has been provided."); } } /** * Tries to parse the given string as one of the 10 primitive types. * @param type The primitive type string to parse. * @returns A valid PrimitiveType if successfully parsed, or undefined if the provided string is not a valid PrimitiveType. * @beta */ function parsePrimitiveType(type) { switch (type.toLowerCase()) { case "binary": return PrimitiveType.Binary; case "boolean": case "bool": return PrimitiveType.Boolean; case "datetime": return PrimitiveType.DateTime; case "double": return PrimitiveType.Double; case "int": return PrimitiveType.Integer; case "long": return PrimitiveType.Long; case "point2d": return PrimitiveType.Point2d; case "point3d": return PrimitiveType.Point3d; case "string": return PrimitiveType.String; case "bentley.geometry.common.igeometry": return PrimitiveType.IGeometry; } return undefined; } /** @beta */ function primitiveTypeToString(type) { switch (type) { case PrimitiveType.Binary: return "binary"; case PrimitiveType.Boolean: return "boolean"; case PrimitiveType.DateTime: return "dateTime"; case PrimitiveType.Double: return "double"; case PrimitiveType.Integer: return "int"; case PrimitiveType.IGeometry: return "Bentley.Geometry.Common.IGeometry"; case PrimitiveType.Long: return "long"; case PrimitiveType.Point2d: return "point2d"; case PrimitiveType.Point3d: return "point3d"; case PrimitiveType.String: return "string"; default: throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidPrimitiveType, "An invalid PrimitiveType has been provided."); } } /** * Parses the given string into the appropriate CustomAttributeContainerType if the string is valid. * @param type The container type string to parse. * @beta */ function parseCustomAttributeContainerType(type) { const typeTokens = type.split(/[|,;]+/); let containerType = 0; typeTokens.forEach((typeToken) => { typeToken = typeToken.trim(); if (typeToken.length === 0) return; typeToken = typeToken.toLowerCase(); switch (typeToken) { case "schema": containerType = containerType | CustomAttributeContainerType.Schema; break; case "entityclass": containerType = containerType | CustomAttributeContainerType.EntityClass; break; case "customattributeclass": containerType = containerType | CustomAttributeContainerType.CustomAttributeClass; break; case "structclass": containerType = containerType | CustomAttributeContainerType.StructClass; break; case "relationshipclass": containerType = containerType | CustomAttributeContainerType.RelationshipClass; break; case "anyclass": containerType = containerType | CustomAttributeContainerType.AnyClass; break; case "primitiveproperty": containerType = containerType | CustomAttributeContainerType.PrimitiveProperty; break; case "structproperty": containerType = containerType | CustomAttributeContainerType.StructProperty; break; case "arrayproperty": containerType = containerType | CustomAttributeContainerType.PrimitiveArrayProperty; break; case "structarrayproperty": containerType = containerType | CustomAttributeContainerType.StructArrayProperty; break; case "navigationproperty": containerType = containerType | CustomAttributeContainerType.NavigationProperty; break; case "anyproperty": containerType = containerType | CustomAttributeContainerType.AnyProperty; break; case "sourcerelationshipconstraint": containerType = containerType | CustomAttributeContainerType.SourceRelationshipConstraint; break; case "targetrelationshipconstraint": containerType = containerType | CustomAttributeContainerType.TargetRelationshipConstraint; break; case "anyrelationshipconstraint": containerType = containerType | CustomAttributeContainerType.AnyRelationshipConstraint; break; case "any": containerType = containerType | CustomAttributeContainerType.Any; break; default: throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidContainerType, `${typeToken} is not a valid CustomAttributeContainerType value.`); } }); return containerType; } /** * Creates a string representing a valid CustomAttributeContainerType. * @param value The CustomAttributeContainerType to stringify. * @return A string representing the provided CustomAttributeContainerType. If the type is not valid, an empty string is returned. * @beta */ function containerTypeToString(type) { const testContainerTypeValue = (compareType, otherType) => { return compareType === (compareType & otherType); }; if (testContainerTypeValue(CustomAttributeContainerType.Any, type)) return Constants_1.ECStringConstants.CONTAINERTYPE_ANY; let containerType = ""; const setOrAppend = (val) => { if (containerType.length === 0) containerType = val; else containerType = `${containerType}, ${val}`; }; if (testContainerTypeValue(CustomAttributeContainerType.Schema, type)) setOrAppend("Schema"); if (testContainerTypeValue(CustomAttributeContainerType.AnyClass, type)) setOrAppend("AnyClass"); else { if (testContainerTypeValue(CustomAttributeContainerType.EntityClass, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_ENTITYCLASS); if (testContainerTypeValue(CustomAttributeContainerType.CustomAttributeClass, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_CUSTOMATTRIBUTECLASS); if (testContainerTypeValue(CustomAttributeContainerType.StructClass, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_STRUCTCLASS); if (testContainerTypeValue(CustomAttributeContainerType.RelationshipClass, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_RELATIONSHIPCLASS); } if (testContainerTypeValue(CustomAttributeContainerType.AnyProperty, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_ANYPROPERTY); else { if (testContainerTypeValue(CustomAttributeContainerType.PrimitiveProperty, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_PRIMITIVEPROPERTY); if (testContainerTypeValue(CustomAttributeContainerType.StructProperty, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_STRUCTPROPERTY); if (testContainerTypeValue(CustomAttributeContainerType.PrimitiveArrayProperty, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_PRIMITIVEARRAYPROPERTY); if (testContainerTypeValue(CustomAttributeContainerType.StructArrayProperty, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_STRUCTARRAYPROPERTY); if (testContainerTypeValue(CustomAttributeContainerType.NavigationProperty, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_NAVIGATIONPROPERTY); } if (testContainerTypeValue(CustomAttributeContainerType.AnyRelationshipConstraint, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_ANYRELATIONSHIPCONSTRAINT); else { if (testContainerTypeValue(CustomAttributeContainerType.SourceRelationshipConstraint, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_SOURCERELATIONSHIPCONSTRAINT); if (testContainerTypeValue(CustomAttributeContainerType.TargetRelationshipConstraint, type)) setOrAppend(Constants_1.ECStringConstants.CONTAINERTYPE_TARGETRELATIONSHIPCONSTRAINT); } return containerType; } /** @beta */ function parseRelationshipEnd(end) { switch (end.toLowerCase()) { case "source": return RelationshipEnd.Source; case "target": return RelationshipEnd.Target; } return undefined; } /** @beta */ function relationshipEndToString(end) { switch (end) { case RelationshipEnd.Source: return Constants_1.ECStringConstants.RELATIONSHIP_END_SOURCE; case RelationshipEnd.Target: return Constants_1.ECStringConstants.RELATIONSHIP_END_TARGET; default: throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidRelationshipEnd, `An invalid RelationshipEnd has been provided.`); } } /** * Takes a string representing a StrengthType, will parse it and return the corresponding StrengthType. * @throws ECSchemaStatus.InvalidStrength if the provided string that is not valid * @param strength * @beta */ function parseStrength(strength) { switch (strength.toLowerCase()) { case "referencing": return StrengthType.Referencing; case "holding": return StrengthType.Holding; case "embedding": return StrengthType.Embedding; } return undefined; } /** @beta */ function strengthToString(strength) { switch (strength) { case StrengthType.Embedding: return "Embedding"; case StrengthType.Holding: return "Holding"; case StrengthType.Referencing: return "Referencing"; default: throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidStrength, `An invalid Strength has been provided.`); } } /** @beta */ function parseStrengthDirection(direction) { switch (direction.toLowerCase()) { case "forward": return StrengthDirection.Forward; case "backward": return StrengthDirection.Backward; } return undefined; } /** @beta */ function strengthDirectionToString(direction) { switch (direction) { case StrengthDirection.Forward: return "Forward"; case StrengthDirection.Backward: return "Backward"; default: throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidStrengthDirection, `An invalid StrengthDirection has been provided.`); } } /** Compares a SchemaItemType against supported type. * @beta */ function isSupportedSchemaItemType(value, supported) { if (value === supported) return true; if (supported === AbstractSchemaItemType.Class && (value === SchemaItemType.EntityClass || value === SchemaItemType.Mixin || value === SchemaItemType.StructClass || value === SchemaItemType.CustomAttributeClass || value === SchemaItemType.RelationshipClass)) { return true; } if (supported === AbstractSchemaItemType.SchemaItem) { return true; } return false; } //# sourceMappingURL=ECObjects.js.map