@trayio/commons 4.48.0 → 4.50.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/codec/SnakeCasePropertyNameCodec.d.ts +12 -0
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts.map +1 -0
- package/dist/codec/SnakeCasePropertyNameCodec.js +74 -0
- package/dist/codec/SnakeCasePropertyNameCodec.unit.test.d.ts +2 -0
- package/dist/codec/SnakeCasePropertyNameCodec.unit.test.d.ts.map +1 -0
- package/dist/codec/SnakeCasePropertyNameCodec.unit.test.js +70 -0
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +1 -0
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
- package/dist/http/HttpClient.abstract.test.js +47 -1
- package/dist/serialization/FormUrlEncodedSerialization.d.ts +10 -0
- package/dist/serialization/FormUrlEncodedSerialization.d.ts.map +1 -0
- package/dist/serialization/FormUrlEncodedSerialization.js +51 -0
- package/dist/serialization/FormUrlEncodedSerialization.unit.test.d.ts +2 -0
- package/dist/serialization/FormUrlEncodedSerialization.unit.test.d.ts.map +1 -0
- package/dist/serialization/FormUrlEncodedSerialization.unit.test.js +7 -0
- package/dist/serialization/Serialization.abstract.test.js +3 -3
- package/dist/serialization/Serialization.d.ts +2 -1
- package/dist/serialization/Serialization.d.ts.map +1 -1
- package/dist/serialization/Serialization.js +1 -0
- package/dist/string/StringExtensions.d.ts +1 -0
- package/dist/string/StringExtensions.d.ts.map +1 -1
- package/dist/string/StringExtensions.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as E from 'fp-ts/lib/Either';
|
|
2
|
+
import { Codec } from './Codec';
|
|
3
|
+
export declare class SnakeCasePropertyNameCodec implements Codec<unknown> {
|
|
4
|
+
static instance: Codec<unknown>;
|
|
5
|
+
encode(value: unknown): unknown;
|
|
6
|
+
decode(value: unknown): E.Either<Error, unknown>;
|
|
7
|
+
private isObject;
|
|
8
|
+
private snakeCasePropertyNameIfPresent;
|
|
9
|
+
private snakeCasePropertyNameFromArrayIfPresent;
|
|
10
|
+
private snakeCasePropertyNameFromObjectIfPresent;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=SnakeCasePropertyNameCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnakeCasePropertyNameCodec.d.ts","sourceRoot":"","sources":["../../src/codec/SnakeCasePropertyNameCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,qBAAa,0BAA2B,YAAW,KAAK,CAAC,OAAO,CAAC;IAChE,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAoC;IAEnE,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IAIhD,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,8BAA8B;IAatC,OAAO,CAAC,uCAAuC;IAW/C,OAAO,CAAC,wCAAwC;CAehD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
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.SnakeCasePropertyNameCodec = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/lib/Either"));
|
|
28
|
+
const StringExtensions_1 = require("../string/StringExtensions");
|
|
29
|
+
class SnakeCasePropertyNameCodec {
|
|
30
|
+
static instance = new SnakeCasePropertyNameCodec();
|
|
31
|
+
encode(value) {
|
|
32
|
+
return this.snakeCasePropertyNameIfPresent(value);
|
|
33
|
+
}
|
|
34
|
+
decode(value) {
|
|
35
|
+
return E.right(this.snakeCasePropertyNameIfPresent(value));
|
|
36
|
+
}
|
|
37
|
+
isObject(value) {
|
|
38
|
+
return typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
39
|
+
}
|
|
40
|
+
snakeCasePropertyNameIfPresent(value) {
|
|
41
|
+
if (value === null) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (this.isObject(value)) {
|
|
45
|
+
return this.snakeCasePropertyNameFromObjectIfPresent(value);
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
return this.snakeCasePropertyNameFromArrayIfPresent(value);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
snakeCasePropertyNameFromArrayIfPresent(value) {
|
|
53
|
+
return value.reduce((acc, propertyValue) => {
|
|
54
|
+
if (propertyValue == null) {
|
|
55
|
+
return acc;
|
|
56
|
+
}
|
|
57
|
+
return [...acc, this.snakeCasePropertyNameIfPresent(propertyValue)];
|
|
58
|
+
}, []);
|
|
59
|
+
}
|
|
60
|
+
snakeCasePropertyNameFromObjectIfPresent(value) {
|
|
61
|
+
return Object.entries(value).reduce((acc, [key, propertyValue]) => {
|
|
62
|
+
if (this.isObject(propertyValue)) {
|
|
63
|
+
const nestedObject = this.snakeCasePropertyNameFromObjectIfPresent(propertyValue);
|
|
64
|
+
return { ...acc, [key]: nestedObject };
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(propertyValue)) {
|
|
67
|
+
const nestedArray = this.snakeCasePropertyNameFromArrayIfPresent(propertyValue);
|
|
68
|
+
return { ...acc, [key]: nestedArray };
|
|
69
|
+
}
|
|
70
|
+
return { ...acc, [StringExtensions_1.StringExtensions.snakeCase(key)]: propertyValue };
|
|
71
|
+
}, {});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.SnakeCasePropertyNameCodec = SnakeCasePropertyNameCodec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnakeCasePropertyNameCodec.unit.test.d.ts","sourceRoot":"","sources":["../../src/codec/SnakeCasePropertyNameCodec.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const SnakeCasePropertyNameCodec_1 = require("./SnakeCasePropertyNameCodec");
|
|
4
|
+
const testSnakeCasePropertyNameCodec = SnakeCasePropertyNameCodec_1.SnakeCasePropertyNameCodec.instance;
|
|
5
|
+
describe('SnakeCasePropertyNameCodec', () => {
|
|
6
|
+
test('should snake case all properties names', () => {
|
|
7
|
+
const value = {
|
|
8
|
+
firstName: 'blah',
|
|
9
|
+
LastName: null,
|
|
10
|
+
addresses: [
|
|
11
|
+
{
|
|
12
|
+
street: 'blah street',
|
|
13
|
+
number: 123,
|
|
14
|
+
city: {
|
|
15
|
+
name: 'London',
|
|
16
|
+
province: null,
|
|
17
|
+
state: null,
|
|
18
|
+
},
|
|
19
|
+
notes_id: 'blah blah blah',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
street: 'blah blah street',
|
|
23
|
+
number: 321,
|
|
24
|
+
city: {
|
|
25
|
+
name: 'New York',
|
|
26
|
+
province: null,
|
|
27
|
+
state: 'NY',
|
|
28
|
+
},
|
|
29
|
+
notesId: null,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
phone: {
|
|
33
|
+
Area_Code: null,
|
|
34
|
+
TelephoneNumber: 1234567,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const actualValue = testSnakeCasePropertyNameCodec.encode(value);
|
|
38
|
+
const expectedValue = {
|
|
39
|
+
first_name: 'blah',
|
|
40
|
+
last_name: null,
|
|
41
|
+
addresses: [
|
|
42
|
+
{
|
|
43
|
+
street: 'blah street',
|
|
44
|
+
number: 123,
|
|
45
|
+
city: {
|
|
46
|
+
name: 'London',
|
|
47
|
+
province: null,
|
|
48
|
+
state: null,
|
|
49
|
+
},
|
|
50
|
+
notes_id: 'blah blah blah',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
street: 'blah blah street',
|
|
54
|
+
number: 321,
|
|
55
|
+
city: {
|
|
56
|
+
name: 'New York',
|
|
57
|
+
province: null,
|
|
58
|
+
state: 'NY',
|
|
59
|
+
},
|
|
60
|
+
notes_id: null,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
phone: {
|
|
64
|
+
area_code: null,
|
|
65
|
+
telephone_number: 1234567,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
expect(actualValue).toEqual(expectedValue);
|
|
69
|
+
});
|
|
70
|
+
});
|
package/dist/http/Http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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AAED,eAAO,MAAM,WAAW,EAAE,oBAyIzB,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACxD,mBAAmB,EACnB,eAAe,CAIf,CAAC;AAEF,eAAO,MAAM,eAAe,SACrB,eAAe,qCAEkC,CAAC"}
|
package/dist/http/Http.js
CHANGED
|
@@ -208,6 +208,7 @@ exports.HttpHeaders = {
|
|
|
208
208
|
};
|
|
209
209
|
exports.serializationFormatToHttpContentType = {
|
|
210
210
|
[Serialization_1.SerializationFormat.Json]: HttpContentType.Json,
|
|
211
|
+
[Serialization_1.SerializationFormat.FormUrlEncoded]: HttpContentType.FormUrlEncoded,
|
|
211
212
|
};
|
|
212
213
|
const isMultiPartBody = (body) => body?.files !== undefined;
|
|
213
214
|
exports.isMultiPartBody = isMultiPartBody;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.abstract.test.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.abstract.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpClient.abstract.test.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.abstract.test.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAO1C,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,QAkmBpD"}
|
|
@@ -31,6 +31,7 @@ const E = __importStar(require("fp-ts/Either"));
|
|
|
31
31
|
const stream_1 = require("stream");
|
|
32
32
|
const function_1 = require("fp-ts/function");
|
|
33
33
|
const t = __importStar(require("io-ts"));
|
|
34
|
+
const td = __importStar(require("io-ts-types"));
|
|
34
35
|
const http_1 = require("http");
|
|
35
36
|
const util_1 = require("util");
|
|
36
37
|
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
@@ -42,8 +43,10 @@ const Http_1 = require("./Http");
|
|
|
42
43
|
const File_1 = require("../file/File");
|
|
43
44
|
const NodeFsFileStorage_1 = require("../file/NodeFsFileStorage");
|
|
44
45
|
const BufferExtensions_1 = require("../buffer/BufferExtensions");
|
|
46
|
+
const FormUrlEncodedSerialization_1 = require("../serialization/FormUrlEncodedSerialization");
|
|
45
47
|
function httpClientTest(httpClient) {
|
|
46
48
|
const serialization = new JsonSerialization_1.JsonSerialization();
|
|
49
|
+
const formUrlEncodedSerialization = new FormUrlEncodedSerialization_1.FormUrlEncodedSerialization();
|
|
47
50
|
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage();
|
|
48
51
|
const testErrorResponseCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
49
52
|
message: t.string,
|
|
@@ -52,6 +55,20 @@ function httpClientTest(httpClient) {
|
|
|
52
55
|
strField: t.string,
|
|
53
56
|
intField: t.number,
|
|
54
57
|
}));
|
|
58
|
+
const testInputFormUrlEncoded = {
|
|
59
|
+
x: 1,
|
|
60
|
+
arr: [1, 2, 3],
|
|
61
|
+
arr2: [1, [2], 3],
|
|
62
|
+
users: [{ username: 'tray' }],
|
|
63
|
+
};
|
|
64
|
+
const testInputFormUrlEncodedCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
65
|
+
x: td.NumberFromString,
|
|
66
|
+
arr: t.array(td.NumberFromString),
|
|
67
|
+
arr2: t.array(t.union([td.NumberFromString, t.array(td.NumberFromString)])),
|
|
68
|
+
users: t.array(t.type({
|
|
69
|
+
username: t.string,
|
|
70
|
+
})),
|
|
71
|
+
}));
|
|
55
72
|
const ReadableCodec = new t.Type('Readable', (input) => input instanceof stream_1.Readable, (input, ctx) => input instanceof stream_1.Readable ? t.success(input) : t.failure(input, ctx), (input) => input);
|
|
56
73
|
const testMultiPartBodyTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
57
74
|
fields: t.record(t.string, t.string),
|
|
@@ -92,7 +109,10 @@ function httpClientTest(httpClient) {
|
|
|
92
109
|
});
|
|
93
110
|
httpRequest.on('end', () => {
|
|
94
111
|
const buffer = Buffer.concat(body);
|
|
95
|
-
const
|
|
112
|
+
const requestSerializer = httpRequest.headers['content-type'] === Http_1.HttpContentType.FormUrlEncoded
|
|
113
|
+
? formUrlEncodedSerialization
|
|
114
|
+
: serialization;
|
|
115
|
+
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));
|
|
96
116
|
httpResponse.end(Buffer.from(response));
|
|
97
117
|
});
|
|
98
118
|
}
|
|
@@ -162,6 +182,14 @@ function httpClientTest(httpClient) {
|
|
|
162
182
|
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
163
183
|
await processHttpRequest(testMultiPartBodyTypeCodec, testMultiPartBodyTypeCodec, req, res, (input) => input, true);
|
|
164
184
|
}
|
|
185
|
+
else if (req.method === 'POST' &&
|
|
186
|
+
req.headers['content-type'] === Http_1.HttpContentType.FormUrlEncoded) {
|
|
187
|
+
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
188
|
+
await processHttpRequest(testInputFormUrlEncodedCodec, testResponseCodec, req, res, (input) => ({
|
|
189
|
+
strField: 'customVal',
|
|
190
|
+
intField: input.arr2[0],
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
165
193
|
else {
|
|
166
194
|
const customHeader = req.headers['x-custom-header'];
|
|
167
195
|
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
@@ -215,6 +243,7 @@ function httpClientTest(httpClient) {
|
|
|
215
243
|
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, {
|
|
216
244
|
headers: {
|
|
217
245
|
'x-custom-header': 'customVal',
|
|
246
|
+
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json,
|
|
218
247
|
},
|
|
219
248
|
pathParams: {},
|
|
220
249
|
queryString: {},
|
|
@@ -300,6 +329,23 @@ function httpClientTest(httpClient) {
|
|
|
300
329
|
}),
|
|
301
330
|
})));
|
|
302
331
|
});
|
|
332
|
+
test('should send a POST request with a formUrlEncoded body', async () => {
|
|
333
|
+
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, {
|
|
334
|
+
headers: {
|
|
335
|
+
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.FormUrlEncoded,
|
|
336
|
+
},
|
|
337
|
+
pathParams: {},
|
|
338
|
+
queryString: {},
|
|
339
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedInput),
|
|
340
|
+
})))();
|
|
341
|
+
const testValue = {
|
|
342
|
+
strField: 'customVal',
|
|
343
|
+
intField: 1,
|
|
344
|
+
};
|
|
345
|
+
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)))));
|
|
346
|
+
const resultE = await result();
|
|
347
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
348
|
+
});
|
|
303
349
|
test('should parse an internal error response', async () => {
|
|
304
350
|
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
305
351
|
headers: { error: '500' },
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
|
+
import { Serialization, SerializationFormat } from './Serialization';
|
|
3
|
+
export declare class FormUrlEncodedSerialization implements Serialization {
|
|
4
|
+
private textEncoder;
|
|
5
|
+
private textDecoder;
|
|
6
|
+
format: SerializationFormat;
|
|
7
|
+
serialize(value: unknown): ArrayBuffer;
|
|
8
|
+
deserialize(value: ArrayBuffer): E.Either<Error, unknown>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=FormUrlEncodedSerialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormUrlEncodedSerialization.d.ts","sourceRoot":"","sources":["../../src/serialization/FormUrlEncodedSerialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAIlC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGrE,qBAAa,2BAA4B,YAAW,aAAa;IAChE,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,WAAW,CAAqB;IAExC,MAAM,EAAE,mBAAmB,CAAsC;IAEjE,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW;IAKtC,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;CASzD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.FormUrlEncodedSerialization = void 0;
|
|
30
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
31
|
+
const util_1 = require("util");
|
|
32
|
+
const function_1 = require("fp-ts/function");
|
|
33
|
+
const qs_1 = __importDefault(require("qs"));
|
|
34
|
+
const Serialization_1 = require("./Serialization");
|
|
35
|
+
const Try_1 = require("../try/Try");
|
|
36
|
+
class FormUrlEncodedSerialization {
|
|
37
|
+
textEncoder = new util_1.TextEncoder();
|
|
38
|
+
textDecoder = new util_1.TextDecoder();
|
|
39
|
+
format = Serialization_1.SerializationFormat.FormUrlEncoded;
|
|
40
|
+
serialize(value) {
|
|
41
|
+
const formEncoded = qs_1.default.stringify(value);
|
|
42
|
+
return this.textEncoder.encode(formEncoded).buffer;
|
|
43
|
+
}
|
|
44
|
+
deserialize(value) {
|
|
45
|
+
if (value.byteLength === 0) {
|
|
46
|
+
return E.right(undefined);
|
|
47
|
+
}
|
|
48
|
+
return (0, function_1.pipe)((0, Try_1.tryToEither)(() => this.textDecoder.decode(value)), E.chain((str) => (0, Try_1.tryToEither)(() => qs_1.default.parse(str))));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.FormUrlEncodedSerialization = FormUrlEncodedSerialization;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormUrlEncodedSerialization.unit.test.d.ts","sourceRoot":"","sources":["../../src/serialization/FormUrlEncodedSerialization.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Serialization_abstract_test_1 = require("./Serialization.abstract.test");
|
|
4
|
+
const FormUrlEncodedSerialization_1 = require("./FormUrlEncodedSerialization");
|
|
5
|
+
describe('FormUrlEncoded', () => {
|
|
6
|
+
(0, Serialization_abstract_test_1.testSerialization)(new FormUrlEncodedSerialization_1.FormUrlEncodedSerialization());
|
|
7
|
+
});
|
|
@@ -32,7 +32,7 @@ function testSerialization(serialization) {
|
|
|
32
32
|
test('should serialize and deserialize a value', () => {
|
|
33
33
|
const testValue = {
|
|
34
34
|
strField: 'str',
|
|
35
|
-
|
|
35
|
+
intStrField: O.some('123'),
|
|
36
36
|
};
|
|
37
37
|
const result = (0, function_1.pipe)(E.right(serialization.serialize(testValue)), E.chain((serialized) => serialization.deserialize(serialized)));
|
|
38
38
|
expect(result).toStrictEqual(E.right(testValue));
|
|
@@ -44,8 +44,8 @@ function testSerialization(serialization) {
|
|
|
44
44
|
expect(result).toStrictEqual(expected);
|
|
45
45
|
});
|
|
46
46
|
test('should deserialize undefined', () => {
|
|
47
|
-
const
|
|
48
|
-
const result = serialization.deserialize(
|
|
47
|
+
const undefinedSerialized = new ArrayBuffer(0);
|
|
48
|
+
const result = serialization.deserialize(undefinedSerialized);
|
|
49
49
|
const expected = E.right(undefined);
|
|
50
50
|
expect(result).toStrictEqual(expected);
|
|
51
51
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serialization.d.ts","sourceRoot":"","sources":["../../src/serialization/Serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,oBAAY,mBAAmB;IAC9B,IAAI,SAAS;
|
|
1
|
+
{"version":3,"file":"Serialization.d.ts","sourceRoot":"","sources":["../../src/serialization/Serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,oBAAY,mBAAmB;IAC9B,IAAI,SAAS;IACb,cAAc,mBAAmB;CACjC;AAED,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,mBAAmB,CAAC;IAE5B,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC;IAEvC,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAC1D"}
|
|
@@ -4,4 +4,5 @@ exports.SerializationFormat = void 0;
|
|
|
4
4
|
var SerializationFormat;
|
|
5
5
|
(function (SerializationFormat) {
|
|
6
6
|
SerializationFormat["Json"] = "Json";
|
|
7
|
+
SerializationFormat["FormUrlEncoded"] = "FormUrlEncoded";
|
|
7
8
|
})(SerializationFormat || (exports.SerializationFormat = SerializationFormat = {}));
|
|
@@ -2,6 +2,7 @@ export interface StringExtensionsInterface {
|
|
|
2
2
|
pascalCase: (str: string) => string;
|
|
3
3
|
titleCase: (str: string) => string;
|
|
4
4
|
camelCase: (str: string) => string;
|
|
5
|
+
snakeCase: (str: string) => string;
|
|
5
6
|
}
|
|
6
7
|
export declare const StringExtensions: StringExtensionsInterface;
|
|
7
8
|
//# sourceMappingURL=StringExtensions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringExtensions.d.ts","sourceRoot":"","sources":["../../src/string/StringExtensions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StringExtensions.d.ts","sourceRoot":"","sources":["../../src/string/StringExtensions.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,yBAAyB;IACzC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACnC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACnC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,gBAAgB,EAAE,yBAM9B,CAAC"}
|
|
@@ -6,4 +6,5 @@ exports.StringExtensions = {
|
|
|
6
6
|
pascalCase: (str) => (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(str)),
|
|
7
7
|
titleCase: (value) => (0, lodash_1.capitalize)((0, lodash_1.startCase)(value).replace(/_|-/g, ' ')),
|
|
8
8
|
camelCase: (str) => (0, lodash_1.camelCase)(str),
|
|
9
|
+
snakeCase: (str) => (0, lodash_1.snakeCase)(str),
|
|
9
10
|
};
|