@itwin/ecschema-metadata 4.0.0-dev.44 → 4.0.0-dev.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Constants.d.ts +23 -23
- package/lib/cjs/Constants.js +33 -33
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/Context.d.ts +139 -139
- package/lib/cjs/Context.js +204 -204
- package/lib/cjs/DelayedPromise.d.ts +88 -88
- package/lib/cjs/DelayedPromise.js +91 -91
- package/lib/cjs/DelayedPromise.js.map +1 -1
- package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
- package/lib/cjs/Deserialization/AbstractParser.js +11 -11
- package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
- package/lib/cjs/Deserialization/Helper.d.ts +251 -251
- package/lib/cjs/Deserialization/Helper.js +843 -843
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
- package/lib/cjs/Deserialization/JsonParser.js +680 -680
- package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
- package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
- package/lib/cjs/Deserialization/JsonProps.js +9 -9
- package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
- package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
- package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
- package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
- package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
- package/lib/cjs/Deserialization/XmlParser.js +973 -973
- package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
- package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
- package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
- package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
- package/lib/cjs/ECName.d.ts +30 -30
- package/lib/cjs/ECName.js +85 -85
- package/lib/cjs/ECName.js.map +1 -1
- package/lib/cjs/ECObjects.d.ts +162 -162
- package/lib/cjs/ECObjects.js +453 -453
- package/lib/cjs/ECObjects.js.map +1 -1
- package/lib/cjs/Exception.d.ts +43 -43
- package/lib/cjs/Exception.js +84 -84
- package/lib/cjs/Exception.js.map +1 -1
- package/lib/cjs/Interfaces.d.ts +66 -66
- package/lib/cjs/Interfaces.js +9 -9
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Metadata/Class.d.ts +243 -243
- package/lib/cjs/Metadata/Class.js +558 -558
- package/lib/cjs/Metadata/Class.js.map +1 -1
- package/lib/cjs/Metadata/Constant.d.ts +64 -64
- package/lib/cjs/Metadata/Constant.js +123 -123
- package/lib/cjs/Metadata/Constant.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
- package/lib/cjs/Metadata/CustomAttribute.js +27 -27
- package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
- package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
- package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
- package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
- package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
- package/lib/cjs/Metadata/EntityClass.js +230 -230
- package/lib/cjs/Metadata/EntityClass.js.map +1 -1
- package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
- package/lib/cjs/Metadata/Enumeration.js +159 -159
- package/lib/cjs/Metadata/Enumeration.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +98 -98
- package/lib/cjs/Metadata/Format.js +242 -242
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
- package/lib/cjs/Metadata/InvertedUnit.js +97 -97
- package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
- package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/Mixin.d.ts +54 -54
- package/lib/cjs/Metadata/Mixin.js +113 -113
- package/lib/cjs/Metadata/Mixin.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
- package/lib/cjs/Metadata/OverrideFormat.js +88 -88
- package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
- package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
- package/lib/cjs/Metadata/Phenomenon.js +59 -59
- package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
- package/lib/cjs/Metadata/Property.d.ts +197 -197
- package/lib/cjs/Metadata/Property.js +491 -491
- package/lib/cjs/Metadata/Property.js.map +1 -1
- package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
- package/lib/cjs/Metadata/PropertyCategory.js +61 -61
- package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
- package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
- package/lib/cjs/Metadata/RelationshipClass.js +349 -349
- package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
- package/lib/cjs/Metadata/Schema.d.ts +291 -291
- package/lib/cjs/Metadata/Schema.js +520 -520
- package/lib/cjs/Metadata/Schema.js.map +1 -1
- package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
- package/lib/cjs/Metadata/SchemaItem.js +136 -136
- package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
- package/lib/cjs/Metadata/Unit.d.ts +76 -76
- package/lib/cjs/Metadata/Unit.js +162 -162
- package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
- package/lib/cjs/Metadata/UnitSystem.js +29 -29
- package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
- package/lib/cjs/PropertyTypes.d.ts +49 -49
- package/lib/cjs/PropertyTypes.js +91 -91
- package/lib/cjs/PropertyTypes.js.map +1 -1
- package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
- package/lib/cjs/SchemaJsonLocater.js +42 -42
- package/lib/cjs/SchemaJsonLocater.js.map +1 -1
- package/lib/cjs/SchemaKey.d.ts +110 -110
- package/lib/cjs/SchemaKey.js +219 -219
- package/lib/cjs/SchemaKey.js.map +1 -1
- package/lib/cjs/SchemaLoader.d.ts +23 -23
- package/lib/cjs/SchemaLoader.js +47 -47
- package/lib/cjs/SchemaLoader.js.map +1 -1
- package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
- package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
- package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
- package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
- package/lib/cjs/UnitConversion/Graph.js +83 -83
- package/lib/cjs/UnitConversion/Graph.js.map +1 -1
- package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
- package/lib/cjs/UnitConversion/Parser.js +42 -42
- package/lib/cjs/UnitConversion/Parser.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
- package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
- package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
- package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
- package/lib/cjs/UnitConversion/UnitTree.js +169 -169
- package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js +234 -234
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
- package/lib/cjs/Validation/SchemaWalker.js +53 -53
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-metadata.d.ts +51 -51
- package/lib/cjs/ecschema-metadata.js +96 -96
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
- package/lib/cjs/utils/SchemaGraph.js +65 -65
- package/lib/cjs/utils/SchemaGraph.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Metadata
|
|
3
|
-
*/
|
|
4
|
-
import { EnumerationProps } from "../Deserialization/JsonProps";
|
|
5
|
-
import { PrimitiveType, SchemaItemType } from "../ECObjects";
|
|
6
|
-
import { Schema } from "./Schema";
|
|
7
|
-
import { SchemaItem } from "./SchemaItem";
|
|
8
|
-
/** @beta */
|
|
9
|
-
export interface Enumerator<T> {
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly value: T;
|
|
12
|
-
readonly label?: string;
|
|
13
|
-
readonly description?: string;
|
|
14
|
-
}
|
|
15
|
-
/** @beta */
|
|
16
|
-
export declare type AnyEnumerator = Enumerator<string | number>;
|
|
17
|
-
/**
|
|
18
|
-
* A Typescript class representation of an ECEnumeration.
|
|
19
|
-
* @beta
|
|
20
|
-
*/
|
|
21
|
-
export declare class Enumeration extends SchemaItem {
|
|
22
|
-
readonly schemaItemType: SchemaItemType.Enumeration;
|
|
23
|
-
protected _type?: PrimitiveType.Integer | PrimitiveType.String;
|
|
24
|
-
protected _isStrict: boolean;
|
|
25
|
-
protected _enumerators: AnyEnumerator[];
|
|
26
|
-
get enumerators(): AnyEnumerator[];
|
|
27
|
-
get type(): PrimitiveType.Integer | PrimitiveType.String | undefined;
|
|
28
|
-
get isStrict(): boolean;
|
|
29
|
-
constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String);
|
|
30
|
-
get isInt(): boolean;
|
|
31
|
-
get isString(): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Gets an enumerator that matches the name provided.
|
|
34
|
-
* @param name The ECName of the Enumerator to find.
|
|
35
|
-
*/
|
|
36
|
-
getEnumeratorByName(name: string): AnyEnumerator | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Gets an enumerator that matches the value provided.
|
|
39
|
-
* @param value The value of the Enumerator to find.
|
|
40
|
-
*/
|
|
41
|
-
getEnumerator(value: string): Enumerator<string> | undefined;
|
|
42
|
-
getEnumerator(value: number): Enumerator<number> | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Checks whether there already exists an enumerator with this name or this value
|
|
45
|
-
* @param name The name of the enumerator we are trying to create
|
|
46
|
-
* @param value The value of the enumerator we are trying to create
|
|
47
|
-
* @internal
|
|
48
|
-
*/
|
|
49
|
-
private findDuplicateEnumerators;
|
|
50
|
-
/**
|
|
51
|
-
* Creates an Enumerator with the provided name and value as well as optional parameters label and description
|
|
52
|
-
* @param name The name of the enumerator
|
|
53
|
-
* @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
|
|
54
|
-
* @param label A localized display label that is used instead of the name in a GUI.
|
|
55
|
-
* @param description A localized description for the enumerator.
|
|
56
|
-
* @return AnyEnumerator object
|
|
57
|
-
*/
|
|
58
|
-
createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator;
|
|
59
|
-
/**
|
|
60
|
-
* Adds enumerator to list of enumerators on this Enumeration
|
|
61
|
-
* @param enumerator The enumerator to add
|
|
62
|
-
*/
|
|
63
|
-
protected addEnumerator(enumerator: AnyEnumerator): void;
|
|
64
|
-
/**
|
|
65
|
-
* Save this Enumeration's properties to an object for serializing to JSON.
|
|
66
|
-
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
67
|
-
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
68
|
-
*/
|
|
69
|
-
toJSON(standalone?: boolean, includeSchemaVersion?: boolean): EnumerationProps;
|
|
70
|
-
/** @internal */
|
|
71
|
-
toXml(schemaXml: Document): Promise<Element>;
|
|
72
|
-
fromJSONSync(enumerationProps: EnumerationProps): void;
|
|
73
|
-
fromJSON(enumerationProps: EnumerationProps): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* @alpha Used in schema editing.
|
|
76
|
-
*/
|
|
77
|
-
protected setIsStrict(isStrict: boolean): void;
|
|
78
|
-
}
|
|
79
|
-
/** @internal
|
|
80
|
-
* An abstract class used for schema editing.
|
|
81
|
-
*/
|
|
82
|
-
export declare abstract class MutableEnumeration extends Enumeration {
|
|
83
|
-
abstract addEnumerator(enumerator: AnyEnumerator): void;
|
|
84
|
-
abstract setIsStrict(isStrict: boolean): void;
|
|
85
|
-
abstract setDisplayLabel(displayLabel: string): void;
|
|
86
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Metadata
|
|
3
|
+
*/
|
|
4
|
+
import { EnumerationProps } from "../Deserialization/JsonProps";
|
|
5
|
+
import { PrimitiveType, SchemaItemType } from "../ECObjects";
|
|
6
|
+
import { Schema } from "./Schema";
|
|
7
|
+
import { SchemaItem } from "./SchemaItem";
|
|
8
|
+
/** @beta */
|
|
9
|
+
export interface Enumerator<T> {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly value: T;
|
|
12
|
+
readonly label?: string;
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
}
|
|
15
|
+
/** @beta */
|
|
16
|
+
export declare type AnyEnumerator = Enumerator<string | number>;
|
|
17
|
+
/**
|
|
18
|
+
* A Typescript class representation of an ECEnumeration.
|
|
19
|
+
* @beta
|
|
20
|
+
*/
|
|
21
|
+
export declare class Enumeration extends SchemaItem {
|
|
22
|
+
readonly schemaItemType: SchemaItemType.Enumeration;
|
|
23
|
+
protected _type?: PrimitiveType.Integer | PrimitiveType.String;
|
|
24
|
+
protected _isStrict: boolean;
|
|
25
|
+
protected _enumerators: AnyEnumerator[];
|
|
26
|
+
get enumerators(): AnyEnumerator[];
|
|
27
|
+
get type(): PrimitiveType.Integer | PrimitiveType.String | undefined;
|
|
28
|
+
get isStrict(): boolean;
|
|
29
|
+
constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String);
|
|
30
|
+
get isInt(): boolean;
|
|
31
|
+
get isString(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Gets an enumerator that matches the name provided.
|
|
34
|
+
* @param name The ECName of the Enumerator to find.
|
|
35
|
+
*/
|
|
36
|
+
getEnumeratorByName(name: string): AnyEnumerator | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Gets an enumerator that matches the value provided.
|
|
39
|
+
* @param value The value of the Enumerator to find.
|
|
40
|
+
*/
|
|
41
|
+
getEnumerator(value: string): Enumerator<string> | undefined;
|
|
42
|
+
getEnumerator(value: number): Enumerator<number> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether there already exists an enumerator with this name or this value
|
|
45
|
+
* @param name The name of the enumerator we are trying to create
|
|
46
|
+
* @param value The value of the enumerator we are trying to create
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
private findDuplicateEnumerators;
|
|
50
|
+
/**
|
|
51
|
+
* Creates an Enumerator with the provided name and value as well as optional parameters label and description
|
|
52
|
+
* @param name The name of the enumerator
|
|
53
|
+
* @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
|
|
54
|
+
* @param label A localized display label that is used instead of the name in a GUI.
|
|
55
|
+
* @param description A localized description for the enumerator.
|
|
56
|
+
* @return AnyEnumerator object
|
|
57
|
+
*/
|
|
58
|
+
createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator;
|
|
59
|
+
/**
|
|
60
|
+
* Adds enumerator to list of enumerators on this Enumeration
|
|
61
|
+
* @param enumerator The enumerator to add
|
|
62
|
+
*/
|
|
63
|
+
protected addEnumerator(enumerator: AnyEnumerator): void;
|
|
64
|
+
/**
|
|
65
|
+
* Save this Enumeration's properties to an object for serializing to JSON.
|
|
66
|
+
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
67
|
+
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
68
|
+
*/
|
|
69
|
+
toJSON(standalone?: boolean, includeSchemaVersion?: boolean): EnumerationProps;
|
|
70
|
+
/** @internal */
|
|
71
|
+
toXml(schemaXml: Document): Promise<Element>;
|
|
72
|
+
fromJSONSync(enumerationProps: EnumerationProps): void;
|
|
73
|
+
fromJSON(enumerationProps: EnumerationProps): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* @alpha Used in schema editing.
|
|
76
|
+
*/
|
|
77
|
+
protected setIsStrict(isStrict: boolean): void;
|
|
78
|
+
}
|
|
79
|
+
/** @internal
|
|
80
|
+
* An abstract class used for schema editing.
|
|
81
|
+
*/
|
|
82
|
+
export declare abstract class MutableEnumeration extends Enumeration {
|
|
83
|
+
abstract addEnumerator(enumerator: AnyEnumerator): void;
|
|
84
|
+
abstract setIsStrict(isStrict: boolean): void;
|
|
85
|
+
abstract setDisplayLabel(displayLabel: string): void;
|
|
86
|
+
}
|
|
87
87
|
//# sourceMappingURL=Enumeration.d.ts.map
|
|
@@ -1,160 +1,160 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module Metadata
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.MutableEnumeration = exports.Enumeration = void 0;
|
|
11
|
-
const ECObjects_1 = require("../ECObjects");
|
|
12
|
-
const Exception_1 = require("../Exception");
|
|
13
|
-
const ECName_1 = require("../ECName");
|
|
14
|
-
const SchemaItem_1 = require("./SchemaItem");
|
|
15
|
-
/**
|
|
16
|
-
* A Typescript class representation of an ECEnumeration.
|
|
17
|
-
* @beta
|
|
18
|
-
*/
|
|
19
|
-
class Enumeration extends SchemaItem_1.SchemaItem {
|
|
20
|
-
constructor(schema, name, primitiveType) {
|
|
21
|
-
super(schema, name);
|
|
22
|
-
this.schemaItemType = ECObjects_1.SchemaItemType.Enumeration;
|
|
23
|
-
this._type = primitiveType;
|
|
24
|
-
this._isStrict = true;
|
|
25
|
-
this._enumerators = [];
|
|
26
|
-
}
|
|
27
|
-
get enumerators() { return this._enumerators; }
|
|
28
|
-
get type() { return this._type; }
|
|
29
|
-
get isStrict() { return this._isStrict; }
|
|
30
|
-
get isInt() { return this._type === ECObjects_1.PrimitiveType.Integer; }
|
|
31
|
-
get isString() { return this._type === ECObjects_1.PrimitiveType.String; }
|
|
32
|
-
/**
|
|
33
|
-
* Gets an enumerator that matches the name provided.
|
|
34
|
-
* @param name The ECName of the Enumerator to find.
|
|
35
|
-
*/
|
|
36
|
-
getEnumeratorByName(name) {
|
|
37
|
-
return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());
|
|
38
|
-
}
|
|
39
|
-
getEnumerator(value) {
|
|
40
|
-
return this.enumerators.find((item) => item.value === value);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Checks whether there already exists an enumerator with this name or this value
|
|
44
|
-
* @param name The name of the enumerator we are trying to create
|
|
45
|
-
* @param value The value of the enumerator we are trying to create
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
findDuplicateEnumerators(name, value) {
|
|
49
|
-
this._enumerators.forEach((element) => {
|
|
50
|
-
if (element.name.toLowerCase() === name.toLowerCase())
|
|
51
|
-
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
|
|
52
|
-
if (element.value === value)
|
|
53
|
-
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Creates an Enumerator with the provided name and value as well as optional parameters label and description
|
|
58
|
-
* @param name The name of the enumerator
|
|
59
|
-
* @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
|
|
60
|
-
* @param label A localized display label that is used instead of the name in a GUI.
|
|
61
|
-
* @param description A localized description for the enumerator.
|
|
62
|
-
* @return AnyEnumerator object
|
|
63
|
-
*/
|
|
64
|
-
createEnumerator(name, value, label, description) {
|
|
65
|
-
if (this.isInt && typeof (value) === "string") // throws if backing type is int and value is string
|
|
66
|
-
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
|
|
67
|
-
if (!this.isInt && typeof (value) === "number") // also throws if backing type is string and value is number
|
|
68
|
-
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
|
|
69
|
-
this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any
|
|
70
|
-
if (!ECName_1.ECName.validate(name))
|
|
71
|
-
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
|
|
72
|
-
return { name, value, label, description };
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Adds enumerator to list of enumerators on this Enumeration
|
|
76
|
-
* @param enumerator The enumerator to add
|
|
77
|
-
*/
|
|
78
|
-
addEnumerator(enumerator) {
|
|
79
|
-
this.enumerators.push(enumerator);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Save this Enumeration's properties to an object for serializing to JSON.
|
|
83
|
-
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
84
|
-
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
85
|
-
*/
|
|
86
|
-
toJSON(standalone = false, includeSchemaVersion = false) {
|
|
87
|
-
const schemaJson = super.toJSON(standalone, includeSchemaVersion);
|
|
88
|
-
schemaJson.type = (this.isInt) ? "int" : "string";
|
|
89
|
-
schemaJson.isStrict = this.isStrict;
|
|
90
|
-
schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {
|
|
91
|
-
const enumJson = { name, value };
|
|
92
|
-
if (undefined !== label)
|
|
93
|
-
enumJson.label = label;
|
|
94
|
-
if (undefined !== description)
|
|
95
|
-
enumJson.description = description;
|
|
96
|
-
return enumJson;
|
|
97
|
-
});
|
|
98
|
-
return schemaJson;
|
|
99
|
-
}
|
|
100
|
-
/** @internal */
|
|
101
|
-
async toXml(schemaXml) {
|
|
102
|
-
const itemElement = await super.toXml(schemaXml);
|
|
103
|
-
if (undefined !== this.type)
|
|
104
|
-
itemElement.setAttribute("backingTypeName", (0, ECObjects_1.primitiveTypeToString)(this.type));
|
|
105
|
-
itemElement.setAttribute("isStrict", String(this.isStrict));
|
|
106
|
-
for (const enumerator of this.enumerators) {
|
|
107
|
-
const enumElement = schemaXml.createElement("ECEnumerator");
|
|
108
|
-
enumElement.setAttribute("name", enumerator.name);
|
|
109
|
-
const enumValue = typeof enumerator.value === "string" ? enumerator.value : enumerator.value.toString();
|
|
110
|
-
enumElement.setAttribute("value", enumValue);
|
|
111
|
-
if (undefined !== enumerator.label)
|
|
112
|
-
enumElement.setAttribute("displayLabel", enumerator.label);
|
|
113
|
-
if (undefined !== enumerator.description)
|
|
114
|
-
enumElement.setAttribute("description", enumerator.description);
|
|
115
|
-
itemElement.appendChild(enumElement);
|
|
116
|
-
}
|
|
117
|
-
return itemElement;
|
|
118
|
-
}
|
|
119
|
-
fromJSONSync(enumerationProps) {
|
|
120
|
-
super.fromJSONSync(enumerationProps);
|
|
121
|
-
if (undefined === this._type) {
|
|
122
|
-
if (/int/i.test(enumerationProps.type))
|
|
123
|
-
this._type = ECObjects_1.PrimitiveType.Integer;
|
|
124
|
-
else if (/string/i.test(enumerationProps.type))
|
|
125
|
-
this._type = ECObjects_1.PrimitiveType.String;
|
|
126
|
-
else
|
|
127
|
-
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;
|
|
131
|
-
if (!primitiveTypePattern.test(enumerationProps.type))
|
|
132
|
-
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be "${(this.isInt) ? "int" : "string"}", not "${(this.isInt) ? "string" : "int"}".`);
|
|
133
|
-
}
|
|
134
|
-
this._isStrict = enumerationProps.isStrict;
|
|
135
|
-
if (undefined !== enumerationProps.enumerators) {
|
|
136
|
-
enumerationProps.enumerators.forEach((enumerator) => {
|
|
137
|
-
// Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.
|
|
138
|
-
// Throws ECObjectsError if there are duplicate names or values present in the enumeration
|
|
139
|
-
this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async fromJSON(enumerationProps) {
|
|
144
|
-
this.fromJSONSync(enumerationProps);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* @alpha Used in schema editing.
|
|
148
|
-
*/
|
|
149
|
-
setIsStrict(isStrict) {
|
|
150
|
-
this._isStrict = isStrict;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.Enumeration = Enumeration;
|
|
154
|
-
/** @internal
|
|
155
|
-
* An abstract class used for schema editing.
|
|
156
|
-
*/
|
|
157
|
-
class MutableEnumeration extends Enumeration {
|
|
158
|
-
}
|
|
159
|
-
exports.MutableEnumeration = MutableEnumeration;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Metadata
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MutableEnumeration = exports.Enumeration = void 0;
|
|
11
|
+
const ECObjects_1 = require("../ECObjects");
|
|
12
|
+
const Exception_1 = require("../Exception");
|
|
13
|
+
const ECName_1 = require("../ECName");
|
|
14
|
+
const SchemaItem_1 = require("./SchemaItem");
|
|
15
|
+
/**
|
|
16
|
+
* A Typescript class representation of an ECEnumeration.
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
class Enumeration extends SchemaItem_1.SchemaItem {
|
|
20
|
+
constructor(schema, name, primitiveType) {
|
|
21
|
+
super(schema, name);
|
|
22
|
+
this.schemaItemType = ECObjects_1.SchemaItemType.Enumeration;
|
|
23
|
+
this._type = primitiveType;
|
|
24
|
+
this._isStrict = true;
|
|
25
|
+
this._enumerators = [];
|
|
26
|
+
}
|
|
27
|
+
get enumerators() { return this._enumerators; }
|
|
28
|
+
get type() { return this._type; }
|
|
29
|
+
get isStrict() { return this._isStrict; }
|
|
30
|
+
get isInt() { return this._type === ECObjects_1.PrimitiveType.Integer; }
|
|
31
|
+
get isString() { return this._type === ECObjects_1.PrimitiveType.String; }
|
|
32
|
+
/**
|
|
33
|
+
* Gets an enumerator that matches the name provided.
|
|
34
|
+
* @param name The ECName of the Enumerator to find.
|
|
35
|
+
*/
|
|
36
|
+
getEnumeratorByName(name) {
|
|
37
|
+
return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
getEnumerator(value) {
|
|
40
|
+
return this.enumerators.find((item) => item.value === value);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks whether there already exists an enumerator with this name or this value
|
|
44
|
+
* @param name The name of the enumerator we are trying to create
|
|
45
|
+
* @param value The value of the enumerator we are trying to create
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
findDuplicateEnumerators(name, value) {
|
|
49
|
+
this._enumerators.forEach((element) => {
|
|
50
|
+
if (element.name.toLowerCase() === name.toLowerCase())
|
|
51
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
|
|
52
|
+
if (element.value === value)
|
|
53
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates an Enumerator with the provided name and value as well as optional parameters label and description
|
|
58
|
+
* @param name The name of the enumerator
|
|
59
|
+
* @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
|
|
60
|
+
* @param label A localized display label that is used instead of the name in a GUI.
|
|
61
|
+
* @param description A localized description for the enumerator.
|
|
62
|
+
* @return AnyEnumerator object
|
|
63
|
+
*/
|
|
64
|
+
createEnumerator(name, value, label, description) {
|
|
65
|
+
if (this.isInt && typeof (value) === "string") // throws if backing type is int and value is string
|
|
66
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
|
|
67
|
+
if (!this.isInt && typeof (value) === "number") // also throws if backing type is string and value is number
|
|
68
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
|
|
69
|
+
this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any
|
|
70
|
+
if (!ECName_1.ECName.validate(name))
|
|
71
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
|
|
72
|
+
return { name, value, label, description };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Adds enumerator to list of enumerators on this Enumeration
|
|
76
|
+
* @param enumerator The enumerator to add
|
|
77
|
+
*/
|
|
78
|
+
addEnumerator(enumerator) {
|
|
79
|
+
this.enumerators.push(enumerator);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Save this Enumeration's properties to an object for serializing to JSON.
|
|
83
|
+
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
84
|
+
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
|
|
85
|
+
*/
|
|
86
|
+
toJSON(standalone = false, includeSchemaVersion = false) {
|
|
87
|
+
const schemaJson = super.toJSON(standalone, includeSchemaVersion);
|
|
88
|
+
schemaJson.type = (this.isInt) ? "int" : "string";
|
|
89
|
+
schemaJson.isStrict = this.isStrict;
|
|
90
|
+
schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {
|
|
91
|
+
const enumJson = { name, value };
|
|
92
|
+
if (undefined !== label)
|
|
93
|
+
enumJson.label = label;
|
|
94
|
+
if (undefined !== description)
|
|
95
|
+
enumJson.description = description;
|
|
96
|
+
return enumJson;
|
|
97
|
+
});
|
|
98
|
+
return schemaJson;
|
|
99
|
+
}
|
|
100
|
+
/** @internal */
|
|
101
|
+
async toXml(schemaXml) {
|
|
102
|
+
const itemElement = await super.toXml(schemaXml);
|
|
103
|
+
if (undefined !== this.type)
|
|
104
|
+
itemElement.setAttribute("backingTypeName", (0, ECObjects_1.primitiveTypeToString)(this.type));
|
|
105
|
+
itemElement.setAttribute("isStrict", String(this.isStrict));
|
|
106
|
+
for (const enumerator of this.enumerators) {
|
|
107
|
+
const enumElement = schemaXml.createElement("ECEnumerator");
|
|
108
|
+
enumElement.setAttribute("name", enumerator.name);
|
|
109
|
+
const enumValue = typeof enumerator.value === "string" ? enumerator.value : enumerator.value.toString();
|
|
110
|
+
enumElement.setAttribute("value", enumValue);
|
|
111
|
+
if (undefined !== enumerator.label)
|
|
112
|
+
enumElement.setAttribute("displayLabel", enumerator.label);
|
|
113
|
+
if (undefined !== enumerator.description)
|
|
114
|
+
enumElement.setAttribute("description", enumerator.description);
|
|
115
|
+
itemElement.appendChild(enumElement);
|
|
116
|
+
}
|
|
117
|
+
return itemElement;
|
|
118
|
+
}
|
|
119
|
+
fromJSONSync(enumerationProps) {
|
|
120
|
+
super.fromJSONSync(enumerationProps);
|
|
121
|
+
if (undefined === this._type) {
|
|
122
|
+
if (/int/i.test(enumerationProps.type))
|
|
123
|
+
this._type = ECObjects_1.PrimitiveType.Integer;
|
|
124
|
+
else if (/string/i.test(enumerationProps.type))
|
|
125
|
+
this._type = ECObjects_1.PrimitiveType.String;
|
|
126
|
+
else
|
|
127
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;
|
|
131
|
+
if (!primitiveTypePattern.test(enumerationProps.type))
|
|
132
|
+
throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be "${(this.isInt) ? "int" : "string"}", not "${(this.isInt) ? "string" : "int"}".`);
|
|
133
|
+
}
|
|
134
|
+
this._isStrict = enumerationProps.isStrict;
|
|
135
|
+
if (undefined !== enumerationProps.enumerators) {
|
|
136
|
+
enumerationProps.enumerators.forEach((enumerator) => {
|
|
137
|
+
// Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.
|
|
138
|
+
// Throws ECObjectsError if there are duplicate names or values present in the enumeration
|
|
139
|
+
this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async fromJSON(enumerationProps) {
|
|
144
|
+
this.fromJSONSync(enumerationProps);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @alpha Used in schema editing.
|
|
148
|
+
*/
|
|
149
|
+
setIsStrict(isStrict) {
|
|
150
|
+
this._isStrict = isStrict;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.Enumeration = Enumeration;
|
|
154
|
+
/** @internal
|
|
155
|
+
* An abstract class used for schema editing.
|
|
156
|
+
*/
|
|
157
|
+
class MutableEnumeration extends Enumeration {
|
|
158
|
+
}
|
|
159
|
+
exports.MutableEnumeration = MutableEnumeration;
|
|
160
160
|
//# sourceMappingURL=Enumeration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,4CAAoF;AACpF,4CAA+D;AAC/D,sCAAmC;AAEnC,6CAA0C;AAa1C;;;GAGG;AACH,MAAa,WAAY,SAAQ,uBAAU;IAUzC,YAAY,MAAc,EAAE,IAAY,EAAE,aAA4D;QACpG,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,WAAW,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAVD,IAAW,WAAW,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAUhD,IAAW,KAAK,KAAc,OAAO,IAAI,CAAC,KAAK,KAAK,yBAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5E,IAAW,QAAQ,KAAc,OAAO,IAAI,CAAC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AC,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;YACzH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,gBAAkC;QAC/D,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,WAAW,CAAC,QAAiB;QACrC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;CAEF;AA/JD,kCA+JC;AAED;;GAEG;AACH,MAAsB,kBAAmB,SAAQ,WAAW;CAI3D;AAJD,gDAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\r\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { ECName } from \"../ECName\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\n\r\n/** @beta */\r\nexport interface Enumerator<T> {\r\n readonly name: string;\r\n readonly value: T;\r\n readonly label?: string;\r\n readonly description?: string;\r\n}\r\n\r\n/** @beta */\r\nexport type AnyEnumerator = Enumerator<string | number>;\r\n\r\n/**\r\n * A Typescript class representation of an ECEnumeration.\r\n * @beta\r\n */\r\nexport class Enumeration extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Enumeration; // eslint-disable-line\r\n protected _type?: PrimitiveType.Integer | PrimitiveType.String;\r\n protected _isStrict: boolean;\r\n protected _enumerators: AnyEnumerator[];\r\n\r\n public get enumerators() { return this._enumerators; }\r\n public get type() { return this._type; }\r\n public get isStrict() { return this._isStrict; }\r\n\r\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Enumeration;\r\n this._type = primitiveType;\r\n this._isStrict = true;\r\n this._enumerators = [];\r\n }\r\n\r\n public get isInt(): boolean { return this._type === PrimitiveType.Integer; }\r\n public get isString(): boolean { return this._type === PrimitiveType.String; }\r\n\r\n /**\r\n * Gets an enumerator that matches the name provided.\r\n * @param name The ECName of the Enumerator to find.\r\n */\r\n public getEnumeratorByName(name: string): AnyEnumerator | undefined {\r\n return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());\r\n }\r\n\r\n /**\r\n * Gets an enumerator that matches the value provided.\r\n * @param value The value of the Enumerator to find.\r\n */\r\n public getEnumerator(value: string): Enumerator<string> | undefined;\r\n public getEnumerator(value: number): Enumerator<number> | undefined;\r\n public getEnumerator(value: string | number): AnyEnumerator | undefined {\r\n return this.enumerators.find((item) => item.value === value);\r\n }\r\n\r\n /**\r\n * Checks whether there already exists an enumerator with this name or this value\r\n * @param name The name of the enumerator we are trying to create\r\n * @param value The value of the enumerator we are trying to create\r\n * @internal\r\n */\r\n private findDuplicateEnumerators(name: string, value: string | number) {\r\n this._enumerators.forEach((element: AnyEnumerator) => { // Name and value must be unique within the ECEnumerations\r\n if (element.name.toLowerCase() === name.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\r\n if (element.value === value)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);\r\n });\r\n }\r\n\r\n /**\r\n * Creates an Enumerator with the provided name and value as well as optional parameters label and description\r\n * @param name The name of the enumerator\r\n * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.\r\n * @param label A localized display label that is used instead of the name in a GUI.\r\n * @param description A localized description for the enumerator.\r\n * @return AnyEnumerator object\r\n */\r\n public createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator {\r\n if (this.isInt && typeof (value) === \"string\") // throws if backing type is int and value is string\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);\r\n if (!this.isInt && typeof (value) === \"number\") // also throws if backing type is string and value is number\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);\r\n this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any\r\n if (!ECName.validate(name))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);\r\n return { name, value, label, description };\r\n }\r\n\r\n /**\r\n * Adds enumerator to list of enumerators on this Enumeration\r\n * @param enumerator The enumerator to add\r\n */\r\n protected addEnumerator(enumerator: AnyEnumerator) {\r\n this.enumerators.push(enumerator);\r\n }\r\n\r\n /**\r\n * Save this Enumeration's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): EnumerationProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.type = (this.isInt) ? \"int\" : \"string\";\r\n schemaJson.isStrict = this.isStrict;\r\n schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {\r\n const enumJson: any = { name, value };\r\n if (undefined !== label)\r\n enumJson.label = label;\r\n if (undefined !== description)\r\n enumJson.description = description;\r\n return enumJson;\r\n });\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n if (undefined !== this.type)\r\n itemElement.setAttribute(\"backingTypeName\", primitiveTypeToString(this.type));\r\n itemElement.setAttribute(\"isStrict\", String(this.isStrict));\r\n\r\n for (const enumerator of this.enumerators) {\r\n const enumElement = schemaXml.createElement(\"ECEnumerator\");\r\n enumElement.setAttribute(\"name\", enumerator.name);\r\n const enumValue = typeof enumerator.value === \"string\" ? enumerator.value : enumerator.value.toString();\r\n enumElement.setAttribute(\"value\", enumValue);\r\n if (undefined !== enumerator.label)\r\n enumElement.setAttribute(\"displayLabel\", enumerator.label);\r\n if (undefined !== enumerator.description)\r\n enumElement.setAttribute(\"description\", enumerator.description);\r\n itemElement.appendChild(enumElement);\r\n }\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(enumerationProps: EnumerationProps) {\r\n super.fromJSONSync(enumerationProps);\r\n if (undefined === this._type) {\r\n if (/int/i.test(enumerationProps.type))\r\n this._type = PrimitiveType.Integer;\r\n else if (/string/i.test(enumerationProps.type))\r\n this._type = PrimitiveType.String;\r\n else\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\r\n } else {\r\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\r\n if (!primitiveTypePattern.test(enumerationProps.type))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be \"${(this.isInt) ? \"int\" : \"string\"}\", not \"${(this.isInt) ? \"string\" : \"int\"}\".`);\r\n }\r\n this._isStrict = enumerationProps.isStrict;\r\n\r\n if (undefined !== enumerationProps.enumerators) {\r\n enumerationProps.enumerators.forEach((enumerator: EnumeratorProps) => {\r\n // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.\r\n // Throws ECObjectsError if there are duplicate names or values present in the enumeration\r\n this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));\r\n });\r\n }\r\n }\r\n\r\n public override async fromJSON(enumerationProps: EnumerationProps) {\r\n this.fromJSONSync(enumerationProps);\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setIsStrict(isStrict: boolean) {\r\n this._isStrict = isStrict;\r\n }\r\n\r\n}\r\n\r\n/** @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableEnumeration extends Enumeration {\r\n public abstract override addEnumerator(enumerator: AnyEnumerator): void;\r\n public abstract override setIsStrict(isStrict: boolean): void;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,4CAAoF;AACpF,4CAA+D;AAC/D,sCAAmC;AAEnC,6CAA0C;AAa1C;;;GAGG;AACH,MAAa,WAAY,SAAQ,uBAAU;IAUzC,YAAY,MAAc,EAAE,IAAY,EAAE,aAA4D;QACpG,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,WAAW,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAVD,IAAW,WAAW,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAUhD,IAAW,KAAK,KAAc,OAAO,IAAI,CAAC,KAAK,KAAK,yBAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5E,IAAW,QAAQ,KAAc,OAAO,IAAI,CAAC,KAAK,KAAK,yBAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9E;;;OAG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UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;YACzH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,gBAAkC;QAC/D,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,WAAW,CAAC,QAAiB;QACrC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;CAEF;AA/JD,kCA+JC;AAED;;GAEG;AACH,MAAsB,kBAAmB,SAAQ,WAAW;CAI3D;AAJD,gDAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Metadata\n */\n\nimport { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { ECName } from \"../ECName\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\n\n/** @beta */\nexport interface Enumerator<T> {\n readonly name: string;\n readonly value: T;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** @beta */\nexport type AnyEnumerator = Enumerator<string | number>;\n\n/**\n * A Typescript class representation of an ECEnumeration.\n * @beta\n */\nexport class Enumeration extends SchemaItem {\n public override readonly schemaItemType!: SchemaItemType.Enumeration; // eslint-disable-line\n protected _type?: PrimitiveType.Integer | PrimitiveType.String;\n protected _isStrict: boolean;\n protected _enumerators: AnyEnumerator[];\n\n public get enumerators() { return this._enumerators; }\n public get type() { return this._type; }\n public get isStrict() { return this._isStrict; }\n\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\n super(schema, name);\n this.schemaItemType = SchemaItemType.Enumeration;\n this._type = primitiveType;\n this._isStrict = true;\n this._enumerators = [];\n }\n\n public get isInt(): boolean { return this._type === PrimitiveType.Integer; }\n public get isString(): boolean { return this._type === PrimitiveType.String; }\n\n /**\n * Gets an enumerator that matches the name provided.\n * @param name The ECName of the Enumerator to find.\n */\n public getEnumeratorByName(name: string): AnyEnumerator | undefined {\n return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());\n }\n\n /**\n * Gets an enumerator that matches the value provided.\n * @param value The value of the Enumerator to find.\n */\n public getEnumerator(value: string): Enumerator<string> | undefined;\n public getEnumerator(value: number): Enumerator<number> | undefined;\n public getEnumerator(value: string | number): AnyEnumerator | undefined {\n return this.enumerators.find((item) => item.value === value);\n }\n\n /**\n * Checks whether there already exists an enumerator with this name or this value\n * @param name The name of the enumerator we are trying to create\n * @param value The value of the enumerator we are trying to create\n * @internal\n */\n private findDuplicateEnumerators(name: string, value: string | number) {\n this._enumerators.forEach((element: AnyEnumerator) => { // Name and value must be unique within the ECEnumerations\n if (element.name.toLowerCase() === name.toLowerCase())\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\n if (element.value === value)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);\n });\n }\n\n /**\n * Creates an Enumerator with the provided name and value as well as optional parameters label and description\n * @param name The name of the enumerator\n * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.\n * @param label A localized display label that is used instead of the name in a GUI.\n * @param description A localized description for the enumerator.\n * @return AnyEnumerator object\n */\n public createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator {\n if (this.isInt && typeof (value) === \"string\") // throws if backing type is int and value is string\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);\n if (!this.isInt && typeof (value) === \"number\") // also throws if backing type is string and value is number\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);\n this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any\n if (!ECName.validate(name))\n throw new ECObjectsError(ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);\n return { name, value, label, description };\n }\n\n /**\n * Adds enumerator to list of enumerators on this Enumeration\n * @param enumerator The enumerator to add\n */\n protected addEnumerator(enumerator: AnyEnumerator) {\n this.enumerators.push(enumerator);\n }\n\n /**\n * Save this Enumeration's properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): EnumerationProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.type = (this.isInt) ? \"int\" : \"string\";\n schemaJson.isStrict = this.isStrict;\n schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {\n const enumJson: any = { name, value };\n if (undefined !== label)\n enumJson.label = label;\n if (undefined !== description)\n enumJson.description = description;\n return enumJson;\n });\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n if (undefined !== this.type)\n itemElement.setAttribute(\"backingTypeName\", primitiveTypeToString(this.type));\n itemElement.setAttribute(\"isStrict\", String(this.isStrict));\n\n for (const enumerator of this.enumerators) {\n const enumElement = schemaXml.createElement(\"ECEnumerator\");\n enumElement.setAttribute(\"name\", enumerator.name);\n const enumValue = typeof enumerator.value === \"string\" ? enumerator.value : enumerator.value.toString();\n enumElement.setAttribute(\"value\", enumValue);\n if (undefined !== enumerator.label)\n enumElement.setAttribute(\"displayLabel\", enumerator.label);\n if (undefined !== enumerator.description)\n enumElement.setAttribute(\"description\", enumerator.description);\n itemElement.appendChild(enumElement);\n }\n\n return itemElement;\n }\n\n public override fromJSONSync(enumerationProps: EnumerationProps) {\n super.fromJSONSync(enumerationProps);\n if (undefined === this._type) {\n if (/int/i.test(enumerationProps.type))\n this._type = PrimitiveType.Integer;\n else if (/string/i.test(enumerationProps.type))\n this._type = PrimitiveType.String;\n else\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\n } else {\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\n if (!primitiveTypePattern.test(enumerationProps.type))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be \"${(this.isInt) ? \"int\" : \"string\"}\", not \"${(this.isInt) ? \"string\" : \"int\"}\".`);\n }\n this._isStrict = enumerationProps.isStrict;\n\n if (undefined !== enumerationProps.enumerators) {\n enumerationProps.enumerators.forEach((enumerator: EnumeratorProps) => {\n // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.\n // Throws ECObjectsError if there are duplicate names or values present in the enumeration\n this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));\n });\n }\n }\n\n public override async fromJSON(enumerationProps: EnumerationProps) {\n this.fromJSONSync(enumerationProps);\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setIsStrict(isStrict: boolean) {\n this._isStrict = isStrict;\n }\n\n}\n\n/** @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableEnumeration extends Enumeration {\n public abstract override addEnumerator(enumerator: AnyEnumerator): void;\n public abstract override setIsStrict(isStrict: boolean): void;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
|