/
Utils.ts
85 lines (77 loc) · 2.37 KB
/
Utils.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
/*---------------------------------------------------------------------------------------------
* 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 { NodeKey } from "./hierarchy/Key";
import { KeySet } from "./KeySet";
/**
* Create a type with `T` properties excluding properties listed in `K`.
*
* Usage example: `Omit<SomeType, "exclude_prop1" | "exclude_prop2">`
*
* @public
*/
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
/**
* Create a type with `T` properties excluding all properties in type `K`.
*
* Usage example: `Subtract<SomeType, ExcludePropertiesInThisType>`
*
* @public
*/
export type Subtract<T, K> = Omit<T, keyof K>;
/**
* Create a type from given type `T` and make specified properties optional.
* @public
*/
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
/**
* A dictionary data structure.
* @public
*/
export interface ValuesDictionary<T> {
[key: string]: T;
}
/**
* A structure for paged responses
* @public
*/
export interface PagedResponse<T> {
/** Total number of items */
total: number;
/** Items for the requested page */
items: T[];
}
/**
* Get total number of instances included in the supplied key set. The
* count is calculated by adding all of the following:
* - `keys.instanceKeysCount`
* - number of `keys.nodeKeys` which are *ECInstance* keys
* - for every grouping node key in `keys.nodeKeys`, number of grouped instances
*
* E.g. if `keys` contains one instance key, one *ECInstance* node key
* and one grouping node key which groups 3 instances, the result is 5.
*
* @public
*/
export const getInstancesCount = (keys: Readonly<KeySet>): number => {
let count = keys.instanceKeysCount;
keys.nodeKeys.forEach((key: NodeKey) => {
if (NodeKey.isInstancesNodeKey(key)) {
count += key.instanceKeys.length;
} else if (NodeKey.isGroupingNodeKey(key)) {
count += key.groupedInstancesCount;
}
});
return count;
};
/**
* Default (recommended) keyset batch size for cases when it needs to be sent
* over HTTP. Sending keys in batches helps avoid HTTP413 error.
*
* @public
*/
export const DEFAULT_KEYS_BATCH_SIZE = 5000;