/
LabelDefinition.ts
131 lines (118 loc) · 3.45 KB
/
LabelDefinition.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Hierarchies
*/
/**
* Data structure that describes raw composite label value.
* @public
*/
export interface LabelCompositeValue {
separator: string;
values: LabelDefinition[];
}
/**
* JSON representation of [[LabelCompositeValue]]
* @public
* @deprecated in 3.x. Use [[LabelCompositeValue]].
*/
export interface LabelCompositeValueJSON {
separator: string;
values: LabelDefinition[];
}
/** @public */
export namespace LabelCompositeValue {
/**
* Serialize given [[LabelCompositeValue]] to JSON
* @deprecated in 3.x. Use [[LabelCompositeValue]].
*/
// eslint-disable-next-line deprecation/deprecation
export function toJSON(compositeValue: LabelCompositeValue): LabelCompositeValueJSON {
return { ...compositeValue };
}
/**
* Deserialize [[LabelCompositeValue]] from JSON
* @deprecated in 3.x. Use [[LabelCompositeValue]].
*/
// eslint-disable-next-line deprecation/deprecation
export function fromJSON(json: LabelCompositeValueJSON): LabelCompositeValue {
return { ...json };
}
}
/**
* Type definition of label raw value.
* @public
*/
export type LabelRawValue = string | number | boolean | LabelCompositeValue;
/**
* JSON representation of [[LabelRawValue]]
* @public
* @deprecated in 3.x. Use [[LabelRawValue]].
*/
export type LabelRawValueJSON = LabelRawValue;
/**
* Data structure that describes label definition.
* @public
*/
export interface LabelDefinition {
/** Display value of label */
displayValue: string;
/** Raw value of label */
rawValue: LabelRawValue;
/** Type name of raw value */
typeName: string;
}
/**
* JSON representation of [[LabelDefinition]]
* @public
* @deprecated in 3.x. Use [[LabelDefinition]].
*/
export interface LabelDefinitionJSON {
displayValue: string;
rawValue: LabelRawValue;
typeName: string;
}
/** @public */
export namespace LabelDefinition {
/**
* Serialize given [[LabelDefinition]] to JSON
* @deprecated in 3.x. Use [[LabelDefinition]].
*/
// eslint-disable-next-line deprecation/deprecation
export function toJSON(labelDefinition: LabelDefinition): LabelDefinitionJSON {
return { ...labelDefinition };
}
/**
* Deserialize [[LabelDefinition]] from JSON
* @deprecated in 3.x. Use [[LabelDefinition]].
*/
// eslint-disable-next-line deprecation/deprecation
export function fromJSON(json: LabelDefinitionJSON | string): LabelDefinition {
if (typeof json === "string") {
return JSON.parse(json);
}
return { ...json };
}
/** @internal */
export const COMPOSITE_DEFINITION_TYPENAME = "composite";
/**
* Checks if provided [[LabelDefinition]] has raw value of type [[LabelCompositeValue]].
* @public
*/
export function isCompositeDefinition(def: LabelDefinition): def is LabelDefinition & { rawValue: LabelCompositeValue } {
return def.typeName === COMPOSITE_DEFINITION_TYPENAME;
}
/**
* Creates [[LabelDefinition]] from string value.
* @public
*/
export function fromLabelString(label: string): LabelDefinition {
return {
displayValue: label,
rawValue: label,
typeName: "string",
};
}
}