@trayio/commons 5.23.0 → 5.24.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/task/Task.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export declare const createTaskEitherFromPromise: <E, T>(block: () => Promise<T>
|
|
|
15
15
|
export declare const createTaskEither: <E, T>(block: () => Promise<Either<E, T>>) => TE.TaskEither<E, T>;
|
|
16
16
|
export declare const createTaskEitherFromEither: <E, T>(either: Either<E, T>) => TE.TaskEither<E, T>;
|
|
17
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>;
|
|
18
19
|
//# sourceMappingURL=Task.d.ts.map
|
package/dist/task/Task.d.ts.map
CHANGED
|
@@ -1 +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,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AAC,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"}
|
package/dist/task/Task.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.createTaskEitherFromPromiseWithSimpleError = exports.createTaskEitherFromEither = exports.createTaskEither = exports.createTaskEitherFromPromise = exports.TaskEitherExtensions = exports.TaskExtensions = void 0;
|
|
26
|
+
exports.taskEitherToPromise = exports.createTaskEitherFromPromiseWithSimpleError = exports.createTaskEitherFromEither = exports.createTaskEither = exports.createTaskEitherFromPromise = exports.TaskEitherExtensions = exports.TaskExtensions = void 0;
|
|
27
27
|
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
28
28
|
const E = __importStar(require("fp-ts/Either"));
|
|
29
29
|
const Error_1 = require("../error/Error");
|
|
@@ -64,3 +64,11 @@ exports.createTaskEitherFromEither = createTaskEitherFromEither;
|
|
|
64
64
|
// TODO: Remove, use the method on the interface
|
|
65
65
|
const createTaskEitherFromPromiseWithSimpleError = (block) => TE.tryCatch(block, (error) => (0, Error_1.castError)(error));
|
|
66
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
|
+
});
|