@autometa/http 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,127 +1,1094 @@
1
- import { Method, ResponseType } from 'axios';
2
1
  import { StatusCodes } from '@autometa/status-codes';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ import { Class } from '@autometa/types';
3
4
 
4
- declare class HTTPResponse<T> {
5
- status: number;
5
+ declare class HTTPResponse<T = unknown> {
6
+ status: StatusCode;
6
7
  statusText: string;
7
8
  data: T;
8
9
  headers: Record<string, string>;
9
- request: {
10
- url: string;
11
- method: Method;
12
- };
13
- static derive<TOriginal, TDerived>(original: HTTPResponse<TOriginal>, data: TDerived): HTTPResponse<TDerived>;
14
- static derive<TOriginal, TDerived>(original: HTTPResponse<TOriginal>, data: (original: TOriginal) => TDerived): HTTPResponse<TDerived>;
10
+ request: HTTPRequest<unknown>;
11
+ constructor();
12
+ static fromRaw<T>(response: HTTPResponse<T>): HTTPResponse<T>;
13
+ /**
14
+ * Decomposes a response, creating an exact copy of the current response,
15
+ * but with a new data value. The data can be provided directly as is, or it
16
+ * can be generated through a callback function which receives the current
17
+ * response data as an argument.
18
+ *
19
+ * ```ts
20
+ * const response = await http.get("/products");
21
+ *
22
+ * // direct value
23
+ * const products = response.data;
24
+ * const firstProduct = response.decompose(products[0]);
25
+ * // callback transformer
26
+ * const secondProduct = response.decompose((products) => products[1]);
27
+ * // callback transformer with destructuring
28
+ * const secondProduct = response.decompose(([product]) => product);
29
+ * ```
30
+ * @param value
31
+ */
32
+ decompose<K>(value: K): HTTPResponse<K>;
33
+ decompose<K>(transformFn: (response: T) => K): HTTPResponse<K>;
15
34
  }
16
- declare class DerivedHTTPResponse<T, K> extends HTTPResponse<T> {
17
- actual: HTTPResponse<K>;
35
+ declare class HTTPResponseBuilder {
36
+ #private;
37
+ static create(): HTTPResponseBuilder;
38
+ derive(): HTTPResponseBuilder;
39
+ status(code: StatusCode): this;
40
+ statusText(text: string): this;
41
+ data<T>(data: T): this;
42
+ headers(dict: Record<string, string>): this;
43
+ header(name: string, value: string): this;
44
+ request(request: HTTPRequest<unknown>): this;
45
+ build(): HTTPResponse<unknown>;
18
46
  }
19
47
 
48
+ type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT" | "get" | "post" | "put" | "delete" | "patch" | "head" | "options" | "trace" | "connect";
49
+ type HTTPAdditionalOptions<T> = {
50
+ [P in keyof T]: T[P];
51
+ };
20
52
  type SchemaParser = {
21
53
  parse: (data: unknown) => unknown;
22
- };
54
+ } | {
55
+ validate: (data: unknown) => unknown;
56
+ } | ((data: unknown) => unknown);
23
57
  type StatusCode<T extends typeof StatusCodes = typeof StatusCodes> = {
24
58
  [P in keyof T]: T[P] extends {
25
59
  status: infer U;
26
60
  } ? U : never;
27
61
  }[keyof T];
28
- type RequestState = {
62
+ type RequestHook = <T = unknown>(state: HTTPRequest<T>) => unknown;
63
+ type ResponseHook<T> = (state: HTTPResponse<T>) => unknown;
64
+
65
+ interface RequestBaseConfig {
66
+ headers?: Record<string, string>;
67
+ params?: Record<string, string | string[] | Record<string, unknown>>;
68
+ baseUrl?: string;
69
+ route?: string[];
70
+ method: HTTPMethod;
71
+ fullUrl(): string;
72
+ }
73
+ interface RequestData<T = unknown> {
74
+ data: T;
75
+ }
76
+ type RequestConfig<T> = RequestBaseConfig & RequestData<T>;
77
+ type RequestConfigBasic = RequestConfig<Record<string, unknown>>;
78
+
79
+ declare class HTTPRequest<T = unknown> implements RequestConfig<T> {
29
80
  headers: Record<string, string>;
30
- params: Record<string, unknown>;
31
- url: string;
81
+ params: Record<string, string | string[] | Record<string, unknown>>;
82
+ baseUrl?: string;
32
83
  route: string[];
33
- responseType: ResponseType | undefined;
34
- data: unknown;
35
- method: Method;
36
- get fullUrl(): string;
37
- };
38
- type RequestHook = (state: RequestState) => unknown;
39
- type ResponseHook<T> = (state: HTTPResponse<T>) => unknown;
84
+ method: HTTPMethod;
85
+ data: T;
86
+ constructor(config?: RequestConfigBasic);
87
+ /**
88
+ * Returns the full URL of the request, including the base url,
89
+ * routes, and query parameters.
90
+ *
91
+ * ```ts
92
+ * console.log(request.fullUrl())// https://example.com/foo?bar=baz?array=1,2,3
93
+ * ```
94
+ *
95
+ * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)
96
+ *
97
+ * N.B this method estimates what the url will be. The actual value
98
+ * might be different depending on your underlying HTTPClient and
99
+ * configuration. For example, query parameters might
100
+ * use different array formats.
101
+ */
102
+ fullUrl(): string;
103
+ /**
104
+ * Returns a new independent copy of the request.
105
+ */
106
+ static derive(original: HTTPRequest<unknown>): HTTPRequest<unknown>;
107
+ }
108
+ declare class HTTPRequestBuilder<T extends HTTPRequest<unknown>> {
109
+ #private;
110
+ constructor(request?: T | (() => T));
111
+ static create<T extends HTTPRequest<unknown>>(): HTTPRequestBuilder<T>;
112
+ get request(): T;
113
+ resolveDynamicHeaders(): this;
114
+ url(url: string): this;
115
+ route(...route: string[]): this;
116
+ param(name: string, value: string | number | boolean | (string | number | boolean)[] | Record<string, string | number | boolean>): this;
117
+ params(dict: Record<string, unknown>): this;
118
+ data<T>(data: T): this;
119
+ header(name: string, value: string | number | boolean | null | (() => string | number | boolean | null)): this;
120
+ headers(dict: Record<string, string>): this;
121
+ get(): T;
122
+ method(method: HTTPMethod): this;
123
+ derive(): HTTPRequestBuilder<T>;
124
+ build(): HTTPRequest<T>;
125
+ }
126
+
127
+ declare let defaultClient: Class<HTTPClient>;
128
+ declare abstract class HTTPClient {
129
+ static Use(): (target: Class<HTTPClient>) => void;
130
+ abstract request<TRequestType, TResponseType>(request: HTTPRequest<TRequestType>, options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
131
+ }
132
+
133
+ declare class AxiosClient extends HTTPClient {
134
+ request<TRequestType, TResponseType>(request: HTTPRequest<TRequestType>, options: HTTPAdditionalOptions<AxiosRequestConfig>): Promise<HTTPResponse<TResponseType>>;
135
+ }
40
136
 
41
137
  declare class SchemaMap {
42
138
  #private;
43
- register(parser: SchemaParser, ...codes: StatusCode[]): (typeof parser)["parse"];
44
- register(parser: SchemaParser, ...range: {
45
- from: StatusCode;
46
- to: StatusCode;
47
- }[]): (typeof parser)["parse"];
48
- register(parser: SchemaParser, ...args: (StatusCode | {
49
- from: StatusCode;
50
- to: StatusCode;
51
- })[]): (typeof parser)["parse"];
52
- registerSingle(parser: SchemaParser, ...codes: StatusCode[]): void;
53
- including(map: SchemaMap): this;
54
- registerRange(parser: SchemaParser, ...range: {
55
- from: StatusCode;
56
- to: StatusCode;
57
- }[]): void;
58
- get(status: StatusCode): SchemaParser | undefined;
59
- validate<T>(status: StatusCode, response: T, strict: boolean): T;
139
+ constructor(map?: Map<StatusCode, SchemaParser> | SchemaMap);
140
+ derive(): SchemaMap;
141
+ registerStatus(parser: SchemaParser, ...codes: StatusCode[]): void;
142
+ registerRange(parser: SchemaParser, from: StatusCode, to: StatusCode): void;
143
+ validate(status: StatusCode, data: unknown, requireSchema: boolean): unknown;
144
+ getParser(status: StatusCode, requireSchema: boolean): SchemaParser;
145
+ toObject(): Record<StatusCode<{
146
+ readonly CONTINUE: {
147
+ readonly status: 100;
148
+ readonly statusText: "Continue";
149
+ };
150
+ readonly SWITCHING_PROTOCOLS: {
151
+ readonly status: 101;
152
+ readonly statusText: "Switching Protocols";
153
+ };
154
+ readonly PROCESSING: {
155
+ readonly status: 102;
156
+ readonly statusText: "Processing";
157
+ };
158
+ readonly OK: {
159
+ readonly status: 200;
160
+ readonly statusText: "OK";
161
+ };
162
+ readonly CREATED: {
163
+ readonly status: 201;
164
+ readonly statusText: "Created";
165
+ };
166
+ readonly ACCEPTED: {
167
+ readonly status: 202;
168
+ readonly statusText: "Accepted";
169
+ };
170
+ readonly NON_AUTHORITATIVE_INFORMATION: {
171
+ readonly status: 203;
172
+ readonly statusText: "Non Authoritative Information";
173
+ };
174
+ readonly NO_CONTENT: {
175
+ readonly status: 204;
176
+ readonly statusText: "No Content";
177
+ };
178
+ readonly RESET_CONTENT: {
179
+ readonly status: 205;
180
+ readonly statusText: "Reset Content";
181
+ };
182
+ readonly PARTIAL_CONTENT: {
183
+ readonly status: 206;
184
+ readonly statusText: "Partial Content";
185
+ };
186
+ readonly MULTI_STATUS: {
187
+ readonly status: 207;
188
+ readonly statusText: "Multi-Status";
189
+ };
190
+ readonly MULTIPLE_CHOICES: {
191
+ readonly status: 300;
192
+ readonly statusText: "Multiple Choices";
193
+ };
194
+ readonly MOVED_PERMANENTLY: {
195
+ readonly status: 301;
196
+ readonly statusText: "Moved Permanently";
197
+ };
198
+ readonly MOVED_TEMPORARILY: {
199
+ readonly status: 302;
200
+ readonly statusText: "Moved Temporarily";
201
+ };
202
+ readonly SEE_OTHER: {
203
+ readonly status: 303;
204
+ readonly statusText: "See Other";
205
+ };
206
+ readonly NOT_MODIFIED: {
207
+ readonly status: 304;
208
+ readonly statusText: "Not Modified";
209
+ };
210
+ readonly USE_PROXY: {
211
+ readonly status: 305;
212
+ readonly statusText: "Use Proxy";
213
+ };
214
+ readonly TEMPORARY_REDIRECT: {
215
+ readonly status: 307;
216
+ readonly statusText: "Temporary Redirect";
217
+ };
218
+ readonly PERMANENT_REDIRECT: {
219
+ readonly status: 308;
220
+ readonly statusText: "Permanent Redirect";
221
+ };
222
+ readonly BAD_REQUEST: {
223
+ readonly status: 400;
224
+ readonly statusText: "Bad Request";
225
+ };
226
+ readonly UNAUTHORIZED: {
227
+ readonly status: 401;
228
+ readonly statusText: "Unauthorized";
229
+ };
230
+ readonly PAYMENT_REQUIRED: {
231
+ readonly status: 402;
232
+ readonly statusText: "Unauthorized";
233
+ };
234
+ readonly FORBIDDEN: {
235
+ readonly status: 403;
236
+ readonly statusText: "Forbidden";
237
+ };
238
+ readonly NOT_FOUND: {
239
+ readonly status: 404;
240
+ readonly statusText: "Not Found";
241
+ };
242
+ readonly METHOD_NOT_ALLOWED: {
243
+ readonly status: 405;
244
+ readonly statusText: "Method Not Allowed";
245
+ };
246
+ readonly NOT_ACCEPTABLE: {
247
+ readonly status: 406;
248
+ readonly statusText: "Not Acceptable";
249
+ };
250
+ readonly PROXY_AUTHENTICATION_REQUIRED: {
251
+ readonly status: 407;
252
+ readonly statusText: "Proxy Authentication Required";
253
+ };
254
+ readonly REQUEST_TIMEOUT: {
255
+ readonly status: 408;
256
+ readonly statusText: "Request Timeout";
257
+ };
258
+ readonly CONFLICT: {
259
+ readonly status: 409;
260
+ readonly statusText: "Conflict";
261
+ };
262
+ readonly GONE: {
263
+ readonly status: 410;
264
+ readonly statusText: "Gone";
265
+ };
266
+ readonly LENGTH_REQUIRED: {
267
+ readonly status: 411;
268
+ readonly statusText: "Length Required";
269
+ };
270
+ readonly PRECONDITION_FAILED: {
271
+ readonly status: 412;
272
+ readonly statusText: "Precondition Failed";
273
+ };
274
+ readonly REQUEST_TOO_LONG: {
275
+ readonly status: 413;
276
+ readonly statusText: "Request Entity Too Large";
277
+ };
278
+ readonly REQUEST_URI_TOO_LONG: {
279
+ readonly status: 414;
280
+ readonly statusText: "Request-URI Too Long";
281
+ };
282
+ readonly UNSUPPORTED_MEDIA_TYPE: {
283
+ readonly status: 415;
284
+ readonly statusText: "Unsupported Media Type";
285
+ };
286
+ readonly REQUESTED_RANGE_NOT_SATISFIABLE: {
287
+ readonly status: 416;
288
+ readonly statusText: "Requested Range Not Satisfiable";
289
+ };
290
+ readonly EXPECTATION_FAILED: {
291
+ readonly status: 417;
292
+ readonly statusText: "Expectation Failed";
293
+ };
294
+ readonly IM_A_TEAPOT: {
295
+ readonly status: 418;
296
+ readonly statusText: "I'm a teapot";
297
+ };
298
+ readonly INSUFFICIENT_SPACE_ON_RESOURCE: {
299
+ readonly status: 419;
300
+ readonly statusText: "Insufficient Space on Resource";
301
+ };
302
+ readonly METHOD_FAILURE: {
303
+ readonly status: 420;
304
+ readonly statusText: "Method Failure";
305
+ };
306
+ readonly MISDIRECTED_REQUEST: {
307
+ readonly status: 421;
308
+ readonly statusText: "Misdirected Request";
309
+ };
310
+ readonly UNPROCESSABLE_ENTITY: {
311
+ readonly status: 422;
312
+ readonly statusText: "Unprocessable Entity";
313
+ };
314
+ readonly LOCKED: {
315
+ readonly status: 423;
316
+ readonly statusText: "Unprocessable Entity";
317
+ };
318
+ readonly FAILED_DEPENDENCY: {
319
+ readonly status: 424;
320
+ readonly statusText: "Failed Dependency";
321
+ };
322
+ readonly PRECONDITION_REQUIRED: {
323
+ readonly status: 428;
324
+ readonly statusText: "Precondition Failed";
325
+ };
326
+ readonly TOO_MANY_REQUESTS: {
327
+ readonly status: 429;
328
+ readonly statusText: "Too Many Requests";
329
+ };
330
+ readonly REQUEST_HEADER_FIELDS_TOO_LARGE: {
331
+ readonly status: 431;
332
+ readonly statusText: "Request Header Fields Too Large";
333
+ };
334
+ readonly UNAVAILABLE_FOR_LEGAL_REASONS: {
335
+ readonly status: 451;
336
+ readonly statusText: "Unavailable For Legal Reasons";
337
+ };
338
+ readonly INTERNAL_SERVER_ERROR: {
339
+ readonly status: 500;
340
+ readonly statusText: "Internal Server Error";
341
+ };
342
+ readonly NOT_IMPLEMENTED: {
343
+ readonly status: 501;
344
+ readonly statusText: "Not Implemented";
345
+ };
346
+ readonly BAD_GATEWAY: {
347
+ readonly status: 502;
348
+ readonly statusText: "Bad Gateway";
349
+ };
350
+ readonly SERVICE_UNAVAILABLE: {
351
+ readonly status: 503;
352
+ readonly statusText: "Service Unavailable";
353
+ };
354
+ readonly GATEWAY_TIMEOUT: {
355
+ readonly status: 504;
356
+ readonly statusText: "Bad Gateway";
357
+ };
358
+ readonly HTTP_VERSION_NOT_SUPPORTED: {
359
+ readonly status: 505;
360
+ readonly statusText: "HTTP Version Not Supported";
361
+ };
362
+ readonly INSUFFICIENT_STORAGE: {
363
+ readonly status: 507;
364
+ readonly statusText: "Insufficient Storage";
365
+ };
366
+ readonly NETWORK_AUTHENTICATION_REQUIRED: {
367
+ readonly status: 511;
368
+ readonly statusText: "Network Authentication Required";
369
+ };
370
+ }>, SchemaParser>;
60
371
  }
61
372
 
62
- declare class HTTPRequestBuilder {
373
+ interface SchemaConfig {
374
+ schemas: SchemaMap;
375
+ requireSchema: boolean;
376
+ allowPlainText: boolean;
377
+ }
378
+ interface HTTPHooks {
379
+ onSend: [string, RequestHook][];
380
+ onReceive: [string, ResponseHook<unknown>][];
381
+ }
382
+ declare class MetaConfig implements SchemaConfig, HTTPHooks {
383
+ schemas: SchemaMap;
384
+ requireSchema: boolean;
385
+ allowPlainText: boolean;
386
+ onSend: [string, RequestHook][];
387
+ onReceive: [string, ResponseHook<unknown>][];
388
+ throwOnServerError: boolean;
389
+ }
390
+ declare class MetaConfigBuilder {
63
391
  #private;
64
- constructor(map: SchemaMap);
65
- requireSchema(value: boolean): this;
66
- get currentState(): RequestState;
67
- get currentUrl(): string;
68
- url(url: string): this;
69
- allowPlainText(value: boolean): this;
70
- schema(parser: SchemaParser, ...codes: StatusCode[]): HTTPRequestBuilder;
392
+ schemaMap(map: SchemaMap): this;
393
+ schema(parser: SchemaParser, ...codes: StatusCode[]): MetaConfigBuilder;
71
394
  schema(parser: SchemaParser, ...range: {
72
395
  from: StatusCode;
73
396
  to: StatusCode;
74
- }[]): HTTPRequestBuilder;
75
- onBeforeSend(...hook: RequestHook[]): this;
76
- onReceivedResponse(...hook: ResponseHook<unknown>[]): this;
77
- route(...route: (string | number | boolean)[]): this;
78
- header<T>(name: string, value: T): this;
79
- headers(dict: Record<string, string>): this;
80
- param<T>(name: string, value: T): this;
81
- params(dict: Record<string, unknown>): this;
82
- data<T>(data: T): this;
83
- post<TReturn>(): Promise<HTTPResponse<TReturn>>;
84
- get<TReturn>(): Promise<HTTPResponse<TReturn>>;
85
- delete<TReturn>(): Promise<HTTPResponse<TReturn>>;
86
- put<TReturn>(): Promise<HTTPResponse<TReturn>>;
87
- patch<TReturn>(): Promise<HTTPResponse<TReturn>>;
88
- private _request;
89
- private constructOptions;
90
- private tryRunBeforeHooks;
91
- private tryRunAfterHooks;
397
+ }[]): MetaConfigBuilder;
398
+ schema(parser: SchemaParser, ...args: (StatusCode | {
399
+ from: StatusCode;
400
+ to: StatusCode;
401
+ })[]): MetaConfigBuilder;
402
+ requireSchema(value: boolean): this;
403
+ allowPlainText(value: boolean): this;
404
+ onBeforeSend(description: string, hook: RequestHook): this;
405
+ throwOnServerError(value: boolean): this;
406
+ onReceiveResponse(description: string, hook: ResponseHook<unknown>): this;
407
+ build(): MetaConfig;
408
+ derive(): MetaConfigBuilder;
92
409
  }
93
410
 
94
- type DynamicHeader = () => string;
411
+ /**
412
+ * The HTTP fixture allows requests to be built and sent to a server. In general,
413
+ * there are 2 modes of operation:
414
+ *
415
+ * * Shared Chain: The shared chain is used to configure the client for all requests, such as
416
+ * routes this instance will always be used. When a shared chain method is called, it returns
417
+ * the same instance of HTTP which can be further chained to configure the client.
418
+ * * Request Chain: The request chain is used to configure a single request, inheriting values
419
+ * set by the shared chain. When called, a new HTTP client instance is created and inherits the values
420
+ * set by it's parent.
421
+ *
422
+ * The 2 modes are intended to simplify configuring an object through an inheritance chain. For example,
423
+ * assume we have an API with 2 controller routes, `/product` and `/seller`. We can set up a Base Client
424
+ * which consumes the HTTP fixture and configures it with the base url of our API.
425
+ *
426
+ * Inheritors can further configure their HTTP instance's routes.
427
+ *
428
+ * ```ts
429
+ * \@Constructor(HTTP)
430
+ * export class BaseClient {
431
+ * constructor(protected readonly http: HTTP) {
432
+ * this.http.url("https://api.example.com");
433
+ * }
434
+ * }
435
+ *
436
+ * export class ProductClient extends BaseClient {
437
+ * constructor(http: HTTP) {
438
+ * super(http);
439
+ * this.http.sharedRoute("product");
440
+ * }
441
+ * getProduct(id: number) {
442
+ * return this.http.route(id).get();
443
+ * }
444
+ *
445
+ * export class SellerClient extends BaseClient {
446
+ * constructor(http: HTTP) {
447
+ * super(http);
448
+ * this.http.sharedRoute("seller");
449
+ * }
450
+ *
451
+ * getSeller(id: number) {
452
+ * return this.http.route(id).get();
453
+ * }
454
+ * }
455
+ * ```
456
+ *
457
+ * 'Schemas' can also be configured. A Schema is a function or an object with a `parse` method, which
458
+ * takes a response data payload and returns a validated object. Schemas are mapped to
459
+ * HTTP Status Codes, and if configured to be required the request will fail if no schema is found
460
+ * matching that code.
461
+ *
462
+ * Defining a schema function:
463
+ *
464
+ * ```
465
+ * // user.schema.ts
466
+ * export function UserSchema(data: unknown) {
467
+ * if(typeof data !== "object") {
468
+ * throw new Error("Expected an object");
469
+ * }
470
+ *
471
+ * if(typeof data.name !== "string") {
472
+ * throw new Error("Expected a string");
473
+ * }
474
+ *
475
+ * return data as { name: string };
476
+ * }
477
+ *
478
+ * // user.controller.ts
479
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
480
+ * export class UserController extends BaseController {
481
+ * constructor(private readonly http: HTTP) {
482
+ * super(http);
483
+ * this.http
484
+ * .sharedRoute("user")
485
+ * .sharedSchema(ErrorSchema, { from: 400, to: 499 });
486
+ * }
487
+ *
488
+ * getUser(id: number) {
489
+ * return this.http.route(id).schema(UserSchema, 200).get();
490
+ * // or
491
+ * return this.http
492
+ * .route(id)
493
+ * .schema(UserSchema, { from: 200, to: 299 })
494
+ * .get();
495
+ * // or
496
+ * return this.http
497
+ * .route(id)
498
+ * .schema(UserSchema, 200, 201, 202)
499
+ * .get();
500
+ * }
501
+ * }
502
+ * ```
503
+ *
504
+ * Validation libraries which use a `.parse` or `.validation`, method, such as Zod or MyZod, can also be used as schemas:
505
+ *
506
+ * ```ts
507
+ * // user.schema.ts
508
+ * import { z } from "myzod";
509
+ *
510
+ * export const UserSchema = z.object({
511
+ * name: z.string()
512
+ * });
513
+ *
514
+ * // user.controller.ts
515
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
516
+ * export class UserController extends BaseController {
517
+ * constructor(private readonly http: HTTP) {
518
+ * super(http);
519
+ * this.http
520
+ * .sharedRoute("user")
521
+ * .sharedSchema(ErrorSchema, { from: 400, to: 499 })
522
+ * }
523
+ *
524
+ * getUser(id: number) {
525
+ * return this.http.route(id).schema(UserSchema, 200).get();
526
+ * }
527
+ * }
528
+ * ```
529
+ */
95
530
  declare class HTTP {
96
531
  #private;
97
- allowPlainText(value: boolean): this;
98
- requireSchema(value: boolean): this;
532
+ private readonly client;
533
+ constructor(client?: HTTPClient, builder?: HTTPRequestBuilder<HTTPRequest<unknown>>, metaConfig?: MetaConfigBuilder);
534
+ static create(client?: HTTPClient, builder?: HTTPRequestBuilder<HTTPRequest<unknown>>, metaConfig?: MetaConfigBuilder): HTTP;
535
+ /**
536
+ * Sets the base url of the request for this client, such as
537
+ * `https://api.example.com`, and could include always-used routes like
538
+ * the api version, such as `/v1` or `/api/v1` at the end.
539
+ *
540
+ * ```ts
541
+ *
542
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
543
+ * export abstract class BaseClient {
544
+ * constructor(protected readonly http: HTTP) {
545
+ * this.http.url("https://api.example.com");
546
+ * }
547
+ * }
548
+ * ```
549
+ * @param url
550
+ * @returns
551
+ */
99
552
  url(url: string): this;
100
- sharedOnBeforeSend(hook: RequestHook): this;
101
- sharedOnReceiveResponse(hook: ResponseHook<unknown>): this;
102
- onBeforeSend(hook: RequestHook): HTTPRequestBuilder;
103
- onReceiveResponse(hook: ResponseHook<unknown>): HTTPRequestBuilder;
553
+ /**
554
+ * If set to true, all requests derived from this client will require a schema be defined
555
+ * matching any response status code. If set to false, a schema will still be used for validation
556
+ * if defined, or the unadulterated original body will be returned if no schema matches.
557
+ *
558
+ * @param required Whether or not a schema is required for all responses.
559
+ * @returns This instance of HTTP.
560
+ */
561
+ requireSchema(required: boolean): this;
562
+ /**
563
+ * If set to true, all requests derived from this client will allow plain text
564
+ * responses. If set to false, plain text responses will throw an serialization error.
565
+ *
566
+ * Useful when an endpoint returns a HTML or plain text response. If the plain text
567
+ * is the value of `true` or `false`, or a number, it will be parsed into the
568
+ * appropriate type.
569
+ *
570
+ * This method is a shared chain method, and will return the same instance of HTTP.
571
+ *
572
+ * @param allow Whether or not plain text responses are allowed.
573
+ * @returns This instance of HTTP.
574
+ */
575
+ sharedAllowPlainText(allow: boolean): this;
576
+ /**
577
+ * If set to true, all requests derived from this client will allow plain text
578
+ * responses. If set to false, plain text responses will throw an serialization error.
579
+ *
580
+ * Useful when an endpoint returns a HTML or plain text response. If the plain text
581
+ * is the value of `true` or `false`, or a number, it will be parsed into the
582
+ * appropriate type.
583
+ *
584
+ * This method is a request chain method, and will return a new instance of HTTP.
585
+ *
586
+ * @param allow Whether or not plain text responses are allowed.
587
+ * @returns A new child instance of HTTP derived from this one.
588
+ */
589
+ allowPlainText(allow: boolean): HTTP;
590
+ /**
591
+ * Attaches a route to the request, such as `/product` or `/user`. Subsequent calls
592
+ * to this method will append the route to the existing route, such as `/product/1`.
593
+ *
594
+ * Numbers will be converted to strings automatically. Routes can be defined one
595
+ * at a time or as a spread argument.
596
+ *
597
+ * ```ts
598
+ * constructor(http: HTTP) {
599
+ * super(http);
600
+ * this.http.sharedRoute("user", id).get();
601
+ * }
602
+ *
603
+ * // or
604
+ *
605
+ * constructor(http: HTTP) {
606
+ * super(http);
607
+ * this.http
608
+ * .sharedRoute("user")
609
+ * .sharedRoute(id)
610
+ * .get();
611
+ * }
612
+ * ```
613
+ *
614
+ * This method is a shared chain method, and will return the same instance of HTTP. All
615
+ * child clients will inherit the routes defined by this method. Useful to configure
616
+ * in the constructor body.
617
+ *
618
+ * @param route A route or spread list of routes to append to the request.
619
+ * @returns This instance of HTTP.
620
+ */
621
+ sharedRoute(...route: (string | number | boolean)[]): this;
622
+ /**
623
+ * Attaches a route to the request, such as `/product` or `/user`. Subsequent calls
624
+ * to this method will append the route to the existing route, such as `/product/1`.
625
+ *
626
+ * Numbers will be converted to strings automatically. Routes can be defined one
627
+ * at a time or as a spread argument.
628
+ *
629
+ * ```ts
630
+ * getUser(id: number) {
631
+ * return this.http.route("user", id).get();
632
+ * }
633
+ *
634
+ * // or
635
+ *
636
+ * getUser(id: number) {
637
+ * return this.http
638
+ * .route("user")
639
+ * .route(id)
640
+ * .get();
641
+ * }
642
+ * ```
643
+ *
644
+ * This method is a request chain method, and will return a new instance of HTTP, inheriting
645
+ * any routes previously defined and appending the new route. Useful to configure
646
+ * in class methods as part of finalizing a request.
647
+ *
648
+ * @param route A route or spread list of routes to append to the request.
649
+ * @returns A new child instance of HTTP derived from this one.
650
+ */
651
+ route(...route: (string | number | boolean)[]): HTTP;
652
+ /**
653
+ * Attaches a shared schema mapping for all requests by this client. Schemas are
654
+ * mapped to HTTP Status Codes, and if configured to be required the request will fail
655
+ * if no schema is found matching that code.
656
+ *
657
+ * The status code mapping can be defined as a single code, a range of codes, or a spread list.
658
+ *
659
+ * ```ts
660
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
661
+ * export class UserController extends BaseController {
662
+ * constructor(private readonly http: HTTP) {
663
+ * super(http);
664
+ * this.http
665
+ * .sharedRoute("user")
666
+ * .sharedSchema(UserSchema, 200)
667
+ * .sharedSchema(EmptySchema, 201, 204)
668
+ * .sharedSchema(ErrorSchema, { from: 400, to: 499 });
669
+ * }
670
+ * }
671
+ * ```
672
+ *
673
+ * This method is a shared chain method, and will return the same instance of HTTP. All
674
+ * child clients will inherit the schemas defined by this method. Useful to configure
675
+ * in the constructor body.
676
+ *
677
+ * @param parser The schema parser to use for this mapping.
678
+ * @param codes A single status code, a range of status codes, or a spread list of status codes.
679
+ * @returns This instance of HTTP.
680
+ */
104
681
  sharedSchema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;
105
682
  sharedSchema(parser: SchemaParser, ...range: {
106
683
  from: StatusCode;
107
684
  to: StatusCode;
108
685
  }[]): HTTP;
109
- schema(parser: SchemaParser, ...codes: StatusCode[]): HTTPRequestBuilder;
686
+ /**
687
+ * Attaches a schema mapping for this request. Schemas are
688
+ * mapped to HTTP Status Codes, and if configured to be required the request will fail
689
+ * if no schema is found matching that code.
690
+ *
691
+ * The status code mapping can be defined as a single code, a range of codes, or a spread list.
692
+ *
693
+ * ```ts
694
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
695
+ * export class UserController extends BaseController {
696
+ * constructor(private readonly http: HTTP) {
697
+ * super(http);
698
+ * this.http
699
+ * .sharedRoute("user")
700
+ * .schema(ErrorSchema, { from: 400, to: 499 });
701
+ * }
702
+ *
703
+ * getUser(id: number) {
704
+ * return this.http.route(id).schema(UserSchema, 200).get();
705
+ * }
706
+ *
707
+ * getUsers(...ids: number[]) {
708
+ * return this.http
709
+ * .route("users")
710
+ * .schema(UserSchema, { from: 200, to: 299 })
711
+ * .schema(UserSchema, 200)
712
+ * .get();
713
+ * }
714
+ * ```
715
+ *
716
+ * This method is a request chain method, and will return a new instance of HTTP, inheriting
717
+ * any schemas previously defined and appending the new schema. Useful to configure
718
+ * in class methods as part of finalizing a request.
719
+ *
720
+ * @param parser The schema parser to use for this mapping.
721
+ * @param codes A single status code, a range of status codes, or a spread list of status codes.
722
+ * @returns A new child instance of HTTP derived from this one.
723
+ */
724
+ schema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;
110
725
  schema(parser: SchemaParser, ...range: {
111
726
  from: StatusCode;
112
727
  to: StatusCode;
113
- }[]): HTTPRequestBuilder;
114
- sharedRoute(...route: string[]): this;
115
- param(name: string, value: string): HTTPRequestBuilder;
116
- params(dict: Record<string, string>): HTTPRequestBuilder;
117
- data<T>(data: T): HTTPRequestBuilder;
118
- sharedHeader(name: string, value: string | DynamicHeader): this;
119
- route(...route: (string | number | boolean)[]): HTTPRequestBuilder;
120
- header<T>(name: string, value: T): HTTPRequestBuilder;
121
- headers(dict: Record<string, string>): HTTPRequestBuilder;
122
- get(): Promise<HTTPResponse<unknown>>;
123
- private builder;
124
- private convertFactoriesToString;
728
+ }[]): HTTP;
729
+ /**
730
+ * Attaches a shared query string parameter to all requests by this client. Query string
731
+ * parameters are key-value pairs which are appended to the request url, such as
732
+ * `https://api.example.com?name=John&age=30`.
733
+ *
734
+ * This method is a shared chain method, and will return the same instance of HTTP. All
735
+ * child clients will inherit the query string parameters defined by this method. Useful to configure
736
+ * in the constructor body.
737
+ *
738
+ * @param name The name of the query string parameter.
739
+ * @param value The value of the query string parameter.
740
+ * @returns This instance of HTTP.
741
+ */
742
+ sharedParam(name: string, value: Record<string, unknown>): HTTP;
743
+ sharedParam(name: string, ...value: (string | number | boolean)[]): HTTP;
744
+ /**
745
+ * `onSend` is a pre-request hook which will be executed in order of definition
746
+ * immediately before the request is sent. This hook can be used to analyze or
747
+ * log the request state.
748
+ *
749
+ * ```ts
750
+ *
751
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
752
+ * export class UserController extends BaseController {
753
+ * constructor(private readonly http: HTTP) {
754
+ * super(http);
755
+ * this.http
756
+ * .sharedRoute("user")
757
+ * .sharedOnSend("log request",
758
+ * (request) => console.log(JSON.stringify(request, null, 2))
759
+ * );
760
+ * }
761
+ * }
762
+ * ```
763
+ *
764
+ * This method is a shared chain method, and will return the same instance of HTTP. All
765
+ * child clients will inherit the onSend hooks defined by this method. Useful to configure
766
+ * in the constructor body.
767
+ *
768
+ * @param description A description of the hook, used for debugging.
769
+ * @param hook The hook to execute.
770
+ * @returns This instance of HTTP.
771
+ */
772
+ sharedOnSend(description: string, hook: RequestHook): this;
773
+ /**
774
+ * `onReceive` is a post-request hook which will be executed in order of definition
775
+ * immediately after the response is received. This hook can be used to analyze or
776
+ * log the response state.
777
+ *
778
+ * ```ts
779
+ *
780
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
781
+ * export class UserController extends BaseController {
782
+ * constructor(private readonly http: HTTP) {
783
+ * super(http);
784
+ * this.http
785
+ * .sharedRoute("user")
786
+ * .sharedOnReceive("log response",
787
+ * (response) => console.log(JSON.stringify(response, null, 2))
788
+ * );
789
+ * }
790
+ * }
791
+ * ```
792
+ *
793
+ * This method is a shared chain method, and will return the same instance of HTTP. All
794
+ * child clients will inherit the onReceive hooks defined by this method. Useful to configure
795
+ * in the constructor body.
796
+ *
797
+ * @param description A description of the hook, used for debugging.
798
+ * @param hook The hook to execute.
799
+ * @returns This instance of HTTP.
800
+ */
801
+ sharedOnReceive(description: string, hook: ResponseHook<unknown>): this;
802
+ /**
803
+ * Attaches a query string parameter object to the request. Query string
804
+ * parameters are key-value pairs which are appended to the request url, such as
805
+ * `https://api.example.com?name=John&age=30`.
806
+ *
807
+ * This method is a shared chain method, and will return the same instance of HTTP. All
808
+ * child clients will inherit the query string parameters defined by this method. Useful to configure
809
+ * in the constructor body.
810
+ *
811
+ * ```ts
812
+ * constructor(http: HTTP) {
813
+ * super(http);
814
+ * this.http
815
+ * .sharedParams({ 'is-test': "true" })
816
+ * ```
817
+ * @param name The name of the query string parameter.
818
+ * @param value The value of the query string parameter.
819
+ * @returns This instance of HTTP.
820
+ */
821
+ sharedParams(dict: Record<string, unknown>): this;
822
+ /**
823
+ * Attaches a query string parameter to the request. Query string
824
+ * parameters are key-value pairs which are appended to the request url, such as
825
+ * `https://api.example.com?name=John&age=30`.
826
+ *
827
+ * This method is a request chain method, and will return a new instance of HTTP, inheriting
828
+ * any query string parameters previously defined and appending the new parameter. Useful to configure
829
+ * in class methods as part of finalizing a request.
830
+ *
831
+ * ```ts
832
+ * getUser(id: number) {
833
+ * return this.http
834
+ * .route(id)
835
+ * .param("name", "John")
836
+ * .param("age", 30)
837
+ * ```
838
+ *
839
+ * Note: Numbers and Booleans will be converted to strings automatically.
840
+ *
841
+ * @param name The name of the query string parameter.
842
+ * @param value The value of the query string parameter.
843
+ * @returns A new child instance of HTTP derived from this one.
844
+ */
845
+ param(name: string, value: Record<string, unknown>): HTTP;
846
+ param(name: string, ...value: (string | number | boolean)[]): HTTP;
847
+ /**
848
+ * Attaches a query string parameter object to the request. Query string
849
+ * parameters are key-value pairs which are appended to the request url, such as
850
+ * `https://api.example.com?name=John&age=30`.
851
+ *
852
+ * This method is a shared chain method, and will return the same instance of HTTP. All
853
+ * child clients will inherit the query string parameters defined by this method. Useful to configure
854
+ * in the constructor body.
855
+ *
856
+ * ```ts
857
+ * getUser(id: number) {
858
+ * return this.http
859
+ * .route(id)
860
+ * .param({ name: "John", age: "30" })
861
+ *
862
+ * @param name The name of the query string parameter.
863
+ * @param value The value of the query string parameter.
864
+ * @returns This instance of HTTP.
865
+ */
866
+ params(dict: Record<string, string>): HTTP;
867
+ /**
868
+ * Attaches a shared data payload to this client. The data payload is the body of the request,
869
+ * and can be any type. If the data payload is an object, it will be serialized to JSON.
870
+ *
871
+ * This method is a shared chain method, and will return the same instance of HTTP. All
872
+ * child clients will inherit the data payload defined by this method. Useful to configure
873
+ * in the constructor body.
874
+ *
875
+ * @param data The data payload to attach to the request.
876
+ * @returns This instance of HTTP.
877
+ */
878
+ sharedData<T>(data: T): this;
879
+ /**
880
+ * Attaches a shared header to this client. Headers are string:string key-value pairs which are
881
+ * sent with the request, such as `Content-Type: application/json`.
882
+ *
883
+ * Numbers, Booleans and Null will be converted to string values automatically.
884
+ *
885
+ * A Factory function can also be provided to generate the header value at the time of request.
886
+ *
887
+ * This method is a shared chain method, and will return the same instance of HTTP. All
888
+ * child clients will inherit the header defined by this method. Useful to configure
889
+ * in the constructor body.
890
+ *
891
+ * @param name The name of the header.
892
+ * @param value The value of the header.
893
+ */
894
+ sharedHeader(name: string, value: string | number | boolean | null | (() => string | number | boolean | null)): this;
895
+ header(name: string, value: string): HTTP;
896
+ /**
897
+ * Attaches a data payload to this request. The data payload is the body of the request,
898
+ * and can be any type. If the data payload is an object, it will be serialized to JSON.
899
+ *
900
+ * This method is a request chain method, and will return a new instance of HTTP, inheriting
901
+ * any data payload previously defined and appending the new payload. Useful to configure
902
+ * in class methods as part of finalizing a request.
903
+ *
904
+ * @param data The data payload to attach to the request.
905
+ * @returns A new child instance of HTTP derived from this one.
906
+ */
907
+ data<T>(data: T): HTTP;
908
+ /**
909
+ * `onSend` is a pre-request hook which will be executed in order of definition
910
+ * immediately before the request is sent. This hook can be used to modify the request,
911
+ * or to log the state of a request before final send-off.
912
+ *
913
+ * ```ts
914
+ *
915
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
916
+ * export class UserController extends BaseController {
917
+ * constructor(private readonly http: HTTP) {
918
+ * super(http);
919
+ * }
920
+ *
921
+ * getUser(id: number) {
922
+ * return this.http
923
+ * .route(id)
924
+ * .onSend("log request",
925
+ * (request) => console.log(JSON.stringify(request, null, 2)
926
+ * )
927
+ * .get();
928
+ * }
929
+ * ```
930
+ *
931
+ * This method is a request chain method, and will return a new instance of HTTP, inheriting
932
+ * any onSend hooks previously defined and appending the new hook. Useful to configure
933
+ * in class methods as part of finalizing a request.
934
+ *
935
+ * @param description A description of the hook, used for debugging.
936
+ * @param hook The hook to execute.
937
+ * @returns A new child instance of HTTP derived from this one.
938
+ */
939
+ onSend(description: string, hook: RequestHook): HTTP;
940
+ /**
941
+ * `onReceive` is a post-request hook which will be executed in order of definition
942
+ * immediately after the response is received. This hook can be used to modify the response,
943
+ * or to log the state of a response after it is received.
944
+ *
945
+ * ```ts
946
+ *
947
+ * \@Fixture(INJECTION_SCOPE.TRANSIENT)
948
+ * export class UserController extends BaseController {
949
+ * constructor(private readonly http: HTTP) {
950
+ * super(http);
951
+ * }
952
+ *
953
+ * getUser(id: number) {
954
+ * return this.http
955
+ * .route(id)
956
+ * .onReceive("log response",
957
+ * (response) => console.log(JSON.stringify(response, null, 2)
958
+ * )
959
+ * .get();
960
+ * }
961
+ * ```
962
+ *
963
+ * This method is a request chain method, and will return a new instance of HTTP, inheriting
964
+ * any onReceive hooks previously defined and appending the new hook. Useful to configure
965
+ * in class methods as part of finalizing a request.
966
+ *
967
+ * @param description A description of the hook, used for debugging.
968
+ * @param hook The hook to execute.
969
+ * @returns A new child instance of HTTP derived from this one.
970
+ */
971
+ onReceive(description: string, hook: ResponseHook<unknown>): HTTP;
972
+ /**
973
+ * Executes the current request state as a GET request.
974
+ *
975
+ * @param options Additional options to pass to the underlying http client, such
976
+ * as e.g Axios configuration values.
977
+ * @returns A promise which resolves to the response.
978
+ */
979
+ get<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
980
+ /**
981
+ * Executes the current request state as a POST request.
982
+ *
983
+ * @param data The data payload to attach to the request.
984
+ * @param options Additional options to pass to the underlying http client, such
985
+ * as e.g Axios configuration values.
986
+ * @returns A promise which resolves to the response.
987
+ */
988
+ post<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
989
+ /**
990
+ * Executes the current request state as a DELETE request.
991
+ *
992
+ * @param options Additional options to pass to the underlying http client, such
993
+ * as e.g Axios configuration values.
994
+ * @returns A promise which resolves to the response.
995
+ * as e.g Axios configuration values.
996
+ */
997
+ delete<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
998
+ /**
999
+ * Executes the current request state as a PUT request.
1000
+ *
1001
+ * @param options Additional options to pass to the underlying http client, such
1002
+ * as e.g Axios configuration values.
1003
+ * @returns A promise which resolves to the response.
1004
+ */
1005
+ put<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
1006
+ /**
1007
+ * Executes the current request state as a PATCH request.
1008
+ *
1009
+ * @param options Additional options to pass to the underlying http client, such
1010
+ * as e.g Axios configuration values.
1011
+ * @returns A promise which resolves to the response.
1012
+ */
1013
+ patch<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
1014
+ head<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
1015
+ options<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
1016
+ trace<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
1017
+ connect<TResponseType>(options?: HTTPAdditionalOptions<unknown>): Promise<HTTPResponse<TResponseType>>;
1018
+ private runOnSendHooks;
1019
+ private runOnReceiveHooks;
125
1020
  }
