@aeriajs/common 0.0.77 → 0.0.79
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/result.d.ts +1 -0
- package/dist/result.js +11 -2
- package/dist/result.mjs +7 -1
- package/package.json +2 -2
package/dist/result.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Result } from '@aeriajs/types';
|
|
2
2
|
export declare const isResult: (value: any) => value is Result.Either<unknown, unknown>;
|
|
3
|
+
export declare const isError: (object: any) => object is Result.Error<unknown>;
|
|
3
4
|
export declare const throwIfError: <TValue>(either: Result.Either<unknown, TValue>, message?: any) => NonNullable<TValue>;
|
package/dist/result.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwIfError = exports.isResult = void 0;
|
|
3
|
+
exports.throwIfError = exports.isError = exports.isResult = void 0;
|
|
4
4
|
const isResult = (value) => {
|
|
5
5
|
return value
|
|
6
6
|
&& value.constructor === Object
|
|
7
7
|
&& (value._tag === 'Error' || value._tag === 'Result');
|
|
8
8
|
};
|
|
9
9
|
exports.isResult = isResult;
|
|
10
|
+
const isError = (object) => {
|
|
11
|
+
return object
|
|
12
|
+
&& object._tag === 'Error'
|
|
13
|
+
&& 'error' in object;
|
|
14
|
+
};
|
|
15
|
+
exports.isError = isError;
|
|
10
16
|
const throwIfError = (either, message) => {
|
|
11
|
-
if (
|
|
17
|
+
if (either.error) {
|
|
12
18
|
if (process.env.NODE_ENV !== 'production') {
|
|
13
19
|
console.trace(JSON.stringify(either.error, null, 2));
|
|
14
20
|
}
|
|
@@ -16,6 +22,9 @@ const throwIfError = (either, message) => {
|
|
|
16
22
|
? `(${message})`
|
|
17
23
|
: ''}`);
|
|
18
24
|
}
|
|
25
|
+
if (!either.result) {
|
|
26
|
+
throw new Error();
|
|
27
|
+
}
|
|
19
28
|
return either.result;
|
|
20
29
|
};
|
|
21
30
|
exports.throwIfError = throwIfError;
|
package/dist/result.mjs
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
export const isResult = (value) => {
|
|
3
3
|
return value && value.constructor === Object && (value._tag === "Error" || value._tag === "Result");
|
|
4
4
|
};
|
|
5
|
+
export const isError = (object) => {
|
|
6
|
+
return object && object._tag === "Error" && "error" in object;
|
|
7
|
+
};
|
|
5
8
|
export const throwIfError = (either, message) => {
|
|
6
|
-
if (
|
|
9
|
+
if (either.error) {
|
|
7
10
|
if (true) {
|
|
8
11
|
console.trace(JSON.stringify(either.error, null, 2));
|
|
9
12
|
}
|
|
10
13
|
throw new Error(`throwIfError threw: ${either.error} ${message ? `(${message})` : ""}`);
|
|
11
14
|
}
|
|
15
|
+
if (!either.result) {
|
|
16
|
+
throw new Error();
|
|
17
|
+
}
|
|
12
18
|
return either.result;
|
|
13
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.79",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"bson": "^6.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
+
"@aeriajs/types": "^0.0.68",
|
|
35
35
|
"bson": "^6.5.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|