-
Notifications
You must be signed in to change notification settings - Fork 208
/
PresentationManagerOptions.ts
352 lines (318 loc) · 11.6 KB
/
PresentationManagerOptions.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Core
*/
import { BeEvent, Id64String } from "@itwin/core-bentley";
import { UnitSystemKey } from "@itwin/core-quantity";
import { Descriptor, SelectionInfo } from "./content/Descriptor";
import { FieldDescriptor } from "./content/Fields";
import { InstanceKey } from "./EC";
import { InstanceFilterDefinition } from "./InstanceFilterDefinition";
import { Ruleset } from "./rules/Ruleset";
import { RulesetVariable } from "./RulesetVariables";
import { SelectionScopeProps } from "./selection/SelectionScope";
import { Item } from "./content/Item";
import { ElementProperties } from "./ElementProperties";
/**
* A generic request options type used for both hierarchy and content requests.
* @public
*/
export interface RequestOptions<TIModel> {
/** iModel to request data from */
imodel: TIModel;
/** Optional locale to use when formatting / localizing data */
locale?: string;
/**
* Unit system to use when formatting property values with units. Default presentation
* unit is used if unit system is not specified.
*/
unitSystem?: UnitSystemKey;
/**
* Expected form of response. This property is set automatically on newer frontends.
* `unparsed-json` — deliver response from native addon without parsing it.
* @internal
*/
transport?: "unparsed-json";
}
/**
* Options for requests that require presentation ruleset. Not
* meant to be used directly, see one of the subclasses.
*
* @public
*/
export interface RequestOptionsWithRuleset<TIModel, TRulesetVariable = RulesetVariable> extends RequestOptions<TIModel> {
/** Ruleset or id of the ruleset to use when requesting data */
rulesetOrId: Ruleset | string;
/** Ruleset variables to use when requesting data */
rulesetVariables?: TRulesetVariable[];
}
/**
* Request type for hierarchy requests.
* @public
*/
export interface HierarchyRequestOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {
/** Key of the parent node to get children for */
parentKey?: TNodeKey;
/**
* An instance filter that should be applied for this hierarchy level.
*
* **Note:** May only be used on hierarchy levels that support filtering - check [[NavNode.supportsFiltering]] before
* requesting filtered children.
*
* @beta
*/
instanceFilter?: InstanceFilterDefinition;
/**
* A limit to how many instances at most should be loaded for a hierarchy level. If the limit is exceeded,
* the request fails with [[PresentationError]] having [[PresentationStatus.ResultSetTooLarge]] error number.
*
* Specifying the limit is useful when creating unlimited size result sets is not meaningful - this allows the library
* to return early as soon as the limit is reached, instead of creating a very large result that's possibly too large to
* be useful to be displayed to end users.
*
* @see [Hierarchies' filtering and limiting]($docs/presentation/hierarchies/FilteringLimiting.md)
* @beta
*/
sizeLimit?: number;
}
/**
* Params for hierarchy level descriptor requests.
* @beta
*/
export interface HierarchyLevelDescriptorRequestOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable>
extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {
/** Key of the parent node to get hierarchy level descriptor for. */
parentKey?: TNodeKey;
}
/**
* Request type of filtering hierarchies by given ECInstance paths.
* @public
*/
export interface FilterByInstancePathsHierarchyRequestOptions<TIModel, TRulesetVariable = RulesetVariable>
extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {
/** A list of paths from root ECInstance to target ECInstance. */
instancePaths: InstanceKey[][];
/**
* An optional index (`0 <= markedIndex < instancePaths.length`) to mark one of the instance paths. The
* path is marked using `NodePathElement.isMarked` flag in the result.
*/
markedIndex?: number;
}
/**
* Request type of filtering hierarchies by given text.
* @public
*/
export interface FilterByTextHierarchyRequestOptions<TIModel, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {
/** Text to filter the hierarchy by. */
filterText: string;
}
/**
* Request type for content sources requests.
* @public
*/
export interface ContentSourcesRequestOptions<TIModel> extends RequestOptions<TIModel> {
/** Full names of classes to get content sources for. Format for a full class name: `SchemaName:ClassName`. */
classes: string[];
}
/**
* Request type for content descriptor requests.
* @public
*/
export interface ContentDescriptorRequestOptions<TIModel, TKeySet, TRulesetVariable = RulesetVariable>
extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {
/**
* Content display type.
* @see [[DefaultContentDisplayTypes]]
*/
displayType: string;
/**
* Content flags used for content customization.
* @see [[ContentFlags]]
*/
contentFlags?: number;
/** Input keys for getting the content */
keys: TKeySet;
/** Information about the selection event that was the cause of this content request */
selection?: SelectionInfo;
}
/**
* Request type for content requests.
* @public
*/
export interface ContentRequestOptions<TIModel, TDescriptor, TKeySet, TRulesetVariable = RulesetVariable>
extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {
/** Content descriptor for customizing the returned content */
descriptor: TDescriptor;
/** Input keys for getting the content */
keys: TKeySet;
/**
* Flag that specifies whether value formatting should be emitted or not.
* Content is returned without `displayValues` when this is set to `true`.
* @alpha
*/
omitFormattedValues?: boolean;
}
/**
* Request type for distinct values' requests.
* @public
*/
export interface DistinctValuesRequestOptions<TIModel, TDescriptor, TKeySet, TRulesetVariable = RulesetVariable>
extends Paged<RequestOptionsWithRuleset<TIModel, TRulesetVariable>> {
/** Content descriptor for customizing the returned content */
descriptor: TDescriptor;
/** Input keys for getting the content */
keys: TKeySet;
/** Descriptor for a field distinct values are requested for */
fieldDescriptor: FieldDescriptor;
}
/**
* Request type for element properties requests
* @public
* @deprecated in 4.x. Use [[SingleElementPropertiesRequestOptions]] or [[MultiElementPropertiesRequestOptions]] directly.
*/
export type ElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> =
| SingleElementPropertiesRequestOptions<TIModel>
| MultiElementPropertiesRequestOptions<TIModel, TParsedContent>;
/**
* Request type for single element properties requests.
* @public
*/
export interface SingleElementPropertiesRequestOptions<TIModel> extends RequestOptions<TIModel> {
/** ID of the element to get properties for. */
elementId: Id64String;
}
/**
* Request type for multiple elements properties requests.
* @public
*/
export interface MultiElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> extends RequestOptions<TIModel> {
/**
* Classes of the elements to get properties for. If [[elementClasses]] is `undefined`, all classes
* are used. Classes should be specified in one of these formats: "<schema name or alias>.<class_name>" or
* "<schema name or alias>:<class_name>".
*/
elementClasses?: string[];
/**
* Content parser that creates a result item based on given content descriptor and content item. Defaults
* to a parser that creates [[ElementProperties]] objects.
* @beta
*/
contentParser?: (descriptor: Descriptor, item: Item) => TParsedContent;
/**
* The properties of multiple elements are going to be retrieved and returned in batches. Depending on the batch
* size load on CPU vs MEMORY load may vary, so changing this attribute allows to fine tune the performance.
* Defaults to `1000`.
*/
batchSize?: number;
}
/**
* Request type for content instance keys' requests.
* @public
*/
export interface ContentInstanceKeysRequestOptions<TIModel, TKeySet, TRulesetVariable = RulesetVariable>
extends Paged<RequestOptionsWithRuleset<TIModel, TRulesetVariable>> {
/**
* Content display type.
* @see [[DefaultContentDisplayTypes]]
*/
displayType?: string;
/** Input keys for getting the content. */
keys: TKeySet;
}
/**
* Request type for label requests
* @public
*/
export interface DisplayLabelRequestOptions<TIModel, TInstanceKey> extends RequestOptions<TIModel> {
/** Key of ECInstance to get label for */
key: TInstanceKey;
}
/**
* Request type for labels requests
* @public
*/
export interface DisplayLabelsRequestOptions<TIModel, TInstanceKey> extends RequestOptions<TIModel> {
/** Keys of ECInstances to get labels for */
keys: TInstanceKey[];
}
/**
* Request options used for selection scope related requests
* @public
*/
export interface SelectionScopeRequestOptions<TIModel> extends RequestOptions<TIModel> {} // eslint-disable-line @typescript-eslint/no-empty-interface
/**
* Request options used for calculating selection based on given instance keys and selection scope.
* @public
*/
export interface ComputeSelectionRequestOptions<TIModel> extends RequestOptions<TIModel> {
elementIds: Id64String[];
scope: SelectionScopeProps;
}
/** @internal */
export function isComputeSelectionRequestOptions<TIModel>(
options: ComputeSelectionRequestOptions<TIModel> | SelectionScopeRequestOptions<TIModel>,
): options is ComputeSelectionRequestOptions<TIModel> {
return !!(options as ComputeSelectionRequestOptions<TIModel>).elementIds;
}
/**
* Data structure for comparing a hierarchy after ruleset or ruleset variable changes.
* @public
*/
export interface HierarchyCompareOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {
prev: {
rulesetOrId?: Ruleset | string;
rulesetVariables?: TRulesetVariable[];
};
expandedNodeKeys?: TNodeKey[];
continuationToken?: {
prevHierarchyNode: string;
currHierarchyNode: string;
};
resultSetSize?: number;
}
/**
* Paging options
* @public
*/
export interface PageOptions {
/** Inclusive start 0-based index of the page */
start?: number;
/** Maximum size of the page */
size?: number;
}
/**
* A wrapper type that injects [[PageOptions]] into supplied type
* @public
*/
export type Paged<TOptions extends {}> = TOptions & {
/** Optional paging parameters */
paging?: PageOptions;
};
/**
* A wrapper type that injects priority into supplied type.
* @public
*/
export type Prioritized<TOptions extends {}> = TOptions & {
/** Optional priority */
priority?: number;
};
/**
* Checks if supplied request options are for single or multiple element properties.
* @internal
*/
export function isSingleElementPropertiesRequestOptions<TIModel, TParsedContent = any>(
options: SingleElementPropertiesRequestOptions<TIModel> | MultiElementPropertiesRequestOptions<TIModel, TParsedContent>,
): options is SingleElementPropertiesRequestOptions<TIModel> {
return (options as SingleElementPropertiesRequestOptions<TIModel>).elementId !== undefined;
}
/**
* A wrapper type that injects cancelEvent into supplied type.
* @public
*/
export type WithCancelEvent<TOptions extends {}> = TOptions & {
/** Event which is triggered when the request is canceled */
cancelEvent?: BeEvent<() => void>;
};