@utiliread/http 1.19.5 → 1.20.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.
Files changed (76) hide show
  1. package/dist/event-aggregator.d.ts +11 -0
  2. package/dist/events.d.ts +11 -0
  3. package/dist/header-names.d.ts +182 -0
  4. package/dist/helpers.d.ts +5 -0
  5. package/dist/http-builder.d.ts +61 -0
  6. package/dist/http-error.d.ts +10 -0
  7. package/dist/http-response.d.ts +18 -0
  8. package/dist/http.d.ts +33 -0
  9. package/dist/http.spec.d.ts +1 -0
  10. package/dist/index.d.ts +16 -231
  11. package/dist/index.js +616 -242
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +601 -215
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/mapper.d.ts +9 -0
  16. package/dist/pagination.d.ts +23 -0
  17. package/dist/{json.d.ts → plugins/json/index.d.ts} +1 -2
  18. package/dist/plugins/json/index.js +87 -0
  19. package/dist/plugins/json/index.js.map +1 -0
  20. package/dist/plugins/json/index.mjs +85 -0
  21. package/dist/plugins/json/index.mjs.map +1 -0
  22. package/dist/{jsonpatch.d.ts → plugins/jsonpatch/index.d.ts} +0 -2
  23. package/dist/plugins/jsonpatch/index.js +21 -0
  24. package/dist/plugins/jsonpatch/index.js.map +1 -0
  25. package/dist/plugins/jsonpatch/index.mjs +19 -0
  26. package/dist/plugins/jsonpatch/index.mjs.map +1 -0
  27. package/dist/{msgpack.d.ts → plugins/msgpack/index.d.ts} +1 -2
  28. package/dist/plugins/msgpack/index.js +41 -0
  29. package/dist/plugins/msgpack/index.js.map +1 -0
  30. package/dist/plugins/msgpack/index.mjs +39 -0
  31. package/dist/plugins/msgpack/index.mjs.map +1 -0
  32. package/dist/problem-details.d.ts +7 -0
  33. package/dist/query-string.d.ts +6 -0
  34. package/dist/query-string.spec.d.ts +1 -0
  35. package/dist/status-codes.d.ts +65 -0
  36. package/dist/timeout-error.d.ts +3 -0
  37. package/json.d.ts +2 -0
  38. package/json.rollup.config.mjs +32 -0
  39. package/jsonpatch.d.ts +2 -0
  40. package/jsonpatch.rollup.config.mjs +32 -0
  41. package/msgpack.d.ts +2 -0
  42. package/msgpack.rollup.config.mjs +37 -0
  43. package/package.json +24 -24
  44. package/rollup.config.mjs +31 -0
  45. package/src/header-names.ts +273 -0
  46. package/src/index.ts +2 -1
  47. package/{plugins/json/src → src/plugins/json}/index.ts +138 -142
  48. package/{plugins/jsonpatch/src → src/plugins/jsonpatch}/index.ts +36 -36
  49. package/{plugins/msgpack/src → src/plugins/msgpack}/index.ts +69 -66
  50. package/src/status-codes.ts +65 -67
  51. package/tsconfig.json +6 -11
  52. package/dist/index.d.ts.map +0 -1
  53. package/dist/json.d.ts.map +0 -1
  54. package/dist/json.js +0 -93
  55. package/dist/json.js.map +0 -1
  56. package/dist/json.mjs +0 -82
  57. package/dist/json.mjs.map +0 -1
  58. package/dist/jsonpatch.d.ts.map +0 -1
  59. package/dist/jsonpatch.js +0 -33
  60. package/dist/jsonpatch.js.map +0 -1
  61. package/dist/jsonpatch.mjs +0 -22
  62. package/dist/jsonpatch.mjs.map +0 -1
  63. package/dist/msgpack.d.ts.map +0 -1
  64. package/dist/msgpack.js +0 -50
  65. package/dist/msgpack.js.map +0 -1
  66. package/dist/msgpack.mjs +0 -39
  67. package/dist/msgpack.mjs.map +0 -1
  68. package/plugins/json/node_modules/@utiliread/http/package.json +0 -4
  69. package/plugins/json/package.json +0 -15
  70. package/plugins/json/tsconfig.json +0 -7
  71. package/plugins/jsonpatch/node_modules/@utiliread/http/package.json +0 -4
  72. package/plugins/jsonpatch/package.json +0 -16
  73. package/plugins/jsonpatch/tsconfig.json +0 -7
  74. package/plugins/msgpack/node_modules/@utiliread/http/package.json +0 -4
  75. package/plugins/msgpack/package.json +0 -16
  76. package/plugins/msgpack/tsconfig.json +0 -7
