@tstdl/base 0.78.0-beta63 → 0.78.0-beta64
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/http/client/adapters/got-http-client.adapter.js +17 -10
- package/http/client/adapters/got-http-client.adapter.js.map +1 -1
- package/http/client/adapters/undici-http-client.adapter.d.ts +1 -2
- package/http/client/adapters/undici-http-client.adapter.js +1 -6
- package/http/client/adapters/undici-http-client.adapter.js.map +1 -1
- package/http/client/http-client-request.d.ts +8 -9
- package/http/client/http-client-request.js +0 -2
- package/http/client/http-client-request.js.map +1 -1
- package/http/client/http-client-response.d.ts +8 -7
- package/http/client/http-client-response.js +2 -1
- package/http/client/http-client-response.js.map +1 -1
- package/http/client/http-client.adapter.d.ts +1 -2
- package/http/client/http-client.adapter.js.map +1 -1
- package/http/client/http-client.d.ts +30 -28
- package/http/client/http-client.js +73 -50
- package/http/client/http-client.js.map +1 -1
- package/http/http-body.d.ts +18 -0
- package/http/http-body.js +52 -0
- package/http/http-body.js.map +1 -0
- package/http/http.error.d.ts +4 -1
- package/http/http.error.js +13 -10
- package/http/http.error.js.map +1 -1
- package/http/index.d.ts +2 -0
- package/http/index.js +2 -0
- package/http/index.js.map +1 -1
- package/http/types.d.ts +1 -11
- package/http/types.js +1 -2
- package/http/types.js.map +1 -1
- package/http/utils.d.ts +12 -0
- package/http/utils.js +94 -0
- package/http/utils.js.map +1 -0
- package/package.json +2 -2
- package/supports.d.ts +4 -0
- package/supports.js +8 -0
- package/supports.js.map +1 -0
- package/utils/clone.js +2 -2
- package/utils/clone.js.map +1 -1
- package/utils/compression.d.ts +10 -6
- package/utils/compression.js +32 -1
- package/utils/compression.js.map +1 -1
- package/utils/encoding.d.ts +7 -0
- package/utils/encoding.js +12 -1
- package/utils/encoding.js.map +1 -1
- package/utils/helpers.js +2 -2
- package/utils/helpers.js.map +1 -1
- package/utils/stream/index.d.ts +2 -0
- package/utils/stream/index.js +2 -0
- package/utils/stream/index.js.map +1 -1
- package/utils/stream/readable-stream-adapter.d.ts +3 -0
- package/utils/stream/readable-stream-adapter.js +42 -0
- package/utils/stream/readable-stream-adapter.js.map +1 -0
- package/utils/stream/readable-stream-from-promise.d.ts +1 -0
- package/utils/stream/readable-stream-from-promise.js +12 -0
- package/utils/stream/readable-stream-from-promise.js.map +1 -0
- package/utils/stream/stream-reader.d.ts +2 -1
- package/utils/stream/stream-reader.js +4 -1
- package/utils/stream/stream-reader.js.map +1 -1
- package/utils/type-guards.d.ts +6 -0
- package/utils/type-guards.js +87 -74
- package/utils/type-guards.js.map +1 -1
- package/http/client/adapters/utils.d.ts +0 -13
- package/http/client/adapters/utils.js +0 -95
- package/http/client/adapters/utils.js.map +0 -1
|
@@ -16,7 +16,6 @@ const promise_1 = require("../../../promise");
|
|
|
16
16
|
const http_headers_1 = require("../../http-headers");
|
|
17
17
|
const http_error_1 = require("../../http.error");
|
|
18
18
|
const http_client_adapter_1 = require("../http-client.adapter");
|
|
19
|
-
const utils_1 = require("./utils");
|
|
20
19
|
let _got;
|
|
21
20
|
async function getGot() {
|
|
22
21
|
if ((0, type_guards_1.isUndefined)(_got)) {
|
|
@@ -43,7 +42,6 @@ let GotHttpClientAdapter = class GotHttpClientAdapter extends http_client_adapte
|
|
|
43
42
|
body: streamWrapper(got, gotRequest, request),
|
|
44
43
|
closeHandler: () => gotRequest.destroy()
|
|
45
44
|
});
|
|
46
|
-
await (0, utils_1.setBody)(response, request.responseType);
|
|
47
45
|
return response;
|
|
48
46
|
}
|
|
49
47
|
catch (error) {
|
|
@@ -58,17 +56,24 @@ GotHttpClientAdapter = __decorate([
|
|
|
58
56
|
exports.GotHttpClientAdapter = GotHttpClientAdapter;
|
|
59
57
|
async function convertError(got, error, request) {
|
|
60
58
|
if (error instanceof got.HTTPError) {
|
|
61
|
-
|
|
59
|
+
const response = convertResponse(got, request, error.response);
|
|
60
|
+
return http_error_1.HttpError.create(http_error_1.HttpErrorReason.Unknown, request, response, error);
|
|
62
61
|
}
|
|
63
62
|
if (error instanceof got.CancelError) {
|
|
64
|
-
|
|
63
|
+
const response = convertResponse(got, request, error.response);
|
|
64
|
+
return http_error_1.HttpError.create(http_error_1.HttpErrorReason.Cancelled, request, response, error);
|
|
65
65
|
}
|
|
66
66
|
if (error instanceof got.TimeoutError) {
|
|
67
|
-
|
|
67
|
+
const response = convertResponse(got, request, error.response);
|
|
68
|
+
return http_error_1.HttpError.create(http_error_1.HttpErrorReason.Timeout, request, response, error);
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
+
if ((error instanceof got.ReadError) || (error instanceof got.MaxRedirectsError)) {
|
|
71
|
+
const response = convertResponse(got, request, error.response);
|
|
72
|
+
return http_error_1.HttpError.create(http_error_1.HttpErrorReason.ResponseError, request, response, error);
|
|
73
|
+
}
|
|
74
|
+
return http_error_1.HttpError.create(http_error_1.HttpErrorReason.Unknown, request, undefined, error);
|
|
70
75
|
}
|
|
71
|
-
|
|
76
|
+
function convertResponse(got, request, gotResponse) {
|
|
72
77
|
if ((0, type_guards_1.isUndefined)(gotResponse)) {
|
|
73
78
|
return undefined;
|
|
74
79
|
}
|
|
@@ -80,7 +85,6 @@ async function convertResponse(got, request, gotResponse) {
|
|
|
80
85
|
body: streamWrapper(got, gotResponse, request),
|
|
81
86
|
closeHandler: () => gotResponse.destroy()
|
|
82
87
|
});
|
|
83
|
-
await (0, utils_1.setBody)(response, request.responseType);
|
|
84
88
|
return response;
|
|
85
89
|
}
|
|
86
90
|
// eslint-disable-next-line max-statements, max-lines-per-function
|
|
@@ -89,7 +93,9 @@ function getGotOptions(got, isStream, { method, headers, body, timeout }) {
|
|
|
89
93
|
isStream,
|
|
90
94
|
retry: { limit: 0, methods: [] },
|
|
91
95
|
followRedirect: true,
|
|
92
|
-
|
|
96
|
+
throwHttpErrors: false,
|
|
97
|
+
method,
|
|
98
|
+
decompress: false
|
|
93
99
|
};
|
|
94
100
|
const options = new got.Options(optionsInit);
|
|
95
101
|
if ((0, type_guards_1.isDefined)(headers)) {
|
|
@@ -135,7 +141,8 @@ async function* streamWrapper(got, readable, httpRequest) {
|
|
|
135
141
|
yield* readable;
|
|
136
142
|
}
|
|
137
143
|
catch (error) {
|
|
138
|
-
|
|
144
|
+
const convertedError = await convertError(got, error, httpRequest);
|
|
145
|
+
throw convertedError;
|
|
139
146
|
}
|
|
140
147
|
}
|
|
141
148
|
//# sourceMappingURL=got-http-client.adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"got-http-client.adapter.js","sourceRoot":"","sources":["../../../../source/http/client/adapters/got-http-client.adapter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,kDAAmD;AACnD,gDAAwC;AACxC,4DAA4E;AAG5E,mCAAkC;AAElC,0BAAwC;AACxC,8CAAmD;AACnD,qDAAiD;AACjD,iDAA8D;AAC9D,gEAA2D;
|
|
1
|
+
{"version":3,"file":"got-http-client.adapter.js","sourceRoot":"","sources":["../../../../source/http/client/adapters/got-http-client.adapter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,kDAAmD;AACnD,gDAAwC;AACxC,4DAA4E;AAG5E,mCAAkC;AAElC,0BAAwC;AACxC,8CAAmD;AACnD,qDAAiD;AACjD,iDAA8D;AAC9D,gEAA2D;AAE3D,IAAI,IAA4B,CAAC;AAEjC,KAAK,UAAU,MAAM;IACnB,IAAI,IAAA,yBAAW,EAAC,IAAI,CAAC,EAAE;QACrB,IAAI,GAAG,MAAO,IAAI,CAAC,iBAAiB,CAAyB,CAAC,CAAC,sDAAsD;KACtH;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAGM,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,uCAAiB;IACzD,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,MAAM,GAAG,GAAG,MAAM,MAAM,EAAE,CAAC;QAE3B,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,eAAe,GAAG,IAA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AS,CAAC,QAAQ,CAAC,uCAAiB,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC,CAAC;KAC3E;AACH,CAAC;AAJD,sEAIC;AAED,KAAK,SAAS,CAAC,CAAC,aAAa,CAAC,GAAe,EAAE,QAAoC,EAAE,WAA8B;IACjH,IAAI;QACF,KAAK,CAAC,CAAC,QAAQ,CAAC;KACjB;IACD,OAAO,KAAK,EAAE;QACZ,MAAM,cAAc,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QACnE,MAAM,cAAc,CAAC;KACtB;AACH,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HttpBodyType } from "../..";
|
|
2
1
|
import type { Dispatcher } from 'undici';
|
|
3
2
|
import type { HttpClientRequest } from '../http-client-request';
|
|
4
3
|
import { HttpClientResponse } from '../http-client-response';
|
|
@@ -9,7 +8,7 @@ export declare type UndiciHttpClientAdapterOptions = {
|
|
|
9
8
|
export declare class UndiciHttpClientAdapter extends HttpClientAdapter {
|
|
10
9
|
private readonly options;
|
|
11
10
|
constructor(options?: UndiciHttpClientAdapterOptions);
|
|
12
|
-
call
|
|
11
|
+
call(httpClientRequest: HttpClientRequest): Promise<HttpClientResponse>;
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* @param register whether to register for {@link HttpClientAdapter}
|
|
@@ -20,7 +20,6 @@ const type_guards_1 = require("../../../utils/type-guards");
|
|
|
20
20
|
const undici_1 = require("undici");
|
|
21
21
|
const http_client_response_1 = require("../http-client-response");
|
|
22
22
|
const http_client_adapter_1 = require("../http-client.adapter");
|
|
23
|
-
const utils_1 = require("./utils");
|
|
24
23
|
let defaultOptions = {};
|
|
25
24
|
let UndiciHttpClientAdapter = class UndiciHttpClientAdapter extends http_client_adapter_1.HttpClientAdapter {
|
|
26
25
|
constructor(options = {}) {
|
|
@@ -69,10 +68,6 @@ let UndiciHttpClientAdapter = class UndiciHttpClientAdapter extends http_client_
|
|
|
69
68
|
body: response.body,
|
|
70
69
|
closeHandler: () => response.body.destroy()
|
|
71
70
|
});
|
|
72
|
-
await (0, utils_1.setBody)(httpClientResponse, httpClientRequest.responseType);
|
|
73
|
-
if ((response.statusCode >= 400 && response.statusCode <= 500)) {
|
|
74
|
-
throw new http_1.HttpError(http_1.HttpErrorReason.ErrorResponse, httpClientRequest, httpClientResponse, `status code ${response.statusCode}`);
|
|
75
|
-
}
|
|
76
71
|
return httpClientResponse;
|
|
77
72
|
}
|
|
78
73
|
catch (error) {
|
|
@@ -80,7 +75,7 @@ let UndiciHttpClientAdapter = class UndiciHttpClientAdapter extends http_client_
|
|
|
80
75
|
const reason = ((error instanceof undici_1.errors.BodyTimeoutError) || (error instanceof undici_1.errors.HeadersTimeoutError)) ? http_1.HttpErrorReason.Timeout
|
|
81
76
|
: (error instanceof undici_1.errors.RequestAbortedError) ? http_1.HttpErrorReason.Cancelled
|
|
82
77
|
: http_1.HttpErrorReason.Unknown;
|
|
83
|
-
throw new http_1.HttpError(reason, httpClientRequest, undefined, error);
|
|
78
|
+
throw new http_1.HttpError(reason, httpClientRequest, undefined, undefined, error);
|
|
84
79
|
}
|
|
85
80
|
throw error;
|
|
86
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undici-http-client.adapter.js","sourceRoot":"","sources":["../../../../source/http/client/adapters/undici-http-client.adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA8D;
|
|
1
|
+
{"version":3,"file":"undici-http-client.adapter.js","sourceRoot":"","sources":["../../../../source/http/client/adapters/undici-http-client.adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA8D;AAC9D,gCAAiE;AACjE,gDAAwC;AACxC,4DAAgD;AAGhD,mCAAyD;AAGzD,kEAA6D;AAC7D,gEAA2D;AAM3D,IAAI,cAAc,GAAmC,EAAE,CAAC;AAGjD,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,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,CAAC,CAAC;aAC7E;YAED,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF,CAAA;AAxEY,uBAAuB;IADnC,IAAA,qBAAS,EAAC,EAAE,uBAAuB,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC;IAI9C,WAAA,IAAA,qBAAS,GAAE,CAAA;;GAHb,uBAAuB,CAwEnC;AAxEY,0DAAuB;AA0EpC;;GAEG;AACH,SAAgB,gCAAgC,CAAC,UAAmE,EAAE;IACpH,cAAc,GAAG,OAAO,CAAC;IAEzB,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI,EAAE;QAC5B,qBAAS,CAAC,QAAQ,CAAC,uCAAiB,EAAE,EAAE,QAAQ,EAAE,uBAAuB,EAAE,CAAC,CAAC;KAC9E;AACH,CAAC;AAND,4EAMC"}
|
|
@@ -10,7 +10,7 @@ import type { HttpQueryObject } from '../http-query';
|
|
|
10
10
|
import { HttpQuery } from '../http-query';
|
|
11
11
|
import type { HttpUrlParametersObject } from '../http-url-parameters';
|
|
12
12
|
import { HttpUrlParameters } from '../http-url-parameters';
|
|
13
|
-
import type {
|
|
13
|
+
import type { HttpMethod } from '../types';
|
|
14
14
|
/** only one type at a time is supported. If multiple are set, behaviour is undefined */
|
|
15
15
|
export declare type HttpRequestBody = {
|
|
16
16
|
text?: string;
|
|
@@ -27,7 +27,7 @@ export declare type HttpRequestAuthorization = {
|
|
|
27
27
|
bearer?: string;
|
|
28
28
|
token?: string;
|
|
29
29
|
};
|
|
30
|
-
export declare type HttpClientRequestOptions
|
|
30
|
+
export declare type HttpClientRequestOptions = Partial<TypedOmit<HttpClientRequest, 'url' | 'method' | 'abortToken' | 'abort' | 'headers' | 'query' | 'body'>> & {
|
|
31
31
|
urlParameter?: HttpUrlParametersObject | HttpUrlParameters;
|
|
32
32
|
headers?: HttpHeadersObject | HttpHeaders;
|
|
33
33
|
query?: HttpQueryObject | HttpQuery;
|
|
@@ -41,12 +41,12 @@ export declare type HttpClientRequestOptions<T extends HttpBodyType = HttpBodyTy
|
|
|
41
41
|
};
|
|
42
42
|
abortToken?: ReadonlyCancellationToken;
|
|
43
43
|
};
|
|
44
|
-
export declare type HttpClientRequestObject
|
|
44
|
+
export declare type HttpClientRequestObject = HttpClientRequestOptions & {
|
|
45
45
|
url: string;
|
|
46
46
|
method?: HttpMethod;
|
|
47
47
|
};
|
|
48
48
|
export declare type CredentialsOptions = 'omit' | 'same-origin' | 'include';
|
|
49
|
-
export declare class HttpClientRequest
|
|
49
|
+
export declare class HttpClientRequest implements Disposable {
|
|
50
50
|
private readonly _abortToken;
|
|
51
51
|
url: string;
|
|
52
52
|
method: HttpMethod;
|
|
@@ -97,7 +97,6 @@ export declare class HttpClientRequest<T extends HttpBodyType = HttpBodyType> im
|
|
|
97
97
|
query: HttpQuery;
|
|
98
98
|
authorization: HttpRequestAuthorization | undefined;
|
|
99
99
|
body: HttpRequestBody | undefined;
|
|
100
|
-
responseType: T;
|
|
101
100
|
credentials: CredentialsOptions;
|
|
102
101
|
/**
|
|
103
102
|
* request timeout in milliseconds
|
|
@@ -115,11 +114,11 @@ export declare class HttpClientRequest<T extends HttpBodyType = HttpBodyType> im
|
|
|
115
114
|
* can be used to cancel the request. Throws HttpError
|
|
116
115
|
*/
|
|
117
116
|
get abortToken(): ReadonlyCancellationToken;
|
|
118
|
-
constructor(url: string, method?: HttpMethod, options?: HttpClientRequestOptions
|
|
119
|
-
constructor(requestObject: HttpClientRequestObject
|
|
117
|
+
constructor(url: string, method?: HttpMethod, options?: HttpClientRequestOptions);
|
|
118
|
+
constructor(requestObject: HttpClientRequestObject);
|
|
120
119
|
[dispose](): void;
|
|
121
120
|
/** abort the request */
|
|
122
121
|
abort(): void;
|
|
123
|
-
clone(): HttpClientRequest
|
|
124
|
-
asObject(): HttpClientRequestObject
|
|
122
|
+
clone(): HttpClientRequest;
|
|
123
|
+
asObject(): HttpClientRequestObject;
|
|
125
124
|
}
|
|
@@ -30,7 +30,6 @@ class HttpClientRequest {
|
|
|
30
30
|
this.query = new http_query_1.HttpQuery(requestOptions.query);
|
|
31
31
|
this.authorization = requestOptions.authorization;
|
|
32
32
|
this.body = normalizeBody(requestOptions.body);
|
|
33
|
-
this.responseType = requestOptions.responseType ?? 'auto';
|
|
34
33
|
this.credentials = requestOptions.credentials ?? 'omit';
|
|
35
34
|
this.timeout = requestOptions.timeout ?? 30000;
|
|
36
35
|
this.throwOnNon200 = requestOptions.throwOnNon200 ?? true;
|
|
@@ -72,7 +71,6 @@ class HttpClientRequest {
|
|
|
72
71
|
query: this.query.asObject(),
|
|
73
72
|
authorization: this.authorization,
|
|
74
73
|
body,
|
|
75
|
-
responseType: this.responseType,
|
|
76
74
|
timeout: this.timeout,
|
|
77
75
|
throwOnNon200: this.throwOnNon200,
|
|
78
76
|
context: this.context
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-client-request.js","sourceRoot":"","sources":["../../../source/http/client/http-client-request.ts"],"names":[],"mappings":";;;AACA,iDAAuC;AAGvC,uEAA+D;AAC/D,6CAAsC;AACtC,yDAAuE;AAEvE,4CAAwC;AAExC,kDAA8C;AAE9C,8CAA0C;AAE1C,gEAA2D;AA2C3D,MAAa,iBAAiB;
|
|
1
|
+
{"version":3,"file":"http-client-request.js","sourceRoot":"","sources":["../../../source/http/client/http-client-request.ts"],"names":[],"mappings":";;;AACA,iDAAuC;AAGvC,uEAA+D;AAC/D,6CAAsC;AACtC,yDAAuE;AAEvE,4CAAwC;AAExC,kDAA8C;AAE9C,8CAA0C;AAE1C,gEAA2D;AA2C3D,MAAa,iBAAiB;IAiF5B,YAAY,WAA6C,EAAE,MAAmB,EAAE,UAAoC,EAAE;QACpH,IAAI,IAAA,sBAAQ,EAAC,WAAW,CAAC,EAAE;YACzB,IAAI,CAAC,GAAG,GAAG,WAAW,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,KAAK,CAAC;SAC/B;aACI;YACH,IAAI,CAAC,GAAG,GAAG,WAAW,CAAC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,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC3C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YAChC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YAC5B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,IAAI;YACJ,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AAvJD,8CAuJC;AAED,SAAS,aAAa,CAAC,IAAsC;IAC3D,IAAI,IAAA,yBAAW,EAAC,IAAI,CAAC,EAAE;QACrB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IAEnC,IAAI,IAAA,uBAAS,EAAC,cAAc,CAAC,IAAI,CAAC,EAAE;QAClC,cAAc,CAAC,IAAI,GAAG,IAAI,oBAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;KACzD;IAED,OAAO,cAA2C,CAAC;AACrD,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { TypedOmit } from "../../types";
|
|
2
|
+
import type { HttpBodySource } from '../http-body';
|
|
3
|
+
import { HttpBody } from '../http-body';
|
|
2
4
|
import type { HttpHeadersObject } from '../http-headers';
|
|
3
5
|
import { HttpHeaders } from '../http-headers';
|
|
4
|
-
import type { HttpBody, HttpBodyType } from '../types';
|
|
5
6
|
import type { HttpClientRequest, HttpClientRequestObject } from './http-client-request';
|
|
6
7
|
export declare type ReadBodyOptions = {
|
|
7
8
|
maxBytes?: number;
|
|
@@ -10,22 +11,22 @@ export declare type HttpClientResponseObject = TypedOmit<HttpClientResponse, 're
|
|
|
10
11
|
request: HttpClientRequestObject;
|
|
11
12
|
headers: HttpHeadersObject;
|
|
12
13
|
};
|
|
13
|
-
export declare type HttpClientResponseOptions
|
|
14
|
-
request: HttpClientRequest
|
|
14
|
+
export declare type HttpClientResponseOptions = {
|
|
15
|
+
request: HttpClientRequest;
|
|
15
16
|
statusCode: number;
|
|
16
17
|
statusMessage: string;
|
|
17
18
|
headers: HttpHeadersObject | HttpHeaders;
|
|
18
|
-
body: HttpBody
|
|
19
|
+
body: HttpBody | HttpBodySource;
|
|
19
20
|
closeHandler: () => void;
|
|
20
21
|
};
|
|
21
|
-
export declare class HttpClientResponse
|
|
22
|
+
export declare class HttpClientResponse {
|
|
22
23
|
private readonly closeHandler;
|
|
23
24
|
readonly request: HttpClientRequest;
|
|
24
25
|
readonly statusCode: number;
|
|
25
26
|
readonly statusMessage: string;
|
|
26
27
|
readonly headers: HttpHeaders;
|
|
27
|
-
readonly body: HttpBody
|
|
28
|
-
constructor(options: HttpClientResponseOptions
|
|
28
|
+
readonly body: HttpBody;
|
|
29
|
+
constructor(options: HttpClientResponseOptions);
|
|
29
30
|
close(): void;
|
|
30
31
|
asObject(): HttpClientResponseObject;
|
|
31
32
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpClientResponse = void 0;
|
|
4
|
+
const http_body_1 = require("../http-body");
|
|
4
5
|
const http_headers_1 = require("../http-headers");
|
|
5
6
|
class HttpClientResponse {
|
|
6
7
|
constructor(options) {
|
|
@@ -8,7 +9,7 @@ class HttpClientResponse {
|
|
|
8
9
|
this.statusCode = options.statusCode;
|
|
9
10
|
this.statusMessage = options.statusMessage;
|
|
10
11
|
this.headers = new http_headers_1.HttpHeaders(options.headers);
|
|
11
|
-
this.body = options.body;
|
|
12
|
+
this.body = (options.body instanceof http_body_1.HttpBody) ? options.body : new http_body_1.HttpBody(options.body, this.headers);
|
|
12
13
|
this.closeHandler = options.closeHandler;
|
|
13
14
|
}
|
|
14
15
|
close() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-client-response.js","sourceRoot":"","sources":["../../../source/http/client/http-client-response.ts"],"names":[],"mappings":";;;AAEA,kDAA8C;
|
|
1
|
+
{"version":3,"file":"http-client-response.js","sourceRoot":"","sources":["../../../source/http/client/http-client-response.ts"],"names":[],"mappings":";;;AAEA,4CAAwC;AAExC,kDAA8C;AAqB9C,MAAa,kBAAkB;IAS7B,YAAY,OAAkC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,IAAI,0BAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,YAAY,oBAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,oBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACzG,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAED,KAAK;QACH,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,QAAQ;QACN,MAAM,GAAG,GAA6B;YACpC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YAChC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YAChC,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;QAEF,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAjCD,gDAiCC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { HttpBodyType } from '../types';
|
|
2
1
|
import type { HttpClientRequest } from './http-client-request';
|
|
3
2
|
import type { HttpClientResponse } from './http-client-response';
|
|
4
3
|
export declare abstract class HttpClientAdapter {
|
|
5
4
|
/**
|
|
6
5
|
* should return a response with an stream (preferred) or Uint8Array if streams are not supported
|
|
7
6
|
*/
|
|
8
|
-
abstract call
|
|
7
|
+
abstract call(request: HttpClientRequest): Promise<HttpClientResponse>;
|
|
9
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.adapter.js","sourceRoot":"","sources":["../../../source/http/client/http-client.adapter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"http-client.adapter.js","sourceRoot":"","sources":["../../../source/http/client/http-client.adapter.ts"],"names":[],"mappings":";;;AAGA,MAAsB,iBAAiB;CAKtC;AALD,8CAKC"}
|
|
@@ -2,7 +2,7 @@ import type { Injectable } from "../../container";
|
|
|
2
2
|
import { resolveArgumentType } from "../../container";
|
|
3
3
|
import type { OneOrMany, UndefinableJson } from "../../types";
|
|
4
4
|
import type { AsyncMiddleware, AsyncMiddlewareHandler, AsyncMiddlewareNext } from "../../utils/middleware";
|
|
5
|
-
import type {
|
|
5
|
+
import type { HttpMethod, HttpValue } from '../types';
|
|
6
6
|
import type { HttpClientRequestOptions } from './http-client-request';
|
|
7
7
|
import { HttpClientRequest } from './http-client-request';
|
|
8
8
|
import type { HttpClientResponse } from './http-client-response';
|
|
@@ -40,33 +40,35 @@ export declare class HttpClient implements Injectable<HttpClientArgument> {
|
|
|
40
40
|
setDefaultHeader(name: string, value: OneOrMany<HttpValue>): void;
|
|
41
41
|
deleteDefaultHeader(name: string): void;
|
|
42
42
|
head(url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
43
|
-
get
|
|
44
|
-
getText(url: string, options?: HttpClientRequestOptions
|
|
45
|
-
getJson<T extends UndefinableJson>(url: string, options?: HttpClientRequestOptions
|
|
46
|
-
getBuffer(url: string, options?: HttpClientRequestOptions
|
|
47
|
-
getStream(url: string, options?: HttpClientRequestOptions
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
43
|
+
get(url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
44
|
+
getText(url: string, options?: HttpClientRequestOptions): Promise<string>;
|
|
45
|
+
getJson<T extends UndefinableJson>(url: string, options?: HttpClientRequestOptions): Promise<T>;
|
|
46
|
+
getBuffer(url: string, options?: HttpClientRequestOptions): Promise<Uint8Array>;
|
|
47
|
+
getStream(url: string, options?: HttpClientRequestOptions): ReadableStream<string> | ReadableStream<Uint8Array>;
|
|
48
|
+
getTextStream(url: string, options?: HttpClientRequestOptions): ReadableStream<string>;
|
|
49
|
+
getBinaryStream(url: string, options?: HttpClientRequestOptions): ReadableStream<Uint8Array>;
|
|
50
|
+
post(url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
51
|
+
postText(url: string, options?: HttpClientRequestOptions): Promise<string>;
|
|
52
|
+
postJson<T extends UndefinableJson>(url: string, options?: HttpClientRequestOptions): Promise<T>;
|
|
53
|
+
postBuffer(url: string, options?: HttpClientRequestOptions): Promise<Uint8Array>;
|
|
54
|
+
postStream(url: string, options?: HttpClientRequestOptions): ReadableStream<Uint8Array>;
|
|
55
|
+
put(url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
56
|
+
putText(url: string, options?: HttpClientRequestOptions): Promise<string>;
|
|
57
|
+
putJson<T extends UndefinableJson = UndefinableJson>(url: string, options?: HttpClientRequestOptions): Promise<T>;
|
|
58
|
+
putBuffer(url: string, options?: HttpClientRequestOptions): Promise<Uint8Array>;
|
|
59
|
+
putStream(url: string, options?: HttpClientRequestOptions): ReadableStream<Uint8Array>;
|
|
60
|
+
patch(url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
61
|
+
patchText(url: string, options?: HttpClientRequestOptions): Promise<string>;
|
|
62
|
+
patchJson<T extends UndefinableJson = UndefinableJson>(url: string, options?: HttpClientRequestOptions): Promise<T>;
|
|
63
|
+
patchBuffer(url: string, options?: HttpClientRequestOptions): Promise<Uint8Array>;
|
|
64
|
+
patchStream(url: string, options?: HttpClientRequestOptions): ReadableStream<Uint8Array>;
|
|
65
|
+
delete(url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
66
|
+
deleteText(url: string, options?: HttpClientRequestOptions): Promise<string>;
|
|
67
|
+
deleteJson<T extends UndefinableJson>(url: string, options?: HttpClientRequestOptions): Promise<T>;
|
|
68
|
+
deleteBuffer(url: string, options?: HttpClientRequestOptions): Promise<Uint8Array>;
|
|
69
|
+
deleteStream(url: string, options?: HttpClientRequestOptions): ReadableStream<Uint8Array>;
|
|
70
|
+
request(method: HttpMethod, url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
71
|
+
rawRequest(request: HttpClientRequest): Promise<HttpClientResponse>;
|
|
70
72
|
private updateHandlers;
|
|
71
73
|
private prepareRequest;
|
|
72
74
|
}
|
|
@@ -19,6 +19,7 @@ const array_1 = require("../../utils/array");
|
|
|
19
19
|
const base64_1 = require("../../utils/base64");
|
|
20
20
|
const encoding_1 = require("../../utils/encoding");
|
|
21
21
|
const middleware_1 = require("../../utils/middleware");
|
|
22
|
+
const readable_stream_from_promise_1 = require("../../utils/stream/readable-stream-from-promise");
|
|
22
23
|
const type_guards_1 = require("../../utils/type-guards");
|
|
23
24
|
const url_builder_1 = require("../../utils/url-builder");
|
|
24
25
|
const http_headers_1 = require("../http-headers");
|
|
@@ -51,102 +52,124 @@ let HttpClient = class HttpClient {
|
|
|
51
52
|
this.headers.remove(name);
|
|
52
53
|
}
|
|
53
54
|
async head(url, options) {
|
|
54
|
-
return this.request('HEAD', url, { ...options
|
|
55
|
+
return this.request('HEAD', url, { ...options });
|
|
55
56
|
}
|
|
56
57
|
async get(url, options) {
|
|
57
58
|
return this.request('GET', url, options);
|
|
58
59
|
}
|
|
59
60
|
async getText(url, options) {
|
|
60
|
-
const response = await this.request('GET', url, { ...options
|
|
61
|
-
return response.body;
|
|
61
|
+
const response = await this.request('GET', url, { ...options });
|
|
62
|
+
return response.body.readAsText();
|
|
62
63
|
}
|
|
63
64
|
async getJson(url, options) {
|
|
64
|
-
const response = await this.request('GET', url, { ...options
|
|
65
|
-
return response.body;
|
|
65
|
+
const response = await this.request('GET', url, { ...options });
|
|
66
|
+
return response.body.readAsJson();
|
|
66
67
|
}
|
|
67
68
|
async getBuffer(url, options) {
|
|
68
|
-
const response = await this.request('GET', url, { ...options
|
|
69
|
-
return response.body;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const response = await this.request('GET', url, { ...options });
|
|
70
|
+
return response.body.readAsBuffer();
|
|
71
|
+
}
|
|
72
|
+
getStream(url, options) {
|
|
73
|
+
return (0, readable_stream_from_promise_1.readableStreamFromPromise)(async () => {
|
|
74
|
+
const response = await this.request('GET', url, { ...options });
|
|
75
|
+
return response.body.readAsStream();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
getTextStream(url, options) {
|
|
79
|
+
return (0, readable_stream_from_promise_1.readableStreamFromPromise)(async () => {
|
|
80
|
+
const response = await this.request('GET', url, { ...options });
|
|
81
|
+
return response.body.readAsTextStream();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
getBinaryStream(url, options) {
|
|
85
|
+
return (0, readable_stream_from_promise_1.readableStreamFromPromise)(async () => {
|
|
86
|
+
const response = await this.request('GET', url, { ...options });
|
|
87
|
+
return response.body.readAsBinaryStream();
|
|
88
|
+
});
|
|
74
89
|
}
|
|
75
90
|
async post(url, options) {
|
|
76
91
|
return this.request('POST', url, options);
|
|
77
92
|
}
|
|
78
93
|
async postText(url, options) {
|
|
79
|
-
const response = await this.request('POST', url, { ...options
|
|
80
|
-
return response.body;
|
|
94
|
+
const response = await this.request('POST', url, { ...options });
|
|
95
|
+
return response.body.readAsText();
|
|
81
96
|
}
|
|
82
97
|
async postJson(url, options) {
|
|
83
|
-
const response = await this.request('POST', url, { ...options
|
|
84
|
-
return response.body;
|
|
98
|
+
const response = await this.request('POST', url, { ...options });
|
|
99
|
+
return response.body.readAsJson();
|
|
85
100
|
}
|
|
86
101
|
async postBuffer(url, options) {
|
|
87
|
-
const response = await this.request('POST', url, { ...options
|
|
88
|
-
return response.body;
|
|
102
|
+
const response = await this.request('POST', url, { ...options });
|
|
103
|
+
return response.body.readAsBuffer();
|
|
89
104
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
postStream(url, options) {
|
|
106
|
+
return (0, readable_stream_from_promise_1.readableStreamFromPromise)(async () => {
|
|
107
|
+
const response = await this.request('POST', url, { ...options });
|
|
108
|
+
return response.body.readAsBinaryStream();
|
|
109
|
+
});
|
|
93
110
|
}
|
|
94
111
|
async put(url, options) {
|
|
95
112
|
return this.request('PUT', url, options);
|
|
96
113
|
}
|
|
97
114
|
async putText(url, options) {
|
|
98
|
-
const response = await this.request('PUT', url, { ...options
|
|
99
|
-
return response.body;
|
|
115
|
+
const response = await this.request('PUT', url, { ...options });
|
|
116
|
+
return response.body.readAsText();
|
|
100
117
|
}
|
|
101
118
|
async putJson(url, options) {
|
|
102
|
-
const response = await this.request('PUT', url, { ...options
|
|
103
|
-
return response.body;
|
|
119
|
+
const response = await this.request('PUT', url, { ...options });
|
|
120
|
+
return response.body.readAsJson();
|
|
104
121
|
}
|
|
105
122
|
async putBuffer(url, options) {
|
|
106
|
-
const response = await this.request('PUT', url, { ...options
|
|
107
|
-
return response.body;
|
|
123
|
+
const response = await this.request('PUT', url, { ...options });
|
|
124
|
+
return response.body.readAsBuffer();
|
|
108
125
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
126
|
+
putStream(url, options) {
|
|
127
|
+
return (0, readable_stream_from_promise_1.readableStreamFromPromise)(async () => {
|
|
128
|
+
const response = await this.request('PUT', url, { ...options });
|
|
129
|
+
return response.body.readAsBinaryStream();
|
|
130
|
+
});
|
|
112
131
|
}
|
|
113
132
|
async patch(url, options) {
|
|
114
133
|
return this.request('PATCH', url, options);
|
|
115
134
|
}
|
|
116
135
|
async patchText(url, options) {
|
|
117
|
-
const response = await this.request('PATCH', url, { ...options
|
|
118
|
-
return response.body;
|
|
136
|
+
const response = await this.request('PATCH', url, { ...options });
|
|
137
|
+
return response.body.readAsText();
|
|
119
138
|
}
|
|
120
139
|
async patchJson(url, options) {
|
|
121
|
-
const response = await this.request('PATCH', url, { ...options
|
|
122
|
-
return response.body;
|
|
140
|
+
const response = await this.request('PATCH', url, { ...options });
|
|
141
|
+
return response.body.readAsJson();
|
|
123
142
|
}
|
|
124
143
|
async patchBuffer(url, options) {
|
|
125
|
-
const response = await this.request('PATCH', url, { ...options
|
|
126
|
-
return response.body;
|
|
144
|
+
const response = await this.request('PATCH', url, { ...options });
|
|
145
|
+
return response.body.readAsBuffer();
|
|
127
146
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
147
|
+
patchStream(url, options) {
|
|
148
|
+
return (0, readable_stream_from_promise_1.readableStreamFromPromise)(async () => {
|
|
149
|
+
const response = await this.request('PATCH', url, { ...options });
|
|
150
|
+
return response.body.readAsBinaryStream();
|
|
151
|
+
});
|
|
131
152
|
}
|
|
132
153
|
async delete(url, options) {
|
|
133
154
|
return this.request('DELETE', url, options);
|
|
134
155
|
}
|
|
135
156
|
async deleteText(url, options) {
|
|
136
|
-
const response = await this.request('DELETE', url, { ...options
|
|
137
|
-
return response.body;
|
|
157
|
+
const response = await this.request('DELETE', url, { ...options });
|
|
158
|
+
return response.body.readAsText();
|
|
138
159
|
}
|
|
139
160
|
async deleteJson(url, options) {
|
|
140
|
-
const response = await this.request('DELETE', url, { ...options
|
|
141
|
-
return response.body;
|
|
161
|
+
const response = await this.request('DELETE', url, { ...options });
|
|
162
|
+
return response.body.readAsJson();
|
|
142
163
|
}
|
|
143
164
|
async deleteBuffer(url, options) {
|
|
144
|
-
const response = await this.request('DELETE', url, { ...options
|
|
145
|
-
return response.body;
|
|
165
|
+
const response = await this.request('DELETE', url, { ...options });
|
|
166
|
+
return response.body.readAsBuffer();
|
|
146
167
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
168
|
+
deleteStream(url, options) {
|
|
169
|
+
return (0, readable_stream_from_promise_1.readableStreamFromPromise)(async () => {
|
|
170
|
+
const response = await this.request('DELETE', url, { ...options });
|
|
171
|
+
return response.body.readAsBinaryStream();
|
|
172
|
+
});
|
|
150
173
|
}
|
|
151
174
|
async request(method, url, options = {}) {
|
|
152
175
|
const request = new http_client_request_1.HttpClientRequest(url, method, options);
|
|
@@ -216,7 +239,8 @@ async function errorMiddleware(request, next) {
|
|
|
216
239
|
try {
|
|
217
240
|
const response = await next(request);
|
|
218
241
|
if (request.throwOnNon200 && ((response.statusCode < 200) || (response.statusCode >= 300))) {
|
|
219
|
-
|
|
242
|
+
const httpError = await http_error_1.HttpError.create(http_error_1.HttpErrorReason.Non200StatusCode, request, response, `Status code ${response.statusCode}.`);
|
|
243
|
+
throw httpError;
|
|
220
244
|
}
|
|
221
245
|
return response;
|
|
222
246
|
}
|
|
@@ -270,8 +294,7 @@ function mapParameters(request, baseUrl) {
|
|
|
270
294
|
}
|
|
271
295
|
}
|
|
272
296
|
if (parameterEntries.size > 0) {
|
|
273
|
-
|
|
274
|
-
throw new http_error_1.HttpError(http_error_1.HttpErrorReason.InvalidRequest, request, undefined, error);
|
|
297
|
+
throw new http_error_1.HttpError(http_error_1.HttpErrorReason.InvalidRequest, request, undefined, 'Not all parameters could be mapped to url, query and body because request is either GET/HEAD or body is already defined');
|
|
275
298
|
}
|
|
276
299
|
if ((0, type_guards_1.isDefined)(request.query)) {
|
|
277
300
|
for (const [key, valueOrValues] of request.query) {
|