@trayio/commons 4.36.1 → 4.37.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/error/Error.d.ts.map +1 -1
- package/dist/error/Error.js +4 -1
- package/dist/task/Task.d.ts +14 -5
- package/dist/task/Task.d.ts.map +1 -1
- package/dist/task/Task.js +43 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/error/Error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/error/Error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAWvC,CAAC"}
|
package/dist/error/Error.js
CHANGED
|
@@ -8,6 +8,9 @@ const castError = (error) => {
|
|
|
8
8
|
if (error instanceof Error) {
|
|
9
9
|
return error;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
if (typeof error === 'object') {
|
|
12
|
+
return new Error(`Internal error: ${JSON.stringify(error)}`);
|
|
13
|
+
}
|
|
14
|
+
return new Error('Unknown internal error');
|
|
12
15
|
};
|
|
13
16
|
exports.castError = castError;
|
package/dist/task/Task.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import * as TSK from 'fp-ts/Task';
|
|
2
3
|
import { Either } from 'fp-ts/lib/Either';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare const
|
|
4
|
+
export interface TaskExtensionsInterface {
|
|
5
|
+
recover: <T>(task: TSK.Task<T>, onError: (error: Error) => T) => TSK.Task<T>;
|
|
6
|
+
}
|
|
7
|
+
export declare const TaskExtensions: TaskExtensionsInterface;
|
|
8
|
+
export interface TaskEitherExtensionsInterface {
|
|
9
|
+
fromPromiseWithSimpleError: <T>(block: () => Promise<T>) => TE.TaskEither<Error, T>;
|
|
10
|
+
}
|
|
11
|
+
export declare const TaskEitherExtensions: TaskEitherExtensionsInterface;
|
|
12
|
+
export declare const createTaskEitherFromPromise: <E, T>(block: () => Promise<T>, errorHandling: (error: Error) => E) => TE.TaskEither<E, T>;
|
|
13
|
+
export declare const createTaskEither: <E, T>(block: () => Promise<Either<E, T>>) => TE.TaskEither<E, T>;
|
|
14
|
+
export declare const createTaskEitherFromEither: <E, T>(either: Either<E, T>) => TE.TaskEither<E, T>;
|
|
15
|
+
export declare const createTaskEitherFromPromiseWithSimpleError: <T>(block: () => Promise<T>) => TE.TaskEither<Error, T>;
|
|
7
16
|
//# 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,EAAE,
|
|
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;AAG1C,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;CAC7E;AAED,eAAO,MAAM,cAAc,EAAE,uBAU5B,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"}
|
package/dist/task/Task.js
CHANGED
|
@@ -1,14 +1,53 @@
|
|
|
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.createTaskEitherFromPromiseWithSimpleError = exports.createTaskEitherFromEither = exports.createTaskEither = exports.createTaskEitherFromPromise = void 0;
|
|
4
|
-
const
|
|
26
|
+
exports.createTaskEitherFromPromiseWithSimpleError = exports.createTaskEitherFromEither = exports.createTaskEither = exports.createTaskEitherFromPromise = exports.TaskEitherExtensions = exports.TaskExtensions = void 0;
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
5
28
|
const Error_1 = require("../error/Error");
|
|
6
|
-
|
|
29
|
+
exports.TaskExtensions = {
|
|
30
|
+
recover: (task, onError) => async () => {
|
|
31
|
+
try {
|
|
32
|
+
return await task();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return onError((0, Error_1.castError)(error));
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
exports.TaskEitherExtensions = {
|
|
40
|
+
fromPromiseWithSimpleError: (block) => TE.tryCatch(block, (error) => (0, Error_1.castError)(error)),
|
|
41
|
+
};
|
|
42
|
+
// TODO: Remove, use TE.tryCatch
|
|
43
|
+
const createTaskEitherFromPromise = (block, errorHandling) => TE.tryCatch(block, (error) => errorHandling((0, Error_1.castError)(error)));
|
|
7
44
|
exports.createTaskEitherFromPromise = createTaskEitherFromPromise;
|
|
45
|
+
// TODO: Remove, use TE.tryCatch
|
|
8
46
|
const createTaskEither = (block) => block;
|
|
9
47
|
exports.createTaskEither = createTaskEither;
|
|
10
48
|
// TODO: Remove, we can use TE.fromEither (double check that the other functions are necessary)
|
|
11
49
|
const createTaskEitherFromEither = (either) => (0, exports.createTaskEither)(() => Promise.resolve(either));
|
|
12
50
|
exports.createTaskEitherFromEither = createTaskEitherFromEither;
|
|
13
|
-
|
|
51
|
+
// TODO: Remove, use the method on the interface
|
|
52
|
+
const createTaskEitherFromPromiseWithSimpleError = (block) => TE.tryCatch(block, (error) => (0, Error_1.castError)(error));
|
|
14
53
|
exports.createTaskEitherFromPromiseWithSimpleError = createTaskEitherFromPromiseWithSimpleError;
|