@trayio/commons 5.35.0-unstable.fd7158a → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base64/Base64.d.ts +10 -5
- package/dist/base64/Base64.d.ts.map +1 -1
- package/dist/base64/Base64.js +40 -8
- package/dist/base64/Base64.unit.test.js +27 -4
- package/dist/buffer/BufferExtensions.d.ts +4 -4
- package/dist/buffer/BufferExtensions.d.ts.map +1 -1
- package/dist/buffer/BufferExtensions.js +38 -25
- package/dist/buffer/BufferExtensions.unit.test.js +45 -22
- package/dist/callsite/CallSite.js +7 -17
- package/dist/codec/CamelCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/CamelCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/CamelCasePropertyNameCodec.js +25 -2
- package/dist/codec/Codec.abstract.test.d.ts +2 -2
- package/dist/codec/Codec.abstract.test.d.ts.map +1 -1
- package/dist/codec/Codec.abstract.test.js +31 -5
- package/dist/codec/Codec.d.ts +2 -2
- package/dist/codec/Codec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.d.ts +2 -2
- package/dist/codec/CompositeCodec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.js +26 -2
- package/dist/codec/PartialRedactionCodec.d.ts +2 -2
- package/dist/codec/PartialRedactionCodec.d.ts.map +1 -1
- package/dist/codec/PartialRedactionCodec.js +25 -2
- package/dist/codec/RemoveNullValuesCodec.d.ts +2 -2
- package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -1
- package/dist/codec/RemoveNullValuesCodec.js +25 -2
- package/dist/codec/RemoveTopLevelTagCodec.d.ts +2 -2
- package/dist/codec/RemoveTopLevelTagCodec.d.ts.map +1 -1
- package/dist/codec/RemoveTopLevelTagCodec.js +25 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts +2 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts.map +1 -1
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.js +25 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.js +38 -15
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/SnakeCasePropertyNameCodec.js +25 -2
- package/dist/codec/TypeCodec.d.ts +8 -24
- package/dist/codec/TypeCodec.d.ts.map +1 -1
- package/dist/codec/TypeCodec.js +48 -40
- package/dist/codec/TypeCodec.unit.test.js +38 -12
- package/dist/dynamicschema/DynamicSchema.d.ts +12 -6
- package/dist/dynamicschema/DynamicSchema.d.ts.map +1 -1
- package/dist/dynamicschema/DynamicSchema.js +41 -18
- package/dist/dynamicschema/DynamicSchema.unit.test.js +75 -51
- package/dist/dynamictype/DynamicType.d.ts +20 -17
- package/dist/dynamictype/DynamicType.d.ts.map +1 -1
- package/dist/dynamictype/DynamicType.js +35 -48
- package/dist/file/FakeFileStorage.d.ts +8 -8
- package/dist/file/FakeFileStorage.d.ts.map +1 -1
- package/dist/file/FakeFileStorage.js +40 -16
- package/dist/file/File.d.ts +14 -10
- package/dist/file/File.d.ts.map +1 -1
- package/dist/file/File.js +24 -31
- package/dist/file/FileStorage.abstract.test.d.ts.map +1 -1
- package/dist/file/FileStorage.abstract.test.js +41 -18
- package/dist/file/NodeFsFileStorage.d.ts +11 -9
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
- package/dist/file/NodeFsFileStorage.integration.test.js +45 -21
- package/dist/file/NodeFsFileStorage.js +29 -37
- package/dist/http/Http.d.ts +13 -11
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +22 -30
- package/dist/http/Http.unit.test.js +26 -3
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
- package/dist/http/HttpClient.abstract.test.js +108 -104
- package/dist/http/HttpClient.d.ts +2 -2
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpController.d.ts +3 -2
- package/dist/http/HttpController.d.ts.map +1 -1
- package/dist/http/HttpTypeDescriptors.d.ts +11 -0
- package/dist/http/HttpTypeDescriptors.d.ts.map +1 -0
- package/dist/http/HttpTypeDescriptors.js +59 -0
- package/dist/http/MultipartHttpRequestBody.integration.test.js +20 -31
- package/dist/http/MultipartHttpRequestBody.unit.test.js +53 -70
- package/dist/record/Record.d.ts +3 -3
- package/dist/record/Record.d.ts.map +1 -1
- package/dist/record/Record.js +30 -9
- package/dist/result/Result.d.ts +3 -3
- package/dist/result/Result.d.ts.map +1 -1
- package/dist/result/Result.js +26 -9
- package/dist/schema/JsonSchemaIntrospector.js +7 -17
- package/dist/sensitive/Sensitive.d.ts +3 -7
- package/dist/sensitive/Sensitive.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.js +39 -23
- package/dist/sensitive/Sensitive.unit.test.d.ts +4 -4
- package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.unit.test.js +46 -20
- package/dist/serialization/FormUrlEncodedSerialization.d.ts +2 -2
- package/dist/serialization/FormUrlEncodedSerialization.d.ts.map +1 -1
- package/dist/serialization/FormUrlEncodedSerialization.js +28 -5
- package/dist/serialization/JsonSerialization.d.ts +2 -2
- package/dist/serialization/JsonSerialization.d.ts.map +1 -1
- package/dist/serialization/JsonSerialization.js +28 -5
- package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -1
- package/dist/serialization/Serialization.abstract.test.js +32 -6
- package/dist/serialization/Serialization.d.ts +2 -2
- package/dist/serialization/Serialization.d.ts.map +1 -1
- package/dist/task/Task.d.ts +19 -0
- package/dist/task/Task.d.ts.map +1 -0
- package/dist/task/Task.js +74 -0
- package/dist/task/Task.unit.test.d.ts +2 -0
- package/dist/task/Task.unit.test.d.ts.map +1 -0
- package/dist/task/Task.unit.test.js +46 -0
- package/dist/try/Try.d.ts +2 -2
- package/dist/try/Try.d.ts.map +1 -1
- package/dist/try/Try.js +32 -2
- package/dist/uuid/Uuid.d.ts +10 -11
- package/dist/uuid/Uuid.d.ts.map +1 -1
- package/dist/uuid/Uuid.js +39 -13
- package/dist/uuid/Uuid.unit.test.js +27 -4
- package/dist/zod/SchemaParser.abstract.test.d.ts.map +1 -1
- package/dist/zod/SchemaParser.abstract.test.js +31 -6
- package/dist/zod/SchemaParser.d.ts +2 -2
- package/dist/zod/SchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.d.ts +4 -3
- package/dist/zod/ZodSchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.js +28 -4
- package/dist/zod/ZodSchemaParser.unit.test.js +25 -2
- package/package.json +9 -4
- package/dist/effect/EffectExtensions.d.ts +0 -29
- package/dist/effect/EffectExtensions.d.ts.map +0 -1
- package/dist/effect/EffectExtensions.js +0 -30
- package/dist/effect/EffectExtensions.unit.test.d.ts +0 -2
- package/dist/effect/EffectExtensions.unit.test.d.ts.map +0 -1
- package/dist/effect/EffectExtensions.unit.test.js +0 -59
- package/dist/effect/Interop.d.ts +0 -53
- package/dist/effect/Interop.d.ts.map +0 -1
- package/dist/effect/Interop.js +0 -56
- package/dist/effect/Interop.unit.test.d.ts +0 -2
- package/dist/effect/Interop.unit.test.d.ts.map +0 -1
- package/dist/effect/Interop.unit.test.js +0 -134
- package/dist/effect/SchemaExtensions.d.ts +0 -11
- package/dist/effect/SchemaExtensions.d.ts.map +0 -1
- package/dist/effect/SchemaExtensions.js +0 -7
- package/dist/effect/SchemaExtensions.unit.test.d.ts +0 -2
- package/dist/effect/SchemaExtensions.unit.test.d.ts.map +0 -1
- package/dist/effect/SchemaExtensions.unit.test.js +0 -29
- package/dist/http/HttpSchemas.d.ts +0 -13
- package/dist/http/HttpSchemas.d.ts.map +0 -1
- package/dist/http/HttpSchemas.js +0 -23
- package/dist/schema/DateFromUnixTime.d.ts +0 -4
- package/dist/schema/DateFromUnixTime.d.ts.map +0 -1
- package/dist/schema/DateFromUnixTime.js +0 -10
- package/dist/schema/DateFromUnixTime.unit.test.d.ts +0 -2
- package/dist/schema/DateFromUnixTime.unit.test.d.ts.map +0 -1
- package/dist/schema/DateFromUnixTime.unit.test.js +0 -11
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Sensitive = void 0;
|
|
4
|
-
const
|
|
27
|
+
const t = __importStar(require("io-ts"));
|
|
28
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
5
29
|
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const sensitiveSchema = (inner) => {
|
|
15
|
-
const decodeInner = effect_1.ParseResult.decodeUnknown(inner);
|
|
16
|
-
const encodeInner = effect_1.ParseResult.encode(inner);
|
|
17
|
-
return effect_1.Schema.transformOrFail(effect_1.Schema.Unknown, effect_1.Schema.declare((u) => isSensitive(u), {
|
|
18
|
-
identifier: 'Sensitive',
|
|
19
|
-
}), {
|
|
20
|
-
strict: true,
|
|
21
|
-
decode: (input, options) => effect_1.ParseResult.map(decodeInner(input, options), fromValue),
|
|
22
|
-
encode: (sensitive, options) => effect_1.ParseResult.map(encodeInner(sensitive.value, options), (encoded) => fromValue(encoded)),
|
|
23
|
-
}).annotations({ identifier: 'Sensitive' });
|
|
24
|
-
};
|
|
30
|
+
const sensitiveTypeDescriptor = (descriptor) => new t.Type('Sensitive', (u) => u instanceof Object && '_tag' in u && u._tag === 'Sensitive', (u, c) => {
|
|
31
|
+
const validation = descriptor.validate(u, c);
|
|
32
|
+
if (E.isLeft(validation)) {
|
|
33
|
+
return t.failure(u, c, validation.left.map((e) => e.message).join('\n'));
|
|
34
|
+
}
|
|
35
|
+
return t.success(exports.Sensitive.fromValue(validation.right));
|
|
36
|
+
}, (a) => exports.Sensitive.fromValue(descriptor.encode(a.value)));
|
|
37
|
+
const sensitiveTypeCodec = (descriptor) => TypeCodec_1.TypeCodec.fromDescriptor(sensitiveTypeDescriptor(descriptor));
|
|
25
38
|
exports.Sensitive = {
|
|
26
|
-
fromValue
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
fromValue: (value) => ({
|
|
40
|
+
value,
|
|
41
|
+
_tag: 'Sensitive',
|
|
42
|
+
}),
|
|
43
|
+
typeDescriptor: (descriptor) => sensitiveTypeDescriptor(descriptor),
|
|
44
|
+
typeCodec: sensitiveTypeCodec,
|
|
29
45
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
2
2
|
import { Codec } from '../codec/Codec';
|
|
3
3
|
import { Sensitive } from './Sensitive';
|
|
4
4
|
export type TestTypeSensitive = {
|
|
5
5
|
strField: string;
|
|
6
|
-
intField: Sensitive<
|
|
6
|
+
intField: Sensitive<O.Option<number>>;
|
|
7
7
|
objectField: Sensitive<{
|
|
8
8
|
int: number;
|
|
9
9
|
str: string;
|
|
10
|
-
optionalObj: Sensitive<
|
|
10
|
+
optionalObj: Sensitive<O.Option<{
|
|
11
11
|
test: string;
|
|
12
12
|
test1: string;
|
|
13
|
-
testArray: Sensitive<
|
|
13
|
+
testArray: Sensitive<O.Option<string>[]>;
|
|
14
14
|
}>>;
|
|
15
15
|
}>;
|
|
16
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sensitive.unit.test.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.unit.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Sensitive.unit.test.d.ts","sourceRoot":"","sources":["../../src/sensitive/Sensitive.unit.test.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,WAAW,EAAE,SAAS,CAAC;QACtB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,EAAE,SAAS,CACrB,CAAC,CAAC,MAAM,CAAC;YACR,IAAI,EAAE,MAAM,CAAC;YACb,KAAK,EAAE,MAAM,CAAC;YACd,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACzC,CAAC,CACF,CAAC;KACF,CAAC,CAAC;CACH,CAAC;AAwBF,eAAO,MAAM,+BAA+B,EAAE,KAAK,CAAC,iBAAiB,CAInE,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,iBAAiB,CACiB,CAAC"}
|
|
@@ -1,37 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.testTypeSensitiveCodec = exports.testTypeSensitiveRedactionCodec = void 0;
|
|
4
|
-
const
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const t = __importStar(require("io-ts"));
|
|
29
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
30
|
+
const td = __importStar(require("io-ts-types"));
|
|
5
31
|
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
6
32
|
const Sensitive_1 = require("./Sensitive");
|
|
7
|
-
const
|
|
8
|
-
strField:
|
|
9
|
-
intField: Sensitive_1.Sensitive.
|
|
10
|
-
objectField: Sensitive_1.Sensitive.
|
|
11
|
-
int:
|
|
12
|
-
str:
|
|
13
|
-
optionalObj: Sensitive_1.Sensitive.
|
|
14
|
-
test:
|
|
15
|
-
test1:
|
|
16
|
-
testArray: Sensitive_1.Sensitive.
|
|
17
|
-
})
|
|
33
|
+
const testTypeSensitiveTypeDescriptor = t.type({
|
|
34
|
+
strField: t.string,
|
|
35
|
+
intField: Sensitive_1.Sensitive.typeDescriptor(td.optionFromNullable(t.number)),
|
|
36
|
+
objectField: Sensitive_1.Sensitive.typeDescriptor(t.type({
|
|
37
|
+
int: t.number,
|
|
38
|
+
str: t.string,
|
|
39
|
+
optionalObj: Sensitive_1.Sensitive.typeDescriptor(td.optionFromNullable(t.type({
|
|
40
|
+
test: t.string,
|
|
41
|
+
test1: t.string,
|
|
42
|
+
testArray: Sensitive_1.Sensitive.typeDescriptor(t.array(td.optionFromNullable(t.string))),
|
|
43
|
+
}))),
|
|
18
44
|
})),
|
|
19
45
|
});
|
|
20
|
-
exports.testTypeSensitiveRedactionCodec = TypeCodec_1.TypeCodec.
|
|
21
|
-
exports.testTypeSensitiveCodec = TypeCodec_1.TypeCodec.
|
|
46
|
+
exports.testTypeSensitiveRedactionCodec = TypeCodec_1.TypeCodec.fromDescriptor(testTypeSensitiveTypeDescriptor, true);
|
|
47
|
+
exports.testTypeSensitiveCodec = TypeCodec_1.TypeCodec.fromDescriptor(testTypeSensitiveTypeDescriptor);
|
|
22
48
|
describe('Sensitive', () => {
|
|
23
49
|
describe('encode/decode sensitive values', () => {
|
|
24
50
|
it('should encode sensitive typed data without the extra layer', () => {
|
|
25
51
|
const testValueEncoded = {
|
|
26
52
|
strField: 'str',
|
|
27
|
-
intField: Sensitive_1.Sensitive.fromValue(
|
|
53
|
+
intField: Sensitive_1.Sensitive.fromValue(O.some(123)),
|
|
28
54
|
objectField: Sensitive_1.Sensitive.fromValue({
|
|
29
55
|
str: 'test',
|
|
30
56
|
int: 123,
|
|
31
|
-
optionalObj: Sensitive_1.Sensitive.fromValue(
|
|
57
|
+
optionalObj: Sensitive_1.Sensitive.fromValue(O.some({
|
|
32
58
|
test: 'test',
|
|
33
59
|
test1: 'test1',
|
|
34
|
-
testArray: Sensitive_1.Sensitive.fromValue([
|
|
60
|
+
testArray: Sensitive_1.Sensitive.fromValue([O.some('test')]),
|
|
35
61
|
})),
|
|
36
62
|
}),
|
|
37
63
|
};
|
|
@@ -66,13 +92,13 @@ describe('Sensitive', () => {
|
|
|
66
92
|
},
|
|
67
93
|
};
|
|
68
94
|
const result = exports.testTypeSensitiveCodec.decode(testValueDecoded);
|
|
69
|
-
const expected =
|
|
95
|
+
const expected = E.right({
|
|
70
96
|
strField: 'str',
|
|
71
|
-
intField: Sensitive_1.Sensitive.fromValue(
|
|
97
|
+
intField: Sensitive_1.Sensitive.fromValue(O.none),
|
|
72
98
|
objectField: Sensitive_1.Sensitive.fromValue({
|
|
73
99
|
str: 'test',
|
|
74
100
|
int: 123,
|
|
75
|
-
optionalObj: Sensitive_1.Sensitive.fromValue(
|
|
101
|
+
optionalObj: Sensitive_1.Sensitive.fromValue(O.some({
|
|
76
102
|
test: 'test',
|
|
77
103
|
test1: 'test1',
|
|
78
104
|
testArray: Sensitive_1.Sensitive.fromValue([]),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
2
|
import { Serialization, SerializationFormat } from './Serialization';
|
|
3
3
|
export declare class FormUrlEncodedSerialization implements Serialization {
|
|
4
4
|
private textEncoder;
|
|
5
5
|
private textDecoder;
|
|
6
6
|
format: SerializationFormat;
|
|
7
7
|
serialize(value: unknown): ArrayBuffer;
|
|
8
|
-
deserialize(value: ArrayBuffer):
|
|
8
|
+
deserialize(value: ArrayBuffer): E.Either<Error, unknown>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=FormUrlEncodedSerialization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormUrlEncodedSerialization.d.ts","sourceRoot":"","sources":["../../src/serialization/FormUrlEncodedSerialization.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
|
@@ -1,28 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
exports.FormUrlEncodedSerialization = void 0;
|
|
7
|
-
const
|
|
30
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
8
31
|
const util_1 = require("util");
|
|
32
|
+
const function_1 = require("fp-ts/function");
|
|
9
33
|
const qs_1 = __importDefault(require("qs"));
|
|
10
34
|
const Serialization_1 = require("./Serialization");
|
|
11
35
|
const Try_1 = require("../try/Try");
|
|
12
|
-
const BufferExtensions_1 = require("../buffer/BufferExtensions");
|
|
13
36
|
class FormUrlEncodedSerialization {
|
|
14
37
|
textEncoder = new util_1.TextEncoder();
|
|
15
38
|
textDecoder = new util_1.TextDecoder();
|
|
16
39
|
format = Serialization_1.SerializationFormat.FormUrlEncoded;
|
|
17
40
|
serialize(value) {
|
|
18
41
|
const formEncoded = qs_1.default.stringify(value);
|
|
19
|
-
return
|
|
42
|
+
return this.textEncoder.encode(formEncoded).buffer;
|
|
20
43
|
}
|
|
21
44
|
deserialize(value) {
|
|
22
45
|
if (value.byteLength === 0) {
|
|
23
|
-
return
|
|
46
|
+
return E.right(undefined);
|
|
24
47
|
}
|
|
25
|
-
return
|
|
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))));
|
|
26
49
|
}
|
|
27
50
|
}
|
|
28
51
|
exports.FormUrlEncodedSerialization = FormUrlEncodedSerialization;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
2
|
import { Serialization, SerializationFormat } from './Serialization';
|
|
3
3
|
export declare class JsonSerialization implements Serialization {
|
|
4
4
|
private textEncoder;
|
|
5
5
|
private textDecoder;
|
|
6
6
|
format: SerializationFormat;
|
|
7
7
|
serialize(value: unknown): ArrayBuffer;
|
|
8
|
-
deserialize(value: ArrayBuffer):
|
|
8
|
+
deserialize(value: ArrayBuffer): E.Either<Error, unknown>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=JsonSerialization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonSerialization.d.ts","sourceRoot":"","sources":["../../src/serialization/JsonSerialization.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
|
@@ -1,24 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.JsonSerialization = void 0;
|
|
4
|
-
const
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
5
28
|
const util_1 = require("util");
|
|
29
|
+
const function_1 = require("fp-ts/function");
|
|
6
30
|
const Serialization_1 = require("./Serialization");
|
|
7
31
|
const Try_1 = require("../try/Try");
|
|
8
|
-
const BufferExtensions_1 = require("../buffer/BufferExtensions");
|
|
9
32
|
class JsonSerialization {
|
|
10
33
|
textEncoder = new util_1.TextEncoder();
|
|
11
34
|
textDecoder = new util_1.TextDecoder();
|
|
12
35
|
format = Serialization_1.SerializationFormat.Json;
|
|
13
36
|
serialize(value) {
|
|
14
37
|
const json = JSON.stringify(value);
|
|
15
|
-
return
|
|
38
|
+
return this.textEncoder.encode(json).buffer;
|
|
16
39
|
}
|
|
17
40
|
deserialize(value) {
|
|
18
41
|
if (value.byteLength === 0) {
|
|
19
|
-
return
|
|
42
|
+
return E.right(undefined);
|
|
20
43
|
}
|
|
21
|
-
return
|
|
44
|
+
return (0, function_1.pipe)((0, Try_1.tryToEither)(() => this.textDecoder.decode(value)), E.chain((str) => (0, Try_1.tryToEither)(() => JSON.parse(str))));
|
|
22
45
|
}
|
|
23
46
|
}
|
|
24
47
|
exports.JsonSerialization = JsonSerialization;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serialization.abstract.test.d.ts","sourceRoot":"","sources":["../../src/serialization/Serialization.abstract.test.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.testSerialization =
|
|
4
|
-
const
|
|
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");
|
|
5
30
|
function testSerialization(serialization) {
|
|
6
31
|
describe('Serialization Test', () => {
|
|
7
32
|
test('should serialize and deserialize a value', () => {
|
|
8
33
|
const testValue = {
|
|
9
34
|
strField: 'str',
|
|
10
|
-
intStrField: '123',
|
|
35
|
+
intStrField: O.some('123'),
|
|
11
36
|
};
|
|
12
|
-
const result = (0,
|
|
13
|
-
expect(result).toStrictEqual(
|
|
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));
|
|
14
39
|
});
|
|
15
40
|
test('should serialize undefined', () => {
|
|
16
41
|
const undefinedType = undefined;
|
|
@@ -21,8 +46,9 @@ function testSerialization(serialization) {
|
|
|
21
46
|
test('should deserialize undefined', () => {
|
|
22
47
|
const undefinedSerialized = new ArrayBuffer(0);
|
|
23
48
|
const result = serialization.deserialize(undefinedSerialized);
|
|
24
|
-
const expected =
|
|
49
|
+
const expected = E.right(undefined);
|
|
25
50
|
expect(result).toStrictEqual(expected);
|
|
26
51
|
});
|
|
27
52
|
});
|
|
28
53
|
}
|
|
54
|
+
exports.testSerialization = testSerialization;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
2
|
export declare enum SerializationFormat {
|
|
3
3
|
Json = "Json",
|
|
4
4
|
FormUrlEncoded = "FormUrlEncoded"
|
|
@@ -6,6 +6,6 @@ export declare enum SerializationFormat {
|
|
|
6
6
|
export interface Serialization {
|
|
7
7
|
format: SerializationFormat;
|
|
8
8
|
serialize(value: unknown): ArrayBuffer;
|
|
9
|
-
deserialize(value: ArrayBuffer):
|
|
9
|
+
deserialize(value: ArrayBuffer): E.Either<Error, unknown>;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=Serialization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serialization.d.ts","sourceRoot":"","sources":["../../src/serialization/Serialization.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import * as TSK from 'fp-ts/Task';
|
|
3
|
+
import { Either } from 'fp-ts/lib/Either';
|
|
4
|
+
import * as E from 'fp-ts/Either';
|
|
5
|
+
export interface TaskExtensionsInterface {
|
|
6
|
+
recover: <T>(task: TSK.Task<T>, onError: (error: Error) => T) => TSK.Task<T>;
|
|
7
|
+
loopTask: <InterstitialResult, FinalResult>(firstTask: TSK.Task<InterstitialResult>, nextTask: (result: InterstitialResult) => E.Either<FinalResult, TSK.Task<InterstitialResult>>) => TSK.Task<FinalResult>;
|
|
8
|
+
}
|
|
9
|
+
export declare const TaskExtensions: TaskExtensionsInterface;
|
|
10
|
+
export interface TaskEitherExtensionsInterface {
|
|
11
|
+
fromPromiseWithSimpleError: <T>(block: () => Promise<T>) => TE.TaskEither<Error, T>;
|
|
12
|
+
}
|
|
13
|
+
export declare const TaskEitherExtensions: TaskEitherExtensionsInterface;
|
|
14
|
+
export declare const createTaskEitherFromPromise: <E, T>(block: () => Promise<T>, errorHandling: (error: Error) => E) => TE.TaskEither<E, T>;
|
|
15
|
+
export declare const createTaskEither: <E, T>(block: () => Promise<Either<E, T>>) => TE.TaskEither<E, T>;
|
|
16
|
+
export declare const createTaskEitherFromEither: <E, T>(either: Either<E, T>) => TE.TaskEither<E, T>;
|
|
17
|
+
export declare const createTaskEitherFromPromiseWithSimpleError: <T>(block: () => Promise<T>) => TE.TaskEither<Error, T>;
|
|
18
|
+
export declare const taskEitherToPromise: <F, T>(te: TE.TaskEither<F, T>) => Promise<T>;
|
|
19
|
+
//# sourceMappingURL=Task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/task/Task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7E,QAAQ,EAAE,CAAC,kBAAkB,EAAE,WAAW,EACzC,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,EACvC,QAAQ,EAAE,CACT,MAAM,EAAE,kBAAkB,KACtB,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,KACpD,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,cAAc,EAAE,uBAgC5B,CAAC;AAEF,MAAM,WAAW,6BAA6B;IAC7C,0BAA0B,EAAE,CAAC,CAAC,EAC7B,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACnB,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7B;AAED,eAAO,MAAM,oBAAoB,EAAE,6BAIlC,CAAC;AAGF,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,EAAE,CAAC,EAC9C,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACvB,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,CAAC,KAC9B,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CACwC,CAAC;AAGhE,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,EACnC,KAAK,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAC9B,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAoB,CAAC;AAG5C,eAAO,MAAM,0BAA0B,EAAE,CAAC,CAAC,EAAE,CAAC,EAC7C,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAChB,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CACyB,CAAC;AAGjD,eAAO,MAAM,0CAA0C,EAAE,CAAC,CAAC,EAC1D,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACnB,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CACqB,CAAC;AAEjD,eAAO,MAAM,mBAAmB,+CAQ/B,CAAC"}
|
|
@@ -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.taskEitherToPromise = exports.createTaskEitherFromPromiseWithSimpleError = exports.createTaskEitherFromEither = exports.createTaskEither = exports.createTaskEitherFromPromise = exports.TaskEitherExtensions = exports.TaskExtensions = void 0;
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
28
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
29
|
+
const Error_1 = require("../error/Error");
|
|
30
|
+
exports.TaskExtensions = {
|
|
31
|
+
recover: (task, onError) => async () => {
|
|
32
|
+
try {
|
|
33
|
+
return await task();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return onError((0, Error_1.castError)(error));
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
loopTask: (firstTask, nextTask) => () => {
|
|
40
|
+
let currentTask = firstTask;
|
|
41
|
+
const iterate = () => currentTask().then((result) => {
|
|
42
|
+
const next = nextTask(result);
|
|
43
|
+
if (E.isLeft(next)) {
|
|
44
|
+
return Promise.resolve(next.left);
|
|
45
|
+
}
|
|
46
|
+
currentTask = next.right;
|
|
47
|
+
return iterate();
|
|
48
|
+
});
|
|
49
|
+
return iterate();
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
exports.TaskEitherExtensions = {
|
|
53
|
+
fromPromiseWithSimpleError: (block) => TE.tryCatch(block, (error) => (0, Error_1.castError)(error)),
|
|
54
|
+
};
|
|
55
|
+
// TODO: Remove, use TE.tryCatch
|
|
56
|
+
const createTaskEitherFromPromise = (block, errorHandling) => TE.tryCatch(block, (error) => errorHandling((0, Error_1.castError)(error)));
|
|
57
|
+
exports.createTaskEitherFromPromise = createTaskEitherFromPromise;
|
|
58
|
+
// TODO: Remove, use TE.tryCatch
|
|
59
|
+
const createTaskEither = (block) => block;
|
|
60
|
+
exports.createTaskEither = createTaskEither;
|
|
61
|
+
// TODO: Remove, we can use TE.fromEither (double check that the other functions are necessary)
|
|
62
|
+
const createTaskEitherFromEither = (either) => (0, exports.createTaskEither)(() => Promise.resolve(either));
|
|
63
|
+
exports.createTaskEitherFromEither = createTaskEitherFromEither;
|
|
64
|
+
// TODO: Remove, use the method on the interface
|
|
65
|
+
const createTaskEitherFromPromiseWithSimpleError = (block) => TE.tryCatch(block, (error) => (0, Error_1.castError)(error));
|
|
66
|
+
exports.createTaskEitherFromPromiseWithSimpleError = createTaskEitherFromPromiseWithSimpleError;
|
|
67
|
+
const taskEitherToPromise = async (te) => {
|
|
68
|
+
const either = await te();
|
|
69
|
+
if (E.isLeft(either)) {
|
|
70
|
+
throw either.left;
|
|
71
|
+
}
|
|
72
|
+
return either.right;
|
|
73
|
+
};
|
|
74
|
+
exports.taskEitherToPromise = taskEitherToPromise;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Task.unit.test.d.ts","sourceRoot":"","sources":["../../src/task/Task.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 TE = __importStar(require("fp-ts/TaskEither"));
|
|
27
|
+
const Task_1 = require("./Task");
|
|
28
|
+
describe('taskEitherToPromise', () => {
|
|
29
|
+
test('resolves with the right value when the TaskEither is Right', async () => {
|
|
30
|
+
const value = { id: 42 };
|
|
31
|
+
const result = await (0, Task_1.taskEitherToPromise)(TE.right(value));
|
|
32
|
+
expect(result).toBe(value);
|
|
33
|
+
});
|
|
34
|
+
test('rejects with the original failure object when the TaskEither is Left', async () => {
|
|
35
|
+
const failure = { tag: 'not_found', status: 404 };
|
|
36
|
+
await expect((0, Task_1.taskEitherToPromise)(TE.left(failure))).rejects.toBe(failure);
|
|
37
|
+
});
|
|
38
|
+
test('rejects with the original string when the Left is a plain string', async () => {
|
|
39
|
+
await expect((0, Task_1.taskEitherToPromise)(TE.left('boom'))).rejects.toBe('boom');
|
|
40
|
+
});
|
|
41
|
+
test('invokes the lazy TaskEither thunk exactly once per call', async () => {
|
|
42
|
+
const thunk = jest.fn(() => Promise.resolve({ _tag: 'Right', right: 'ok' }));
|
|
43
|
+
await (0, Task_1.taskEitherToPromise)(thunk);
|
|
44
|
+
expect(thunk).toHaveBeenCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
});
|
package/dist/try/Try.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const tryToEither: <T>(block: () => T) =>
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
|
+
export declare const tryToEither: <T>(block: () => T) => E.Either<Error, T>;
|
|
3
3
|
//# sourceMappingURL=Try.d.ts.map
|
package/dist/try/Try.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Try.d.ts","sourceRoot":"","sources":["../../src/try/Try.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Try.d.ts","sourceRoot":"","sources":["../../src/try/Try.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAQjE,CAAC"}
|