forked from globus/globus-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
134 lines (129 loc) · 4.48 KB
/
types.ts
File metadata and controls
134 lines (129 loc) · 4.48 KB
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
import { AuthorizationRequirementsError } from '../../core/errors.js';
/**
* @see https://docs.globus.org/api/transfer/overview/#errors
*/
export type ErrorDocument = {
code: string;
message: string;
request_id: string;
resource: string;
/**
* If a Globus Auth policy failure was encountered, and caused the error, this property will be present.
*/
authorization_parameters?: AuthorizationRequirementsError['authorization_parameters'];
};
/**
* @see https://docs.globus.org/api/transfer/overview/#common_query_parameters
*/
export type CommonQueryParameters = {
orderby?: string;
fields?: string;
filter?: string;
};
/**
* Used to define query parameter types for the Transfer service.
* @private **Intended for internal service method definition only.**
*
* @param Parameters The allowed query parameters for the request, `PaginationType` (if no custom parameters are supported), or `undefined` if only the common query parameters are supported.
* @param PaginationType The type of pagination the request uses, if any.
* If not specified, no pagination query parameters will be included.
* @param IncludeCommon Whether to include Transfer common query parameters as allowed query parameters.
* Defaults to `true`, which includes common query parameters.
* Set to `false` to exclude common query parameters.
*
* @example `QueryParameters<'Marker'>` Supports marker pagination query parameters and common query parameters.
* @example `QueryParameters<{ endpoint_id: string }, 'Offset'>` Supports a custom query parameter `endpoint_id`, offset pagination, and common query parameters.
*/
export type QueryParameters<
Parameters extends Record<string, unknown> | keyof Pagination | undefined = Record<
string,
unknown
>,
PaginationType extends keyof Pagination | undefined = undefined,
IncludeCommon extends boolean = true,
> = (Parameters extends keyof Pagination
? Pagination[Parameters] extends { Query: infer Q }
? Q
: {}
: Parameters extends Record<string, unknown>
? Parameters
: {}) &
(PaginationType extends keyof Pagination ? Pagination[PaginationType]['Query'] : {}) &
(IncludeCommon extends true ? CommonQueryParameters : {});
/**
* Add pagination response members to an object; Use for creating paginated responses in the Transfer service.
* @private **Intended for internal service method definition only.**
* @param PaginationType The type of pagination the response uses.
* @param Response The response to extend with the pagination response.
* @example `PaginatedResponse<'Offset', { DATA_TYPE: 'task_list'; tasks: TaskDocument[] }>`
*/
export type PaginatedResponse<Type extends keyof Pagination, Response> = Response &
Pagination[Type]['Response'];
/**
* Pagination used by the Transfer service.
*
* Each pagination definition contains a `Query` and `Response` type.
* - The `Query` type is used to define the query parameters used by the pagination method.
* - The `Response` type is used to define the response properties returned by the pagination method (usually as
* top-level keys in the response body).
*
* Service methods **SHOULD** include the supported pagination members in their query parameters and response types, these
* are just made available as a convenience.
*
* @see https://docs.globus.org/api/transfer/overview/#paging
*/
export type Pagination = {
/**
* @see https://docs.globus.org/api/transfer/overview/#offset_paging
*/
Offset: {
Query: {
limit?: `${number}` | number;
offset?: `${number}` | number;
};
Response: {
limit: number;
offset: number;
has_next_page?: `${boolean}` | boolean;
total?: number;
};
};
/**
* @see https://docs.globus.org/api/transfer/overview/#marker_paging
*/
Marker: {
Query: {
marker?: `${number}` | number;
};
Response: {
marker: number | null;
next_marker: number | null;
};
};
/**
* @see https://docs.globus.org/api/transfer/overview/#last_key_paging
*/
LastKey: {
Query: {
limit?: `${number}` | number;
last_key: string;
};
Response: {
has_next_page: `${boolean}` | boolean;
last_key: string | null;
limit: number;
};
};
/**
* @see https://docs.globus.org/api/transfer/overview/#next_token_paging
*/
NextToken: {
Query: {
next_token?: string;
max_results?: `${number}` | number;
};
Response: {
next_token: string | null;
};
};
};