-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpayloads.ts
37 lines (33 loc) · 1.27 KB
/
payloads.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
export type PayloadTime = {
readonly start: number
readonly finish: number
readonly duration: number
readonly processing: number
readonly date_start: string
readonly date_finish: string
}
export type GetPayload<P> = {
readonly result: P
readonly time: PayloadTime
}
export type ListPayload<P> = {
readonly result: readonly P[]
readonly error?: string
readonly total: number
readonly next?: number
readonly time: PayloadTime
}
// `C` stands for a map of names to structural types they will uphold in result
// `[]` in language of ill Bitrix means `undefined`. Just deal with it.
// Also, it will return object if command names specified and array if names are numbers. Deal with it.
export type BatchPayload<C> = {
readonly result: {
readonly result: { readonly [P in keyof C]?: C[P] } | ReadonlyArray<C[keyof C]>
readonly result_error: { readonly [P in keyof C]?: string } | readonly string[]
readonly result_total: { readonly [P in keyof C]?: number } | readonly number[]
readonly result_next: { readonly [P in keyof C]?: number } | readonly number[]
readonly result_time: { readonly [P in keyof C]?: PayloadTime } | readonly PayloadTime[]
}
readonly time: PayloadTime
}
export type Payload<P> = GetPayload<P> | ListPayload<P> | BatchPayload<P>