@trayio/commons 0.11.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/LICENSE.txt +22 -0
- package/dist/base64/Base64.d.ts +18 -0
- package/dist/base64/Base64.d.ts.map +1 -0
- package/dist/base64/Base64.js +52 -0
- package/dist/base64/Base64.unit.test.d.ts +2 -0
- package/dist/base64/Base64.unit.test.d.ts.map +1 -0
- package/dist/base64/Base64.unit.test.js +50 -0
- package/dist/buffer/Buffer.d.ts +5 -0
- package/dist/buffer/Buffer.d.ts.map +1 -0
- package/dist/buffer/Buffer.js +52 -0
- package/dist/buffer/Buffer.unit.test.d.ts +2 -0
- package/dist/buffer/Buffer.unit.test.d.ts.map +1 -0
- package/dist/buffer/Buffer.unit.test.js +19 -0
- package/dist/cli/CliLogging.d.ts +11 -0
- package/dist/cli/CliLogging.d.ts.map +1 -0
- package/dist/cli/CliLogging.js +9 -0
- package/dist/codec/Codec.abstract.test.d.ts +8 -0
- package/dist/codec/Codec.abstract.test.d.ts.map +1 -0
- package/dist/codec/Codec.abstract.test.js +42 -0
- package/dist/codec/Codec.d.ts +6 -0
- package/dist/codec/Codec.d.ts.map +1 -0
- package/dist/codec/Codec.js +2 -0
- package/dist/codec/CompositeCodec.d.ts +11 -0
- package/dist/codec/CompositeCodec.d.ts.map +1 -0
- package/dist/codec/CompositeCodec.js +44 -0
- package/dist/codec/RemoveNullValuesCodec.d.ts +11 -0
- package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -0
- package/dist/codec/RemoveNullValuesCodec.js +61 -0
- package/dist/codec/TypeCodec.d.ts +15 -0
- package/dist/codec/TypeCodec.d.ts.map +1 -0
- package/dist/codec/TypeCodec.js +51 -0
- package/dist/codec/TypeCodec.unit.test.d.ts +2 -0
- package/dist/codec/TypeCodec.unit.test.d.ts.map +1 -0
- package/dist/codec/TypeCodec.unit.test.js +97 -0
- package/dist/dynamictype/DynamicType.d.ts +18 -0
- package/dist/dynamictype/DynamicType.d.ts.map +1 -0
- package/dist/dynamictype/DynamicType.js +46 -0
- package/dist/error/Error.d.ts +2 -0
- package/dist/error/Error.d.ts.map +1 -0
- package/dist/error/Error.js +13 -0
- package/dist/file/File.d.ts +17 -0
- package/dist/file/File.d.ts.map +1 -0
- package/dist/file/File.js +31 -0
- package/dist/file/FileStorage.abstract.test.d.ts +3 -0
- package/dist/file/FileStorage.abstract.test.d.ts.map +1 -0
- package/dist/file/FileStorage.abstract.test.js +78 -0
- package/dist/file/NodeFsFileStorage.d.ts +10 -0
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -0
- package/dist/file/NodeFsFileStorage.integration.test.d.ts +2 -0
- package/dist/file/NodeFsFileStorage.integration.test.d.ts.map +1 -0
- package/dist/file/NodeFsFileStorage.integration.test.js +5 -0
- package/dist/file/NodeFsFileStorage.js +57 -0
- package/dist/http/Http.d.ts +51 -0
- package/dist/http/Http.d.ts.map +1 -0
- package/dist/http/Http.js +62 -0
- package/dist/http/HttpClient.abstract.test.d.ts +3 -0
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -0
- package/dist/http/HttpClient.abstract.test.js +191 -0
- package/dist/http/HttpClient.d.ts +6 -0
- package/dist/http/HttpClient.d.ts.map +1 -0
- package/dist/http/HttpClient.js +2 -0
- package/dist/http/HttpController.d.ts +11 -0
- package/dist/http/HttpController.d.ts.map +1 -0
- package/dist/http/HttpController.js +2 -0
- package/dist/logging/Logging.d.ts +10 -0
- package/dist/logging/Logging.d.ts.map +1 -0
- package/dist/logging/Logging.js +2 -0
- package/dist/record/Record.d.ts +4 -0
- package/dist/record/Record.d.ts.map +1 -0
- package/dist/record/Record.js +35 -0
- package/dist/result/Result.d.ts +31 -0
- package/dist/result/Result.d.ts.map +1 -0
- package/dist/result/Result.js +68 -0
- package/dist/serialization/JsonSerialization.d.ts +10 -0
- package/dist/serialization/JsonSerialization.d.ts.map +1 -0
- package/dist/serialization/JsonSerialization.js +49 -0
- package/dist/serialization/JsonSerialization.unit.test.d.ts +2 -0
- package/dist/serialization/JsonSerialization.unit.test.d.ts.map +1 -0
- package/dist/serialization/JsonSerialization.unit.test.js +5 -0
- package/dist/serialization/Serialization.abstract.test.d.ts +3 -0
- package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -0
- package/dist/serialization/Serialization.abstract.test.js +54 -0
- package/dist/serialization/Serialization.d.ts +10 -0
- package/dist/serialization/Serialization.d.ts.map +1 -0
- package/dist/serialization/Serialization.js +7 -0
- package/dist/string/StringExtensions.d.ts +6 -0
- package/dist/string/StringExtensions.d.ts.map +1 -0
- package/dist/string/StringExtensions.js +8 -0
- package/dist/string/StringExtensions.unit.test.d.ts +2 -0
- package/dist/string/StringExtensions.unit.test.d.ts.map +1 -0
- package/dist/string/StringExtensions.unit.test.js +39 -0
- package/dist/task/Task.d.ts +7 -0
- package/dist/task/Task.d.ts.map +1 -0
- package/dist/task/Task.js +14 -0
- package/dist/try/Try.d.ts +3 -0
- package/dist/try/Try.d.ts.map +1 -0
- package/dist/try/Try.js +37 -0
- package/package.json +38 -0
|
@@ -0,0 +1,191 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.httpClientTest = void 0;
|
|
36
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
37
|
+
const function_1 = require("fp-ts/function");
|
|
38
|
+
const t = __importStar(require("io-ts"));
|
|
39
|
+
const http_1 = require("http");
|
|
40
|
+
const util_1 = require("util");
|
|
41
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
42
|
+
const Task_1 = require("../task/Task");
|
|
43
|
+
const JsonSerialization_1 = require("../serialization/JsonSerialization");
|
|
44
|
+
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
45
|
+
const Http_1 = require("./Http");
|
|
46
|
+
function httpClientTest(httpClient) {
|
|
47
|
+
const serialization = new JsonSerialization_1.JsonSerialization();
|
|
48
|
+
const testErrorResponseCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
49
|
+
message: t.string,
|
|
50
|
+
}));
|
|
51
|
+
const testResponseCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
52
|
+
strField: t.string,
|
|
53
|
+
intField: t.number,
|
|
54
|
+
}));
|
|
55
|
+
const testInputCodec = TypeCodec_1.TypeCodec.fromDescriptor(t.type({
|
|
56
|
+
inputField: t.number,
|
|
57
|
+
}));
|
|
58
|
+
function sendHttpResponse(httpResponse, response, responseCodec) {
|
|
59
|
+
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)));
|
|
60
|
+
httpResponse.end(Buffer.from(serializedResponse));
|
|
61
|
+
}
|
|
62
|
+
function processHttpRequest(requestCodec, responseCodec, httpRequest, httpResponse, process) {
|
|
63
|
+
const body = [];
|
|
64
|
+
httpRequest.on('data', (chunk) => {
|
|
65
|
+
body.push(chunk);
|
|
66
|
+
});
|
|
67
|
+
httpRequest.on('end', () => {
|
|
68
|
+
const buffer = Buffer.concat(body);
|
|
69
|
+
const response = (0, function_1.pipe)(serialization.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(() => (new util_1.TextEncoder().encode('Error serializing value').buffer)));
|
|
70
|
+
httpResponse.end(Buffer.from(response));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const requestListener = (req, res) => {
|
|
74
|
+
if (req.method === 'GET' && typeof req.headers['error'] === 'string') {
|
|
75
|
+
const errorCode = +req.headers['error'];
|
|
76
|
+
res.writeHead(errorCode, {
|
|
77
|
+
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json,
|
|
78
|
+
});
|
|
79
|
+
const errorResponse = {
|
|
80
|
+
message: `some error message ${errorCode}`,
|
|
81
|
+
};
|
|
82
|
+
sendHttpResponse(res, errorResponse, testErrorResponseCodec);
|
|
83
|
+
}
|
|
84
|
+
else if (req.method === 'GET') {
|
|
85
|
+
const customHeader = req.headers['x-custom-header'];
|
|
86
|
+
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
87
|
+
const response = {
|
|
88
|
+
strField: customHeader,
|
|
89
|
+
intField: 123,
|
|
90
|
+
};
|
|
91
|
+
sendHttpResponse(res, response, testResponseCodec);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const customHeader = req.headers['x-custom-header'];
|
|
95
|
+
res.writeHead(200, { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json });
|
|
96
|
+
processHttpRequest(testInputCodec, testResponseCodec, req, res, (input) => ({
|
|
97
|
+
strField: customHeader,
|
|
98
|
+
intField: input.inputField,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const host = 'localhost';
|
|
103
|
+
const port = 8000; // TODO: Get random port
|
|
104
|
+
const baseUrl = `http://${host}:${port}`;
|
|
105
|
+
const server = (0, http_1.createServer)(requestListener);
|
|
106
|
+
describe('HttpClient Test', () => {
|
|
107
|
+
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
yield new Promise((resolve) => {
|
|
109
|
+
server.listen(port, host, resolve);
|
|
110
|
+
});
|
|
111
|
+
}));
|
|
112
|
+
afterAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
yield new Promise((resolve, reject) => {
|
|
114
|
+
server.close((error) => {
|
|
115
|
+
if (error) {
|
|
116
|
+
reject(error);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
resolve();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
test('should send a GET request', () => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const response = yield httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
126
|
+
headers: { 'x-custom-header': 'customVal' },
|
|
127
|
+
pathParams: {},
|
|
128
|
+
queryString: {},
|
|
129
|
+
body: new ArrayBuffer(0),
|
|
130
|
+
})();
|
|
131
|
+
const testValue = {
|
|
132
|
+
strField: 'customVal',
|
|
133
|
+
intField: 123,
|
|
134
|
+
};
|
|
135
|
+
const result = (0, function_1.pipe)(response, E.chain((httpResponse) => serialization.deserialize(httpResponse.body)), E.chain((encoded) => testResponseCodec.decode(encoded)));
|
|
136
|
+
expect(result).toStrictEqual(E.right(testValue));
|
|
137
|
+
}));
|
|
138
|
+
test('should send a POST request', () => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const testInput = {
|
|
140
|
+
inputField: 321,
|
|
141
|
+
};
|
|
142
|
+
const response = yield (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, {
|
|
143
|
+
headers: { 'x-custom-header': 'customVal' },
|
|
144
|
+
pathParams: {},
|
|
145
|
+
queryString: {},
|
|
146
|
+
body: serializedInput,
|
|
147
|
+
})))();
|
|
148
|
+
const testValue = {
|
|
149
|
+
strField: 'customVal',
|
|
150
|
+
intField: 321,
|
|
151
|
+
};
|
|
152
|
+
const result = (0, function_1.pipe)(response, E.chain((httpResponse) => serialization.deserialize(httpResponse.body)), E.chain((encoded) => testResponseCodec.decode(encoded)));
|
|
153
|
+
expect(result).toStrictEqual(E.right(testValue));
|
|
154
|
+
}));
|
|
155
|
+
test('should parse an internal error response', () => __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
const response = yield httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
157
|
+
headers: { error: '500' },
|
|
158
|
+
pathParams: {},
|
|
159
|
+
queryString: {},
|
|
160
|
+
body: new ArrayBuffer(0),
|
|
161
|
+
})();
|
|
162
|
+
const testErrorResponse = {
|
|
163
|
+
message: 'some error message 500',
|
|
164
|
+
};
|
|
165
|
+
const expectedResponse = (0, function_1.pipe)(response, E.bindTo('httpResponse'), E.bind('serialisedErrorResponse', () => E.right(serialization.serialize(testErrorResponseCodec.encode(testErrorResponse)))), E.map(({ httpResponse, serialisedErrorResponse }) => ({
|
|
166
|
+
headers: httpResponse.headers,
|
|
167
|
+
statusCode: 500,
|
|
168
|
+
body: Buffer.from(serialisedErrorResponse),
|
|
169
|
+
})));
|
|
170
|
+
expect(response).toStrictEqual(expectedResponse);
|
|
171
|
+
}));
|
|
172
|
+
test('should parse a not found error response', () => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
const response = yield httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
174
|
+
headers: { error: '404' },
|
|
175
|
+
pathParams: {},
|
|
176
|
+
queryString: {},
|
|
177
|
+
body: new ArrayBuffer(0),
|
|
178
|
+
})();
|
|
179
|
+
const testErrorResponse = {
|
|
180
|
+
message: 'some error message 404',
|
|
181
|
+
};
|
|
182
|
+
const expectedResponse = (0, function_1.pipe)(response, E.bindTo('httpResponse'), E.bind('serialisedErrorResponse', () => E.right(serialization.serialize(testErrorResponseCodec.encode(testErrorResponse)))), E.map(({ httpResponse, serialisedErrorResponse }) => ({
|
|
183
|
+
headers: httpResponse.headers,
|
|
184
|
+
statusCode: 404,
|
|
185
|
+
body: Buffer.from(serialisedErrorResponse),
|
|
186
|
+
})));
|
|
187
|
+
expect(response).toStrictEqual(expectedResponse);
|
|
188
|
+
}));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
exports.httpClientTest = httpClientTest;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TaskEither } from 'fp-ts/TaskEither';
|
|
2
|
+
import { HttpMethod, HttpRequest, HttpResponse } from './Http';
|
|
3
|
+
export interface HttpClient {
|
|
4
|
+
execute(method: HttpMethod, url: string, request: HttpRequest): TaskEither<Error, HttpResponse>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as T from 'fp-ts/Task';
|
|
2
|
+
import { HttpMethod, HttpRequest, HttpResponse } from './Http';
|
|
3
|
+
export interface HttpController {
|
|
4
|
+
getEndpoints: () => ReadonlyArray<HttpEndpoint>;
|
|
5
|
+
}
|
|
6
|
+
export interface HttpEndpoint {
|
|
7
|
+
path: string;
|
|
8
|
+
method: HttpMethod;
|
|
9
|
+
execute: (request: HttpRequest) => T.Task<HttpResponse>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=HttpController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpController.d.ts","sourceRoot":"","sources":["../../src/http/HttpController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/D,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,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Logging {
|
|
2
|
+
info(message: string, octx: ObservabilityContext): void;
|
|
3
|
+
debug(message: string, octx: ObservabilityContext): void;
|
|
4
|
+
error(message: string, octx: ObservabilityContext): void;
|
|
5
|
+
warning(message: string, octx: ObservabilityContext): void;
|
|
6
|
+
}
|
|
7
|
+
export interface ObservabilityContext {
|
|
8
|
+
[key: string]: string | number | Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logging.d.ts","sourceRoot":"","sources":["../../src/logging/Logging.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACvB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAExD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAEzD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAEzD,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC3D;AAED,MAAM,WAAW,oBAAoB;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
2
|
+
export declare const addValueToRecordIfPresent: <K extends string | number | symbol, V>(record: Record<K, V>, key: K, valueOpt: O.Option<V>) => Record<K, V>;
|
|
3
|
+
export declare const addValuesToRecordIfPresent: <K extends string | number | symbol, V>(record: Record<K, V>, valuesToAdd: Record<K, O.Option<V>>) => Record<K, V>;
|
|
4
|
+
//# sourceMappingURL=Record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Record.d.ts","sourceRoot":"","sources":["../../src/record/Record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,eAAO,MAAM,yBAAyB,8GAUpC,CAAC;AAEH,eAAO,MAAM,0BAA0B,oHAMC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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.addValuesToRecordIfPresent = exports.addValueToRecordIfPresent = void 0;
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
28
|
+
const A = __importStar(require("fp-ts/Array"));
|
|
29
|
+
const addValueToRecordIfPresent = (record, key, valueOpt) => O.getOrElse(() => record)(O.map((value) => {
|
|
30
|
+
record[key] = value;
|
|
31
|
+
return record;
|
|
32
|
+
})(valueOpt));
|
|
33
|
+
exports.addValueToRecordIfPresent = addValueToRecordIfPresent;
|
|
34
|
+
const addValuesToRecordIfPresent = (record, valuesToAdd) => A.reduce(record, (acc, key) => (0, exports.addValueToRecordIfPresent)(acc, key, valuesToAdd[key]))(Object.keys(valuesToAdd));
|
|
35
|
+
exports.addValuesToRecordIfPresent = addValuesToRecordIfPresent;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
|
+
export type Failure<E> = {
|
|
3
|
+
readonly _tag: 'Failure';
|
|
4
|
+
readonly isSuccess: false;
|
|
5
|
+
readonly isFailure: true;
|
|
6
|
+
readonly error: E;
|
|
7
|
+
};
|
|
8
|
+
export type Success<T> = {
|
|
9
|
+
readonly _tag: 'Success';
|
|
10
|
+
readonly isSuccess: true;
|
|
11
|
+
readonly isFailure: false;
|
|
12
|
+
readonly value: T;
|
|
13
|
+
};
|
|
14
|
+
export type Result<E, T> = Failure<E> | Success<T>;
|
|
15
|
+
export declare class ResultFailureError<E> extends Error {
|
|
16
|
+
failureCause: E;
|
|
17
|
+
constructor(failureCause: E);
|
|
18
|
+
}
|
|
19
|
+
export interface ResultInterface {
|
|
20
|
+
success: <E, T>(value: T) => Result<E, T>;
|
|
21
|
+
failure: <E, T>(error: E) => Result<E, T>;
|
|
22
|
+
getSuccessfulValueOrFail: <E, T>(result: Result<E, T>) => T;
|
|
23
|
+
map: <E, T, R>(result: Result<E, T>, mapping: (value: T) => R) => Result<E, R>;
|
|
24
|
+
}
|
|
25
|
+
export declare const Result: ResultInterface;
|
|
26
|
+
export interface ResultInternalInterface {
|
|
27
|
+
fromEitherWithSimpleError: <T>(either: E.Either<Error, T>) => Result<Error, T>;
|
|
28
|
+
fromEitherWithSimpleErrorAndUnknown: <T>(either: E.Either<Error, unknown>) => Result<Error, T>;
|
|
29
|
+
}
|
|
30
|
+
export declare const ResultInternal: ResultInternalInterface;
|
|
31
|
+
//# sourceMappingURL=Result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["../../src/result/Result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEnD,qBAAa,kBAAkB,CAAC,CAAC,CAAE,SAAQ,KAAK;IAC5B,YAAY,EAAE,CAAC;gBAAf,YAAY,EAAE,CAAC;CAOlC;AAED,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,wBAAwB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC5D,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACZ,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KACpB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAClB;AAED,eAAO,MAAM,MAAM,EAAE,eAgCpB,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACvC,yBAAyB,EAAE,CAAC,CAAC,EAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,KACtB,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACtB,mCAAmC,EAAE,CAAC,CAAC,EACtC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,KAC5B,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CACtB;AAED,eAAO,MAAM,cAAc,EAAE,uBAgB5B,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.ResultInternal = exports.Result = exports.ResultFailureError = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
class ResultFailureError extends Error {
|
|
29
|
+
constructor(failureCause) {
|
|
30
|
+
super(`Result could not be read because it is a failure: ${JSON.stringify(failureCause)}`);
|
|
31
|
+
this.failureCause = failureCause;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.ResultFailureError = ResultFailureError;
|
|
35
|
+
exports.Result = {
|
|
36
|
+
success: (value) => ({
|
|
37
|
+
_tag: 'Success',
|
|
38
|
+
isSuccess: true,
|
|
39
|
+
isFailure: false,
|
|
40
|
+
value,
|
|
41
|
+
}),
|
|
42
|
+
failure: (error) => ({
|
|
43
|
+
_tag: 'Failure',
|
|
44
|
+
isSuccess: false,
|
|
45
|
+
isFailure: true,
|
|
46
|
+
error,
|
|
47
|
+
}),
|
|
48
|
+
getSuccessfulValueOrFail(result) {
|
|
49
|
+
switch (result.isSuccess) {
|
|
50
|
+
case true:
|
|
51
|
+
return result.value;
|
|
52
|
+
case false:
|
|
53
|
+
throw new ResultFailureError(result.error);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
map: (result, mapping) => {
|
|
57
|
+
switch (result.isSuccess) {
|
|
58
|
+
case true:
|
|
59
|
+
return exports.Result.success(mapping(result.value));
|
|
60
|
+
case false:
|
|
61
|
+
return exports.Result.failure(result.error);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
exports.ResultInternal = {
|
|
66
|
+
fromEitherWithSimpleError: (either) => E.match((error) => exports.Result.failure(error), (value) => exports.Result.success(value))(either),
|
|
67
|
+
fromEitherWithSimpleErrorAndUnknown: (either) => E.match((error) => exports.Result.failure(error), (value) => exports.Result.success(value))(either),
|
|
68
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
|
+
import { Serialization, SerializationFormat } from './Serialization';
|
|
3
|
+
export declare class JsonSerialization 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=JsonSerialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSerialization.d.ts","sourceRoot":"","sources":["../../src/serialization/JsonSerialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGrE,qBAAa,iBAAkB,YAAW,aAAa;IACtD,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,WAAW,CAAqB;IAExC,MAAM,EAAE,mBAAmB,CAA4B;IAEvD,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,49 @@
|
|
|
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.JsonSerialization = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const util_1 = require("util");
|
|
29
|
+
const function_1 = require("fp-ts/function");
|
|
30
|
+
const Serialization_1 = require("./Serialization");
|
|
31
|
+
const Try_1 = require("../try/Try");
|
|
32
|
+
class JsonSerialization {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.textEncoder = new util_1.TextEncoder();
|
|
35
|
+
this.textDecoder = new util_1.TextDecoder();
|
|
36
|
+
this.format = Serialization_1.SerializationFormat.Json;
|
|
37
|
+
}
|
|
38
|
+
serialize(value) {
|
|
39
|
+
const json = JSON.stringify(value);
|
|
40
|
+
return this.textEncoder.encode(json).buffer;
|
|
41
|
+
}
|
|
42
|
+
deserialize(value) {
|
|
43
|
+
if (value.byteLength === 0) {
|
|
44
|
+
return E.right(undefined);
|
|
45
|
+
}
|
|
46
|
+
return (0, function_1.pipe)((0, Try_1.tryToEither)(() => this.textDecoder.decode(value)), E.chain((str) => (0, Try_1.tryToEither)(() => JSON.parse(str))));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.JsonSerialization = JsonSerialization;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSerialization.unit.test.d.ts","sourceRoot":"","sources":["../../src/serialization/JsonSerialization.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Serialization_abstract_test_1 = require("./Serialization.abstract.test");
|
|
4
|
+
const JsonSerialization_1 = require("./JsonSerialization");
|
|
5
|
+
(0, Serialization_abstract_test_1.testSerialization)(new JsonSerialization_1.JsonSerialization());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Serialization.abstract.test.d.ts","sourceRoot":"","sources":["../../src/serialization/Serialization.abstract.test.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,aAAa,QAyC7D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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.testSerialization = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
+
const function_1 = require("fp-ts/function");
|
|
30
|
+
function testSerialization(serialization) {
|
|
31
|
+
describe('Serialization Test', () => {
|
|
32
|
+
test('should serialize and deserialize a value', () => {
|
|
33
|
+
const testValue = {
|
|
34
|
+
strField: 'str',
|
|
35
|
+
intField: O.some(123),
|
|
36
|
+
};
|
|
37
|
+
const result = (0, function_1.pipe)(E.right(serialization.serialize(testValue)), E.chain((serialized) => serialization.deserialize(serialized)));
|
|
38
|
+
expect(result).toStrictEqual(E.right(testValue));
|
|
39
|
+
});
|
|
40
|
+
test('should serialize undefined', () => {
|
|
41
|
+
const undefinedType = undefined;
|
|
42
|
+
const result = serialization.serialize(undefinedType);
|
|
43
|
+
const expected = new ArrayBuffer(0);
|
|
44
|
+
expect(result).toStrictEqual(expected);
|
|
45
|
+
});
|
|
46
|
+
test('should deserialize undefined', () => {
|
|
47
|
+
const undefinedSerialised = new ArrayBuffer(0);
|
|
48
|
+
const result = serialization.deserialize(undefinedSerialised);
|
|
49
|
+
const expected = E.right(undefined);
|
|
50
|
+
expect(result).toStrictEqual(expected);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.testSerialization = testSerialization;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
|
+
export declare enum SerializationFormat {
|
|
3
|
+
Json = "Json"
|
|
4
|
+
}
|
|
5
|
+
export interface Serialization {
|
|
6
|
+
format: SerializationFormat;
|
|
7
|
+
serialize(value: unknown): ArrayBuffer;
|
|
8
|
+
deserialize(value: ArrayBuffer): E.Either<Error, unknown>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Serialization.d.ts.map
|
|
@@ -0,0 +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;CACb;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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SerializationFormat = void 0;
|
|
4
|
+
var SerializationFormat;
|
|
5
|
+
(function (SerializationFormat) {
|
|
6
|
+
SerializationFormat["Json"] = "Json";
|
|
7
|
+
})(SerializationFormat || (exports.SerializationFormat = SerializationFormat = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringExtensions.d.ts","sourceRoot":"","sources":["../../src/string/StringExtensions.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,yBAAyB;IACzC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,gBAAgB,EAAE,yBAI9B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringExtensions = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
exports.StringExtensions = {
|
|
6
|
+
pascalCase: (str) => (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(str)),
|
|
7
|
+
titleCase: (value) => (0, lodash_1.capitalize)((0, lodash_1.startCase)(value).replace(/_|-/g, ' ')),
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringExtensions.unit.test.d.ts","sourceRoot":"","sources":["../../src/string/StringExtensions.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const StringExtensions_1 = require("./StringExtensions");
|
|
4
|
+
describe('StringExtensions', () => {
|
|
5
|
+
describe('pascalCase', () => {
|
|
6
|
+
it('should convert lowercase string to pascal case', () => {
|
|
7
|
+
expect(StringExtensions_1.StringExtensions.pascalCase('helloWorld')).toBe('HelloWorld');
|
|
8
|
+
});
|
|
9
|
+
it('should convert snake_case string to pascal case', () => {
|
|
10
|
+
expect(StringExtensions_1.StringExtensions.pascalCase('snake_case_example')).toBe('SnakeCaseExample');
|
|
11
|
+
});
|
|
12
|
+
it('should convert kebab-case string to pascal case', () => {
|
|
13
|
+
expect(StringExtensions_1.StringExtensions.pascalCase('kebab-case-example')).toBe('KebabCaseExample');
|
|
14
|
+
});
|
|
15
|
+
it('should handle empty string', () => {
|
|
16
|
+
expect(StringExtensions_1.StringExtensions.pascalCase('')).toBe('');
|
|
17
|
+
});
|
|
18
|
+
it('should handle single-letter string', () => {
|
|
19
|
+
expect(StringExtensions_1.StringExtensions.pascalCase('a')).toBe('A');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('titleCase', () => {
|
|
23
|
+
it('should convert lowercase string to title case', () => {
|
|
24
|
+
expect(StringExtensions_1.StringExtensions.titleCase('hello world')).toBe('Hello world');
|
|
25
|
+
});
|
|
26
|
+
it('should convert snake_case string to title case', () => {
|
|
27
|
+
expect(StringExtensions_1.StringExtensions.titleCase('snake_case_example')).toBe('Snake case example');
|
|
28
|
+
});
|
|
29
|
+
it('should convert kebab-case string to title case', () => {
|
|
30
|
+
expect(StringExtensions_1.StringExtensions.titleCase('kebab-case-example')).toBe('Kebab case example');
|
|
31
|
+
});
|
|
32
|
+
it('should handle empty string', () => {
|
|
33
|
+
expect(StringExtensions_1.StringExtensions.titleCase('')).toBe('');
|
|
34
|
+
});
|
|
35
|
+
it('should handle single-letter string', () => {
|
|
36
|
+
expect(StringExtensions_1.StringExtensions.titleCase('a')).toBe('A');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|