@trayio/commons 0.0.1-beta
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/BufferExtensions.d.ts +9 -0
- package/dist/buffer/BufferExtensions.d.ts.map +1 -0
- package/dist/buffer/BufferExtensions.js +68 -0
- package/dist/buffer/BufferExtensions.unit.test.d.ts +2 -0
- package/dist/buffer/BufferExtensions.unit.test.d.ts.map +1 -0
- package/dist/buffer/BufferExtensions.unit.test.js +47 -0
- package/dist/callsite/CallSite.d.ts +9 -0
- package/dist/callsite/CallSite.d.ts.map +1 -0
- package/dist/callsite/CallSite.js +50 -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 +12 -0
- package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -0
- package/dist/codec/RemoveNullValuesCodec.js +76 -0
- package/dist/codec/TypeCodec.d.ts +16 -0
- package/dist/codec/TypeCodec.d.ts.map +1 -0
- package/dist/codec/TypeCodec.js +58 -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 +20 -0
- package/dist/dynamictype/DynamicType.d.ts.map +1 -0
- package/dist/dynamictype/DynamicType.js +49 -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/FakeFileStorage.d.ts +12 -0
- package/dist/file/FakeFileStorage.d.ts.map +1 -0
- package/dist/file/FakeFileStorage.integration.test.d.ts +2 -0
- package/dist/file/FakeFileStorage.integration.test.d.ts.map +1 -0
- package/dist/file/FakeFileStorage.integration.test.js +7 -0
- package/dist/file/FakeFileStorage.js +60 -0
- package/dist/file/File.d.ts +29 -0
- package/dist/file/File.d.ts.map +1 -0
- package/dist/file/File.js +36 -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 +109 -0
- package/dist/file/NodeFsFileStorage.d.ts +12 -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 +7 -0
- package/dist/file/NodeFsFileStorage.js +82 -0
- package/dist/http/Http.d.ts +55 -0
- package/dist/http/Http.d.ts.map +1 -0
- package/dist/http/Http.js +64 -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 +354 -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/StringConversions.d.ts +6 -0
- package/dist/string/StringConversions.d.ts.map +1 -0
- package/dist/string/StringConversions.js +16 -0
- package/dist/string/StringConversions.unit.test.d.ts +2 -0
- package/dist/string/StringConversions.unit.test.d.ts.map +1 -0
- package/dist/string/StringConversions.unit.test.js +36 -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 +41 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Tray.io, Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as t from 'io-ts';
|
|
2
|
+
import * as E from 'fp-ts/Either';
|
|
3
|
+
import { Codec } from '../codec/Codec';
|
|
4
|
+
declare const base64TypeDescriptor: t.BrandC<t.StringC, Base64Brand>;
|
|
5
|
+
export type Base64 = t.TypeOf<typeof base64TypeDescriptor>;
|
|
6
|
+
export interface Base64Brand {
|
|
7
|
+
readonly Base64: unique symbol;
|
|
8
|
+
}
|
|
9
|
+
export interface Base64Interface {
|
|
10
|
+
typeDescriptor: t.BrandC<t.StringC, Base64Brand>;
|
|
11
|
+
typeCodec: Codec<Base64>;
|
|
12
|
+
fromBase64String: (value: string) => E.Either<Error, Base64>;
|
|
13
|
+
encodeBinary: (value: ArrayBuffer) => Base64;
|
|
14
|
+
decodeBinary: (value: Base64) => ArrayBuffer;
|
|
15
|
+
}
|
|
16
|
+
export declare const Base64: Base64Interface;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=Base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Base64.d.ts","sourceRoot":"","sources":["../../src/base64/Base64.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAUvC,QAAA,MAAM,oBAAoB,kCAIzB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAK3D,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACjD,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7D,YAAY,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;IAC7C,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;CAC7C;AAED,eAAO,MAAM,MAAM,EAAE,eAqBpB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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.Base64 = void 0;
|
|
27
|
+
const t = __importStar(require("io-ts"));
|
|
28
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
29
|
+
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
30
|
+
const isBase64 = (s) => {
|
|
31
|
+
// It does not match an empty string, which is the base64 encoding of zero-length binary data according to RFC 4648
|
|
32
|
+
const exp = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
33
|
+
return exp.test(s);
|
|
34
|
+
};
|
|
35
|
+
const base64TypeDescriptor = t.brand(t.string, (input) => isBase64(input), 'Base64');
|
|
36
|
+
const base64TypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(base64TypeDescriptor);
|
|
37
|
+
exports.Base64 = {
|
|
38
|
+
typeDescriptor: base64TypeDescriptor,
|
|
39
|
+
typeCodec: base64TypeCodec,
|
|
40
|
+
fromBase64String: (value) => base64TypeCodec.decode(value),
|
|
41
|
+
encodeBinary: (value) => {
|
|
42
|
+
const base64data = Buffer.from(value).toString('base64');
|
|
43
|
+
return E.getOrElse(() => {
|
|
44
|
+
throw new Error('This should never be thrown');
|
|
45
|
+
})(base64TypeCodec.decode(base64data));
|
|
46
|
+
},
|
|
47
|
+
decodeBinary: (value) => {
|
|
48
|
+
const base64String = base64TypeCodec.encode(value);
|
|
49
|
+
const binary = Buffer.from(base64String, 'base64');
|
|
50
|
+
return binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Base64.unit.test.d.ts","sourceRoot":"","sources":["../../src/base64/Base64.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const Base64_1 = require("./Base64");
|
|
28
|
+
const JsonSerialization_1 = require("../serialization/JsonSerialization");
|
|
29
|
+
describe('Base64', () => {
|
|
30
|
+
test('should create base64 type for valid string', () => {
|
|
31
|
+
const testValue = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg==';
|
|
32
|
+
const base64Result = Base64_1.Base64.fromBase64String(testValue);
|
|
33
|
+
const base64 = E.getOrElse((error) => {
|
|
34
|
+
throw new Error('Should have been right');
|
|
35
|
+
})(base64Result);
|
|
36
|
+
expect(base64.toString()).toStrictEqual(testValue);
|
|
37
|
+
});
|
|
38
|
+
test('should encode and decode an ArrayBuffer', () => {
|
|
39
|
+
const testValue = { test: 'value' };
|
|
40
|
+
const arrayBuffer = new JsonSerialization_1.JsonSerialization().serialize(testValue);
|
|
41
|
+
const encoded = Base64_1.Base64.encodeBinary(arrayBuffer);
|
|
42
|
+
const decoded = Base64_1.Base64.decodeBinary(encoded);
|
|
43
|
+
expect(decoded).toStrictEqual(arrayBuffer);
|
|
44
|
+
});
|
|
45
|
+
test('should fail when string is invalid', () => {
|
|
46
|
+
const testValue = 'tests';
|
|
47
|
+
const base64Result = Base64_1.Base64.fromBase64String(testValue);
|
|
48
|
+
expect(E.isLeft(base64Result)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
4
|
+
export interface BufferExtensionsInterface {
|
|
5
|
+
readableToArrayBuffer: (stream: Readable) => TE.TaskEither<Error, ArrayBuffer>;
|
|
6
|
+
arrayBufferToReadable: (arrayBuffer: ArrayBuffer) => Readable;
|
|
7
|
+
}
|
|
8
|
+
export declare const BufferExtensions: BufferExtensionsInterface;
|
|
9
|
+
//# sourceMappingURL=BufferExtensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferExtensions.d.ts","sourceRoot":"","sources":["../../src/buffer/BufferExtensions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,MAAM,WAAW,yBAAyB;IACzC,qBAAqB,EAAE,CACtB,MAAM,EAAE,QAAQ,KACZ,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACvC,qBAAqB,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,QAAQ,CAAC;CAC9D;AAED,eAAO,MAAM,gBAAgB,EAAE,yBAiB9B,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
|
+
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
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
35
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
36
|
+
var m = o[Symbol.asyncIterator], i;
|
|
37
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
38
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
39
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.BufferExtensions = void 0;
|
|
43
|
+
const stream_1 = require("stream");
|
|
44
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
45
|
+
exports.BufferExtensions = {
|
|
46
|
+
readableToArrayBuffer: (stream) => TE.tryCatch(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
var _a, e_1, _b, _c;
|
|
48
|
+
const chunks = [];
|
|
49
|
+
try {
|
|
50
|
+
for (var _d = true, stream_2 = __asyncValues(stream), stream_2_1; stream_2_1 = yield stream_2.next(), _a = stream_2_1.done, !_a; _d = true) {
|
|
51
|
+
_c = stream_2_1.value;
|
|
52
|
+
_d = false;
|
|
53
|
+
const chunk = _c;
|
|
54
|
+
chunks.push(chunk);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
58
|
+
finally {
|
|
59
|
+
try {
|
|
60
|
+
if (!_d && !_a && (_b = stream_2.return)) yield _b.call(stream_2);
|
|
61
|
+
}
|
|
62
|
+
finally { if (e_1) throw e_1.error; }
|
|
63
|
+
}
|
|
64
|
+
const buffer = Buffer.concat(chunks);
|
|
65
|
+
return Uint8Array.from(buffer).buffer;
|
|
66
|
+
}), (error) => error),
|
|
67
|
+
arrayBufferToReadable: (arrayBuffer) => stream_1.Readable.from(Buffer.from(arrayBuffer)),
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferExtensions.unit.test.d.ts","sourceRoot":"","sources":["../../src/buffer/BufferExtensions.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
36
|
+
const util_1 = require("util");
|
|
37
|
+
const BufferExtensions_1 = require("./BufferExtensions");
|
|
38
|
+
describe('Buffer Tests', () => {
|
|
39
|
+
it('should convert a buffer to a stream, then stream back to a buffer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const readableStream = BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new util_1.TextEncoder().encode('test').buffer);
|
|
41
|
+
const bufferResult = yield BufferExtensions_1.BufferExtensions.readableToArrayBuffer(readableStream)();
|
|
42
|
+
const buffer = E.getOrElse((error) => {
|
|
43
|
+
throw new Error(error.message);
|
|
44
|
+
})(bufferResult);
|
|
45
|
+
expect(buffer).toEqual(new util_1.TextEncoder().encode('test').buffer);
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CallSite.d.ts","sourceRoot":"","sources":["../../src/callsite/CallSite.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,iBAAiB;IACjC,mBAAmB,EAAE,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3C;AAED,eAAO,MAAM,QAAQ,EAAE,iBAsBtB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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.CallSite = void 0;
|
|
27
|
+
const pathLib = __importStar(require("path"));
|
|
28
|
+
exports.CallSite = {
|
|
29
|
+
getCurrentCallSites: () => {
|
|
30
|
+
let callSites = [];
|
|
31
|
+
const _prepareStackTrace = Error.prepareStackTrace;
|
|
32
|
+
Error.prepareStackTrace = (_, stack) => {
|
|
33
|
+
callSites = stack.slice(2); // do not include this function and the immediate caller function
|
|
34
|
+
return stack;
|
|
35
|
+
};
|
|
36
|
+
new Error().stack; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
|
37
|
+
Error.prepareStackTrace = _prepareStackTrace;
|
|
38
|
+
const result = callSites
|
|
39
|
+
.filter((callSite) => callSite.getFileName() !== null) // skip iterations
|
|
40
|
+
.map((callSite) => {
|
|
41
|
+
const filePath = callSite.getFileName();
|
|
42
|
+
const folderPath = pathLib.normalize(pathLib.join(filePath, '..'));
|
|
43
|
+
return {
|
|
44
|
+
filePath,
|
|
45
|
+
folderPath,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
return result;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DynamicObject } from '../dynamictype/DynamicType';
|
|
2
|
+
export interface CliLogging {
|
|
3
|
+
log(message: string | DynamicObject): void;
|
|
4
|
+
logBlock(message: string, color: CliColors): void;
|
|
5
|
+
}
|
|
6
|
+
export declare enum CliColors {
|
|
7
|
+
blue = 0,
|
|
8
|
+
red = 1,
|
|
9
|
+
yellow = 2
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CliLogging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CliLogging.d.ts","sourceRoot":"","sources":["../../src/cli/CliLogging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,WAAW,UAAU;IAC1B,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CAClD;AAED,oBAAY,SAAS;IACpB,IAAI,IAAA;IACJ,GAAG,IAAA;IACH,MAAM,IAAA;CACN"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliColors = void 0;
|
|
4
|
+
var CliColors;
|
|
5
|
+
(function (CliColors) {
|
|
6
|
+
CliColors[CliColors["blue"] = 0] = "blue";
|
|
7
|
+
CliColors[CliColors["red"] = 1] = "red";
|
|
8
|
+
CliColors[CliColors["yellow"] = 2] = "yellow";
|
|
9
|
+
})(CliColors || (exports.CliColors = CliColors = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
2
|
+
import { Codec } from './Codec';
|
|
3
|
+
export type TestType = {
|
|
4
|
+
strField: string;
|
|
5
|
+
intField: O.Option<number>;
|
|
6
|
+
};
|
|
7
|
+
export declare function testCodec(testTypeCodec: Codec<TestType>): void;
|
|
8
|
+
//# sourceMappingURL=Codec.abstract.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Codec.abstract.test.d.ts","sourceRoot":"","sources":["../../src/codec/Codec.abstract.test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CAC3B,CAAC;AAEF,wBAAgB,SAAS,CAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,QAgBvD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.testCodec = 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 testCodec(testTypeCodec) {
|
|
31
|
+
describe('Type Codec Test', () => {
|
|
32
|
+
test('should encode and decode a value', () => {
|
|
33
|
+
const testValue = {
|
|
34
|
+
strField: 'str',
|
|
35
|
+
intField: O.some(123),
|
|
36
|
+
};
|
|
37
|
+
const result = (0, function_1.pipe)(E.right(testTypeCodec.encode(testValue)), E.chain((encoded) => testTypeCodec.decode(encoded)));
|
|
38
|
+
expect(result).toStrictEqual(E.right(testValue));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.testCodec = testCodec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Codec.d.ts","sourceRoot":"","sources":["../../src/codec/Codec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,MAAM,WAAW,KAAK,CAAC,CAAC;IACvB,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC;IAE1B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC3C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as E from 'fp-ts/lib/Either';
|
|
2
|
+
import { Codec } from './Codec';
|
|
3
|
+
export declare class CompositeCodec<T> implements Codec<T> {
|
|
4
|
+
private innerCodec;
|
|
5
|
+
private outerCodec;
|
|
6
|
+
static fromCodecs<T>(innerCodec: Codec<T>, outerCodec: Codec<unknown>): Codec<T>;
|
|
7
|
+
private constructor();
|
|
8
|
+
encode(value: T): unknown;
|
|
9
|
+
decode(value: unknown): E.Either<Error, T>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CompositeCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompositeCodec.d.ts","sourceRoot":"","sources":["../../src/codec/CompositeCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,cAAc,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IACjD,OAAO,CAAC,UAAU,CAAW;IAC7B,OAAO,CAAC,UAAU,CAAiB;IAEnC,MAAM,CAAC,UAAU,CAAC,CAAC,EAClB,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,EACpB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,GACxB,KAAK,CAAC,CAAC,CAAC;IAIX,OAAO;IAKP,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO;IAIzB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;CAM1C"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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.CompositeCodec = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/lib/Either"));
|
|
28
|
+
const function_1 = require("fp-ts/function");
|
|
29
|
+
class CompositeCodec {
|
|
30
|
+
static fromCodecs(innerCodec, outerCodec) {
|
|
31
|
+
return new CompositeCodec(innerCodec, outerCodec);
|
|
32
|
+
}
|
|
33
|
+
constructor(innerCodec, outerCodec) {
|
|
34
|
+
this.innerCodec = innerCodec;
|
|
35
|
+
this.outerCodec = outerCodec;
|
|
36
|
+
}
|
|
37
|
+
encode(value) {
|
|
38
|
+
return this.outerCodec.encode(this.innerCodec.encode(value));
|
|
39
|
+
}
|
|
40
|
+
decode(value) {
|
|
41
|
+
return (0, function_1.pipe)(this.outerCodec.decode(value), E.chain((decodedValue) => this.innerCodec.decode(decodedValue)));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.CompositeCodec = CompositeCodec;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as E from 'fp-ts/lib/Either';
|
|
2
|
+
import { Codec } from './Codec';
|
|
3
|
+
export declare class RemoveNullValuesCodec 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 removeNullValuesIfPresent;
|
|
9
|
+
private removeNullFromArrayIfPresent;
|
|
10
|
+
private removeNullFromObjectIfPresent;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=RemoveNullValuesCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoveNullValuesCodec.d.ts","sourceRoot":"","sources":["../../src/codec/RemoveNullValuesCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,qBAAsB,YAAW,KAAK,CAAC,OAAO,CAAC;IAC3D,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAA+B;IAE9D,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,yBAAyB;IAajC,OAAO,CAAC,4BAA4B;IASpC,OAAO,CAAC,6BAA6B;CAgBrC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
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.RemoveNullValuesCodec = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/lib/Either"));
|
|
28
|
+
class RemoveNullValuesCodec {
|
|
29
|
+
encode(value) {
|
|
30
|
+
return this.removeNullValuesIfPresent(value);
|
|
31
|
+
}
|
|
32
|
+
decode(value) {
|
|
33
|
+
return E.right(this.removeNullValuesIfPresent(value));
|
|
34
|
+
}
|
|
35
|
+
isObject(value) {
|
|
36
|
+
return typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
37
|
+
}
|
|
38
|
+
removeNullValuesIfPresent(value) {
|
|
39
|
+
if (value === null) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if (this.isObject(value)) {
|
|
43
|
+
return this.removeNullFromObjectIfPresent(value);
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
return this.removeNullFromArrayIfPresent(value);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
removeNullFromArrayIfPresent(value) {
|
|
51
|
+
return value.reduce((acc, propertyValue) => {
|
|
52
|
+
if (propertyValue == null) {
|
|
53
|
+
return acc;
|
|
54
|
+
}
|
|
55
|
+
return [...acc, this.removeNullValuesIfPresent(propertyValue)];
|
|
56
|
+
}, []);
|
|
57
|
+
}
|
|
58
|
+
removeNullFromObjectIfPresent(value) {
|
|
59
|
+
return Object.entries(value).reduce((acc, [key, propertyValue]) => {
|
|
60
|
+
if (propertyValue == null) {
|
|
61
|
+
return acc;
|
|
62
|
+
}
|
|
63
|
+
if (this.isObject(propertyValue)) {
|
|
64
|
+
const nestedObject = this.removeNullFromObjectIfPresent(propertyValue);
|
|
65
|
+
return Object.assign(Object.assign({}, acc), { [key]: nestedObject });
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(propertyValue)) {
|
|
68
|
+
const nestedArray = this.removeNullFromArrayIfPresent(propertyValue);
|
|
69
|
+
return Object.assign(Object.assign({}, acc), { [key]: nestedArray });
|
|
70
|
+
}
|
|
71
|
+
return Object.assign(Object.assign({}, acc), { [key]: propertyValue });
|
|
72
|
+
}, {});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.RemoveNullValuesCodec = RemoveNullValuesCodec;
|
|
76
|
+
RemoveNullValuesCodec.instance = new RemoveNullValuesCodec();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as E from 'fp-ts/lib/Either';
|
|
2
|
+
import * as t from 'io-ts';
|
|
3
|
+
import { Codec } from './Codec';
|
|
4
|
+
export declare class TypeCodec<T> implements Codec<T> {
|
|
5
|
+
static fromDescriptor<T>(descriptor: t.Type<T, unknown>): Codec<T>;
|
|
6
|
+
static undefined: Codec<undefined>;
|
|
7
|
+
static unknown: Codec<unknown>;
|
|
8
|
+
static emptyRecord: Codec<{}>;
|
|
9
|
+
static stringRecord: Codec<Record<string, string>>;
|
|
10
|
+
static partialRecord: <K extends Record<string, unknown>, G extends t.Any>(k: t.KeyofType<K>, type: G) => t.PartialC<Record<string, G>>;
|
|
11
|
+
private descriptor;
|
|
12
|
+
private constructor();
|
|
13
|
+
encode(value: T): unknown;
|
|
14
|
+
decode(value: unknown): E.Either<Error, T>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=TypeCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeCodec.d.ts","sourceRoot":"","sources":["../../src/codec/TypeCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAK3B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,SAAS,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAC5C,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IAIlE,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAEhC;IAEF,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAgD;IAC9E,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,CAA4C;IACzE,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAElB;IAIhC,MAAM,CAAC,aAAa,oHAGoB;IAExC,OAAO,CAAC,UAAU,CAAqB;IAEvC,OAAO;IAIP,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO;IAIzB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;CAQ1C"}
|