forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.d.ts
349 lines (267 loc) · 6.69 KB
/
rest.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
// Type definitions for rest.js v1.2.0
// Project: https://github.com/cujojs/rest
// Definitions by: Wim Looman <https://github.com/Nemo157>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../when/when.d.ts" />
declare module "rest" {
import when = require("when");
export = rest;
function rest(path: string): rest.ResponsePromise;
function rest(request: rest.Request): rest.ResponsePromise;
module rest {
export function setDefaultClient(client: Client): void;
export function getDefaultClient(): Client;
export function resetDefaultClient(): void;
export function wrap<T>(interceptor: Interceptor<T>, config?: T): Client;
export interface Request {
method?: string;
path?: string;
params?: any;
headers?: any;
entity?: any;
}
export interface Status {
code: number;
text?: string;
}
export interface Headers {
[index: string]: any // string or string[]
}
export interface Response {
request: Request;
raw: any;
status: Status;
headers: Headers;
entity: any;
}
export interface ResponsePromise extends when.Promise<Response> {
entity(): when.Promise<any>;
status(): when.Promise<number>;
headers(): when.Promise<Headers>;
header(headerName: string): when.Promise<any>; // string or string[]
}
export interface Interceptor<T> {
(parent?: Client, config?: T): Client;
}
export interface Client {
(path: string): ResponsePromise;
(request: Request): ResponsePromise;
skip(): Client;
wrap<T>(interceptor: Interceptor<T>, config?: T): Client;
}
export interface Meta {
client: Client;
arguments: any;
}
}
}
declare module "rest/interceptor" {
import when = require("when");
import rest = require("rest");
function interceptor<T, U>(config: interceptor.Config<T, U>): rest.Interceptor<T>;
module interceptor {
interface Config<T, U> {
init?: (config: T) => U;
request?: (request: rest.Request, config: U, meta: rest.Meta) => rest.Request | when.Promise<rest.Request>;
response?: (response: rest.Response, config: U, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
success?: (response: rest.Response, config: U, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
error?: (response: rest.Response, config: U, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
}
}
export = interceptor;
}
declare module "rest/interceptor/defaultRequest" {
import rest = require("rest");
var defaultRequest: rest.Interceptor<defaultRequest.Config>;
module defaultRequest {
interface Config {
method?: string;
path?: string;
params?: any;
headers?: any;
entity?: any;
mixin?: any;
}
}
export = defaultRequest;
}
declare module "rest/interceptor/hateoas" {
import rest = require("rest");
var hateoas: rest.Interceptor<hateoas.Config>;
module hateoas {
interface Config {
target?: string;
client?: rest.Client;
}
}
export = hateoas;
}
declare module "rest/interceptor/location" {
import rest = require("rest");
var location: rest.Interceptor<location.Config>;
module location {
interface Config {
client?: rest.Client;
code?: number;
}
}
export = location;
}
declare module "rest/interceptor/mime" {
import rest = require("rest");
import registry = require("rest/mime/registry");
var mime: rest.Interceptor<mime.Config>;
module mime {
interface Config {
mime?: string;
accept?: string;
registry?: registry.Registry;
permissive?: boolean;
}
}
export = mime;
}
declare module "rest/interceptor/pathPrefix" {
import rest = require("rest");
var pathPrefix: rest.Interceptor<pathPrefix.Config>;
module pathPrefix {
interface Config {
prefix?: string;
}
}
export = pathPrefix;
}
declare module "rest/interceptor/basicAuth" {
import rest = require("rest");
var basicAuth: rest.Interceptor<basicAuth.Config>;
module basicAuth {
interface Config {
username?: string;
password?: string;
}
}
export = basicAuth;
}
declare module "rest/interceptor/oAuth" {
import rest = require("rest");
var oAuth: rest.Interceptor<oAuth.Config>;
module oAuth {
interface DismissWindow {
(): void;
}
interface Config {
token?: string;
clientId?: string;
scope?: string;
authorizationUrl?: string;
redirectUrl?: string;
windowStrategy?: (url: string) => DismissWindow;
oAuthCallback?: (hash: string) => void;
oAuthCallbackName?: string;
}
}
export = oAuth;
}
declare module "rest/interceptor/csrf" {
import rest = require("rest");
var csrf: rest.Interceptor<csrf.Config>;
module csrf {
interface Config {
name?: string;
token?: string;
}
}
export = csrf;
}
declare module "rest/interceptor/errorCode" {
import rest = require("rest");
var errorCode: rest.Interceptor<errorCode.Config>;
module errorCode {
interface Config {
code?: number;
}
}
export = errorCode;
}
declare module "rest/interceptor/retry" {
import rest = require("rest");
var retry: rest.Interceptor<retry.Config>;
module retry {
interface Config {
initial?: number;
multiplier?: number;
max?: number;
}
}
export = retry;
}
declare module "rest/interceptor/timeout" {
import rest = require("rest");
var timeout: rest.Interceptor<timeout.Config>;
module timeout {
interface Config {
timeout?: number;
transient?: boolean;
}
}
export = timeout;
}
declare module "rest/interceptor/jsonp" {
import rest = require("rest");
var jsonp: rest.Interceptor<jsonp.Config>;
module jsonp {
interface Config {
callback?: {
param?: string;
prefix?: string;
name?: string;
}
}
}
export = jsonp;
}
declare module "rest/interceptor/ie/xdomain" {
import rest = require("rest");
var xdomain: rest.Interceptor<{}>;
export = xdomain;
}
declare module "rest/interceptor/ie/xhr" {
import rest = require("rest");
var xhr: rest.Interceptor<{}>;
export = xhr;
}
declare module "rest/mime/registry" {
import when = require("when");
var registry: registry.Registry;
module registry {
interface MIMEConverter {
read(value: string): any | when.Promise<any>;
write(value: any): string | when.Promise<string>;
}
interface Registry {
lookup(mimeType: string): when.Promise<MIMEConverter>;
register(mimeType: string, converter: MIMEConverter): void;
}
}
export = registry;
}
declare module "rest/client/xhr" {
import rest = require("rest");
var xhr: rest.Client;
export = xhr;
}
declare module "rest/client/node" {
import rest = require("rest");
var node: rest.Client;
export = node;
}
declare module "rest/client/jsonp" {
import rest = require("rest");
var jsonp: rest.Client;
export = jsonp;
}
declare module "rest/client/xdr" {
import rest = require("rest");
var xdr: rest.Client;
export = xdr;
}