@@ -0,0 +1,11 @@
1
+ type Callback<P extends any[] = any[]> = (...params: P) => void | Promise<void>;
2
+ export declare class EventAggregator<P extends any[]> {
3
+ private callbacks;
4
+ get any(): boolean;
5
+ subscribe(callback: Callback<P>): Subscription;
6
+ publish(...params: P): Promise<void>;
7
+ }
8
+ export interface Subscription {
9
+ dispose(): void;
10
+ }
11
+ export {};
@@ -0,0 +1,11 @@
1
+ import { HttpBuilder, HttpBuilderOfT, Message } from "./http-builder";
2
+ import { HttpResponse } from "./http-response";
3
+ interface Events {
4
+ sent: (response: HttpResponse, request: Message) => void | Promise<void>;
5
+ }
6
+ interface EventsOfT<T> extends Events {
7
+ received: (response: HttpResponse, request: Message, value: T) => void | Promise<void>;
8
+ }
9
+ export declare function events<P extends any[]>(action: (...params: P) => HttpBuilder, configure: (...params: P) => Partial<Events>): (...params: P) => HttpBuilder;
10
+ export declare function events<B extends HttpBuilderOfT<T>, P extends any[], T>(action: (...params: P) => B, configure: (...params: P) => Partial<EventsOfT<T>>): (...params: P) => B;
11
+ export {};
@@ -0,0 +1,182 @@
1
+ /** Gets the `Accept` HTTP header name. */
2
+ export declare const accept = "Accept";
3
+ /** Gets the `Accept-Charset` HTTP header name. */
4
+ export declare const acceptCharset = "Accept-Charset";
5
+ /** Gets the `Accept-Encoding` HTTP header name. */
6
+ export declare const acceptEncoding = "Accept-Encoding";
7
+ /** Gets the `Accept-Language` HTTP header name. */
8
+ export declare const acceptLanguage = "Accept-Language";
9
+ /** Gets the `Accept-Ranges` HTTP header name. */
10
+ export declare const acceptRanges = "Accept-Ranges";
11
+ /** Gets the `Access-Control-Allow-Credentials` HTTP header name. */
12
+ export declare const accessControlAllowCredentials = "Access-Control-Allow-Credentials";
13
+ /** Gets the `Access-Control-Allow-Headers` HTTP header name. */
14
+ export declare const accessControlAllowHeaders = "Access-Control-Allow-Headers";
15
+ /** Gets the `Access-Control-Allow-Methods` HTTP header name. */
16
+ export declare const accessControlAllowMethods = "Access-Control-Allow-Methods";
17
+ /** Gets the `Access-Control-Allow-Origin` HTTP header name. */
18
+ export declare const accessControlAllowOrigin = "Access-Control-Allow-Origin";
19
+ /** Gets the `Access-Control-Expose-Headers` HTTP header name. */
20
+ export declare const accessControlExposeHeaders = "Access-Control-Expose-Headers";
21
+ /** Gets the `Access-Control-Max-Age` HTTP header name. */
22
+ export declare const accessControlMaxAge = "Access-Control-Max-Age";
23
+ /** Gets the `Access-Control-Request-Headers` HTTP header name. */
24
+ export declare const accessControlRequestHeaders = "Access-Control-Request-Headers";
25
+ /** Gets the `Access-Control-Request-Method` HTTP header name. */
26
+ export declare const accessControlRequestMethod = "Access-Control-Request-Method";
27
+ /** Gets the `Age` HTTP header name. */
28
+ export declare const age = "Age";
29
+ /** Gets the `Allow` HTTP header name. */
30
+ export declare const allow = "Allow";
31
+ /** Gets the `Alt-Svc` HTTP header name. */
32
+ export declare const altSvc = "Alt-Svc";
33
+ /** Gets the `Authorization` HTTP header name. */
34
+ export declare const authorization = "Authorization";
35
+ /** Gets the `baggage` HTTP header name. */
36
+ export declare const baggage = "baggage";
37
+ /** Gets the `Cache-Control` HTTP header name. */
38
+ export declare const cacheControl = "Cache-Control";
39
+ /** Gets the `Connection` HTTP header name. */
40
+ export declare const connection = "Connection";
41
+ /** Gets the `Content-Disposition` HTTP header name. */
42
+ export declare const contentDisposition = "Content-Disposition";
43
+ /** Gets the `Content-Encoding` HTTP header name. */
44
+ export declare const contentEncoding = "Content-Encoding";
45
+ /** Gets the `Content-Language` HTTP header name. */
46
+ export declare const contentLanguage = "Content-Language";
47
+ /** Gets the `Content-Length` HTTP header name. */
48
+ export declare const contentLength = "Content-Length";
49
+ /** Gets the `Content-Location` HTTP header name. */
50
+ export declare const contentLocation = "Content-Location";
51
+ /** Gets the `Content-MD5` HTTP header name. */
52
+ export declare const contentMD5 = "Content-MD5";
53
+ /** Gets the `Content-Range` HTTP header name. */
54
+ export declare const contentRange = "Content-Range";
55
+ /** Gets the `Content-Security-Policy` HTTP header name. */
56
+ export declare const contentSecurityPolicy = "Content-Security-Policy";
57
+ /** Gets the `Content-Security-Policy-Report-Only` HTTP header name. */
58
+ export declare const contentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only";
59
+ /** Gets the `Content-Type` HTTP header name. */
60
+ export declare const contentType = "Content-Type";
61
+ /** Gets the `Correlation-Context` HTTP header name. */
62
+ export declare const correlationContext = "Correlation-Context";
63
+ /** Gets the `Cookie` HTTP header name. */
64
+ export declare const cookie = "Cookie";
65
+ /** Gets the `Date` HTTP header name. */
66
+ export declare const date = "Date";
67
+ /** Gets the `DNT` HTTP header name. */
68
+ export declare const dnt = "DNT";
69
+ /** Gets the `ETag` HTTP header name. */
70
+ export declare const eTag = "ETag";
71
+ /** Gets the `Expires` HTTP header name. */
72
+ export declare const expires = "Expires";
73
+ /** Gets the `Expect` HTTP header name. */
74
+ export declare const expect = "Expect";
75
+ /** Gets the `From` HTTP header name. */
76
+ export declare const from = "From";
77
+ /** Gets the `Grpc-Accept-Encoding` HTTP header name. */
78
+ export declare const grpcAcceptEncoding = "Grpc-Accept-Encoding";
79
+ /** Gets the `Grpc-Encoding` HTTP header name. */
80
+ export declare const grpcEncoding = "Grpc-Encoding";
81
+ /** Gets the `Grpc-Message` HTTP header name. */
82
+ export declare const grpcMessage = "Grpc-Message";
83
+ /** Gets the `Grpc-Status` HTTP header name. */
84
+ export declare const grpcStatus = "Grpc-Status";
85
+ /** Gets the `Grpc-Timeout` HTTP header name. */
86
+ export declare const grpcTimeout = "Grpc-Timeout";
87
+ /** Gets the `Host` HTTP header name. */
88
+ export declare const host = "Host";
89
+ /** Gets the `Keep-Alive` HTTP header name. */
90
+ export declare const keepAlive = "Keep-Alive";
91
+ /** Gets the `If-Match` HTTP header name. */
92
+ export declare const ifMatch = "If-Match";
93
+ /** Gets the `If-Modified-Since` HTTP header name. */
94
+ export declare const ifModifiedSince = "If-Modified-Since";
95
+ /** Gets the `If-None-Match` HTTP header name. */
96
+ export declare const ifNoneMatch = "If-None-Match";
97
+ /** Gets the `If-Range` HTTP header name. */
98
+ export declare const ifRange = "If-Range";
99
+ /** Gets the `If-Unmodified-Since` HTTP header name. */
100
+ export declare const ifUnmodifiedSince = "If-Unmodified-Since";
101
+ /** Gets the `Last-Modified` HTTP header name. */
102
+ export declare const lastModified = "Last-Modified";
103
+ /** Gets the `Link` HTTP header name. */
104
+ export declare const link = "Link";
105
+ /** Gets the `Location` HTTP header name. */
106
+ export declare const location = "Location";
107
+ /** Gets the `Max-Forwards` HTTP header name. */
108
+ export declare const maxForwards = "Max-Forwards";
109
+ /** Gets the `Origin` HTTP header name. */
110
+ export declare const origin = "Origin";
111
+ /** Gets the `Pragma` HTTP header name. */
112
+ export declare const pragma = "Pragma";
113
+ /** Gets the `Proxy-Authenticate` HTTP header name. */
114
+ export declare const proxyAuthenticate = "Proxy-Authenticate";
115
+ /** Gets the `Proxy-Authorization` HTTP header name. */
116
+ export declare const proxyAuthorization = "Proxy-Authorization";
117
+ /** Gets the `Proxy-Connection` HTTP header name. */
118
+ export declare const proxyConnection = "Proxy-Connection";
119
+ /** Gets the `Range` HTTP header name. */
120
+ export declare const range = "Range";
121
+ /** Gets the `Referer` HTTP header name. */
122
+ export declare const referer = "Referer";
123
+ /** Gets the `Retry-After` HTTP header name. */
124
+ export declare const retryAfter = "Retry-After";
125
+ /** Gets the `Request-Id` HTTP header name. */
126
+ export declare const requestId = "Request-Id";
127
+ /** Gets the `Sec-WebSocket-Accept` HTTP header name. */
128
+ export declare const secWebSocketAccept = "Sec-WebSocket-Accept";
129
+ /** Gets the `Sec-WebSocket-Key` HTTP header name. */
130
+ export declare const secWebSocketKey = "Sec-WebSocket-Key";
131
+ /** Gets the `Sec-WebSocket-Protocol` HTTP header name. */
132
+ export declare const secWebSocketProtocol = "Sec-WebSocket-Protocol";
133
+ /** Gets the `Sec-WebSocket-Version` HTTP header name. */
134
+ export declare const secWebSocketVersion = "Sec-WebSocket-Version";
135
+ /** Gets the `Sec-WebSocket-Extensions` HTTP header name. */
136
+ export declare const secWebSocketExtensions = "Sec-WebSocket-Extensions";
137
+ /** Gets the `Server` HTTP header name. */
138
+ export declare const server = "Server";
139
+ /** Gets the `Set-Cookie` HTTP header name. */
140
+ export declare const setCookie = "Set-Cookie";
141
+ /** Gets the `Strict-Transport-Security` HTTP header name. */
142
+ export declare const strictTransportSecurity = "Strict-Transport-Security";
143
+ /** Gets the `TE` HTTP header name. */
144
+ export declare const te = "TE";
145
+ /** Gets the `Trailer` HTTP header name. */
146
+ export declare const trailer = "Trailer";
147
+ /** Gets the `Transfer-Encoding` HTTP header name. */
148
+ export declare const transferEncoding = "Transfer-Encoding";
149
+ /** Gets the `Translate` HTTP header name. */
150
+ export declare const translate = "Translate";
151
+ /** Gets the `traceparent` HTTP header name. */
152
+ export declare const traceParent = "traceparent";
153
+ /** Gets the `tracestate` HTTP header name. */
154
+ export declare const traceState = "tracestate";
155
+ /** Gets the `Upgrade` HTTP header name. */
156
+ export declare const upgrade = "Upgrade";
157
+ /** Gets the `Upgrade-Insecure-Requests` HTTP header name. */
158
+ export declare const upgradeInsecureRequests = "Upgrade-Insecure-Requests";
159
+ /** Gets the `User-Agent` HTTP header name. */
160
+ export declare const userAgent = "User-Agent";
161
+ /** Gets the `Vary` HTTP header name. */
162
+ export declare const vary = "Vary";
163
+ /** Gets the `Via` HTTP header name. */
164
+ export declare const via = "Via";
165
+ /** Gets the `Warning` HTTP header name. */
166
+ export declare const warning = "Warning";
167
+ /** Gets the `Sec-WebSocket-Protocol` HTTP header name. */
168
+ export declare const webSocketSubProtocols = "Sec-WebSocket-Protocol";
169
+ /** Gets the `WWW-Authenticate` HTTP header name. */
170
+ export declare const wWWAuthenticate = "WWW-Authenticate";
171
+ /** Gets the `X-Content-Type-Options` HTTP header name. */
172
+ export declare const xContentTypeOptions = "X-Content-Type-Options";
173
+ /** Gets the `X-Frame-Options` HTTP header name. */
174
+ export declare const xFrameOptions = "X-Frame-Options";
175
+ /** Gets the `X-Powered-By` HTTP header name. */
176
+ export declare const xPoweredBy = "X-Powered-By";
177
+ /** Gets the `X-Requested-With` HTTP header name. */
178
+ export declare const xRequestedWith = "X-Requested-With";
179
+ /** Gets the `X-UA-Compatible` HTTP header name. */
180
+ export declare const xUACompatible = "X-UA-Compatible";
181
+ /** Gets the `X-XSS-Protection` HTTP header name. */
182
+ export declare const xXSSProtection = "X-XSS-Protection";
@@ -0,0 +1,5 @@
1
+ import { HttpError } from "./http-error";
2
+ import { TimeoutError } from "./timeout-error";
3
+ export declare function isHttpError(error: Error): error is HttpError;
4
+ export declare function isAbortError(error: Error): boolean;
5
+ export declare function isTimeoutError(error: Error): error is TimeoutError;
@@ -0,0 +1,61 @@
1
+ import { Fetch } from "./http";
2
+ import { HttpResponse, HttpResponseOfT } from "./http-response";
3
+ import { Http } from "./http";
4
+ export declare class HttpBuilder {
5
+ message: Message;
6
+ options: RequestOptions;
7
+ private _ensureSuccessStatusCode;
8
+ private _onSend;
9
+ private _onSent;
10
+ constructor(message: Message, options: RequestOptions,
11
+ /** @internal */ http: Http);
12
+ onSend(callback: (request: Message) => void | Promise<void>): this;
13
+ onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): this;
14
+ useHandler<T>(handler: (response: HttpResponse) => Promise<T>): HttpBuilderOfT<T>;
15
+ send(abortSignal?: AbortSignal): Promise<HttpResponse>;
16
+ getUrl(): string;
17
+ ensureSuccessStatusCode(ensureSuccessStatusCode?: boolean): this;
18
+ useCors(mode: RequestMode): this;
19
+ useTimeout(timeout: number | null): this;
20
+ with(content: any, contentType?: string): this;
21
+ withForm(content: FormData): this;
22
+ addHeader(name: string, value: string): this;
23
+ expectString(): HttpBuilderOfT<string>;
24
+ expectBinary(): HttpBuilderOfT<ArrayBuffer>;
25
+ }
26
+ export declare class HttpBuilderOfT<T> extends HttpBuilder {
27
+ private inner;
28
+ private handler;
29
+ private _onReceived;
30
+ constructor(inner: HttpBuilder, handler: (response: HttpResponse) => Promise<T>);
31
+ onSend(callback: (request: Message) => void | Promise<void>): this;
32
+ onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): this;
33
+ ensureSuccessStatusCode(ensureSuccessStatusCode?: boolean): this;
34
+ useCors(mode: RequestMode): this;
35
+ useTimeout(timeout: number): this;
36
+ allowEmptyResponse(): HttpBuilderOfT<T | null>;
37
+ onReceived(callback: (response: HttpResponseOfT<T>, request: Message, value: T) => void | Promise<void>): this;
38
+ send(abortSignal?: AbortSignal): SendPromise<T>;
39
+ transfer(abortSignal?: AbortSignal): Promise<T>;
40
+ private handleReceive;
41
+ }
42
+ export type HttpMethod = "HEAD" | "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
43
+ export interface Message {
44
+ method: HttpMethod;
45
+ url: string;
46
+ headers: Headers;
47
+ content?: any;
48
+ contentType?: string;
49
+ mode?: RequestMode;
50
+ properties: {
51
+ [key: string]: any;
52
+ };
53
+ }
54
+ export interface RequestOptions {
55
+ fetch: Fetch;
56
+ timeout?: number;
57
+ baseUrl?: string;
58
+ }
59
+ export interface SendPromise<T> extends Promise<HttpResponseOfT<T>> {
60
+ thenReceive(): Promise<T>;
61
+ }
@@ -0,0 +1,10 @@
1
+ import { HttpResponse } from "./http-response";
2
+ import { ProblemDetails } from "./problem-details";
3
+ export declare class HttpError extends Error {
4
+ statusCode: number;
5
+ private response;
6
+ private detailsPromise?;
7
+ get hasDetails(): boolean | undefined;
8
+ constructor(statusCode: number, response?: HttpResponse | undefined);
9
+ details<TDetails = ProblemDetails>(): Promise<TDetails>;
10
+ }
@@ -0,0 +1,18 @@
1
+ export declare class HttpResponse {
2
+ rawResponse: Response;
3
+ get url(): string;
4
+ get statusCode(): number;
5
+ get headers(): Headers;
6
+ get isInformational(): boolean;
7
+ get isSuccessful(): boolean;
8
+ get isRedirection(): boolean;
9
+ get isClientError(): boolean;
10
+ get isServerError(): boolean;
11
+ constructor(rawResponse: Response);
12
+ ensureSuccessfulStatusCode(): this;
13
+ }
14
+ export declare class HttpResponseOfT<T> extends HttpResponse {
15
+ private handler;
16
+ constructor(rawResponse: Response, handler: (response: HttpResponse) => Promise<T>);
17
+ receive(): Promise<T>;
18
+ }
package/dist/http.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { Subscription } from "./event-aggregator";
2
+ import { HttpBuilder, HttpMethod, Message } from "./http-builder";
3
+ import { HttpResponse, HttpResponseOfT } from "./http-response";
4
+ export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
5
+ export declare class Http {
6
+ static defaults: HttpOptions;
7
+ private static instance?;
8
+ options: HttpOptions;
9
+ constructor(options?: Partial<HttpOptions>);
10
+ static request(method: HttpMethod, url: string, params?: any): HttpBuilder;
11
+ static head(url: string, params?: any): HttpBuilder;
12
+ static post(url: string, params?: any): HttpBuilder;
13
+ static get(url: string, params?: any): HttpBuilder;
14
+ static put(url: string, params?: any): HttpBuilder;
15
+ static patch(url: string, params?: any): HttpBuilder;
16
+ static delete(url: string, params?: any): HttpBuilder;
17
+ private static getInstance;
18
+ request(method: HttpMethod, url: string, params?: any): HttpBuilder;
19
+ head(url: string, params?: any): HttpBuilder;
20
+ post(url: string, params?: any): HttpBuilder;
21
+ get(url: string, params?: any): HttpBuilder;
22
+ put(url: string, params?: any): HttpBuilder;
23
+ patch(url: string, params?: any): HttpBuilder;
24
+ delete(url: string, params?: any): HttpBuilder;
25
+ onSend(callback: (request: Message) => void | Promise<void>): Subscription;
26
+ onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): Subscription;
27
+ onReceived(callback: (response: HttpResponseOfT<any>, request: Message, value: any) => void | Promise<void>): Subscription;
28
+ }
29
+ export interface HttpOptions {
30
+ fetch?: Fetch;
31
+ timeout?: number;
32
+ baseUrl?: string;
33
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,231 +1,16 @@
1
- export interface Subscription {
2
- dispose(): void;
3
- }
4
- export type ProblemDetails = {
5
- detail?: string;
6
- instance?: string;
7
- status?: number;
8
- title?: string;
9
- type: string;
10
- } & Record<string, any>;
11
- export class HttpError extends Error {
12
- statusCode: number;
13
- get hasDetails(): boolean | undefined;
14
- constructor(statusCode: number, response?: HttpResponse | undefined);
15
- details<TDetails = ProblemDetails>(): Promise<TDetails>;
16
- }
17
- export class HttpResponse {
18
- rawResponse: Response;
19
- get url(): string;
20
- get statusCode(): number;
21
- get headers(): Headers;
22
- get isInformational(): boolean;
23
- get isSuccessful(): boolean;
24
- get isRedirection(): boolean;
25
- get isClientError(): boolean;
26
- get isServerError(): boolean;
27
- constructor(rawResponse: Response);
28
- ensureSuccessfulStatusCode(): this;
29
- }
30
- export class HttpResponseOfT<T> extends HttpResponse {
31
- constructor(rawResponse: Response, handler: (response: HttpResponse) => Promise<T>);
32
- receive(): Promise<T>;
33
- }
34
- export class TimeoutError extends Error {
35
- constructor();
36
- }
37
- export class HttpBuilder {
38
- message: Message;
39
- options: RequestOptions;
40
- constructor(message: Message, options: RequestOptions,
41
- /** @internal */ http: Http);
42
- onSend(callback: (request: Message) => void | Promise<void>): this;
43
- onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): this;
44
- useHandler<T>(handler: (response: HttpResponse) => Promise<T>): HttpBuilderOfT<T>;
45
- send(abortSignal?: AbortSignal): Promise<HttpResponse>;
46
- getUrl(): string;
47
- ensureSuccessStatusCode(ensureSuccessStatusCode?: boolean): this;
48
- useCors(mode: RequestMode): this;
49
- useTimeout(timeout: number | null): this;
50
- with(content: any, contentType?: string): this;
51
- withForm(content: FormData): this;
52
- addHeader(name: string, value: string): this;
53
- expectString(): HttpBuilderOfT<string>;
54
- expectBinary(): HttpBuilderOfT<ArrayBuffer>;
55
- }
56
- export class HttpBuilderOfT<T> extends HttpBuilder {
57
- constructor(inner: HttpBuilder, handler: (response: HttpResponse) => Promise<T>);
58
- onSend(callback: (request: Message) => void | Promise<void>): this;
59
- onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): this;
60
- ensureSuccessStatusCode(ensureSuccessStatusCode?: boolean): this;
61
- useCors(mode: RequestMode): this;
62
- useTimeout(timeout: number): this;
63
- allowEmptyResponse(): HttpBuilderOfT<T | null>;
64
- onReceived(callback: (response: HttpResponseOfT<T>, request: Message, value: T) => void | Promise<void>): this;
65
- send(abortSignal?: AbortSignal): SendPromise<T>;
66
- transfer(abortSignal?: AbortSignal): Promise<T>;
67
- }
68
- type HttpMethod = "HEAD" | "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
69
- export interface Message {
70
- method: HttpMethod;
71
- url: string;
72
- headers: Headers;
73
- content?: any;
74
- contentType?: string;
75
- mode?: RequestMode;
76
- properties: {
77
- [key: string]: any;
78
- };
79
- }
80
- interface RequestOptions {
81
- fetch: Fetch;
82
- timeout?: number;
83
- baseUrl?: string;
84
- }
85
- interface SendPromise<T> extends Promise<HttpResponseOfT<T>> {
86
- thenReceive(): Promise<T>;
87
- }
88
- export class QueryString {
89
- static serialize(params: any): string;
90
- static append(url: string, params: any): string;
91
- static getParameter(name: string): string | null | undefined;
92
- }
93
- export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
94
- export class Http {
95
- static defaults: HttpOptions;
96
- options: HttpOptions;
97
- constructor(options?: Partial<HttpOptions>);
98
- static request(method: HttpMethod, url: string, params?: any): HttpBuilder;
99
- static head(url: string, params?: any): HttpBuilder;
100
- static post(url: string, params?: any): HttpBuilder;
101
- static get(url: string, params?: any): HttpBuilder;
102
- static put(url: string, params?: any): HttpBuilder;
103
- static patch(url: string, params?: any): HttpBuilder;
104
- static delete(url: string, params?: any): HttpBuilder;
105
- request(method: HttpMethod, url: string, params?: any): HttpBuilder;
106
- head(url: string, params?: any): HttpBuilder;
107
- post(url: string, params?: any): HttpBuilder;
108
- get(url: string, params?: any): HttpBuilder;
109
- put(url: string, params?: any): HttpBuilder;
110
- patch(url: string, params?: any): HttpBuilder;
111
- delete(url: string, params?: any): HttpBuilder;
112
- onSend(callback: (request: Message) => void | Promise<void>): Subscription;
113
- onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): Subscription;
114
- onReceived(callback: (response: HttpResponseOfT<any>, request: Message, value: any) => void | Promise<void>): Subscription;
115
- }
116
- interface HttpOptions {
117
- fetch?: Fetch;
118
- timeout?: number;
119
- baseUrl?: string;
120
- }
121
- export interface Page {
122
- number?: number;
123
- size: number;
124
- }
125
- export interface PaginationResult<T> {
126
- meta: {
127
- pageCount: number;
128
- pageSize: number;
129
- totalItems: number;
130
- };
131
- data: T[];
132
- }
133
- export interface InfinitePage {
134
- continuationToken?: string;
135
- size: number;
136
- }
137
- export interface InfinitePaginationResult<T> {
138
- meta: {
139
- pageSize: number;
140
- continuationToken: string | null;
141
- };
142
- data: T[];
143
- }
144
- interface Events {
145
- sent: (response: HttpResponse, request: Message) => void | Promise<void>;
146
- }
147
- interface EventsOfT<T> extends Events {
148
- received: (response: HttpResponse, request: Message, value: T) => void | Promise<void>;
149
- }
150
- export function events<P extends any[]>(action: (...params: P) => HttpBuilder, configure: (...params: P) => Partial<Events>): (...params: P) => HttpBuilder;
151
- export function events<B extends HttpBuilderOfT<T>, P extends any[], T>(action: (...params: P) => B, configure: (...params: P) => Partial<EventsOfT<T>>): (...params: P) => B;
152
- export function isHttpError(error: Error): error is HttpError;
153
- export function isAbortError(error: Error): boolean;
154
- export function isTimeoutError(error: Error): error is TimeoutError;
155
- export const statusCodes: Readonly<{
156
- status100Continue: 100;
157
- status101SwitchingProtocols: 101;
158
- status102Processing: 102;
159
- status200OK: 200;
160
- status201Created: 201;
161
- status202Accepted: 202;
162
- status203NonAuthoritative: 203;
163
- status204NoContent: 204;
164
- status205ResetContent: 205;
165
- status206PartialContent: 206;
166
- status207MultiStatus: 207;
167
- status208AlreadyReported: 208;
168
- status226IMUsed: 226;
169
- status300MultipleChoices: 300;
170
- status301MovedPermanently: 301;
171
- status302Found: 302;
172
- status303SeeOther: 303;
173
- status304NotModified: 304;
174
- status305UseProxy: 305;
175
- status306SwitchProxy: 306;
176
- status307TemporaryRedirect: 307;
177
- status308PermanentRedirect: 308;
178
- status400BadRequest: 400;
179
- status401Unauthorized: 401;
180
- status402PaymentRequired: 402;
181
- status403Forbidden: 403;
182
- status404NotFound: 404;
183
- status405MethodNotAllowed: 405;
184
- status406NotAcceptable: 406;
185
- status407ProxyAuthenticationRequired: 407;
186
- status408RequestTimeout: 408;
187
- status409Conflict: 409;
188
- status410Gone: 410;
189
- status411LengthRequired: 411;
190
- status412PreconditionFailed: 412;
191
- status413RequestEntityTooLarge: 413;
192
- status413PayloadTooLarge: 413;
193
- status414RequestUriTooLong: 414;
194
- status414UriTooLong: 414;
195
- status415UnsupportedMediaType: 415;
196
- status416RequestedRangeNotSatisfiable: 416;
197
- status416RangeNotSatisfiable: 416;
198
- status417ExpectationFailed: 417;
199
- status418ImATeapot: 418;
200
- status419AuthenticationTimeout: 419;
201
- status421MisdirectedRequest: 421;
202
- status422UnprocessableEntity: 422;
203
- status423Locked: 423;
204
- status424FailedDependency: 424;
205
- status426UpgradeRequired: 426;
206
- status428PreconditionRequired: 428;
207
- status429TooManyRequests: 429;
208
- status431RequestHeaderFieldsTooLarge: 431;
209
- status451UnavailableForLegalReasons: 451;
210
- status500InternalServerError: 500;
211
- status501NotImplemented: 501;
212
- status502BadGateway: 502;
213
- status503ServiceUnavailable: 503;
214
- status504GatewayTimeout: 504;
215
- status505HttpVersionNotsupported: 505;
216
- status506VariantAlsoNegotiates: 506;
217
- status507InsufficientStorage: 507;
218
- status508LoopDetected: 508;
219
- status510NotExtended: 510;
220
- status511NetworkAuthenticationRequired: 511;
221
- }>;
222
- type DeserializeFn<T> = (source: any, type: Type<T>) => T | null | undefined;
223
- export type Type<T> = {
224
- new (): T;
225
- };
226
- export type Mapper<T> = (source: any) => T;
227
- export type TypeOrMapper<T> = Type<T> | Mapper<T>;
228
- export function getNullableMapper<T>(deserialize: DeserializeFn<T>, typeOrMap: Type<T> | Mapper<T> | undefined): Mapper<T | null>;
229
- export function getMapper<T>(deserialize: DeserializeFn<T>, typeOrMap: Type<T> | Mapper<T> | undefined): Mapper<T>;
230
-
231
- //# sourceMappingURL=index.d.ts.map
1
+ export { Http } from "./http";
2
+ export type { Page, PaginationResult, InfinitePage, InfinitePaginationResult, } from "./pagination";
3
+ export type { ProblemDetails } from "./problem-details";
4
+ export { QueryString } from "./query-string";
5
+ export { HttpResponse, HttpResponseOfT } from "./http-response";
6
+ export { HttpBuilder, HttpBuilderOfT } from "./http-builder";
7
+ export type { Message } from "./http-builder";
8
+ export { HttpError } from "./http-error";
9
+ export { TimeoutError } from "./timeout-error";
10
+ export { events } from "./events";
11
+ export * from "./helpers";
12
+ export type { Fetch } from "./http";
13
+ export type { Subscription } from "./event-aggregator";
14
+ export * as headerNames from "./header-names";
15
+ export * as statusCodes from "./status-codes";
16
+ export * from "./mapper";