-
Notifications
You must be signed in to change notification settings - Fork 25
/
purest.d.ts
439 lines (423 loc) · 8.11 KB
/
purest.d.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
import {
RequestOptions as RequestComposeOptions,
AuthOptions,
ClientResponse,
BufferResponse,
StreamResponse,
} from 'request-compose'
// ----------------------------------------------------------------------------
/**
* Purest instance config
*/
export interface PurestInstanceConfig {
/**
* Purest providers config
*/
config?: PurestConfig
/**
* Provider name
*/
provider?: string
/**
* Instance defaults
*/
defaults?: PurestOptions
/**
* Method aliases
*/
methods?: PurestMethods
}
/**
* Purest config
*/
export interface PurestConfig {
/**
* Provider name
*/
[provider: string]: {
[endpoint: string]: PurestOptions | undefined
} | undefined
}
/**
* Request options
*/
export interface PurestOptions extends RequestComposeOptions {
/**
* Path part to replace the {path} with, or absolute URL
*/
get?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
head?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
post?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
put?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
patch?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
options?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
delete?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
trace?: string
/**
* Path part to replace the {path} with, or absolute URL
*/
connect?: string
/**
* Return the response body as buffer
*/
buffer?: boolean
/**
* Return the response stream
*/
stream?: boolean
/**
* Origin part of the URL
*/
origin?: string
/**
* Path part of the URL; to be used with origin
*/
path?: string
/**
* {subdomain} part of the URL to replace in origin
*/
subdomain?: string
/**
* {version} part of the URL to replace in path
*/
version?: string
/**
* {type} part of the URL to replace in path; usually json or xml
*/
type?: string
/**
* Endpoint name to use
*/
endpoint?: string
/**
* List of values to replace {auth} with, or basic auth
*/
auth?: string | [] | AuthOptions
}
/**
* Method Overrides
*/
export interface PurestMethods {
/**
* get method aliases
*/
get?: string[]
/**
* head method aliases
*/
head?: string[]
/**
* post method aliases
*/
post?: string[]
/**
* put method aliases
*/
put?: string[]
/**
* patch method aliases
*/
patch?: string[]
/**
* options method aliases
*/
options?: string[]
/**
* delete method aliases
*/
delete?: string[]
/**
* trace method aliases
*/
trace?: string[]
/**
* connect method aliases
*/
connect?: string[]
/**
* method method aliases
*/
method?: string[]
/**
* headers method aliases
*/
headers?: string[]
/**
* timeout method aliases
*/
timeout?: string[]
/**
* agent method aliases
*/
agent?: string[]
/**
* url method aliases
*/
url?: string[]
/**
* proxy method aliases
*/
proxy?: string[]
/**
* qs method aliases
*/
qs?: string[]
/**
* form method aliases
*/
form?: string[]
/**
* json method aliases
*/
json?: string[]
/**
* body method aliases
*/
body?: string[]
/**
* multipart method aliases
*/
multipart?: string[]
/**
* oauth method aliases
*/
oauth?: string[]
/**
* encoding method aliases
*/
encoding?: string[]
/**
* redirect method aliases
*/
redirect?: string[]
/**
* request method aliases
*/
request?: string[]
/**
* buffer method aliases
*/
buffer?: string[]
/**
* stream method aliases
*/
stream?: string[]
/**
* origin method aliases
*/
origin?: string[]
/**
* path method aliases
*/
path?: string[]
/**
* subdomain method aliases
*/
subdomain?: string[]
/**
* version method aliases
*/
version?: string[]
/**
* type method aliases
*/
type?: string[]
/**
* endpoint method aliases
*/
endpoint?: string[]
/**
* auth method aliases
*/
auth?: string[]
}
// ----------------------------------------------------------------------------
/**
* Purest request instance
*/
export type PurestRequest = (options: PurestOptions) => Promise<PurestResponse>
/**
* Purest endpoint instance
*/
export type PurestEndpoint = (endpoint?: string) => PurestAPI
/**
* Purest chain instance
*/
export interface PurestAPI {
/**
* Path part to replace the {path} with, or absolute URL
*/
get(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
head(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
post(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
put(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
patch(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
options(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
delete(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
trace(path?: string): PurestAPI
/**
* Path part to replace the {path} with, or absolute URL
*/
connect(path?: string): PurestAPI
/**
* HTTP method name
*/
method(name: string): PurestAPI
/**
* HTTP headers
*/
headers(headers: object): PurestAPI
/**
* Request timeout in milliseconds, defaults to 3000
*/
timeout(timeout: number): PurestAPI
/**
* HTTP agent
*/
agent(agent: object): PurestAPI
/**
* Absolute URL
*/
url(url: string): PurestAPI
/**
* Proxy URL; for HTTP use Agent instead
*/
proxy(proxy: string): PurestAPI
/**
* URL querystring
*/
qs(querystring: object | string): PurestAPI
/**
* application/x-www-form-urlencoded request body
*/
form(form: object | string): PurestAPI
/**
* JSON encoded request body
*/
json(json: object | string): PurestAPI
/**
* Raw request body
*/
body(body: string | Buffer | object): PurestAPI
/**
* multipart/form-data as object or multipart/related as array
*/
multipart(body: object | []): PurestAPI
/**
* OAuth 1.0a authentication
*/
oauth(oauth: object): PurestAPI
/**
* Response encoding
*/
encoding(name: string): PurestAPI
/**
* Redirect options
*/
redirect(options: object): PurestAPI
/**
* Parsed response body
*/
request(options?: PurestOptions): Promise<ClientResponse>
/**
* Response body as buffer
*/
buffer(options?: PurestOptions): Promise<BufferResponse>
/**
* Response stream
*/
stream(options?: PurestOptions): Promise<StreamResponse>
/**
* Origin part of the URL
*/
origin(origin: string): PurestAPI
/**
* Path part of the URL; to be used with origin
*/
path(path: string): PurestAPI
/**
* {subdomain} part of the URL to replace in origin
*/
subdomain(subdomain: string): PurestAPI
/**
* {version} part of the URL to replace in path
*/
version(version: string): PurestAPI
/**
* {type} part of the URL to replace in path; usually json or xml
*/
type(type: string): PurestAPI
/**
* Endpoint name to use
*/
endpoint(name: string): PurestAPI
/**
* List of values to replace {auth} with
*/
auth(...values: string[]): PurestAPI
/**
* Array of values to replace {auth} with
*/
auth(value: string[]): PurestAPI
/**
* Basic auth
*/
auth(basic: {user: string, pass: string}): PurestAPI
}
// ----------------------------------------------------------------------------
/**
* Purest response
*/
export type PurestResponse = ClientResponse & BufferResponse & StreamResponse
// ----------------------------------------------------------------------------
/**
* Purest
*/
declare function purest (config?: PurestInstanceConfig): PurestRequest & PurestEndpoint & PurestAPI
/**
* Purest
*/
declare module purest {}
export default purest