126
1021
 
127
- export { DerivedHTTPResponse, DynamicHeader, HTTP, HTTPResponse, RequestHook, RequestState, ResponseHook, SchemaParser, StatusCode };
1022
+ /**
1023
+ * Schema which does not care about data validation.
1024
+ *
1025
+ * Useful if `requireSchema` is set to true, but a specific
1026
+ * endpoints response does not matter.
1027
+ * @param data
1028
+ * @returns
1029
+ */
1030
+ declare function AnySchema(data: unknown): unknown;
1031
+ /**
1032
+ * Schema which validates that a response is empty. This can mean
1033
+ * the data payload was `null`, `undefined` or the string `'null'`.
1034
+ *
1035
+ * Useful if `requireSchema` is set to true, but a specific
1036
+ * endpoints response should be null or not defined.
1037
+ * @param data
1038
+ * @returns
1039
+ */
1040
+ declare function EmptySchema(data: unknown): null | undefined;
1041
+ /**
1042
+ * Schema which validates a response was null.
1043
+ *
1044
+ * Useful if `requireSchema` is set to true, but a specific
1045
+ * endpoints response should be null.
1046
+ * @param data
1047
+ * @returns
1048
+ */
1049
+ declare function NullSchema(data: unknown): null;
1050
+ /**
1051
+ * Schema which validates a response was undefined.
1052
+ *
1053
+ * Useful if `requireSchema` is set to true, but a specific
1054
+ * endpoints response should be undefined.
1055
+ *
1056
+ * @param data
1057
+ * @returns
1058
+ */
1059
+ declare function UndefinedSchema(data: unknown): undefined;
1060
+ /**
1061
+ * Schema which validates a response was a boolean, or a string of value
1062
+ * `'true'` or `'false'`.
1063
+ *
1064
+ * Useful if `requireSchema` is set to true, but a specific
1065
+ * endpoints response should be a boolean.
1066
+ *
1067
+ * @param data
1068
+ * @returns
1069
+ */
1070
+ declare function BooleanSchema(data: unknown): any;
1071
+ /**
1072
+ * Schema which validates a response was a number, or a string of value
1073
+ * of a number.
1074
+ *
1075
+ * Useful if `requireSchema` is set to true, but a specific
1076
+ * endpoints response should be a number.
1077
+ *
1078
+ * @param data
1079
+ * @returns
1080
+ */
1081
+ declare function NumberSchema(data: unknown): any;
1082
+ /**
1083
+ * Schema which validates a response was a string.
1084
+ *
1085
+ * Useful if `requireSchema` is set to true, but a specific
1086
+ * endpoints response should be a string.
1087
+ *
1088
+ * @param data
1089
+ * @returns
1090
+ */
1091
+ declare function StringSchema(data: unknown): string;
1092
+ declare function JSONSchema<T = unknown>(data: unknown): any;
1093
+
1094
+ export { AnySchema, AxiosClient, BooleanSchema, EmptySchema, HTTP, HTTPAdditionalOptions, HTTPClient, HTTPMethod, HTTPRequest, HTTPRequestBuilder, HTTPResponse, HTTPResponseBuilder, JSONSchema, NullSchema, NumberSchema, RequestHook, ResponseHook, SchemaParser, StringSchema, UndefinedSchema, defaultClient };