@aeriajs/common 0.0.58 → 0.0.60
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/endpointError.d.ts +8 -0
- package/dist/endpointError.js +17 -0
- package/dist/endpointError.mjs +11 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.mjs +3 -2
- package/dist/isEmptyObject.d.ts +1 -0
- package/dist/isEmptyObject.js +7 -0
- package/dist/isEmptyObject.mjs +4 -0
- package/dist/result.d.ts +17 -0
- package/dist/result.js +28 -0
- package/dist/result.mjs +23 -0
- package/dist/schema.d.ts +24 -40
- package/dist/schema.js +33 -49
- package/dist/schema.mjs +30 -46
- package/package.json +2 -2
- package/dist/either.d.ts +0 -7
- package/dist/either.js +0 -35
- package/dist/either.mjs +0 -27
- package/dist/error.d.ts +0 -7
- package/dist/error.js +0 -34
- package/dist/error.mjs +0 -26
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EndpointError } from '@aeriajs/types';
|
|
2
|
+
import { Result } from './result.js';
|
|
3
|
+
export declare const endpointError: <const TEndpointError extends EndpointError>(value: TEndpointError) => {
|
|
4
|
+
readonly _tag: "Error";
|
|
5
|
+
readonly error: TEndpointError;
|
|
6
|
+
readonly result: undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const isEndpointError: (object: EndpointError | any) => object is Result.Error<EndpointError<any>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEndpointError = exports.endpointError = void 0;
|
|
4
|
+
const types_1 = require("@aeriajs/types");
|
|
5
|
+
const result_js_1 = require("./result.js");
|
|
6
|
+
const endpointError = (value) => {
|
|
7
|
+
return result_js_1.Result.error(Object.assign({
|
|
8
|
+
[types_1.ERROR_SYMBOL]: true,
|
|
9
|
+
}, value));
|
|
10
|
+
};
|
|
11
|
+
exports.endpointError = endpointError;
|
|
12
|
+
const isEndpointError = (object) => {
|
|
13
|
+
return object
|
|
14
|
+
&& object.error
|
|
15
|
+
&& (types_1.ERROR_SYMBOL in object.error || types_1.ERROR_SYMBOL_DESCRIPTION in object.error);
|
|
16
|
+
};
|
|
17
|
+
exports.isEndpointError = isEndpointError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { ERROR_SYMBOL, ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
|
|
3
|
+
import { Result } from "./result.mjs";
|
|
4
|
+
export const endpointError = (value) => {
|
|
5
|
+
return Result.error(Object.assign({
|
|
6
|
+
[ERROR_SYMBOL]: true
|
|
7
|
+
}, value));
|
|
8
|
+
};
|
|
9
|
+
export const isEndpointError = (object) => {
|
|
10
|
+
return object && object.error && (ERROR_SYMBOL in object.error || ERROR_SYMBOL_DESCRIPTION in object.error);
|
|
11
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export * from './date.js';
|
|
|
5
5
|
export * from './deepClone.js';
|
|
6
6
|
export * from './deepMerge.js';
|
|
7
7
|
export * from './dynamicImport.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
8
|
+
export * from './result.js';
|
|
9
|
+
export * from './endpointError.js';
|
|
10
10
|
export * from './evaluateCondition.js';
|
|
11
11
|
export * from './formatValue.js';
|
|
12
12
|
export * from './freshItem.js';
|
|
@@ -14,6 +14,7 @@ export * from './getMissingProperties.js';
|
|
|
14
14
|
export * from './getReferenceProperty.js';
|
|
15
15
|
export * from './getValueFromPath.js';
|
|
16
16
|
export * from './http.js';
|
|
17
|
+
export * from './isEmptyObject.js';
|
|
17
18
|
export * from './isGranted.js';
|
|
18
19
|
export * from './isObjectId.js';
|
|
19
20
|
export * from './isReference.js';
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,8 @@ __exportStar(require("./date.js"), exports);
|
|
|
21
21
|
__exportStar(require("./deepClone.js"), exports);
|
|
22
22
|
__exportStar(require("./deepMerge.js"), exports);
|
|
23
23
|
__exportStar(require("./dynamicImport.js"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./result.js"), exports);
|
|
25
|
+
__exportStar(require("./endpointError.js"), exports);
|
|
26
26
|
__exportStar(require("./evaluateCondition.js"), exports);
|
|
27
27
|
__exportStar(require("./formatValue.js"), exports);
|
|
28
28
|
__exportStar(require("./freshItem.js"), exports);
|
|
@@ -30,6 +30,7 @@ __exportStar(require("./getMissingProperties.js"), exports);
|
|
|
30
30
|
__exportStar(require("./getReferenceProperty.js"), exports);
|
|
31
31
|
__exportStar(require("./getValueFromPath.js"), exports);
|
|
32
32
|
__exportStar(require("./http.js"), exports);
|
|
33
|
+
__exportStar(require("./isEmptyObject.js"), exports);
|
|
33
34
|
__exportStar(require("./isGranted.js"), exports);
|
|
34
35
|
__exportStar(require("./isObjectId.js"), exports);
|
|
35
36
|
__exportStar(require("./isReference.js"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -6,8 +6,8 @@ export * from "./date.mjs";
|
|
|
6
6
|
export * from "./deepClone.mjs";
|
|
7
7
|
export * from "./deepMerge.mjs";
|
|
8
8
|
export * from "./dynamicImport.mjs";
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
9
|
+
export * from "./result.mjs";
|
|
10
|
+
export * from "./endpointError.mjs";
|
|
11
11
|
export * from "./evaluateCondition.mjs";
|
|
12
12
|
export * from "./formatValue.mjs";
|
|
13
13
|
export * from "./freshItem.mjs";
|
|
@@ -15,6 +15,7 @@ export * from "./getMissingProperties.mjs";
|
|
|
15
15
|
export * from "./getReferenceProperty.mjs";
|
|
16
16
|
export * from "./getValueFromPath.mjs";
|
|
17
17
|
export * from "./http.mjs";
|
|
18
|
+
export * from "./isEmptyObject.mjs";
|
|
18
19
|
export * from "./isGranted.mjs";
|
|
19
20
|
export * from "./isObjectId.mjs";
|
|
20
21
|
export * from "./isReference.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isEmptyObject: (object: any) => any;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEmptyObject = void 0;
|
|
4
|
+
const isEmptyObject = (object) => {
|
|
5
|
+
return object && Object.keys(object).length === 0 && object.constructor === Object;
|
|
6
|
+
};
|
|
7
|
+
exports.isEmptyObject = isEmptyObject;
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Result as R } from '@aeriajs/types/result';
|
|
2
|
+
export declare namespace Result {
|
|
3
|
+
type Error<T> = R.Error<T>;
|
|
4
|
+
type Result<T> = R.Result<T>;
|
|
5
|
+
type Either<Error, Result> = R.Either<Error, Result>;
|
|
6
|
+
const error: <const TValue>(value: TValue) => {
|
|
7
|
+
readonly _tag: "Error";
|
|
8
|
+
readonly error: TValue;
|
|
9
|
+
readonly result: undefined;
|
|
10
|
+
};
|
|
11
|
+
const result: <const TValue>(value: TValue) => {
|
|
12
|
+
readonly _tag: "Result";
|
|
13
|
+
readonly error: undefined;
|
|
14
|
+
readonly result: TValue;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare const throwIfError: <TValue>(either: R.Either<unknown, TValue>, message?: any) => NonNullable<TValue>;
|
package/dist/result.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwIfError = exports.Result = void 0;
|
|
4
|
+
var Result;
|
|
5
|
+
(function (Result) {
|
|
6
|
+
Result.error = (value) => ({
|
|
7
|
+
_tag: 'Error',
|
|
8
|
+
error: value,
|
|
9
|
+
result: undefined,
|
|
10
|
+
});
|
|
11
|
+
Result.result = (value) => ({
|
|
12
|
+
_tag: 'Result',
|
|
13
|
+
error: undefined,
|
|
14
|
+
result: value,
|
|
15
|
+
});
|
|
16
|
+
})(Result || (exports.Result = Result = {}));
|
|
17
|
+
const throwIfError = (either, message) => {
|
|
18
|
+
if (!either.result) {
|
|
19
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
20
|
+
console.trace(JSON.stringify(either.error, null, 2));
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`throwIfError threw: ${either.error} ${message
|
|
23
|
+
? `(${message})`
|
|
24
|
+
: ''}`);
|
|
25
|
+
}
|
|
26
|
+
return either.result;
|
|
27
|
+
};
|
|
28
|
+
exports.throwIfError = throwIfError;
|
package/dist/result.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export var Result;
|
|
3
|
+
((Result2) => {
|
|
4
|
+
Result2.error = (value) => ({
|
|
5
|
+
_tag: "Error",
|
|
6
|
+
error: value,
|
|
7
|
+
result: void 0
|
|
8
|
+
});
|
|
9
|
+
Result2.result = (value) => ({
|
|
10
|
+
_tag: "Result",
|
|
11
|
+
error: void 0,
|
|
12
|
+
result: value
|
|
13
|
+
});
|
|
14
|
+
})(Result || (Result = {}));
|
|
15
|
+
export const throwIfError = (either, message) => {
|
|
16
|
+
if (!either.result) {
|
|
17
|
+
if (true) {
|
|
18
|
+
console.trace(JSON.stringify(either.error, null, 2));
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`throwIfError threw: ${either.error} ${message ? `(${message})` : ""}`);
|
|
21
|
+
}
|
|
22
|
+
return either.result;
|
|
23
|
+
};
|
package/dist/schema.d.ts
CHANGED
|
@@ -18,60 +18,44 @@ export declare const rightSchema: <const TObject extends Property>(object: TObje
|
|
|
18
18
|
readonly value: Property;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
export declare const
|
|
21
|
+
export declare const endpointErrorSchema: <const THTTPStatus extends HTTPStatus[], const TCode extends string[]>(error: {
|
|
22
22
|
httpStatus: THTTPStatus;
|
|
23
23
|
code: TCode;
|
|
24
24
|
}) => {
|
|
25
25
|
readonly type: "object";
|
|
26
|
+
readonly required: readonly ["httpStatus", "code"];
|
|
26
27
|
readonly properties: {
|
|
27
|
-
readonly
|
|
28
|
-
readonly
|
|
28
|
+
readonly httpStatus: {
|
|
29
|
+
readonly enum: THTTPStatus;
|
|
30
|
+
};
|
|
31
|
+
readonly code: {
|
|
32
|
+
readonly enum: TCode;
|
|
33
|
+
};
|
|
34
|
+
readonly message: {
|
|
35
|
+
readonly type: "string";
|
|
29
36
|
};
|
|
30
|
-
readonly
|
|
37
|
+
readonly details: {
|
|
31
38
|
readonly type: "object";
|
|
32
|
-
readonly
|
|
33
|
-
readonly properties: {
|
|
34
|
-
readonly httpStatus: {
|
|
35
|
-
readonly enum: THTTPStatus;
|
|
36
|
-
};
|
|
37
|
-
readonly code: {
|
|
38
|
-
readonly enum: TCode;
|
|
39
|
-
};
|
|
40
|
-
readonly message: {
|
|
41
|
-
readonly type: "string";
|
|
42
|
-
};
|
|
43
|
-
readonly details: {
|
|
44
|
-
readonly type: "object";
|
|
45
|
-
readonly variable: true;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
39
|
+
readonly variable: true;
|
|
48
40
|
};
|
|
49
41
|
};
|
|
50
42
|
};
|
|
51
|
-
export declare const
|
|
43
|
+
export declare const genericEndpointErrorSchema: () => {
|
|
52
44
|
readonly type: "object";
|
|
45
|
+
readonly required: readonly ["httpStatus", "code"];
|
|
53
46
|
readonly properties: {
|
|
54
|
-
readonly
|
|
55
|
-
readonly
|
|
47
|
+
readonly httpStatus: {
|
|
48
|
+
readonly type: "number";
|
|
49
|
+
};
|
|
50
|
+
readonly code: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
};
|
|
53
|
+
readonly message: {
|
|
54
|
+
readonly type: "string";
|
|
56
55
|
};
|
|
57
|
-
readonly
|
|
56
|
+
readonly details: {
|
|
58
57
|
readonly type: "object";
|
|
59
|
-
readonly
|
|
60
|
-
readonly properties: {
|
|
61
|
-
readonly httpStatus: {
|
|
62
|
-
readonly type: "number";
|
|
63
|
-
};
|
|
64
|
-
readonly code: {
|
|
65
|
-
readonly type: "string";
|
|
66
|
-
};
|
|
67
|
-
readonly message: {
|
|
68
|
-
readonly type: "string";
|
|
69
|
-
};
|
|
70
|
-
readonly details: {
|
|
71
|
-
readonly type: "object";
|
|
72
|
-
readonly variable: true;
|
|
73
|
-
};
|
|
74
|
-
};
|
|
58
|
+
readonly variable: true;
|
|
75
59
|
};
|
|
76
60
|
};
|
|
77
61
|
};
|
package/dist/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.genericEndpointErrorSchema = exports.endpointErrorSchema = exports.rightSchema = exports.leftSchema = exports.fromLiteral = void 0;
|
|
4
4
|
const mapValueToProperty = (value) => {
|
|
5
5
|
if (value.constructor === Object) {
|
|
6
6
|
return Object.assign({
|
|
@@ -72,69 +72,53 @@ const rightSchema = (object) => {
|
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
74
|
exports.rightSchema = rightSchema;
|
|
75
|
-
const
|
|
75
|
+
const endpointErrorSchema = (error) => {
|
|
76
76
|
return {
|
|
77
77
|
type: 'object',
|
|
78
|
+
required: [
|
|
79
|
+
'httpStatus',
|
|
80
|
+
'code',
|
|
81
|
+
],
|
|
78
82
|
properties: {
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
httpStatus: {
|
|
84
|
+
enum: error.httpStatus,
|
|
85
|
+
},
|
|
86
|
+
code: {
|
|
87
|
+
enum: error.code,
|
|
88
|
+
},
|
|
89
|
+
message: {
|
|
90
|
+
type: 'string',
|
|
81
91
|
},
|
|
82
|
-
|
|
92
|
+
details: {
|
|
83
93
|
type: 'object',
|
|
84
|
-
|
|
85
|
-
'httpStatus',
|
|
86
|
-
'code',
|
|
87
|
-
],
|
|
88
|
-
properties: {
|
|
89
|
-
httpStatus: {
|
|
90
|
-
enum: error.httpStatus,
|
|
91
|
-
},
|
|
92
|
-
code: {
|
|
93
|
-
enum: error.code,
|
|
94
|
-
},
|
|
95
|
-
message: {
|
|
96
|
-
type: 'string',
|
|
97
|
-
},
|
|
98
|
-
details: {
|
|
99
|
-
type: 'object',
|
|
100
|
-
variable: true,
|
|
101
|
-
},
|
|
102
|
-
},
|
|
94
|
+
variable: true,
|
|
103
95
|
},
|
|
104
96
|
},
|
|
105
97
|
};
|
|
106
98
|
};
|
|
107
|
-
exports.
|
|
108
|
-
const
|
|
99
|
+
exports.endpointErrorSchema = endpointErrorSchema;
|
|
100
|
+
const genericEndpointErrorSchema = () => {
|
|
109
101
|
return {
|
|
110
102
|
type: 'object',
|
|
103
|
+
required: [
|
|
104
|
+
'httpStatus',
|
|
105
|
+
'code',
|
|
106
|
+
],
|
|
111
107
|
properties: {
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
httpStatus: {
|
|
109
|
+
type: 'number',
|
|
110
|
+
},
|
|
111
|
+
code: {
|
|
112
|
+
type: 'string',
|
|
113
|
+
},
|
|
114
|
+
message: {
|
|
115
|
+
type: 'string',
|
|
114
116
|
},
|
|
115
|
-
|
|
117
|
+
details: {
|
|
116
118
|
type: 'object',
|
|
117
|
-
|
|
118
|
-
'httpStatus',
|
|
119
|
-
'code',
|
|
120
|
-
],
|
|
121
|
-
properties: {
|
|
122
|
-
httpStatus: {
|
|
123
|
-
type: 'number',
|
|
124
|
-
},
|
|
125
|
-
code: {
|
|
126
|
-
type: 'string',
|
|
127
|
-
},
|
|
128
|
-
message: {
|
|
129
|
-
type: 'string',
|
|
130
|
-
},
|
|
131
|
-
details: {
|
|
132
|
-
type: 'object',
|
|
133
|
-
variable: true,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
119
|
+
variable: true,
|
|
136
120
|
},
|
|
137
121
|
},
|
|
138
122
|
};
|
|
139
123
|
};
|
|
140
|
-
exports.
|
|
124
|
+
exports.genericEndpointErrorSchema = genericEndpointErrorSchema;
|
package/dist/schema.mjs
CHANGED
|
@@ -67,66 +67,50 @@ export const rightSchema = (object) => {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
|
-
export const
|
|
70
|
+
export const endpointErrorSchema = (error) => {
|
|
71
71
|
return {
|
|
72
72
|
type: "object",
|
|
73
|
+
required: [
|
|
74
|
+
"httpStatus",
|
|
75
|
+
"code"
|
|
76
|
+
],
|
|
73
77
|
properties: {
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
httpStatus: {
|
|
79
|
+
enum: error.httpStatus
|
|
80
|
+
},
|
|
81
|
+
code: {
|
|
82
|
+
enum: error.code
|
|
83
|
+
},
|
|
84
|
+
message: {
|
|
85
|
+
type: "string"
|
|
76
86
|
},
|
|
77
|
-
|
|
87
|
+
details: {
|
|
78
88
|
type: "object",
|
|
79
|
-
|
|
80
|
-
"httpStatus",
|
|
81
|
-
"code"
|
|
82
|
-
],
|
|
83
|
-
properties: {
|
|
84
|
-
httpStatus: {
|
|
85
|
-
enum: error.httpStatus
|
|
86
|
-
},
|
|
87
|
-
code: {
|
|
88
|
-
enum: error.code
|
|
89
|
-
},
|
|
90
|
-
message: {
|
|
91
|
-
type: "string"
|
|
92
|
-
},
|
|
93
|
-
details: {
|
|
94
|
-
type: "object",
|
|
95
|
-
variable: true
|
|
96
|
-
}
|
|
97
|
-
}
|
|
89
|
+
variable: true
|
|
98
90
|
}
|
|
99
91
|
}
|
|
100
92
|
};
|
|
101
93
|
};
|
|
102
|
-
export const
|
|
94
|
+
export const genericEndpointErrorSchema = () => {
|
|
103
95
|
return {
|
|
104
96
|
type: "object",
|
|
97
|
+
required: [
|
|
98
|
+
"httpStatus",
|
|
99
|
+
"code"
|
|
100
|
+
],
|
|
105
101
|
properties: {
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
httpStatus: {
|
|
103
|
+
type: "number"
|
|
104
|
+
},
|
|
105
|
+
code: {
|
|
106
|
+
type: "string"
|
|
107
|
+
},
|
|
108
|
+
message: {
|
|
109
|
+
type: "string"
|
|
108
110
|
},
|
|
109
|
-
|
|
111
|
+
details: {
|
|
110
112
|
type: "object",
|
|
111
|
-
|
|
112
|
-
"httpStatus",
|
|
113
|
-
"code"
|
|
114
|
-
],
|
|
115
|
-
properties: {
|
|
116
|
-
httpStatus: {
|
|
117
|
-
type: "number"
|
|
118
|
-
},
|
|
119
|
-
code: {
|
|
120
|
-
type: "string"
|
|
121
|
-
},
|
|
122
|
-
message: {
|
|
123
|
-
type: "string"
|
|
124
|
-
},
|
|
125
|
-
details: {
|
|
126
|
-
type: "object",
|
|
127
|
-
variable: true
|
|
128
|
-
}
|
|
129
|
-
}
|
|
113
|
+
variable: true
|
|
130
114
|
}
|
|
131
115
|
}
|
|
132
116
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
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.56",
|
|
35
35
|
"bson": "^6.5.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
package/dist/either.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Either, Left, Right } from '@aeriajs/types';
|
|
2
|
-
export declare const left: <const TValue>(value: TValue) => Left<TValue>;
|
|
3
|
-
export declare const right: <const TValue>(value: TValue) => Right<TValue>;
|
|
4
|
-
export declare const isLeft: <TValue>(either: Either<TValue, any>) => either is Left<TValue>;
|
|
5
|
-
export declare const isRight: <TValue>(either: Either<any, TValue>) => either is Right<TValue>;
|
|
6
|
-
export declare const unwrapEither: <L, R>(either: Either<L, R>) => L | R;
|
|
7
|
-
export declare const throwIfLeft: <L, R>(either: Either<L, R>, message?: any) => R;
|
package/dist/either.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwIfLeft = exports.unwrapEither = exports.isRight = exports.isLeft = exports.right = exports.left = void 0;
|
|
4
|
-
const left = (value) => ({
|
|
5
|
-
_tag: 'Left',
|
|
6
|
-
value,
|
|
7
|
-
});
|
|
8
|
-
exports.left = left;
|
|
9
|
-
const right = (value) => ({
|
|
10
|
-
_tag: 'Right',
|
|
11
|
-
value,
|
|
12
|
-
});
|
|
13
|
-
exports.right = right;
|
|
14
|
-
const isLeft = (either) => {
|
|
15
|
-
return either._tag === 'Left';
|
|
16
|
-
};
|
|
17
|
-
exports.isLeft = isLeft;
|
|
18
|
-
const isRight = (either) => {
|
|
19
|
-
return either._tag === 'Right';
|
|
20
|
-
};
|
|
21
|
-
exports.isRight = isRight;
|
|
22
|
-
const unwrapEither = (either) => {
|
|
23
|
-
return either.value;
|
|
24
|
-
};
|
|
25
|
-
exports.unwrapEither = unwrapEither;
|
|
26
|
-
const throwIfLeft = (either, message) => {
|
|
27
|
-
if (either._tag !== 'Right') {
|
|
28
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
29
|
-
console.trace(JSON.stringify(either.value, null, 2));
|
|
30
|
-
}
|
|
31
|
-
throw new Error(`throwIfLeft threw: ${either.value} (${message || '-'})`);
|
|
32
|
-
}
|
|
33
|
-
return either.value;
|
|
34
|
-
};
|
|
35
|
-
exports.throwIfLeft = throwIfLeft;
|
package/dist/either.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const left = (value) => ({
|
|
3
|
-
_tag: "Left",
|
|
4
|
-
value
|
|
5
|
-
});
|
|
6
|
-
export const right = (value) => ({
|
|
7
|
-
_tag: "Right",
|
|
8
|
-
value
|
|
9
|
-
});
|
|
10
|
-
export const isLeft = (either) => {
|
|
11
|
-
return either._tag === "Left";
|
|
12
|
-
};
|
|
13
|
-
export const isRight = (either) => {
|
|
14
|
-
return either._tag === "Right";
|
|
15
|
-
};
|
|
16
|
-
export const unwrapEither = (either) => {
|
|
17
|
-
return either.value;
|
|
18
|
-
};
|
|
19
|
-
export const throwIfLeft = (either, message) => {
|
|
20
|
-
if (either._tag !== "Right") {
|
|
21
|
-
if (true) {
|
|
22
|
-
console.trace(JSON.stringify(either.value, null, 2));
|
|
23
|
-
}
|
|
24
|
-
throw new Error(`throwIfLeft threw: ${either.value} (${message || "-"})`);
|
|
25
|
-
}
|
|
26
|
-
return either.value;
|
|
27
|
-
};
|
package/dist/error.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { EndpointError, EndpointErrorContent } from '@aeriajs/types';
|
|
2
|
-
export declare const error: <const TEndpointErrorContent extends EndpointErrorContent>(value: TEndpointErrorContent) => EndpointError & {
|
|
3
|
-
value: TEndpointErrorContent;
|
|
4
|
-
};
|
|
5
|
-
export declare const isError: (object: EndpointError | any) => object is EndpointError<any>;
|
|
6
|
-
export declare const unwrapError: <TEndpointErrorContent extends EndpointErrorContent>(error: EndpointError<TEndpointErrorContent>) => TEndpointErrorContent;
|
|
7
|
-
export declare const throwIfError: <TValue>(value: TValue, message?: any) => Exclude<TValue, EndpointError<any>>;
|
package/dist/error.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwIfError = exports.unwrapError = exports.isError = exports.error = void 0;
|
|
4
|
-
const types_1 = require("@aeriajs/types");
|
|
5
|
-
const error = (value) => {
|
|
6
|
-
const wrappedError = {
|
|
7
|
-
[types_1.ERROR_SYMBOL]: true,
|
|
8
|
-
_tag: 'Error',
|
|
9
|
-
value,
|
|
10
|
-
};
|
|
11
|
-
return wrappedError;
|
|
12
|
-
};
|
|
13
|
-
exports.error = error;
|
|
14
|
-
const isError = (object) => {
|
|
15
|
-
return object
|
|
16
|
-
&& typeof object === 'object'
|
|
17
|
-
&& (types_1.ERROR_SYMBOL in object || types_1.ERROR_SYMBOL_DESCRIPTION in object);
|
|
18
|
-
};
|
|
19
|
-
exports.isError = isError;
|
|
20
|
-
const unwrapError = (error) => {
|
|
21
|
-
return error.value;
|
|
22
|
-
};
|
|
23
|
-
exports.unwrapError = unwrapError;
|
|
24
|
-
const throwIfError = (value, message) => {
|
|
25
|
-
if ((0, exports.isError)(value)) {
|
|
26
|
-
const error = (0, exports.unwrapError)(value);
|
|
27
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
28
|
-
console.trace(JSON.stringify(error, null, 2));
|
|
29
|
-
}
|
|
30
|
-
throw new Error(`throwIfLeft threw: ${error.code} (${message || '-'})`);
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
};
|
|
34
|
-
exports.throwIfError = throwIfError;
|
package/dist/error.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { ERROR_SYMBOL, ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
|
|
3
|
-
export const error = (value) => {
|
|
4
|
-
const wrappedError = {
|
|
5
|
-
[ERROR_SYMBOL]: true,
|
|
6
|
-
_tag: "Error",
|
|
7
|
-
value
|
|
8
|
-
};
|
|
9
|
-
return wrappedError;
|
|
10
|
-
};
|
|
11
|
-
export const isError = (object) => {
|
|
12
|
-
return object && typeof object === "object" && (ERROR_SYMBOL in object || ERROR_SYMBOL_DESCRIPTION in object);
|
|
13
|
-
};
|
|
14
|
-
export const unwrapError = (error2) => {
|
|
15
|
-
return error2.value;
|
|
16
|
-
};
|
|
17
|
-
export const throwIfError = (value, message) => {
|
|
18
|
-
if (isError(value)) {
|
|
19
|
-
const error2 = unwrapError(value);
|
|
20
|
-
if (true) {
|
|
21
|
-
console.trace(JSON.stringify(error2, null, 2));
|
|
22
|
-
}
|
|
23
|
-
throw new Error(`throwIfLeft threw: ${error2.code} (${message || "-"})`);
|
|
24
|
-
}
|
|
25
|
-
return value;
|
|
26
|
-
};
|