@devp0nt/error0 1.0.0-next.18 → 1.0.0-next.3
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/cjs/index.d.cts +198 -194
- package/dist/cjs/index.js +19 -32
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +198 -194
- package/dist/esm/index.js +17 -31
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -3
- package/src/index.test.ts +6 -14
- package/src/index.ts +117 -139
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,80 +1,110 @@
|
|
|
1
1
|
import * as undici_types from 'undici-types';
|
|
2
2
|
import { Meta0 } from '@devp0nt/meta0';
|
|
3
|
-
import {
|
|
3
|
+
import { HttpStatusCode, AxiosError } from 'axios';
|
|
4
4
|
import { ZodError } from 'zod';
|
|
5
5
|
|
|
6
|
+
interface Error0Input {
|
|
7
|
+
message?: string;
|
|
8
|
+
tag?: string;
|
|
9
|
+
code?: string;
|
|
10
|
+
httpStatus?: HttpStatusCode | HttpStatusCodeString;
|
|
11
|
+
expected?: boolean | ExpectedFn;
|
|
12
|
+
clientMessage?: string;
|
|
13
|
+
cause?: Error0Cause;
|
|
14
|
+
stack?: string;
|
|
15
|
+
meta?: Meta0.Meta0OrValueTypeNullish;
|
|
16
|
+
zodError?: ZodError;
|
|
17
|
+
axiosError?: AxiosError;
|
|
18
|
+
}
|
|
19
|
+
interface Error0GeneralProps {
|
|
20
|
+
message: Error0Input['message'];
|
|
21
|
+
tag: Error0Input['tag'];
|
|
22
|
+
code: Error0Input['code'];
|
|
23
|
+
httpStatus: number | undefined;
|
|
24
|
+
expected: boolean | undefined;
|
|
25
|
+
clientMessage: Error0Input['clientMessage'];
|
|
26
|
+
anyMessage: string | undefined;
|
|
27
|
+
cause: Error0Input['cause'];
|
|
28
|
+
stack: Error['stack'];
|
|
29
|
+
meta: Meta0.ValueType;
|
|
30
|
+
zodError?: ZodError;
|
|
31
|
+
axiosError?: AxiosError;
|
|
32
|
+
}
|
|
33
|
+
type HttpStatusCodeString = keyof typeof HttpStatusCode;
|
|
34
|
+
type Error0Cause = Error | Error0 | unknown;
|
|
35
|
+
type ExpectedFn = (error: Error0GeneralProps) => boolean | undefined;
|
|
6
36
|
declare class Error0 extends Error {
|
|
7
37
|
readonly __I_AM_ERROR_0: true;
|
|
8
|
-
readonly tag?:
|
|
9
|
-
readonly code?:
|
|
10
|
-
readonly httpStatus?:
|
|
11
|
-
readonly expected?:
|
|
12
|
-
readonly clientMessage?:
|
|
13
|
-
readonly anyMessage?:
|
|
14
|
-
readonly cause?:
|
|
15
|
-
readonly meta?: Meta0.
|
|
16
|
-
readonly zodError?:
|
|
17
|
-
readonly axiosError?:
|
|
38
|
+
readonly tag?: Error0GeneralProps['tag'];
|
|
39
|
+
readonly code?: Error0GeneralProps['code'];
|
|
40
|
+
readonly httpStatus?: Error0GeneralProps['httpStatus'];
|
|
41
|
+
readonly expected?: Error0GeneralProps['expected'];
|
|
42
|
+
readonly clientMessage?: Error0GeneralProps['clientMessage'];
|
|
43
|
+
readonly anyMessage?: Error0GeneralProps['anyMessage'];
|
|
44
|
+
readonly cause?: Error0GeneralProps['cause'];
|
|
45
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
46
|
+
readonly zodError?: Error0GeneralProps['zodError'];
|
|
47
|
+
readonly axiosError?: Error0GeneralProps['axiosError'];
|
|
18
48
|
static defaultMessage: string;
|
|
19
|
-
static defaultCode?:
|
|
20
|
-
static defaultHttpStatus?:
|
|
21
|
-
static defaultExpected?:
|
|
22
|
-
static defaultClientMessage?:
|
|
49
|
+
static defaultCode?: Error0GeneralProps['code'];
|
|
50
|
+
static defaultHttpStatus?: Error0GeneralProps['httpStatus'];
|
|
51
|
+
static defaultExpected?: Error0GeneralProps['expected'];
|
|
52
|
+
static defaultClientMessage?: Error0GeneralProps['clientMessage'];
|
|
23
53
|
static defaultMeta?: Meta0.Meta0OrValueTypeNullish;
|
|
24
|
-
readonly propsOriginal:
|
|
54
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
25
55
|
constructor(message: string);
|
|
26
|
-
constructor(input:
|
|
27
|
-
constructor(message: string, input:
|
|
56
|
+
constructor(input: Error0Input);
|
|
57
|
+
constructor(message: string, input: Error0Input);
|
|
28
58
|
constructor(error: Error);
|
|
29
|
-
constructor(error: Error, input:
|
|
59
|
+
constructor(error: Error, input: Error0Input);
|
|
30
60
|
constructor(value: unknown);
|
|
31
|
-
constructor(value: unknown, input:
|
|
61
|
+
constructor(value: unknown, input: Error0Input);
|
|
32
62
|
static defaultMaxLevel: number;
|
|
33
|
-
static _safeParseInput(error0Input: Record<string, unknown>):
|
|
63
|
+
static _safeParseInput(error0Input: Record<string, unknown>): Error0Input;
|
|
34
64
|
static _getSelfGeneralProps({ error0Input, message, stack, }: {
|
|
35
|
-
error0Input:
|
|
65
|
+
error0Input: Error0Input;
|
|
36
66
|
message: string;
|
|
37
|
-
stack:
|
|
38
|
-
}):
|
|
39
|
-
static _getSelfPropsFloated(causesProps:
|
|
40
|
-
static _getExtraError0PropsByZodError(zodError: ZodError): Partial<
|
|
41
|
-
static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<
|
|
42
|
-
static _assignError0Props(error0Props:
|
|
43
|
-
static _normalizeSelfExpected(error0Props:
|
|
44
|
-
static _isExpected(causesProps:
|
|
45
|
-
static _getPropsFromUnknown(error: unknown, defaults?:
|
|
46
|
-
static _getCausesPropsFromUnknown(error: unknown, maxLevel: number):
|
|
47
|
-
static _getCausesPropsFromError0Props(error0Props:
|
|
48
|
-
static _getClosestPropValue<TPropKey extends keyof
|
|
49
|
-
static _getFilledPropValues<TPropKey extends keyof
|
|
50
|
-
static _getMergedMetaValue(causesProps:
|
|
51
|
-
static _removeConstructorStackPart(stack:
|
|
52
|
-
static _mergeStack(prevStack:
|
|
67
|
+
stack: Error0GeneralProps['stack'];
|
|
68
|
+
}): Error0GeneralProps;
|
|
69
|
+
static _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps;
|
|
70
|
+
static _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps>;
|
|
71
|
+
static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps>;
|
|
72
|
+
static _assignError0Props(error0Props: Error0GeneralProps, extraError0Props: Partial<Error0GeneralProps>): void;
|
|
73
|
+
static _normalizeSelfExpected(error0Props: Error0GeneralProps, expectedProvided: Error0Input['expected']): boolean | undefined;
|
|
74
|
+
static _isExpected(causesProps: Error0GeneralProps[]): boolean;
|
|
75
|
+
static _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps;
|
|
76
|
+
static _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[];
|
|
77
|
+
static _getCausesPropsFromError0Props(error0Props: Error0GeneralProps, maxLevel: number): Error0GeneralProps[];
|
|
78
|
+
static _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]> | undefined;
|
|
79
|
+
static _getFilledPropValues<TPropKey extends keyof Error0Input>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]>[];
|
|
80
|
+
static _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType;
|
|
81
|
+
static _removeConstructorStackPart(stack: Error0GeneralProps['stack']): Error0GeneralProps['stack'];
|
|
82
|
+
static _mergeStack(prevStack: Error0GeneralProps['stack'], nextStack: Error0GeneralProps['stack']): Error0GeneralProps['stack'];
|
|
53
83
|
static isError0(error: unknown): error is Error0;
|
|
54
84
|
static isLikelyError0(error: unknown): error is Error0;
|
|
55
|
-
static _toError0(error: unknown, inputOverride?:
|
|
56
|
-
static from(error: unknown, inputOverride?:
|
|
85
|
+
static _toError0(error: unknown, inputOverride?: Error0Input): Error0;
|
|
86
|
+
static from(error: unknown, inputOverride?: Error0Input): Error0;
|
|
57
87
|
static extend(props: {
|
|
58
|
-
defaultMessage?:
|
|
59
|
-
defaultCode?:
|
|
60
|
-
defaultHttpStatus?:
|
|
61
|
-
defaultExpected?:
|
|
62
|
-
defaultClientMessage?:
|
|
88
|
+
defaultMessage?: Error0GeneralProps['message'];
|
|
89
|
+
defaultCode?: Error0GeneralProps['code'];
|
|
90
|
+
defaultHttpStatus?: Error0GeneralProps['httpStatus'];
|
|
91
|
+
defaultExpected?: Error0GeneralProps['expected'];
|
|
92
|
+
defaultClientMessage?: Error0GeneralProps['clientMessage'];
|
|
63
93
|
defaultMeta?: Meta0.Meta0OrValueTypeNullish;
|
|
64
94
|
}): {
|
|
65
95
|
new (message: string): {
|
|
66
96
|
readonly __I_AM_ERROR_0: true;
|
|
67
|
-
readonly tag?:
|
|
68
|
-
readonly code?:
|
|
69
|
-
readonly httpStatus?:
|
|
70
|
-
readonly expected?:
|
|
71
|
-
readonly clientMessage?:
|
|
72
|
-
readonly anyMessage?:
|
|
73
|
-
readonly cause?:
|
|
74
|
-
readonly meta?: Meta0.
|
|
75
|
-
readonly zodError?:
|
|
76
|
-
readonly axiosError?:
|
|
77
|
-
readonly propsOriginal:
|
|
97
|
+
readonly tag?: Error0GeneralProps["tag"];
|
|
98
|
+
readonly code?: Error0GeneralProps["code"];
|
|
99
|
+
readonly httpStatus?: Error0GeneralProps["httpStatus"];
|
|
100
|
+
readonly expected?: Error0GeneralProps["expected"];
|
|
101
|
+
readonly clientMessage?: Error0GeneralProps["clientMessage"];
|
|
102
|
+
readonly anyMessage?: Error0GeneralProps["anyMessage"];
|
|
103
|
+
readonly cause?: Error0GeneralProps["cause"];
|
|
104
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
105
|
+
readonly zodError?: Error0GeneralProps["zodError"];
|
|
106
|
+
readonly axiosError?: Error0GeneralProps["axiosError"];
|
|
107
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
78
108
|
toJSON(): {
|
|
79
109
|
message: string;
|
|
80
110
|
tag: string | undefined;
|
|
@@ -93,19 +123,19 @@ declare class Error0 extends Error {
|
|
|
93
123
|
message: string;
|
|
94
124
|
stack?: string;
|
|
95
125
|
};
|
|
96
|
-
new (input:
|
|
126
|
+
new (input: Error0Input): {
|
|
97
127
|
readonly __I_AM_ERROR_0: true;
|
|
98
|
-
readonly tag?:
|
|
99
|
-
readonly code?:
|
|
100
|
-
readonly httpStatus?:
|
|
101
|
-
readonly expected?:
|
|
102
|
-
readonly clientMessage?:
|
|
103
|
-
readonly anyMessage?:
|
|
104
|
-
readonly cause?:
|
|
105
|
-
readonly meta?: Meta0.
|
|
106
|
-
readonly zodError?:
|
|
107
|
-
readonly axiosError?:
|
|
108
|
-
readonly propsOriginal:
|
|
128
|
+
readonly tag?: Error0GeneralProps["tag"];
|
|
129
|
+
readonly code?: Error0GeneralProps["code"];
|
|
130
|
+
readonly httpStatus?: Error0GeneralProps["httpStatus"];
|
|
131
|
+
readonly expected?: Error0GeneralProps["expected"];
|
|
132
|
+
readonly clientMessage?: Error0GeneralProps["clientMessage"];
|
|
133
|
+
readonly anyMessage?: Error0GeneralProps["anyMessage"];
|
|
134
|
+
readonly cause?: Error0GeneralProps["cause"];
|
|
135
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
136
|
+
readonly zodError?: Error0GeneralProps["zodError"];
|
|
137
|
+
readonly axiosError?: Error0GeneralProps["axiosError"];
|
|
138
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
109
139
|
toJSON(): {
|
|
110
140
|
message: string;
|
|
111
141
|
tag: string | undefined;
|
|
@@ -124,19 +154,19 @@ declare class Error0 extends Error {
|
|
|
124
154
|
message: string;
|
|
125
155
|
stack?: string;
|
|
126
156
|
};
|
|
127
|
-
new (message: string, input:
|
|
157
|
+
new (message: string, input: Error0Input): {
|
|
128
158
|
readonly __I_AM_ERROR_0: true;
|
|
129
|
-
readonly tag?:
|
|
130
|
-
readonly code?:
|
|
131
|
-
readonly httpStatus?:
|
|
132
|
-
readonly expected?:
|
|
133
|
-
readonly clientMessage?:
|
|
134
|
-
readonly anyMessage?:
|
|
135
|
-
readonly cause?:
|
|
136
|
-
readonly meta?: Meta0.
|
|
137
|
-
readonly zodError?:
|
|
138
|
-
readonly axiosError?:
|
|
139
|
-
readonly propsOriginal:
|
|
159
|
+
readonly tag?: Error0GeneralProps["tag"];
|
|
160
|
+
readonly code?: Error0GeneralProps["code"];
|
|
161
|
+
readonly httpStatus?: Error0GeneralProps["httpStatus"];
|
|
162
|
+
readonly expected?: Error0GeneralProps["expected"];
|
|
163
|
+
readonly clientMessage?: Error0GeneralProps["clientMessage"];
|
|
164
|
+
readonly anyMessage?: Error0GeneralProps["anyMessage"];
|
|
165
|
+
readonly cause?: Error0GeneralProps["cause"];
|
|
166
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
167
|
+
readonly zodError?: Error0GeneralProps["zodError"];
|
|
168
|
+
readonly axiosError?: Error0GeneralProps["axiosError"];
|
|
169
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
140
170
|
toJSON(): {
|
|
141
171
|
message: string;
|
|
142
172
|
tag: string | undefined;
|
|
@@ -157,17 +187,17 @@ declare class Error0 extends Error {
|
|
|
157
187
|
};
|
|
158
188
|
new (error: Error): {
|
|
159
189
|
readonly __I_AM_ERROR_0: true;
|
|
160
|
-
readonly tag?:
|
|
161
|
-
readonly code?:
|
|
162
|
-
readonly httpStatus?:
|
|
163
|
-
readonly expected?:
|
|
164
|
-
readonly clientMessage?:
|
|
165
|
-
readonly anyMessage?:
|
|
166
|
-
readonly cause?:
|
|
167
|
-
readonly meta?: Meta0.
|
|
168
|
-
readonly zodError?:
|
|
169
|
-
readonly axiosError?:
|
|
170
|
-
readonly propsOriginal:
|
|
190
|
+
readonly tag?: Error0GeneralProps["tag"];
|
|
191
|
+
readonly code?: Error0GeneralProps["code"];
|
|
192
|
+
readonly httpStatus?: Error0GeneralProps["httpStatus"];
|
|
193
|
+
readonly expected?: Error0GeneralProps["expected"];
|
|
194
|
+
readonly clientMessage?: Error0GeneralProps["clientMessage"];
|
|
195
|
+
readonly anyMessage?: Error0GeneralProps["anyMessage"];
|
|
196
|
+
readonly cause?: Error0GeneralProps["cause"];
|
|
197
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
198
|
+
readonly zodError?: Error0GeneralProps["zodError"];
|
|
199
|
+
readonly axiosError?: Error0GeneralProps["axiosError"];
|
|
200
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
171
201
|
toJSON(): {
|
|
172
202
|
message: string;
|
|
173
203
|
tag: string | undefined;
|
|
@@ -186,19 +216,19 @@ declare class Error0 extends Error {
|
|
|
186
216
|
message: string;
|
|
187
217
|
stack?: string;
|
|
188
218
|
};
|
|
189
|
-
new (error: Error, input:
|
|
219
|
+
new (error: Error, input: Error0Input): {
|
|
190
220
|
readonly __I_AM_ERROR_0: true;
|
|
191
|
-
readonly tag?:
|
|
192
|
-
readonly code?:
|
|
193
|
-
readonly httpStatus?:
|
|
194
|
-
readonly expected?:
|
|
195
|
-
readonly clientMessage?:
|
|
196
|
-
readonly anyMessage?:
|
|
197
|
-
readonly cause?:
|
|
198
|
-
readonly meta?: Meta0.
|
|
199
|
-
readonly zodError?:
|
|
200
|
-
readonly axiosError?:
|
|
201
|
-
readonly propsOriginal:
|
|
221
|
+
readonly tag?: Error0GeneralProps["tag"];
|
|
222
|
+
readonly code?: Error0GeneralProps["code"];
|
|
223
|
+
readonly httpStatus?: Error0GeneralProps["httpStatus"];
|
|
224
|
+
readonly expected?: Error0GeneralProps["expected"];
|
|
225
|
+
readonly clientMessage?: Error0GeneralProps["clientMessage"];
|
|
226
|
+
readonly anyMessage?: Error0GeneralProps["anyMessage"];
|
|
227
|
+
readonly cause?: Error0GeneralProps["cause"];
|
|
228
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
229
|
+
readonly zodError?: Error0GeneralProps["zodError"];
|
|
230
|
+
readonly axiosError?: Error0GeneralProps["axiosError"];
|
|
231
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
202
232
|
toJSON(): {
|
|
203
233
|
message: string;
|
|
204
234
|
tag: string | undefined;
|
|
@@ -219,17 +249,17 @@ declare class Error0 extends Error {
|
|
|
219
249
|
};
|
|
220
250
|
new (value: unknown): {
|
|
221
251
|
readonly __I_AM_ERROR_0: true;
|
|
222
|
-
readonly tag?:
|
|
223
|
-
readonly code?:
|
|
224
|
-
readonly httpStatus?:
|
|
225
|
-
readonly expected?:
|
|
226
|
-
readonly clientMessage?:
|
|
227
|
-
readonly anyMessage?:
|
|
228
|
-
readonly cause?:
|
|
229
|
-
readonly meta?: Meta0.
|
|
230
|
-
readonly zodError?:
|
|
231
|
-
readonly axiosError?:
|
|
232
|
-
readonly propsOriginal:
|
|
252
|
+
readonly tag?: Error0GeneralProps["tag"];
|
|
253
|
+
readonly code?: Error0GeneralProps["code"];
|
|
254
|
+
readonly httpStatus?: Error0GeneralProps["httpStatus"];
|
|
255
|
+
readonly expected?: Error0GeneralProps["expected"];
|
|
256
|
+
readonly clientMessage?: Error0GeneralProps["clientMessage"];
|
|
257
|
+
readonly anyMessage?: Error0GeneralProps["anyMessage"];
|
|
258
|
+
readonly cause?: Error0GeneralProps["cause"];
|
|
259
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
260
|
+
readonly zodError?: Error0GeneralProps["zodError"];
|
|
261
|
+
readonly axiosError?: Error0GeneralProps["axiosError"];
|
|
262
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
233
263
|
toJSON(): {
|
|
234
264
|
message: string;
|
|
235
265
|
tag: string | undefined;
|
|
@@ -248,19 +278,19 @@ declare class Error0 extends Error {
|
|
|
248
278
|
message: string;
|
|
249
279
|
stack?: string;
|
|
250
280
|
};
|
|
251
|
-
new (value: unknown, input:
|
|
281
|
+
new (value: unknown, input: Error0Input): {
|
|
252
282
|
readonly __I_AM_ERROR_0: true;
|
|
253
|
-
readonly tag?:
|
|
254
|
-
readonly code?:
|
|
255
|
-
readonly httpStatus?:
|
|
256
|
-
readonly expected?:
|
|
257
|
-
readonly clientMessage?:
|
|
258
|
-
readonly anyMessage?:
|
|
259
|
-
readonly cause?:
|
|
260
|
-
readonly meta?: Meta0.
|
|
261
|
-
readonly zodError?:
|
|
262
|
-
readonly axiosError?:
|
|
263
|
-
readonly propsOriginal:
|
|
283
|
+
readonly tag?: Error0GeneralProps["tag"];
|
|
284
|
+
readonly code?: Error0GeneralProps["code"];
|
|
285
|
+
readonly httpStatus?: Error0GeneralProps["httpStatus"];
|
|
286
|
+
readonly expected?: Error0GeneralProps["expected"];
|
|
287
|
+
readonly clientMessage?: Error0GeneralProps["clientMessage"];
|
|
288
|
+
readonly anyMessage?: Error0GeneralProps["anyMessage"];
|
|
289
|
+
readonly cause?: Error0GeneralProps["cause"];
|
|
290
|
+
readonly meta?: Meta0.Meta0OrValueTypeNullish;
|
|
291
|
+
readonly zodError?: Error0GeneralProps["zodError"];
|
|
292
|
+
readonly axiosError?: Error0GeneralProps["axiosError"];
|
|
293
|
+
readonly propsOriginal: Error0GeneralProps;
|
|
264
294
|
toJSON(): {
|
|
265
295
|
message: string;
|
|
266
296
|
tag: string | undefined;
|
|
@@ -286,47 +316,47 @@ declare class Error0 extends Error {
|
|
|
286
316
|
defaultClientMessage: string | undefined;
|
|
287
317
|
defaultMeta: Meta0;
|
|
288
318
|
defaultMaxLevel: number;
|
|
289
|
-
_safeParseInput(error0Input: Record<string, unknown>):
|
|
319
|
+
_safeParseInput(error0Input: Record<string, unknown>): Error0Input;
|
|
290
320
|
_getSelfGeneralProps({ error0Input, message, stack, }: {
|
|
291
|
-
error0Input:
|
|
321
|
+
error0Input: Error0Input;
|
|
292
322
|
message: string;
|
|
293
|
-
stack:
|
|
294
|
-
}):
|
|
295
|
-
_getSelfPropsFloated(causesProps:
|
|
296
|
-
_getExtraError0PropsByZodError(zodError: ZodError): Partial<
|
|
297
|
-
_getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<
|
|
298
|
-
_assignError0Props(error0Props:
|
|
299
|
-
_normalizeSelfExpected(error0Props:
|
|
300
|
-
_isExpected(causesProps:
|
|
301
|
-
_getPropsFromUnknown(error: unknown, defaults?:
|
|
302
|
-
_getCausesPropsFromUnknown(error: unknown, maxLevel: number):
|
|
303
|
-
_getCausesPropsFromError0Props(error0Props:
|
|
304
|
-
_getClosestPropValue<TPropKey extends keyof
|
|
305
|
-
_getFilledPropValues<TPropKey extends keyof
|
|
306
|
-
_getMergedMetaValue(causesProps:
|
|
307
|
-
_removeConstructorStackPart(stack:
|
|
308
|
-
_mergeStack(prevStack:
|
|
323
|
+
stack: Error0GeneralProps["stack"];
|
|
324
|
+
}): Error0GeneralProps;
|
|
325
|
+
_getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps;
|
|
326
|
+
_getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps>;
|
|
327
|
+
_getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps>;
|
|
328
|
+
_assignError0Props(error0Props: Error0GeneralProps, extraError0Props: Partial<Error0GeneralProps>): void;
|
|
329
|
+
_normalizeSelfExpected(error0Props: Error0GeneralProps, expectedProvided: Error0Input["expected"]): boolean | undefined;
|
|
330
|
+
_isExpected(causesProps: Error0GeneralProps[]): boolean;
|
|
331
|
+
_getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps;
|
|
332
|
+
_getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[];
|
|
333
|
+
_getCausesPropsFromError0Props(error0Props: Error0GeneralProps, maxLevel: number): Error0GeneralProps[];
|
|
334
|
+
_getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]> | undefined;
|
|
335
|
+
_getFilledPropValues<TPropKey extends keyof Error0Input>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]>[];
|
|
336
|
+
_getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType;
|
|
337
|
+
_removeConstructorStackPart(stack: Error0GeneralProps["stack"]): Error0GeneralProps["stack"];
|
|
338
|
+
_mergeStack(prevStack: Error0GeneralProps["stack"], nextStack: Error0GeneralProps["stack"]): Error0GeneralProps["stack"];
|
|
309
339
|
isError0(error: unknown): error is Error0;
|
|
310
340
|
isLikelyError0(error: unknown): error is Error0;
|
|
311
|
-
_toError0(error: unknown, inputOverride?:
|
|
312
|
-
from(error: unknown, inputOverride?:
|
|
341
|
+
_toError0(error: unknown, inputOverride?: Error0Input): Error0;
|
|
342
|
+
from(error: unknown, inputOverride?: Error0Input): Error0;
|
|
313
343
|
extend(props: {
|
|
314
|
-
defaultMessage?:
|
|
315
|
-
defaultCode?:
|
|
316
|
-
defaultHttpStatus?:
|
|
317
|
-
defaultExpected?:
|
|
318
|
-
defaultClientMessage?:
|
|
344
|
+
defaultMessage?: Error0GeneralProps["message"];
|
|
345
|
+
defaultCode?: Error0GeneralProps["code"];
|
|
346
|
+
defaultHttpStatus?: Error0GeneralProps["httpStatus"];
|
|
347
|
+
defaultExpected?: Error0GeneralProps["expected"];
|
|
348
|
+
defaultClientMessage?: Error0GeneralProps["clientMessage"];
|
|
319
349
|
defaultMeta?: Meta0.Meta0OrValueTypeNullish;
|
|
320
350
|
}): /*elided*/ any;
|
|
321
351
|
extendCollection<T extends Record<string, typeof Error0>>(classes: T, props: {
|
|
322
|
-
defaultMessage?:
|
|
323
|
-
defaultCode?:
|
|
324
|
-
defaultHttpStatus?:
|
|
325
|
-
defaultExpected?:
|
|
326
|
-
defaultClientMessage?:
|
|
352
|
+
defaultMessage?: Error0GeneralProps["message"];
|
|
353
|
+
defaultCode?: Error0GeneralProps["code"];
|
|
354
|
+
defaultHttpStatus?: Error0GeneralProps["httpStatus"];
|
|
355
|
+
defaultExpected?: Error0GeneralProps["expected"];
|
|
356
|
+
defaultClientMessage?: Error0GeneralProps["clientMessage"];
|
|
327
357
|
defaultMeta?: Meta0.Meta0OrValueTypeNullish;
|
|
328
358
|
}): T;
|
|
329
|
-
toJSON(error: unknown, inputOverride?:
|
|
359
|
+
toJSON(error: unknown, inputOverride?: Error0Input): {
|
|
330
360
|
message: string;
|
|
331
361
|
tag: string | undefined;
|
|
332
362
|
code: string | undefined;
|
|
@@ -344,11 +374,11 @@ declare class Error0 extends Error {
|
|
|
344
374
|
stackTraceLimit: number;
|
|
345
375
|
};
|
|
346
376
|
static extendCollection<T extends Record<string, typeof Error0>>(classes: T, props: {
|
|
347
|
-
defaultMessage?:
|
|
348
|
-
defaultCode?:
|
|
349
|
-
defaultHttpStatus?:
|
|
350
|
-
defaultExpected?:
|
|
351
|
-
defaultClientMessage?:
|
|
377
|
+
defaultMessage?: Error0GeneralProps['message'];
|
|
378
|
+
defaultCode?: Error0GeneralProps['code'];
|
|
379
|
+
defaultHttpStatus?: Error0GeneralProps['httpStatus'];
|
|
380
|
+
defaultExpected?: Error0GeneralProps['expected'];
|
|
381
|
+
defaultClientMessage?: Error0GeneralProps['clientMessage'];
|
|
352
382
|
defaultMeta?: Meta0.Meta0OrValueTypeNullish;
|
|
353
383
|
}): T;
|
|
354
384
|
toJSON(): {
|
|
@@ -364,7 +394,7 @@ declare class Error0 extends Error {
|
|
|
364
394
|
stack: string | undefined;
|
|
365
395
|
__I_AM_ERROR_0: true;
|
|
366
396
|
};
|
|
367
|
-
static toJSON(error: unknown, inputOverride?:
|
|
397
|
+
static toJSON(error: unknown, inputOverride?: Error0Input): {
|
|
368
398
|
message: string;
|
|
369
399
|
tag: string | undefined;
|
|
370
400
|
code: string | undefined;
|
|
@@ -380,38 +410,12 @@ declare class Error0 extends Error {
|
|
|
380
410
|
toResponse(data?: Record<string, unknown>): undici_types.Response;
|
|
381
411
|
}
|
|
382
412
|
declare namespace Error0 {
|
|
383
|
-
interface Input {
|
|
384
|
-
message?: string;
|
|
385
|
-
tag?: string;
|
|
386
|
-
code?: string;
|
|
387
|
-
httpStatus?: HttpStatusCode | HttpStatusCodeString;
|
|
388
|
-
expected?: boolean | Error0.ExpectedFn;
|
|
389
|
-
clientMessage?: string;
|
|
390
|
-
cause?: Error0Cause;
|
|
391
|
-
stack?: string;
|
|
392
|
-
meta?: Meta0.Meta0OrValueTypeNullish;
|
|
393
|
-
zodError?: ZodError;
|
|
394
|
-
axiosError?: AxiosError;
|
|
395
|
-
}
|
|
396
|
-
interface GeneralProps {
|
|
397
|
-
message: Input['message'];
|
|
398
|
-
tag: Input['tag'];
|
|
399
|
-
code: Input['code'];
|
|
400
|
-
httpStatus: number | undefined;
|
|
401
|
-
expected: boolean | undefined;
|
|
402
|
-
clientMessage: Input['clientMessage'];
|
|
403
|
-
anyMessage: string | undefined;
|
|
404
|
-
cause: Input['cause'];
|
|
405
|
-
stack: Error['stack'];
|
|
406
|
-
meta: Meta0.ValueType;
|
|
407
|
-
zodError?: ZodError;
|
|
408
|
-
axiosError?: AxiosError;
|
|
409
|
-
}
|
|
410
|
-
type HttpStatusCodeString = keyof typeof HttpStatusCode;
|
|
411
|
-
type Error0Cause = Error | Error0 | unknown;
|
|
412
|
-
type ExpectedFn = (error: GeneralProps) => boolean | undefined;
|
|
413
413
|
type JSON = ReturnType<Error0['toJSON']>;
|
|
414
414
|
type Collection = Record<string, typeof Error0>;
|
|
415
415
|
}
|
|
416
|
+
declare const e0s: {
|
|
417
|
+
Default: typeof Error0;
|
|
418
|
+
Expected: typeof Error0;
|
|
419
|
+
};
|
|
416
420
|
|
|
417
|
-
export { Error0 };
|
|
421
|
+
export { Error0, type Error0Input, e0s };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { Meta0 } from "@devp0nt/meta0";
|
|
2
|
-
import { meta0PluginTag } from "@devp0nt/meta0/plugins/meta0-plugin-tag";
|
|
3
2
|
import { HttpStatusCode, isAxiosError } from "axios";
|
|
4
3
|
import get from "lodash/get.js";
|
|
5
4
|
import { ZodError } from "zod";
|
|
6
5
|
const isFilled = (value) => value !== null && value !== void 0 && value !== "";
|
|
7
|
-
const toStringOrUndefined = (value) => {
|
|
8
|
-
return typeof value === "string" ? value : void 0;
|
|
9
|
-
};
|
|
10
|
-
const toNumberOrUndefined = (value) => {
|
|
11
|
-
if (typeof value === "number") {
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
const number = Number(value);
|
|
15
|
-
if (typeof value === "string" && !Number.isNaN(number)) {
|
|
16
|
-
return number;
|
|
17
|
-
}
|
|
18
|
-
return void 0;
|
|
19
|
-
};
|
|
20
|
-
const toBooleanOrUndefined = (value) => {
|
|
21
|
-
if (typeof value === "boolean") {
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
return void 0;
|
|
25
|
-
};
|
|
26
6
|
class Error0 extends Error {
|
|
27
7
|
__I_AM_ERROR_0 = true;
|
|
28
8
|
tag;
|
|
@@ -103,16 +83,15 @@ class Error0 extends Error {
|
|
|
103
83
|
message,
|
|
104
84
|
stack
|
|
105
85
|
}) {
|
|
106
|
-
const meta0 = Meta0.extend(
|
|
86
|
+
const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta);
|
|
107
87
|
const meta = meta0.getValue();
|
|
108
|
-
const finalTag =
|
|
109
|
-
delete meta.tagPrefix;
|
|
88
|
+
const finalTag = meta0.getFinalTag(error0Input.tag);
|
|
110
89
|
const clientMessage = error0Input.clientMessage || this.defaultClientMessage;
|
|
111
90
|
const result = {
|
|
112
91
|
message: error0Input.message || this.defaultMessage,
|
|
113
92
|
tag: finalTag,
|
|
114
|
-
code: error0Input.code ||
|
|
115
|
-
httpStatus: typeof error0Input.httpStatus === "number" ? error0Input.httpStatus : error0Input.httpStatus && typeof error0Input.httpStatus === "string" && error0Input.httpStatus in HttpStatusCode ? HttpStatusCode[error0Input.httpStatus] :
|
|
93
|
+
code: error0Input.code || meta.code || this.defaultCode,
|
|
94
|
+
httpStatus: typeof error0Input.httpStatus === "number" ? error0Input.httpStatus : error0Input.httpStatus && typeof error0Input.httpStatus === "string" && error0Input.httpStatus in HttpStatusCode ? HttpStatusCode[error0Input.httpStatus] : meta.httpStatus || this.defaultHttpStatus,
|
|
116
95
|
expected: void 0,
|
|
117
96
|
clientMessage,
|
|
118
97
|
anyMessage: clientMessage || message,
|
|
@@ -124,7 +103,7 @@ class Error0 extends Error {
|
|
|
124
103
|
};
|
|
125
104
|
result.expected = this._normalizeSelfExpected(
|
|
126
105
|
result,
|
|
127
|
-
typeof error0Input.expected === "boolean" || typeof error0Input.expected === "function" ? error0Input.expected :
|
|
106
|
+
typeof error0Input.expected === "boolean" || typeof error0Input.expected === "function" ? error0Input.expected : meta.expected || this.defaultExpected
|
|
128
107
|
);
|
|
129
108
|
result.stack = this._removeConstructorStackPart(stack);
|
|
130
109
|
return result;
|
|
@@ -134,7 +113,7 @@ class Error0 extends Error {
|
|
|
134
113
|
const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack);
|
|
135
114
|
const closestTag = this._getClosestPropValue(causesProps, "tag");
|
|
136
115
|
const meta = this._getMergedMetaValue(causesProps);
|
|
137
|
-
const tag =
|
|
116
|
+
const tag = Meta0.getFinalTag(meta, closestTag);
|
|
138
117
|
const propsFloated = {
|
|
139
118
|
message: this._getClosestPropValue(causesProps, "message"),
|
|
140
119
|
tag,
|
|
@@ -268,8 +247,8 @@ class Error0 extends Error {
|
|
|
268
247
|
return void 0;
|
|
269
248
|
}
|
|
270
249
|
// private static getClosestByGetter<TResult>(
|
|
271
|
-
// causesProps:
|
|
272
|
-
// getter: (props:
|
|
250
|
+
// causesProps: Error0GeneralProps[],
|
|
251
|
+
// getter: (props: Error0GeneralProps) => TResult,
|
|
273
252
|
// ): NonNullable<TResult> | undefined {
|
|
274
253
|
// for (const causeProps of causesProps) {
|
|
275
254
|
// const result = getter(causeProps)
|
|
@@ -370,7 +349,7 @@ class Error0 extends Error {
|
|
|
370
349
|
static defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus;
|
|
371
350
|
static defaultExpected = props.defaultExpected ?? parent.defaultExpected;
|
|
372
351
|
static defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage;
|
|
373
|
-
static defaultMeta = Meta0.extend(
|
|
352
|
+
static defaultMeta = Meta0.extend(props.defaultMeta, parent.defaultMeta);
|
|
374
353
|
};
|
|
375
354
|
}
|
|
376
355
|
static extendCollection(classes, props) {
|
|
@@ -408,7 +387,14 @@ class Error0 extends Error {
|
|
|
408
387
|
);
|
|
409
388
|
}
|
|
410
389
|
}
|
|
390
|
+
const e0s = {
|
|
391
|
+
Default: Error0,
|
|
392
|
+
Expected: Error0.extend({
|
|
393
|
+
defaultExpected: true
|
|
394
|
+
})
|
|
395
|
+
};
|
|
411
396
|
export {
|
|
412
|
-
Error0
|
|
397
|
+
Error0,
|
|
398
|
+
e0s
|
|
413
399
|
};
|
|
414
400
|
//# sourceMappingURL=index.js.map
|