@trayio/commons 5.35.0-unstable.fd7158a → 6.0.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/base64/Base64.d.ts +10 -5
- package/dist/base64/Base64.d.ts.map +1 -1
- package/dist/base64/Base64.js +40 -8
- package/dist/base64/Base64.unit.test.js +27 -4
- package/dist/buffer/BufferExtensions.d.ts +4 -4
- package/dist/buffer/BufferExtensions.d.ts.map +1 -1
- package/dist/buffer/BufferExtensions.js +38 -25
- package/dist/buffer/BufferExtensions.unit.test.js +45 -22
- package/dist/callsite/CallSite.js +7 -17
- package/dist/codec/CamelCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/CamelCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/CamelCasePropertyNameCodec.js +25 -2
- package/dist/codec/Codec.abstract.test.d.ts +2 -2
- package/dist/codec/Codec.abstract.test.d.ts.map +1 -1
- package/dist/codec/Codec.abstract.test.js +31 -5
- package/dist/codec/Codec.d.ts +2 -2
- package/dist/codec/Codec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.d.ts +2 -2
- package/dist/codec/CompositeCodec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.js +26 -2
- package/dist/codec/PartialRedactionCodec.d.ts +2 -2
- package/dist/codec/PartialRedactionCodec.d.ts.map +1 -1
- package/dist/codec/PartialRedactionCodec.js +25 -2
- package/dist/codec/RemoveNullValuesCodec.d.ts +2 -2
- package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -1
- package/dist/codec/RemoveNullValuesCodec.js +25 -2
- package/dist/codec/RemoveTopLevelTagCodec.d.ts +2 -2
- package/dist/codec/RemoveTopLevelTagCodec.d.ts.map +1 -1
- package/dist/codec/RemoveTopLevelTagCodec.js +25 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts +2 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts.map +1 -1
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.js +25 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.js +38 -15
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/SnakeCasePropertyNameCodec.js +25 -2
- package/dist/codec/TypeCodec.d.ts +8 -24
- package/dist/codec/TypeCodec.d.ts.map +1 -1
- package/dist/codec/TypeCodec.js +48 -40
- package/dist/codec/TypeCodec.unit.test.js +38 -12
- package/dist/dynamicschema/DynamicSchema.d.ts +12 -6
- package/dist/dynamicschema/DynamicSchema.d.ts.map +1 -1
- package/dist/dynamicschema/DynamicSchema.js +41 -18
- package/dist/dynamicschema/DynamicSchema.unit.test.js +75 -51
- package/dist/dynamictype/DynamicType.d.ts +20 -17
- package/dist/dynamictype/DynamicType.d.ts.map +1 -1
- package/dist/dynamictype/DynamicType.js +35 -48
- package/dist/file/FakeFileStorage.d.ts +8 -8
- package/dist/file/FakeFileStorage.d.ts.map +1 -1
- package/dist/file/FakeFileStorage.js +40 -16
- package/dist/file/File.d.ts +14 -10
- package/dist/file/File.d.ts.map +1 -1
- package/dist/file/File.js +24 -31
- package/dist/file/FileStorage.abstract.test.d.ts.map +1 -1
- package/dist/file/FileStorage.abstract.test.js +41 -18
- package/dist/file/NodeFsFileStorage.d.ts +11 -9
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
- package/dist/file/NodeFsFileStorage.integration.test.js +45 -21
- package/dist/file/NodeFsFileStorage.js +29 -37
- package/dist/http/Http.d.ts +13 -11
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +22 -30
- package/dist/http/Http.unit.test.js +26 -3
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
- package/dist/http/HttpClient.abstract.test.js +108 -104
- package/dist/http/HttpClient.d.ts +2 -2
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpController.d.ts +3 -2
- package/dist/http/HttpController.d.ts.map +1 -1
- package/dist/http/HttpTypeDescriptors.d.ts +11 -0
- package/dist/http/HttpTypeDescriptors.d.ts.map +1 -0
- package/dist/http/HttpTypeDescriptors.js +59 -0
- package/dist/http/MultipartHttpRequestBody.integration.test.js +20 -31
- package/dist/http/MultipartHttpRequestBody.unit.test.js +53 -70
- package/dist/record/Record.d.ts +3 -3
- package/dist/record/Record.d.ts.map +1 -1
- package/dist/record/Record.js +30 -9
- package/dist/result/Result.d.ts +3 -3
- package/dist/result/Result.d.ts.map +1 -1
- package/dist/result/Result.js +26 -9
- package/dist/schema/JsonSchemaIntrospector.js +7 -17
- package/dist/sensitive/Sensitive.d.ts +3 -7
- package/dist/sensitive/Sensitive.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.js +39 -23
- package/dist/sensitive/Sensitive.unit.test.d.ts +4 -4
- package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.unit.test.js +46 -20
- package/dist/serialization/FormUrlEncodedSerialization.d.ts +2 -2
- package/dist/serialization/FormUrlEncodedSerialization.d.ts.map +1 -1
- package/dist/serialization/FormUrlEncodedSerialization.js +28 -5
- package/dist/serialization/JsonSerialization.d.ts +2 -2
- package/dist/serialization/JsonSerialization.d.ts.map +1 -1
- package/dist/serialization/JsonSerialization.js +28 -5
- package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -1
- package/dist/serialization/Serialization.abstract.test.js +32 -6
- package/dist/serialization/Serialization.d.ts +2 -2
- package/dist/serialization/Serialization.d.ts.map +1 -1
- package/dist/task/Task.d.ts +19 -0
- package/dist/task/Task.d.ts.map +1 -0
- package/dist/task/Task.js +74 -0
- package/dist/task/Task.unit.test.d.ts +2 -0
- package/dist/task/Task.unit.test.d.ts.map +1 -0
- package/dist/task/Task.unit.test.js +46 -0
- package/dist/try/Try.d.ts +2 -2
- package/dist/try/Try.d.ts.map +1 -1
- package/dist/try/Try.js +32 -2
- package/dist/uuid/Uuid.d.ts +10 -11
- package/dist/uuid/Uuid.d.ts.map +1 -1
- package/dist/uuid/Uuid.js +39 -13
- package/dist/uuid/Uuid.unit.test.js +27 -4
- package/dist/zod/SchemaParser.abstract.test.d.ts.map +1 -1
- package/dist/zod/SchemaParser.abstract.test.js +31 -6
- package/dist/zod/SchemaParser.d.ts +2 -2
- package/dist/zod/SchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.d.ts +4 -3
- package/dist/zod/ZodSchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.js +28 -4
- package/dist/zod/ZodSchemaParser.unit.test.js +25 -2
- package/package.json +9 -4
- package/dist/effect/EffectExtensions.d.ts +0 -29
- package/dist/effect/EffectExtensions.d.ts.map +0 -1
- package/dist/effect/EffectExtensions.js +0 -30
- package/dist/effect/EffectExtensions.unit.test.d.ts +0 -2
- package/dist/effect/EffectExtensions.unit.test.d.ts.map +0 -1
- package/dist/effect/EffectExtensions.unit.test.js +0 -59
- package/dist/effect/Interop.d.ts +0 -53
- package/dist/effect/Interop.d.ts.map +0 -1
- package/dist/effect/Interop.js +0 -56
- package/dist/effect/Interop.unit.test.d.ts +0 -2
- package/dist/effect/Interop.unit.test.d.ts.map +0 -1
- package/dist/effect/Interop.unit.test.js +0 -134
- package/dist/effect/SchemaExtensions.d.ts +0 -11
- package/dist/effect/SchemaExtensions.d.ts.map +0 -1
- package/dist/effect/SchemaExtensions.js +0 -7
- package/dist/effect/SchemaExtensions.unit.test.d.ts +0 -2
- package/dist/effect/SchemaExtensions.unit.test.d.ts.map +0 -1
- package/dist/effect/SchemaExtensions.unit.test.js +0 -29
- package/dist/http/HttpSchemas.d.ts +0 -13
- package/dist/http/HttpSchemas.d.ts.map +0 -1
- package/dist/http/HttpSchemas.js +0 -23
- package/dist/schema/DateFromUnixTime.d.ts +0 -4
- package/dist/schema/DateFromUnixTime.d.ts.map +0 -1
- package/dist/schema/DateFromUnixTime.js +0 -10
- package/dist/schema/DateFromUnixTime.unit.test.d.ts +0 -2
- package/dist/schema/DateFromUnixTime.unit.test.d.ts.map +0 -1
- package/dist/schema/DateFromUnixTime.unit.test.js +0 -11
|
@@ -1,16 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.httpClientTest =
|
|
7
|
-
const
|
|
29
|
+
exports.httpClientTest = void 0;
|
|
30
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
31
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
8
32
|
const stream_1 = require("stream");
|
|
9
33
|
const selfsigned_1 = __importDefault(require("selfsigned"));
|
|
34
|
+
const function_1 = require("fp-ts/function");
|
|
35
|
+
const t = __importStar(require("io-ts"));
|
|
36
|
+
const td = __importStar(require("io-ts-types"));
|
|
10
37
|
const http_1 = require("http");
|
|
11
38
|
const https_1 = require("https");
|
|
12
39
|
const util_1 = require("util");
|
|
40
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
13
41
|
const formidable_1 = __importDefault(require("formidable"));
|
|
42
|
+
const Task_1 = require("../task/Task");
|
|
14
43
|
const JsonSerialization_1 = require("../serialization/JsonSerialization");
|
|
15
44
|
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
16
45
|
const Http_1 = require("./Http");
|
|
@@ -22,12 +51,12 @@ function httpClientTest(httpClient) {
|
|
|
22
51
|
const serialization = new JsonSerialization_1.JsonSerialization();
|
|
23
52
|
const formUrlEncodedSerialization = new FormUrlEncodedSerialization_1.FormUrlEncodedSerialization();
|
|
24
53
|
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage();
|
|
25
|
-
const testErrorResponseCodec = TypeCodec_1.TypeCodec.
|
|
26
|
-
message:
|
|
54
|
+
const testErrorResponseCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
55
|
+
message: t.string,
|
|
27
56
|
}));
|
|
28
|
-
const testResponseCodec = TypeCodec_1.TypeCodec.
|
|
29
|
-
strField:
|
|
30
|
-
intField:
|
|
57
|
+
const testResponseCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
58
|
+
strField: t.string,
|
|
59
|
+
intField: t.number,
|
|
31
60
|
}));
|
|
32
61
|
const testInputFormUrlEncoded = {
|
|
33
62
|
x: 1,
|
|
@@ -35,29 +64,26 @@ function httpClientTest(httpClient) {
|
|
|
35
64
|
arr2: [1, [2], 3],
|
|
36
65
|
users: [{ username: 'tray' }],
|
|
37
66
|
};
|
|
38
|
-
const testInputFormUrlEncodedCodec = TypeCodec_1.TypeCodec.
|
|
39
|
-
x:
|
|
40
|
-
arr:
|
|
41
|
-
arr2:
|
|
42
|
-
users:
|
|
43
|
-
username:
|
|
44
|
-
}))
|
|
67
|
+
const testInputFormUrlEncodedCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
68
|
+
x: td.NumberFromString,
|
|
69
|
+
arr: t.array(td.NumberFromString),
|
|
70
|
+
arr2: t.array(t.union([td.NumberFromString, t.array(td.NumberFromString)])),
|
|
71
|
+
users: t.array(t.type({
|
|
72
|
+
username: t.string,
|
|
73
|
+
})),
|
|
45
74
|
}));
|
|
46
|
-
const testMultiPartBodyTypeCodec = TypeCodec_1.TypeCodec.
|
|
47
|
-
fields:
|
|
48
|
-
files:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
content: effect_1.Schema.Any,
|
|
53
|
-
}),
|
|
54
|
-
}),
|
|
75
|
+
const testMultiPartBodyTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
76
|
+
fields: t.record(t.string, t.string),
|
|
77
|
+
files: t.record(t.string, t.type({
|
|
78
|
+
reference: File_1.fileDescriptorDescriptor,
|
|
79
|
+
content: t.any,
|
|
80
|
+
})),
|
|
55
81
|
}));
|
|
56
|
-
const testInputCodec = TypeCodec_1.TypeCodec.
|
|
57
|
-
inputField:
|
|
82
|
+
const testInputCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
83
|
+
inputField: t.number,
|
|
58
84
|
}));
|
|
59
85
|
function sendHttpResponse(httpResponse, response, responseCodec) {
|
|
60
|
-
const serializedResponse = (0,
|
|
86
|
+
const serializedResponse = (0, function_1.pipe)(E.right(responseCodec.encode(response)), E.map((encodedResponse) => serialization.serialize(encodedResponse)), E.getOrElse(() => (new util_1.TextEncoder().encode('Error serializing value').buffer)));
|
|
61
87
|
httpResponse.end(Buffer.from(serializedResponse));
|
|
62
88
|
}
|
|
63
89
|
async function processHttpRequest(requestCodec, responseCodec, httpRequest, httpResponse, process, isMultiPartBody = false) {
|
|
@@ -76,7 +102,7 @@ function httpClientTest(httpClient) {
|
|
|
76
102
|
fields: flattenFields(fields),
|
|
77
103
|
files: flattenFiles(files),
|
|
78
104
|
};
|
|
79
|
-
const response = (0,
|
|
105
|
+
const response = (0, function_1.pipe)(requestCodec.decode(input), E.map(process), E.map((result) => new util_1.TextEncoder().encode(JSON.stringify(responseCodec.encode(result))).buffer), E.getOrElse(() => new util_1.TextEncoder().encode('Error serializing value').buffer));
|
|
80
106
|
httpResponse.end(Buffer.from(response));
|
|
81
107
|
}
|
|
82
108
|
const body = [];
|
|
@@ -88,7 +114,7 @@ function httpClientTest(httpClient) {
|
|
|
88
114
|
const requestSerializer = httpRequest.headers['content-type'] === Http_1.HttpContentType.FormUrlEncoded
|
|
89
115
|
? formUrlEncodedSerialization
|
|
90
116
|
: serialization;
|
|
91
|
-
const response = (0,
|
|
117
|
+
const response = (0, function_1.pipe)(requestSerializer.deserialize(buffer), E.chain((encodedRequest) => requestCodec.decode(encodedRequest)), E.map(process), E.map((result) => responseCodec.encode(result)), E.map((encodedResult) => serialization.serialize(encodedResult)), E.getOrElse((error) => new util_1.TextEncoder().encode(error.message).buffer));
|
|
92
118
|
httpResponse.end(Buffer.from(response));
|
|
93
119
|
});
|
|
94
120
|
}
|
|
@@ -155,8 +181,7 @@ function httpClientTest(httpClient) {
|
|
|
155
181
|
sendHttpResponse(res, response, testResponseCodec);
|
|
156
182
|
}
|
|
157
183
|
else if (req.method === 'GET') {
|
|
158
|
-
|
|
159
|
-
const customHeader = req.headers['x-custom-header'] ?? '';
|
|
184
|
+
const customHeader = req.headers['x-custom-header'];
|
|
160
185
|
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
161
186
|
const response = {
|
|
162
187
|
strField: customHeader,
|
|
@@ -193,8 +218,6 @@ function httpClientTest(httpClient) {
|
|
|
193
218
|
const httpsServerUrl = `https://${host}:${httpsPort}`;
|
|
194
219
|
// Generate self-signed certificates for Https server, override type as it didn't include client certs
|
|
195
220
|
const certs = selfsigned_1.default.generate([], {
|
|
196
|
-
// 2048 bits: OpenSSL 3 (Node 17+) rejects smaller keys with "ee key too small"
|
|
197
|
-
keySize: 2048,
|
|
198
221
|
clientCertificate: true,
|
|
199
222
|
clientCertificateCN: 'client',
|
|
200
223
|
extensions: [{ name: 'basicConstraints', cA: true }],
|
|
@@ -237,85 +260,74 @@ function httpClientTest(httpClient) {
|
|
|
237
260
|
});
|
|
238
261
|
});
|
|
239
262
|
test('should send a GET request', async () => {
|
|
240
|
-
const response = await
|
|
263
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
241
264
|
headers: { 'x-custom-header': 'customVal' },
|
|
242
265
|
pathParams: {},
|
|
243
266
|
queryString: {},
|
|
244
267
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
245
|
-
})))
|
|
268
|
+
}))();
|
|
246
269
|
const testValue = {
|
|
247
270
|
strField: 'customVal',
|
|
248
271
|
intField: 123,
|
|
249
272
|
};
|
|
250
|
-
const result = (0,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}));
|
|
254
|
-
const resultE = await effect_1.Effect.runPromise(result);
|
|
255
|
-
expect(resultE).toStrictEqual(effect_1.Either.right(testValue));
|
|
273
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
274
|
+
const resultE = await result();
|
|
275
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
256
276
|
});
|
|
257
277
|
test('should preserve header casing when headerOption preserveCasing is true', async () => {
|
|
258
|
-
const response = await
|
|
278
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
259
279
|
headers: { 'Upper-Cased-Header': 'CasedValue' },
|
|
260
280
|
pathParams: {},
|
|
261
281
|
queryString: {},
|
|
262
282
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
263
|
-
headerOptions:
|
|
264
|
-
|
|
265
|
-
}),
|
|
266
|
-
}))));
|
|
283
|
+
headerOptions: O.some({ preserveHeaderCasing: O.some(true) }),
|
|
284
|
+
}))();
|
|
267
285
|
const testValue = {
|
|
268
286
|
strField: 'CasedValue',
|
|
269
287
|
intField: 123,
|
|
270
288
|
};
|
|
271
|
-
const result = (0,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}));
|
|
275
|
-
const resultE = await effect_1.Effect.runPromise(result);
|
|
276
|
-
expect(resultE).toStrictEqual(effect_1.Either.right(testValue));
|
|
289
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
290
|
+
const resultE = await result();
|
|
291
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
277
292
|
});
|
|
278
293
|
test('should send a GET request with an empty header', async () => {
|
|
279
|
-
const response = await
|
|
294
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
280
295
|
headers: { '': '' },
|
|
281
296
|
pathParams: {},
|
|
282
297
|
queryString: {},
|
|
283
298
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
284
|
-
})))
|
|
285
|
-
if (
|
|
299
|
+
}))();
|
|
300
|
+
if (E.isLeft(response)) {
|
|
286
301
|
throw new Error('Got left expected right');
|
|
287
302
|
}
|
|
288
303
|
expect(response.right.statusCode).toEqual(200);
|
|
289
304
|
});
|
|
290
305
|
test('should send a GET request with a certificate', async () => {
|
|
291
|
-
const response = await
|
|
306
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, httpsServerUrl, Http_1.HttpRequest.create({
|
|
292
307
|
headers: { 'x-custom-header': 'customVal' },
|
|
293
308
|
pathParams: {},
|
|
294
309
|
queryString: {},
|
|
295
310
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
296
|
-
agent:
|
|
297
|
-
certificate:
|
|
311
|
+
agent: O.some({
|
|
312
|
+
certificate: O.some({
|
|
298
313
|
key: certs.clientprivate,
|
|
299
314
|
cert: certs.clientcert,
|
|
300
315
|
}),
|
|
301
316
|
}),
|
|
302
|
-
})))
|
|
317
|
+
}))();
|
|
303
318
|
const testValue = {
|
|
304
319
|
strField: 'customVal',
|
|
305
320
|
intField: 123,
|
|
306
321
|
};
|
|
307
|
-
const result = (0,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}));
|
|
311
|
-
const resultE = await effect_1.Effect.runPromise(result);
|
|
312
|
-
expect(resultE).toStrictEqual(effect_1.Either.right(testValue));
|
|
322
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
323
|
+
const resultE = await result();
|
|
324
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
313
325
|
});
|
|
314
326
|
test('should send a POST request', async () => {
|
|
315
327
|
const testInput = {
|
|
316
328
|
inputField: 321,
|
|
317
329
|
};
|
|
318
|
-
const response = await
|
|
330
|
+
const response = await (0, function_1.pipe)((0, Task_1.createTaskEitherFromEither)(E.right(testInputCodec.encode(testInput))), TE.map((encoded) => serialization.serialize(encoded)), TE.chain((serializedInput) => httpClient.execute(Http_1.HttpMethod.Post, baseUrl, Http_1.HttpRequest.create({
|
|
319
331
|
headers: {
|
|
320
332
|
'x-custom-header': 'customVal',
|
|
321
333
|
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json,
|
|
@@ -323,37 +335,34 @@ function httpClientTest(httpClient) {
|
|
|
323
335
|
pathParams: {},
|
|
324
336
|
queryString: {},
|
|
325
337
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedInput),
|
|
326
|
-
})))))
|
|
338
|
+
}))))();
|
|
327
339
|
const testValue = {
|
|
328
340
|
strField: 'customVal',
|
|
329
341
|
intField: 321,
|
|
330
342
|
};
|
|
331
|
-
const result = (0,
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}));
|
|
335
|
-
const resultE = await effect_1.Effect.runPromise(result);
|
|
336
|
-
expect(resultE).toStrictEqual(effect_1.Either.right(testValue));
|
|
343
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
344
|
+
const resultE = await result();
|
|
345
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
337
346
|
});
|
|
338
347
|
test('should send a POST request with multipart body', async () => {
|
|
339
|
-
await
|
|
340
|
-
await
|
|
341
|
-
const file1 = await
|
|
348
|
+
await fileStorage.delete('file1')();
|
|
349
|
+
await fileStorage.delete('file2')();
|
|
350
|
+
const file1 = await fileStorage.write({
|
|
342
351
|
reference: {
|
|
343
352
|
_tag: 'FileDescriptor',
|
|
344
353
|
key: 'file1',
|
|
345
354
|
metadata: { name: 'file1' },
|
|
346
355
|
},
|
|
347
356
|
content: stream_1.Readable.from('file 1 content'),
|
|
348
|
-
}))
|
|
349
|
-
const file2 = await
|
|
357
|
+
})();
|
|
358
|
+
const file2 = await fileStorage.write({
|
|
350
359
|
reference: {
|
|
351
360
|
_tag: 'FileDescriptor',
|
|
352
361
|
key: 'file2',
|
|
353
362
|
metadata: { name: 'file2' },
|
|
354
363
|
},
|
|
355
364
|
content: stream_1.Readable.from('file 2 content'),
|
|
356
|
-
}))
|
|
365
|
+
})();
|
|
357
366
|
if (file1._tag === 'Left') {
|
|
358
367
|
throw file1.left;
|
|
359
368
|
}
|
|
@@ -376,7 +385,7 @@ function httpClientTest(httpClient) {
|
|
|
376
385
|
},
|
|
377
386
|
},
|
|
378
387
|
};
|
|
379
|
-
const response = await
|
|
388
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Post, baseUrl, Http_1.HttpRequest.create({
|
|
380
389
|
headers: {
|
|
381
390
|
'x-custom-header': 'customVal',
|
|
382
391
|
'content-type': Http_1.HttpContentType.MultipartRequestBody,
|
|
@@ -384,13 +393,10 @@ function httpClientTest(httpClient) {
|
|
|
384
393
|
pathParams: {},
|
|
385
394
|
queryString: {},
|
|
386
395
|
body: testInput,
|
|
387
|
-
})))
|
|
388
|
-
const result = (0,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}));
|
|
392
|
-
const resultE = await effect_1.Effect.runPromise(result);
|
|
393
|
-
expect(resultE).toEqual(effect_1.Either.right(expect.objectContaining({
|
|
396
|
+
}))();
|
|
397
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testMultiPartBodyTypeCodec.decode(encoded)))));
|
|
398
|
+
const resultE = await result();
|
|
399
|
+
expect(resultE).toEqual(E.right(expect.objectContaining({
|
|
394
400
|
fields: testInput.fields,
|
|
395
401
|
files: expect.objectContaining({
|
|
396
402
|
file1: expect.objectContaining({
|
|
@@ -411,58 +417,56 @@ function httpClientTest(httpClient) {
|
|
|
411
417
|
})));
|
|
412
418
|
});
|
|
413
419
|
test('should send a POST request with a formUrlEncoded body', async () => {
|
|
414
|
-
const response = await
|
|
420
|
+
const response = await (0, function_1.pipe)((0, Task_1.createTaskEitherFromEither)(E.right(testInputFormUrlEncodedCodec.encode(testInputFormUrlEncoded))), TE.map((encoded) => formUrlEncodedSerialization.serialize(encoded)), TE.chain((serializedInput) => httpClient.execute(Http_1.HttpMethod.Post, baseUrl, Http_1.HttpRequest.create({
|
|
415
421
|
headers: {
|
|
416
422
|
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.FormUrlEncoded,
|
|
417
423
|
},
|
|
418
424
|
pathParams: {},
|
|
419
425
|
queryString: {},
|
|
420
426
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedInput),
|
|
421
|
-
})))))
|
|
427
|
+
}))))();
|
|
422
428
|
const testValue = {
|
|
423
429
|
strField: 'customVal',
|
|
424
430
|
intField: 1,
|
|
425
431
|
};
|
|
426
|
-
const result = (0,
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}));
|
|
430
|
-
const resultE = await effect_1.Effect.runPromise(result);
|
|
431
|
-
expect(resultE).toStrictEqual(effect_1.Either.right(testValue));
|
|
432
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
433
|
+
const resultE = await result();
|
|
434
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
432
435
|
});
|
|
433
436
|
test('should parse an internal error response', async () => {
|
|
434
|
-
const response = await
|
|
437
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
435
438
|
headers: { error: '500' },
|
|
436
439
|
pathParams: {},
|
|
437
440
|
queryString: {},
|
|
438
441
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
439
|
-
})))
|
|
442
|
+
}))();
|
|
440
443
|
const testErrorResponse = {
|
|
441
444
|
message: 'some error message 500',
|
|
442
445
|
};
|
|
443
|
-
if (
|
|
446
|
+
if (E.isLeft(response)) {
|
|
444
447
|
throw response.left;
|
|
445
448
|
}
|
|
446
|
-
const responseBodyE = await
|
|
449
|
+
const responseBodyE = await BufferExtensions_1.BufferExtensions.readableToArrayBuffer(response.right.body)();
|
|
447
450
|
expect(response.right.statusCode).toStrictEqual(500);
|
|
448
|
-
expect(responseBodyE).toStrictEqual(
|
|
451
|
+
expect(responseBodyE).toStrictEqual(E.right(serialization.serialize(testErrorResponseCodec.encode(testErrorResponse))));
|
|
449
452
|
});
|
|
450
453
|
test('should parse a not found error response', async () => {
|
|
451
|
-
const response = await
|
|
454
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
452
455
|
headers: { error: '404' },
|
|
453
456
|
pathParams: {},
|
|
454
457
|
queryString: {},
|
|
455
458
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
456
|
-
})))
|
|
459
|
+
}))();
|
|
457
460
|
const testErrorResponse = {
|
|
458
461
|
message: 'some error message 404',
|
|
459
462
|
};
|
|
460
|
-
if (
|
|
463
|
+
if (E.isLeft(response)) {
|
|
461
464
|
throw response.left;
|
|
462
465
|
}
|
|
463
|
-
const responseBodyE = await
|
|
466
|
+
const responseBodyE = await BufferExtensions_1.BufferExtensions.readableToArrayBuffer(response.right.body)();
|
|
464
467
|
expect(response.right.statusCode).toStrictEqual(404);
|
|
465
|
-
expect(responseBodyE).toStrictEqual(
|
|
468
|
+
expect(responseBodyE).toStrictEqual(E.right(serialization.serialize(testErrorResponseCodec.encode(testErrorResponse))));
|
|
466
469
|
});
|
|
467
470
|
});
|
|
468
471
|
}
|
|
472
|
+
exports.httpClientTest = httpClientTest;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TaskEither } from 'fp-ts/TaskEither';
|
|
2
2
|
import { HttpMethod, HttpRequest, HttpResponse } from './Http';
|
|
3
3
|
export interface HttpClient {
|
|
4
|
-
execute(method: HttpMethod, url: string, request: HttpRequest):
|
|
4
|
+
execute(method: HttpMethod, url: string, request: HttpRequest): TaskEither<Error, HttpResponse>;
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/D,MAAM,WAAW,UAAU;IAC1B,OAAO,CACN,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,GAClB,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;CACnC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as T from 'fp-ts/Task';
|
|
2
|
+
import * as O from 'fp-ts/Option';
|
|
2
3
|
import { HttpMethod, HttpRequest, HttpResponse } from './Http';
|
|
3
4
|
import { Logging } from '../logging/Logging';
|
|
4
5
|
export interface HttpController {
|
|
@@ -7,6 +8,6 @@ export interface HttpController {
|
|
|
7
8
|
export interface HttpEndpoint {
|
|
8
9
|
path: string;
|
|
9
10
|
method: HttpMethod;
|
|
10
|
-
execute: (logger:
|
|
11
|
+
execute: (logger: O.Option<Logging>) => (request: HttpRequest) => T.Task<HttpResponse>;
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=HttpController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpController.d.ts","sourceRoot":"","sources":["../../src/http/HttpController.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"HttpController.d.ts","sourceRoot":"","sources":["../../src/http/HttpController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAChC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC9B,YAAY,EAAE,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,CACR,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KACrB,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;CACpD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as t from 'io-ts';
|
|
2
|
+
import { HttpAgent, HttpCertificate, HttpContentType, HttpHeaders, HttpMethod, HttpQueryString, HttpQueryStringSingleValue, HttpQueryStringValue } from './Http';
|
|
3
|
+
export declare const httpMethodTypeDescriptor: t.Type<HttpMethod, unknown>;
|
|
4
|
+
export declare const httpContentTypeTypeDescriptor: t.Type<HttpContentType, unknown>;
|
|
5
|
+
export declare const httpQueryStringSingleValueTypeDescriptor: t.Type<HttpQueryStringSingleValue, unknown>;
|
|
6
|
+
export declare const httpQueryStringValueTypeDescriptor: t.Type<HttpQueryStringValue, unknown>;
|
|
7
|
+
export declare const httpQueryStringTypeDescriptor: t.Type<HttpQueryString, unknown>;
|
|
8
|
+
export declare const httpHeadersTypeDescriptor: t.Type<HttpHeaders, unknown>;
|
|
9
|
+
export declare const httpCertificateTypeDescriptor: t.Type<HttpCertificate, unknown>;
|
|
10
|
+
export declare const httpAgentTypeDescriptor: t.Type<HttpAgent, unknown>;
|
|
11
|
+
//# sourceMappingURL=HttpTypeDescriptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpTypeDescriptors.d.ts","sourceRoot":"","sources":["../../src/http/HttpTypeDescriptors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,EACN,SAAS,EACT,eAAe,EACf,eAAe,EACf,WAAW,EACX,UAAU,EACV,eAAe,EACf,0BAA0B,EAC1B,oBAAoB,EACpB,MAAM,QAAQ,CAAC;AAEhB,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAWhE,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAUzE,CAAC;AAEH,eAAO,MAAM,wCAAwC,EAAE,CAAC,CAAC,IAAI,CAC5D,0BAA0B,EAC1B,OAAO,CACkE,CAAC;AAE3E,eAAO,MAAM,kCAAkC,EAAE,CAAC,CAAC,IAAI,CACtD,oBAAoB,EACpB,OAAO,CAOP,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CACD,CAAC;AAE3E,eAAO,MAAM,yBAAyB,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAIlE,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAOzE,CAAC;AAEH,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAK9D,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.httpAgentTypeDescriptor = exports.httpCertificateTypeDescriptor = exports.httpHeadersTypeDescriptor = exports.httpQueryStringTypeDescriptor = exports.httpQueryStringValueTypeDescriptor = exports.httpQueryStringSingleValueTypeDescriptor = exports.httpContentTypeTypeDescriptor = exports.httpMethodTypeDescriptor = void 0;
|
|
27
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
28
|
+
const t = __importStar(require("io-ts"));
|
|
29
|
+
const Http_1 = require("./Http");
|
|
30
|
+
exports.httpMethodTypeDescriptor = t.union([
|
|
31
|
+
t.literal(Http_1.HttpMethod.Delete),
|
|
32
|
+
t.literal(Http_1.HttpMethod.Get),
|
|
33
|
+
t.literal(Http_1.HttpMethod.Head),
|
|
34
|
+
t.literal(Http_1.HttpMethod.Options),
|
|
35
|
+
t.literal(Http_1.HttpMethod.Patch),
|
|
36
|
+
t.literal(Http_1.HttpMethod.Post),
|
|
37
|
+
t.literal(Http_1.HttpMethod.Put),
|
|
38
|
+
], 'HttpMethod');
|
|
39
|
+
exports.httpContentTypeTypeDescriptor = t.union([
|
|
40
|
+
t.literal(Http_1.HttpContentType.FormUrlEncoded),
|
|
41
|
+
t.literal(Http_1.HttpContentType.Json),
|
|
42
|
+
t.literal(Http_1.HttpContentType.MultipartRequestBody),
|
|
43
|
+
t.literal(Http_1.HttpContentType.OctetStream),
|
|
44
|
+
t.literal(Http_1.HttpContentType.Text),
|
|
45
|
+
], 'HttpContentType');
|
|
46
|
+
exports.httpQueryStringSingleValueTypeDescriptor = t.union([t.string, t.number, t.boolean], 'HttpQueryStringSingleValue');
|
|
47
|
+
exports.httpQueryStringValueTypeDescriptor = t.union([
|
|
48
|
+
exports.httpQueryStringSingleValueTypeDescriptor,
|
|
49
|
+
t.array(exports.httpQueryStringSingleValueTypeDescriptor),
|
|
50
|
+
], 'HttpQueryStringValue');
|
|
51
|
+
exports.httpQueryStringTypeDescriptor = t.record(t.string, exports.httpQueryStringValueTypeDescriptor, 'HttpQueryString');
|
|
52
|
+
exports.httpHeadersTypeDescriptor = t.record(t.string, t.union([t.string, t.array(t.string)]), 'HttpHeaders');
|
|
53
|
+
exports.httpCertificateTypeDescriptor = t.type({
|
|
54
|
+
cert: t.string,
|
|
55
|
+
key: t.string,
|
|
56
|
+
}, 'HttpCertificate');
|
|
57
|
+
exports.httpAgentTypeDescriptor = t.type({
|
|
58
|
+
certificate: (0, io_ts_types_1.optionFromNullable)(exports.httpCertificateTypeDescriptor),
|
|
59
|
+
}, 'HttpAgent');
|