@aeriajs/common 0.0.54 → 0.0.56
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/either.d.ts +5 -5
- package/dist/either.js +4 -4
- package/dist/either.mjs +2 -2
- package/dist/error.d.ts +6 -5
- package/dist/error.js +25 -9
- package/dist/error.mjs +20 -8
- package/dist/pipe.d.ts +2 -2
- package/dist/pipe.js +1 -1
- package/dist/pipe.mjs +1 -1
- package/dist/schema.d.ts +25 -20
- package/dist/schema.js +23 -20
- package/dist/schema.mjs +23 -20
- package/package.json +2 -2
package/dist/either.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Either, Left, Right } from '@aeriajs/types';
|
|
2
|
-
export declare const left: <const
|
|
3
|
-
export declare const right: <const
|
|
4
|
-
export declare const isLeft: <
|
|
5
|
-
export declare const isRight: <
|
|
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
6
|
export declare const unwrapEither: <L, R>(either: Either<L, R>) => L | R;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const throwIfLeft: <L, R>(either: Either<L, R>, message?: any) => R;
|
package/dist/either.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.throwIfLeft = exports.unwrapEither = exports.isRight = exports.isLeft = exports.right = exports.left = void 0;
|
|
4
4
|
const left = (value) => ({
|
|
5
5
|
_tag: 'Left',
|
|
6
6
|
value,
|
|
@@ -23,13 +23,13 @@ const unwrapEither = (either) => {
|
|
|
23
23
|
return either.value;
|
|
24
24
|
};
|
|
25
25
|
exports.unwrapEither = unwrapEither;
|
|
26
|
-
const
|
|
26
|
+
const throwIfLeft = (either, message) => {
|
|
27
27
|
if (either._tag !== 'Right') {
|
|
28
28
|
if (process.env.NODE_ENV !== 'production') {
|
|
29
29
|
console.trace(JSON.stringify(either.value, null, 2));
|
|
30
30
|
}
|
|
31
|
-
throw new Error(`
|
|
31
|
+
throw new Error(`throwIfLeft threw: ${either.value} (${message || '-'})`);
|
|
32
32
|
}
|
|
33
33
|
return either.value;
|
|
34
34
|
};
|
|
35
|
-
exports.
|
|
35
|
+
exports.throwIfLeft = throwIfLeft;
|
package/dist/either.mjs
CHANGED
|
@@ -16,12 +16,12 @@ export const isRight = (either) => {
|
|
|
16
16
|
export const unwrapEither = (either) => {
|
|
17
17
|
return either.value;
|
|
18
18
|
};
|
|
19
|
-
export const
|
|
19
|
+
export const throwIfLeft = (either, message) => {
|
|
20
20
|
if (either._tag !== "Right") {
|
|
21
21
|
if (true) {
|
|
22
22
|
console.trace(JSON.stringify(either.value, null, 2));
|
|
23
23
|
}
|
|
24
|
-
throw new Error(`
|
|
24
|
+
throw new Error(`throwIfLeft threw: ${either.value} (${message || "-"})`);
|
|
25
25
|
}
|
|
26
26
|
return either.value;
|
|
27
27
|
};
|
package/dist/error.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { EndpointError, EndpointErrorContent
|
|
2
|
-
export declare const error: <TEndpointErrorContent extends EndpointErrorContent>(
|
|
3
|
-
|
|
4
|
-
readonly error: TEndpointErrorContent;
|
|
1
|
+
import type { EndpointError, EndpointErrorContent } from '@aeriajs/types';
|
|
2
|
+
export declare const error: <const TEndpointErrorContent extends EndpointErrorContent>(value: TEndpointErrorContent) => EndpointError & {
|
|
3
|
+
value: TEndpointErrorContent;
|
|
5
4
|
};
|
|
6
|
-
export declare const isError: (object: any) => object is EndpointError<
|
|
5
|
+
export declare const isError: <TEndpointErrorContent extends EndpointErrorContent>(object: EndpointError<TEndpointErrorContent> | any) => object is EndpointError<TEndpointErrorContent>;
|
|
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
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isError = exports.error = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
return {
|
|
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,
|
|
10
8
|
_tag: 'Error',
|
|
11
|
-
|
|
9
|
+
value,
|
|
12
10
|
};
|
|
11
|
+
return wrappedError;
|
|
13
12
|
};
|
|
14
13
|
exports.error = error;
|
|
15
14
|
const isError = (object) => {
|
|
16
|
-
return object
|
|
15
|
+
return object
|
|
16
|
+
&& typeof object === 'object'
|
|
17
|
+
&& (types_1.ERROR_SYMBOL in object || types_1.ERROR_SYMBOL_DESCRIPTION in object);
|
|
17
18
|
};
|
|
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
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
return {
|
|
2
|
+
import { ERROR_SYMBOL, ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
|
|
3
|
+
export const error = (value) => {
|
|
4
|
+
const wrappedError = {
|
|
5
|
+
[ERROR_SYMBOL]: true,
|
|
8
6
|
_tag: "Error",
|
|
9
|
-
|
|
7
|
+
value
|
|
10
8
|
};
|
|
9
|
+
return wrappedError;
|
|
11
10
|
};
|
|
12
11
|
export const isError = (object) => {
|
|
13
|
-
return 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;
|
|
14
26
|
};
|
package/dist/pipe.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type PipeOptions = {
|
|
2
|
-
returnFirst?: boolean | ((value: any) =>
|
|
2
|
+
returnFirst?: boolean | ((value: any) => any);
|
|
3
3
|
};
|
|
4
|
-
export declare const pipe: <TFunction extends (...args: any) => any>(functions: TFunction[], options?: PipeOptions) => (value: Parameters<TFunction>[0], ...args: Parameters<TFunction> extends [unknown, ...infer Tail] ? Tail : []) => Promise<
|
|
4
|
+
export declare const pipe: <TFunction extends (...args: any) => any>(functions: TFunction[], options?: PipeOptions) => (value: Parameters<TFunction>[0], ...args: Parameters<TFunction> extends [unknown, ...infer Tail] ? Tail : []) => Promise<any>;
|
package/dist/pipe.js
CHANGED
package/dist/pipe.mjs
CHANGED
package/dist/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Property, ObjectToSchema,
|
|
1
|
+
import type { Property, ObjectToSchema, HTTPStatus } from '@aeriajs/types';
|
|
2
2
|
export declare const fromLiteral: <const TObject, TRequired extends (keyof TObject & string)[]>(object: TObject, required?: TRequired) => ObjectToSchema<TObject, TRequired>;
|
|
3
3
|
export declare const leftSchema: <const TObject extends Property>(object: TObject) => {
|
|
4
4
|
readonly type: "object";
|
|
@@ -18,28 +18,33 @@ export declare const rightSchema: <const TObject extends Property>(object: TObje
|
|
|
18
18
|
readonly value: Property;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
export declare const endpointErrorSchema: (error:
|
|
21
|
+
export declare const endpointErrorSchema: <const THTTPStatus extends HTTPStatus[], const TCode extends string[]>(error: {
|
|
22
|
+
httpStatus: THTTPStatus;
|
|
23
|
+
code: TCode;
|
|
24
|
+
}) => {
|
|
22
25
|
readonly type: "object";
|
|
23
26
|
readonly properties: {
|
|
24
|
-
readonly
|
|
25
|
-
readonly const:
|
|
26
|
-
};
|
|
27
|
-
readonly code: {
|
|
28
|
-
readonly const: string;
|
|
29
|
-
};
|
|
30
|
-
readonly message: {
|
|
31
|
-
readonly const: string;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
} | {
|
|
35
|
-
readonly type: "object";
|
|
36
|
-
readonly properties: {
|
|
37
|
-
readonly httpCode: {
|
|
38
|
-
readonly const: string;
|
|
27
|
+
readonly _tag: {
|
|
28
|
+
readonly const: "Error";
|
|
39
29
|
};
|
|
40
|
-
readonly
|
|
41
|
-
readonly
|
|
30
|
+
readonly value: {
|
|
31
|
+
readonly type: "object";
|
|
32
|
+
readonly required: readonly ["httpStatus", "code"];
|
|
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
|
+
};
|
|
42
48
|
};
|
|
43
|
-
readonly message?: undefined;
|
|
44
49
|
};
|
|
45
50
|
};
|
package/dist/schema.js
CHANGED
|
@@ -73,30 +73,33 @@ const rightSchema = (object) => {
|
|
|
73
73
|
};
|
|
74
74
|
exports.rightSchema = rightSchema;
|
|
75
75
|
const endpointErrorSchema = (error) => {
|
|
76
|
-
if (error.message) {
|
|
77
|
-
return {
|
|
78
|
-
type: 'object',
|
|
79
|
-
properties: {
|
|
80
|
-
httpCode: {
|
|
81
|
-
const: error.code,
|
|
82
|
-
},
|
|
83
|
-
code: {
|
|
84
|
-
const: error.code,
|
|
85
|
-
},
|
|
86
|
-
message: {
|
|
87
|
-
const: error.message,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
76
|
return {
|
|
93
77
|
type: 'object',
|
|
94
78
|
properties: {
|
|
95
|
-
|
|
96
|
-
const:
|
|
79
|
+
_tag: {
|
|
80
|
+
const: 'Error',
|
|
97
81
|
},
|
|
98
|
-
|
|
99
|
-
|
|
82
|
+
value: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
required: [
|
|
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
|
+
},
|
|
100
103
|
},
|
|
101
104
|
},
|
|
102
105
|
};
|
package/dist/schema.mjs
CHANGED
|
@@ -68,30 +68,33 @@ export const rightSchema = (object) => {
|
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
70
|
export const endpointErrorSchema = (error) => {
|
|
71
|
-
if (error.message) {
|
|
72
|
-
return {
|
|
73
|
-
type: "object",
|
|
74
|
-
properties: {
|
|
75
|
-
httpCode: {
|
|
76
|
-
const: error.code
|
|
77
|
-
},
|
|
78
|
-
code: {
|
|
79
|
-
const: error.code
|
|
80
|
-
},
|
|
81
|
-
message: {
|
|
82
|
-
const: error.message
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
71
|
return {
|
|
88
72
|
type: "object",
|
|
89
73
|
properties: {
|
|
90
|
-
|
|
91
|
-
const:
|
|
74
|
+
_tag: {
|
|
75
|
+
const: "Error"
|
|
92
76
|
},
|
|
93
|
-
|
|
94
|
-
|
|
77
|
+
value: {
|
|
78
|
+
type: "object",
|
|
79
|
+
required: [
|
|
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
|
+
}
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.56",
|
|
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.53",
|
|
35
35
|
"bson": "^6.5.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|