@devp0nt/error0 1.0.0-next.42 → 1.0.0-next.44
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.cjs +204 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +108 -37
- package/dist/esm/index.d.ts +108 -37
- package/dist/esm/index.js +204 -20
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.test.ts +293 -12
- package/src/index.ts +444 -81
package/dist/cjs/index.d.cts
CHANGED
|
@@ -2,7 +2,9 @@ type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) :
|
|
|
2
2
|
type NormalizeUnknownToUndefined<T> = IsUnknown<T> extends true ? undefined : T;
|
|
3
3
|
type IsOnlyUndefined<T> = [Exclude<T, undefined>] extends [never] ? true : false;
|
|
4
4
|
type InferFirstArg<TFn> = TFn extends (...args: infer TArgs) => unknown ? TArgs extends [infer TFirst, ...unknown[]] ? TFirst : undefined : undefined;
|
|
5
|
-
type InferPluginPropInput<TProp extends ErrorPluginPropOptions<any, any, any>> =
|
|
5
|
+
type InferPluginPropInput<TProp extends ErrorPluginPropOptions<any, any, any, any>> = TProp extends {
|
|
6
|
+
init: infer TInit;
|
|
7
|
+
} ? NormalizeUnknownToUndefined<InferFirstArg<TInit>> : undefined;
|
|
6
8
|
type ErrorPluginPropInit<TInputValue, TOutputValue> = ((input: TInputValue) => TOutputValue) | (() => TOutputValue);
|
|
7
9
|
type ErrorPluginPropSerialize<TOutputValue, TError extends Error0> = ((options: {
|
|
8
10
|
value: TOutputValue;
|
|
@@ -13,19 +15,37 @@ type ErrorPluginPropDeserialize<TOutputValue> = ((options: {
|
|
|
13
15
|
value: unknown;
|
|
14
16
|
serialized: Record<string, unknown>;
|
|
15
17
|
}) => TOutputValue | undefined) | false;
|
|
16
|
-
type
|
|
17
|
-
init: ErrorPluginPropInit<TInputValue, TOutputValue>;
|
|
18
|
+
type ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {
|
|
18
19
|
resolve: (options: {
|
|
19
|
-
|
|
20
|
+
own: TOutputValue | undefined;
|
|
20
21
|
flow: Array<TOutputValue | undefined>;
|
|
21
22
|
error: TError;
|
|
22
|
-
}) =>
|
|
23
|
-
serialize: ErrorPluginPropSerialize<
|
|
23
|
+
}) => TResolveValue;
|
|
24
|
+
serialize: ErrorPluginPropSerialize<TResolveValue, TError>;
|
|
24
25
|
deserialize: ErrorPluginPropDeserialize<TOutputValue>;
|
|
25
26
|
};
|
|
27
|
+
type ErrorPluginPropOptionsWithInit<TInputValue, TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {
|
|
28
|
+
init: ErrorPluginPropInit<TInputValue, TOutputValue>;
|
|
29
|
+
};
|
|
30
|
+
type ErrorPluginPropOptionsWithoutInit<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {
|
|
31
|
+
init?: undefined;
|
|
32
|
+
};
|
|
33
|
+
type ErrorPluginPropOptions<TInputValue = undefined, TOutputValue = unknown, TError extends Error0 = Error0, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = ErrorPluginPropOptionsWithInit<TInputValue, TOutputValue, TError, TResolveValue> | ErrorPluginPropOptionsWithoutInit<TOutputValue, TError, TResolveValue>;
|
|
26
34
|
type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
|
|
27
35
|
type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
|
|
28
36
|
type ErrorPluginAdaptFn<TError extends Error0 = Error0, TOutputProps extends Record<string, unknown> = Record<never, never>> = ((error: TError) => void) | ((error: TError) => ErrorPluginAdaptResult<TOutputProps>);
|
|
37
|
+
type ErrorPluginStackSerialize<TError extends Error0> = ((options: {
|
|
38
|
+
value: string | undefined;
|
|
39
|
+
error: TError;
|
|
40
|
+
isPublic: boolean;
|
|
41
|
+
}) => unknown) | boolean | 'merge';
|
|
42
|
+
type ErrorPluginStack<TError extends Error0 = Error0> = ErrorPluginStackSerialize<TError>;
|
|
43
|
+
type ErrorPluginCauseSerialize<TError extends Error0> = ((options: {
|
|
44
|
+
value: unknown;
|
|
45
|
+
error: TError;
|
|
46
|
+
isPublic: boolean;
|
|
47
|
+
}) => unknown) | boolean;
|
|
48
|
+
type ErrorPluginCause<TError extends Error0 = Error0> = ErrorPluginCauseSerialize<TError>;
|
|
29
49
|
type ErrorMethodRecord = {
|
|
30
50
|
args: unknown[];
|
|
31
51
|
output: unknown;
|
|
@@ -40,15 +60,18 @@ type ErrorPlugin<TProps extends ErrorPluginProps = Record<never, never>, TMethod
|
|
|
40
60
|
props?: TProps;
|
|
41
61
|
methods?: TMethods;
|
|
42
62
|
adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>;
|
|
63
|
+
stack?: ErrorPluginStack;
|
|
64
|
+
cause?: ErrorPluginCause;
|
|
43
65
|
};
|
|
44
|
-
type AddPropToPluginProps<TProps extends ErrorPluginProps, TKey extends string, TInputValue, TOutputValue> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue>>;
|
|
66
|
+
type AddPropToPluginProps<TProps extends ErrorPluginProps, TKey extends string, TInputValue, TOutputValue, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>;
|
|
45
67
|
type AddMethodToPluginMethods<TMethods extends ErrorPluginMethods, TKey extends string, TArgs extends unknown[], TOutputValue> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>;
|
|
46
68
|
type PluginOutputProps<TProps extends ErrorPluginProps> = {
|
|
47
|
-
[TKey in keyof TProps]: TProps[TKey] extends ErrorPluginPropOptions<any, infer
|
|
69
|
+
[TKey in keyof TProps]: TProps[TKey] extends ErrorPluginPropOptions<any, any, any, infer TResolveValue> ? TResolveValue : never;
|
|
48
70
|
};
|
|
49
71
|
type ErrorPluginsMap = {
|
|
50
72
|
props: Record<string, {
|
|
51
73
|
init: unknown;
|
|
74
|
+
output: unknown;
|
|
52
75
|
resolve: unknown;
|
|
53
76
|
}>;
|
|
54
77
|
methods: Record<string, ErrorMethodRecord>;
|
|
@@ -61,16 +84,29 @@ type ErrorInputPluginProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
|
61
84
|
[TKey in keyof TPluginsMap['props'] as IsOnlyUndefined<TPluginsMap['props'][TKey]['init']> extends true ? never : TKey]?: TPluginsMap['props'][TKey]['init'];
|
|
62
85
|
};
|
|
63
86
|
type ErrorInput<TPluginsMap extends ErrorPluginsMap> = IsEmptyObject<TPluginsMap['props']> extends true ? ErrorInputBase : ErrorInputBase & ErrorInputPluginProps<TPluginsMap>;
|
|
64
|
-
type
|
|
65
|
-
[TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve']
|
|
87
|
+
type ErrorResolvedProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
88
|
+
[TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve'];
|
|
89
|
+
};
|
|
90
|
+
type ErrorOwnProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
91
|
+
[TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['output'] | undefined;
|
|
92
|
+
};
|
|
93
|
+
type ErrorOwnMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
94
|
+
own: {
|
|
95
|
+
(): ErrorOwnProps<TPluginsMap>;
|
|
96
|
+
<TKey extends keyof TPluginsMap['props'] & string>(key: TKey): ErrorOwnProps<TPluginsMap>[TKey];
|
|
97
|
+
};
|
|
98
|
+
flow: <TKey extends keyof TPluginsMap['props'] & string>(key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>;
|
|
66
99
|
};
|
|
67
|
-
type
|
|
100
|
+
type ErrorResolveMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
101
|
+
resolve: () => ErrorResolvedProps<TPluginsMap>;
|
|
102
|
+
};
|
|
103
|
+
type ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
68
104
|
[TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
|
|
69
105
|
args: infer TArgs extends unknown[];
|
|
70
106
|
output: infer TOutput;
|
|
71
107
|
} ? (...args: TArgs) => TOutput : never;
|
|
72
108
|
};
|
|
73
|
-
type
|
|
109
|
+
type ErrorResolved<TPluginsMap extends ErrorPluginsMap> = ErrorResolvedProps<TPluginsMap> & ErrorMethods<TPluginsMap>;
|
|
74
110
|
type ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
75
111
|
[TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
|
|
76
112
|
args: infer TArgs extends unknown[];
|
|
@@ -80,14 +116,16 @@ type ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
|
80
116
|
type EmptyPluginsMap = {
|
|
81
117
|
props: Record<never, {
|
|
82
118
|
init: never;
|
|
119
|
+
output: never;
|
|
83
120
|
resolve: never;
|
|
84
121
|
}>;
|
|
85
122
|
methods: Record<never, ErrorMethodRecord>;
|
|
86
123
|
};
|
|
87
124
|
type PluginPropsMapOf<TPlugin extends ErrorPlugin> = {
|
|
88
|
-
[TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue> ? {
|
|
125
|
+
[TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue, any, infer TResolveValue> ? {
|
|
89
126
|
init: InferPluginPropInput<NonNullable<TPlugin['props']>[TKey]>;
|
|
90
|
-
|
|
127
|
+
output: TOutputValue;
|
|
128
|
+
resolve: TResolveValue;
|
|
91
129
|
} : never;
|
|
92
130
|
};
|
|
93
131
|
type PluginMethodsMapOf<TPlugin extends ErrorPlugin> = {
|
|
@@ -104,14 +142,19 @@ type ExtendErrorPluginsMap<TMap extends ErrorPluginsMap, TPlugin extends ErrorPl
|
|
|
104
142
|
props: TMap['props'] & ErrorPluginsMapOfPlugin<TPlugin>['props'];
|
|
105
143
|
methods: TMap['methods'] & ErrorPluginsMapOfPlugin<TPlugin>['methods'];
|
|
106
144
|
};
|
|
107
|
-
type ExtendErrorPluginsMapWithProp<TMap extends ErrorPluginsMap, TKey extends string, TInputValue, TOutputValue> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue>>>>;
|
|
145
|
+
type ExtendErrorPluginsMapWithProp<TMap extends ErrorPluginsMap, TKey extends string, TInputValue, TOutputValue, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>>>;
|
|
108
146
|
type ExtendErrorPluginsMapWithMethod<TMap extends ErrorPluginsMap, TKey extends string, TArgs extends unknown[], TOutputValue> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<never, never>, Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>>>;
|
|
109
147
|
type PluginsMapOf<TClass> = TClass extends {
|
|
110
148
|
__pluginsMap?: infer TPluginsMap;
|
|
111
149
|
} ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
|
|
150
|
+
type PluginsMapOfInstance<TInstance> = TInstance extends {
|
|
151
|
+
constructor: {
|
|
152
|
+
__pluginsMap?: infer TPluginsMap;
|
|
153
|
+
};
|
|
154
|
+
} ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
|
|
112
155
|
type PluginsMapFromParts<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>;
|
|
113
|
-
type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 &
|
|
114
|
-
type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 &
|
|
156
|
+
type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TMap>;
|
|
157
|
+
type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 & ErrorResolved<PluginsMapFromParts<TProps, TMethods>>;
|
|
115
158
|
type PluginOfBuilder<TBuilder> = TBuilder extends PluginError0<infer TProps, infer TMethods> ? ErrorPlugin<TProps, TMethods> : never;
|
|
116
159
|
declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never>, TMethods extends ErrorPluginMethods = Record<never, never>> {
|
|
117
160
|
private readonly _plugin;
|
|
@@ -120,29 +163,43 @@ declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never
|
|
|
120
163
|
methods: TMethods;
|
|
121
164
|
};
|
|
122
165
|
constructor(plugin?: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>);
|
|
123
|
-
prop<TKey extends string, TInputValue, TOutputValue>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods
|
|
166
|
+
prop<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>;
|
|
124
167
|
method<TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>>;
|
|
125
168
|
adapt(value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
|
|
126
|
-
|
|
169
|
+
stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
170
|
+
cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
171
|
+
use<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>;
|
|
127
172
|
use<TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>>;
|
|
128
173
|
use(kind: 'adapt', value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
|
|
174
|
+
use(kind: 'stack', value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
175
|
+
use(kind: 'cause', value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
129
176
|
}
|
|
130
177
|
type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
|
|
131
|
-
new (message: string, input?: ErrorInput<TPluginsMap>): Error0 &
|
|
178
|
+
new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
|
|
132
179
|
new (input: {
|
|
133
180
|
message: string;
|
|
134
|
-
} & ErrorInput<TPluginsMap>): Error0 &
|
|
181
|
+
} & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
|
|
135
182
|
readonly __pluginsMap?: TPluginsMap;
|
|
136
|
-
from: (error: unknown) => Error0 &
|
|
183
|
+
from: (error: unknown) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
|
|
184
|
+
resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>;
|
|
137
185
|
serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>;
|
|
138
|
-
|
|
186
|
+
own: {
|
|
187
|
+
(error: object): ErrorOwnProps<TPluginsMap>;
|
|
188
|
+
<TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey): ErrorOwnProps<TPluginsMap>[TKey];
|
|
189
|
+
};
|
|
190
|
+
flow: <TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>;
|
|
191
|
+
prop: <TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>) => ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
139
192
|
method: <TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
|
|
140
|
-
adapt: (value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>,
|
|
193
|
+
adapt: (value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>) => ClassError0<TPluginsMap>;
|
|
194
|
+
stack: (value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>;
|
|
195
|
+
cause: (value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>;
|
|
141
196
|
use: {
|
|
142
197
|
<TBuilder extends PluginError0>(plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<TPluginsMap, PluginOfBuilder<TBuilder>>>;
|
|
143
|
-
<TKey extends string, TInputValue, TOutputValue>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap
|
|
198
|
+
<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
144
199
|
<TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
|
|
145
|
-
(kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>,
|
|
200
|
+
(kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>): ClassError0<TPluginsMap>;
|
|
201
|
+
(kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>;
|
|
202
|
+
(kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>;
|
|
146
203
|
};
|
|
147
204
|
plugin: () => PluginError0;
|
|
148
205
|
} & ErrorStaticMethods<TPluginsMap>;
|
|
@@ -156,14 +213,24 @@ declare class Error0 extends Error {
|
|
|
156
213
|
message: string;
|
|
157
214
|
} & ErrorInput<EmptyPluginsMap>);
|
|
158
215
|
private static readonly isSelfProperty;
|
|
159
|
-
static
|
|
160
|
-
|
|
161
|
-
static
|
|
216
|
+
private static _ownByKey;
|
|
217
|
+
private static _flowByKey;
|
|
218
|
+
static own<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorOwnProps<PluginsMapOf<TThis>>;
|
|
219
|
+
static own<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(this: TThis, error: unknown, key: TKey): ErrorOwnProps<PluginsMapOf<TThis>>[TKey];
|
|
220
|
+
own<TThis extends Error0>(this: TThis): ErrorOwnProps<PluginsMapOfInstance<TThis>>;
|
|
221
|
+
own<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(this: TThis, key: TKey): ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey];
|
|
222
|
+
static flow<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(this: TThis, error: unknown, key: TKey): Array<ErrorOwnProps<PluginsMapOf<TThis>>[TKey]>;
|
|
223
|
+
static flow(error: unknown, key: string): unknown[];
|
|
224
|
+
flow<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(this: TThis, key: TKey): Array<ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey]>;
|
|
162
225
|
flow(key: string): unknown[];
|
|
226
|
+
static resolve<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorResolvedProps<PluginsMapOf<TThis>>;
|
|
227
|
+
static resolve(error: unknown): Record<string, unknown>;
|
|
228
|
+
resolve<TThis extends Error0>(this: TThis): ErrorResolvedProps<PluginsMapOfInstance<TThis>>;
|
|
229
|
+
resolve(): Record<string, unknown>;
|
|
163
230
|
static causes(error: unknown, instancesOnly?: false): unknown[];
|
|
164
231
|
static causes<T extends typeof Error0>(this: T, error: unknown, instancesOnly: true): Array<InstanceType<T>>;
|
|
165
|
-
causes<
|
|
166
|
-
causes<
|
|
232
|
+
causes<TThis extends Error0>(this: TThis, instancesOnly?: false): [TThis, ...unknown[]];
|
|
233
|
+
causes<TThis extends Error0>(this: TThis, instancesOnly: true): [TThis, ...TThis[]];
|
|
167
234
|
static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T>;
|
|
168
235
|
static isSerialized(error: unknown): error is Record<string, unknown>;
|
|
169
236
|
static from(error: unknown): Error0;
|
|
@@ -173,16 +240,20 @@ declare class Error0 extends Error {
|
|
|
173
240
|
private static _extractMessage;
|
|
174
241
|
private static _useWithPlugin;
|
|
175
242
|
private static _pluginFromBuilder;
|
|
176
|
-
static prop<TThis extends typeof Error0, TKey extends string, TInputValue, TOutputValue>(this: TThis, key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis
|
|
243
|
+
static prop<TThis extends typeof Error0, TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(this: TThis, key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
177
244
|
static method<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(this: TThis, key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>;
|
|
178
|
-
static adapt<TThis extends typeof Error0>(this: TThis, value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>,
|
|
245
|
+
static adapt<TThis extends typeof Error0>(this: TThis, value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
246
|
+
static stack<TThis extends typeof Error0>(this: TThis, value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
247
|
+
static cause<TThis extends typeof Error0>(this: TThis, value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
179
248
|
static use<TThis extends typeof Error0, TBuilder extends PluginError0>(this: TThis, plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>;
|
|
180
|
-
static use<TThis extends typeof Error0, TKey extends string, TInputValue, TOutputValue>(this: TThis, kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis
|
|
249
|
+
static use<TThis extends typeof Error0, TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(this: TThis, kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
181
250
|
static use<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(this: TThis, kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>;
|
|
182
|
-
static use<TThis extends typeof Error0>(this: TThis, kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>,
|
|
251
|
+
static use<TThis extends typeof Error0>(this: TThis, kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
252
|
+
static use<TThis extends typeof Error0>(this: TThis, kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
253
|
+
static use<TThis extends typeof Error0>(this: TThis, kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
183
254
|
static plugin(): PluginError0;
|
|
184
255
|
static serialize(error: unknown, isPublic?: boolean): Record<string, unknown>;
|
|
185
|
-
serialize(isPublic?: boolean):
|
|
256
|
+
serialize(isPublic?: boolean): Record<string, unknown>;
|
|
186
257
|
}
|
|
187
258
|
|
|
188
|
-
export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type
|
|
259
|
+
export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) :
|
|
|
2
2
|
type NormalizeUnknownToUndefined<T> = IsUnknown<T> extends true ? undefined : T;
|
|
3
3
|
type IsOnlyUndefined<T> = [Exclude<T, undefined>] extends [never] ? true : false;
|
|
4
4
|
type InferFirstArg<TFn> = TFn extends (...args: infer TArgs) => unknown ? TArgs extends [infer TFirst, ...unknown[]] ? TFirst : undefined : undefined;
|
|
5
|
-
type InferPluginPropInput<TProp extends ErrorPluginPropOptions<any, any, any>> =
|
|
5
|
+
type InferPluginPropInput<TProp extends ErrorPluginPropOptions<any, any, any, any>> = TProp extends {
|
|
6
|
+
init: infer TInit;
|
|
7
|
+
} ? NormalizeUnknownToUndefined<InferFirstArg<TInit>> : undefined;
|
|
6
8
|
type ErrorPluginPropInit<TInputValue, TOutputValue> = ((input: TInputValue) => TOutputValue) | (() => TOutputValue);
|
|
7
9
|
type ErrorPluginPropSerialize<TOutputValue, TError extends Error0> = ((options: {
|
|
8
10
|
value: TOutputValue;
|
|
@@ -13,19 +15,37 @@ type ErrorPluginPropDeserialize<TOutputValue> = ((options: {
|
|
|
13
15
|
value: unknown;
|
|
14
16
|
serialized: Record<string, unknown>;
|
|
15
17
|
}) => TOutputValue | undefined) | false;
|
|
16
|
-
type
|
|
17
|
-
init: ErrorPluginPropInit<TInputValue, TOutputValue>;
|
|
18
|
+
type ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {
|
|
18
19
|
resolve: (options: {
|
|
19
|
-
|
|
20
|
+
own: TOutputValue | undefined;
|
|
20
21
|
flow: Array<TOutputValue | undefined>;
|
|
21
22
|
error: TError;
|
|
22
|
-
}) =>
|
|
23
|
-
serialize: ErrorPluginPropSerialize<
|
|
23
|
+
}) => TResolveValue;
|
|
24
|
+
serialize: ErrorPluginPropSerialize<TResolveValue, TError>;
|
|
24
25
|
deserialize: ErrorPluginPropDeserialize<TOutputValue>;
|
|
25
26
|
};
|
|
27
|
+
type ErrorPluginPropOptionsWithInit<TInputValue, TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {
|
|
28
|
+
init: ErrorPluginPropInit<TInputValue, TOutputValue>;
|
|
29
|
+
};
|
|
30
|
+
type ErrorPluginPropOptionsWithoutInit<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {
|
|
31
|
+
init?: undefined;
|
|
32
|
+
};
|
|
33
|
+
type ErrorPluginPropOptions<TInputValue = undefined, TOutputValue = unknown, TError extends Error0 = Error0, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = ErrorPluginPropOptionsWithInit<TInputValue, TOutputValue, TError, TResolveValue> | ErrorPluginPropOptionsWithoutInit<TOutputValue, TError, TResolveValue>;
|
|
26
34
|
type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
|
|
27
35
|
type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
|
|
28
36
|
type ErrorPluginAdaptFn<TError extends Error0 = Error0, TOutputProps extends Record<string, unknown> = Record<never, never>> = ((error: TError) => void) | ((error: TError) => ErrorPluginAdaptResult<TOutputProps>);
|
|
37
|
+
type ErrorPluginStackSerialize<TError extends Error0> = ((options: {
|
|
38
|
+
value: string | undefined;
|
|
39
|
+
error: TError;
|
|
40
|
+
isPublic: boolean;
|
|
41
|
+
}) => unknown) | boolean | 'merge';
|
|
42
|
+
type ErrorPluginStack<TError extends Error0 = Error0> = ErrorPluginStackSerialize<TError>;
|
|
43
|
+
type ErrorPluginCauseSerialize<TError extends Error0> = ((options: {
|
|
44
|
+
value: unknown;
|
|
45
|
+
error: TError;
|
|
46
|
+
isPublic: boolean;
|
|
47
|
+
}) => unknown) | boolean;
|
|
48
|
+
type ErrorPluginCause<TError extends Error0 = Error0> = ErrorPluginCauseSerialize<TError>;
|
|
29
49
|
type ErrorMethodRecord = {
|
|
30
50
|
args: unknown[];
|
|
31
51
|
output: unknown;
|
|
@@ -40,15 +60,18 @@ type ErrorPlugin<TProps extends ErrorPluginProps = Record<never, never>, TMethod
|
|
|
40
60
|
props?: TProps;
|
|
41
61
|
methods?: TMethods;
|
|
42
62
|
adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>;
|
|
63
|
+
stack?: ErrorPluginStack;
|
|
64
|
+
cause?: ErrorPluginCause;
|
|
43
65
|
};
|
|
44
|
-
type AddPropToPluginProps<TProps extends ErrorPluginProps, TKey extends string, TInputValue, TOutputValue> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue>>;
|
|
66
|
+
type AddPropToPluginProps<TProps extends ErrorPluginProps, TKey extends string, TInputValue, TOutputValue, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>;
|
|
45
67
|
type AddMethodToPluginMethods<TMethods extends ErrorPluginMethods, TKey extends string, TArgs extends unknown[], TOutputValue> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>;
|
|
46
68
|
type PluginOutputProps<TProps extends ErrorPluginProps> = {
|
|
47
|
-
[TKey in keyof TProps]: TProps[TKey] extends ErrorPluginPropOptions<any, infer
|
|
69
|
+
[TKey in keyof TProps]: TProps[TKey] extends ErrorPluginPropOptions<any, any, any, infer TResolveValue> ? TResolveValue : never;
|
|
48
70
|
};
|
|
49
71
|
type ErrorPluginsMap = {
|
|
50
72
|
props: Record<string, {
|
|
51
73
|
init: unknown;
|
|
74
|
+
output: unknown;
|
|
52
75
|
resolve: unknown;
|
|
53
76
|
}>;
|
|
54
77
|
methods: Record<string, ErrorMethodRecord>;
|
|
@@ -61,16 +84,29 @@ type ErrorInputPluginProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
|
61
84
|
[TKey in keyof TPluginsMap['props'] as IsOnlyUndefined<TPluginsMap['props'][TKey]['init']> extends true ? never : TKey]?: TPluginsMap['props'][TKey]['init'];
|
|
62
85
|
};
|
|
63
86
|
type ErrorInput<TPluginsMap extends ErrorPluginsMap> = IsEmptyObject<TPluginsMap['props']> extends true ? ErrorInputBase : ErrorInputBase & ErrorInputPluginProps<TPluginsMap>;
|
|
64
|
-
type
|
|
65
|
-
[TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve']
|
|
87
|
+
type ErrorResolvedProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
88
|
+
[TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve'];
|
|
89
|
+
};
|
|
90
|
+
type ErrorOwnProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
91
|
+
[TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['output'] | undefined;
|
|
92
|
+
};
|
|
93
|
+
type ErrorOwnMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
94
|
+
own: {
|
|
95
|
+
(): ErrorOwnProps<TPluginsMap>;
|
|
96
|
+
<TKey extends keyof TPluginsMap['props'] & string>(key: TKey): ErrorOwnProps<TPluginsMap>[TKey];
|
|
97
|
+
};
|
|
98
|
+
flow: <TKey extends keyof TPluginsMap['props'] & string>(key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>;
|
|
66
99
|
};
|
|
67
|
-
type
|
|
100
|
+
type ErrorResolveMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
101
|
+
resolve: () => ErrorResolvedProps<TPluginsMap>;
|
|
102
|
+
};
|
|
103
|
+
type ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
68
104
|
[TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
|
|
69
105
|
args: infer TArgs extends unknown[];
|
|
70
106
|
output: infer TOutput;
|
|
71
107
|
} ? (...args: TArgs) => TOutput : never;
|
|
72
108
|
};
|
|
73
|
-
type
|
|
109
|
+
type ErrorResolved<TPluginsMap extends ErrorPluginsMap> = ErrorResolvedProps<TPluginsMap> & ErrorMethods<TPluginsMap>;
|
|
74
110
|
type ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
75
111
|
[TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
|
|
76
112
|
args: infer TArgs extends unknown[];
|
|
@@ -80,14 +116,16 @@ type ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
|
80
116
|
type EmptyPluginsMap = {
|
|
81
117
|
props: Record<never, {
|
|
82
118
|
init: never;
|
|
119
|
+
output: never;
|
|
83
120
|
resolve: never;
|
|
84
121
|
}>;
|
|
85
122
|
methods: Record<never, ErrorMethodRecord>;
|
|
86
123
|
};
|
|
87
124
|
type PluginPropsMapOf<TPlugin extends ErrorPlugin> = {
|
|
88
|
-
[TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue> ? {
|
|
125
|
+
[TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue, any, infer TResolveValue> ? {
|
|
89
126
|
init: InferPluginPropInput<NonNullable<TPlugin['props']>[TKey]>;
|
|
90
|
-
|
|
127
|
+
output: TOutputValue;
|
|
128
|
+
resolve: TResolveValue;
|
|
91
129
|
} : never;
|
|
92
130
|
};
|
|
93
131
|
type PluginMethodsMapOf<TPlugin extends ErrorPlugin> = {
|
|
@@ -104,14 +142,19 @@ type ExtendErrorPluginsMap<TMap extends ErrorPluginsMap, TPlugin extends ErrorPl
|
|
|
104
142
|
props: TMap['props'] & ErrorPluginsMapOfPlugin<TPlugin>['props'];
|
|
105
143
|
methods: TMap['methods'] & ErrorPluginsMapOfPlugin<TPlugin>['methods'];
|
|
106
144
|
};
|
|
107
|
-
type ExtendErrorPluginsMapWithProp<TMap extends ErrorPluginsMap, TKey extends string, TInputValue, TOutputValue> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue>>>>;
|
|
145
|
+
type ExtendErrorPluginsMapWithProp<TMap extends ErrorPluginsMap, TKey extends string, TInputValue, TOutputValue, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>>>;
|
|
108
146
|
type ExtendErrorPluginsMapWithMethod<TMap extends ErrorPluginsMap, TKey extends string, TArgs extends unknown[], TOutputValue> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<never, never>, Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>>>;
|
|
109
147
|
type PluginsMapOf<TClass> = TClass extends {
|
|
110
148
|
__pluginsMap?: infer TPluginsMap;
|
|
111
149
|
} ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
|
|
150
|
+
type PluginsMapOfInstance<TInstance> = TInstance extends {
|
|
151
|
+
constructor: {
|
|
152
|
+
__pluginsMap?: infer TPluginsMap;
|
|
153
|
+
};
|
|
154
|
+
} ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
|
|
112
155
|
type PluginsMapFromParts<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>;
|
|
113
|
-
type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 &
|
|
114
|
-
type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 &
|
|
156
|
+
type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TMap>;
|
|
157
|
+
type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 & ErrorResolved<PluginsMapFromParts<TProps, TMethods>>;
|
|
115
158
|
type PluginOfBuilder<TBuilder> = TBuilder extends PluginError0<infer TProps, infer TMethods> ? ErrorPlugin<TProps, TMethods> : never;
|
|
116
159
|
declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never>, TMethods extends ErrorPluginMethods = Record<never, never>> {
|
|
117
160
|
private readonly _plugin;
|
|
@@ -120,29 +163,43 @@ declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never
|
|
|
120
163
|
methods: TMethods;
|
|
121
164
|
};
|
|
122
165
|
constructor(plugin?: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>);
|
|
123
|
-
prop<TKey extends string, TInputValue, TOutputValue>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods
|
|
166
|
+
prop<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>;
|
|
124
167
|
method<TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>>;
|
|
125
168
|
adapt(value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
|
|
126
|
-
|
|
169
|
+
stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
170
|
+
cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
171
|
+
use<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>;
|
|
127
172
|
use<TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>>;
|
|
128
173
|
use(kind: 'adapt', value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
|
|
174
|
+
use(kind: 'stack', value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
175
|
+
use(kind: 'cause', value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
129
176
|
}
|
|
130
177
|
type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
|
|
131
|
-
new (message: string, input?: ErrorInput<TPluginsMap>): Error0 &
|
|
178
|
+
new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
|
|
132
179
|
new (input: {
|
|
133
180
|
message: string;
|
|
134
|
-
} & ErrorInput<TPluginsMap>): Error0 &
|
|
181
|
+
} & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
|
|
135
182
|
readonly __pluginsMap?: TPluginsMap;
|
|
136
|
-
from: (error: unknown) => Error0 &
|
|
183
|
+
from: (error: unknown) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
|
|
184
|
+
resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>;
|
|
137
185
|
serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>;
|
|
138
|
-
|
|
186
|
+
own: {
|
|
187
|
+
(error: object): ErrorOwnProps<TPluginsMap>;
|
|
188
|
+
<TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey): ErrorOwnProps<TPluginsMap>[TKey];
|
|
189
|
+
};
|
|
190
|
+
flow: <TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>;
|
|
191
|
+
prop: <TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>) => ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
139
192
|
method: <TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
|
|
140
|
-
adapt: (value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>,
|
|
193
|
+
adapt: (value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>) => ClassError0<TPluginsMap>;
|
|
194
|
+
stack: (value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>;
|
|
195
|
+
cause: (value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>;
|
|
141
196
|
use: {
|
|
142
197
|
<TBuilder extends PluginError0>(plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<TPluginsMap, PluginOfBuilder<TBuilder>>>;
|
|
143
|
-
<TKey extends string, TInputValue, TOutputValue>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap
|
|
198
|
+
<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
144
199
|
<TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
|
|
145
|
-
(kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>,
|
|
200
|
+
(kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>): ClassError0<TPluginsMap>;
|
|
201
|
+
(kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>;
|
|
202
|
+
(kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>;
|
|
146
203
|
};
|
|
147
204
|
plugin: () => PluginError0;
|
|
148
205
|
} & ErrorStaticMethods<TPluginsMap>;
|
|
@@ -156,14 +213,24 @@ declare class Error0 extends Error {
|
|
|
156
213
|
message: string;
|
|
157
214
|
} & ErrorInput<EmptyPluginsMap>);
|
|
158
215
|
private static readonly isSelfProperty;
|
|
159
|
-
static
|
|
160
|
-
|
|
161
|
-
static
|
|
216
|
+
private static _ownByKey;
|
|
217
|
+
private static _flowByKey;
|
|
218
|
+
static own<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorOwnProps<PluginsMapOf<TThis>>;
|
|
219
|
+
static own<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(this: TThis, error: unknown, key: TKey): ErrorOwnProps<PluginsMapOf<TThis>>[TKey];
|
|
220
|
+
own<TThis extends Error0>(this: TThis): ErrorOwnProps<PluginsMapOfInstance<TThis>>;
|
|
221
|
+
own<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(this: TThis, key: TKey): ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey];
|
|
222
|
+
static flow<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(this: TThis, error: unknown, key: TKey): Array<ErrorOwnProps<PluginsMapOf<TThis>>[TKey]>;
|
|
223
|
+
static flow(error: unknown, key: string): unknown[];
|
|
224
|
+
flow<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(this: TThis, key: TKey): Array<ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey]>;
|
|
162
225
|
flow(key: string): unknown[];
|
|
226
|
+
static resolve<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorResolvedProps<PluginsMapOf<TThis>>;
|
|
227
|
+
static resolve(error: unknown): Record<string, unknown>;
|
|
228
|
+
resolve<TThis extends Error0>(this: TThis): ErrorResolvedProps<PluginsMapOfInstance<TThis>>;
|
|
229
|
+
resolve(): Record<string, unknown>;
|
|
163
230
|
static causes(error: unknown, instancesOnly?: false): unknown[];
|
|
164
231
|
static causes<T extends typeof Error0>(this: T, error: unknown, instancesOnly: true): Array<InstanceType<T>>;
|
|
165
|
-
causes<
|
|
166
|
-
causes<
|
|
232
|
+
causes<TThis extends Error0>(this: TThis, instancesOnly?: false): [TThis, ...unknown[]];
|
|
233
|
+
causes<TThis extends Error0>(this: TThis, instancesOnly: true): [TThis, ...TThis[]];
|
|
167
234
|
static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T>;
|
|
168
235
|
static isSerialized(error: unknown): error is Record<string, unknown>;
|
|
169
236
|
static from(error: unknown): Error0;
|
|
@@ -173,16 +240,20 @@ declare class Error0 extends Error {
|
|
|
173
240
|
private static _extractMessage;
|
|
174
241
|
private static _useWithPlugin;
|
|
175
242
|
private static _pluginFromBuilder;
|
|
176
|
-
static prop<TThis extends typeof Error0, TKey extends string, TInputValue, TOutputValue>(this: TThis, key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis
|
|
243
|
+
static prop<TThis extends typeof Error0, TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(this: TThis, key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
177
244
|
static method<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(this: TThis, key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>;
|
|
178
|
-
static adapt<TThis extends typeof Error0>(this: TThis, value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>,
|
|
245
|
+
static adapt<TThis extends typeof Error0>(this: TThis, value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
246
|
+
static stack<TThis extends typeof Error0>(this: TThis, value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
247
|
+
static cause<TThis extends typeof Error0>(this: TThis, value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
179
248
|
static use<TThis extends typeof Error0, TBuilder extends PluginError0>(this: TThis, plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>;
|
|
180
|
-
static use<TThis extends typeof Error0, TKey extends string, TInputValue, TOutputValue>(this: TThis, kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis
|
|
249
|
+
static use<TThis extends typeof Error0, TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(this: TThis, kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
181
250
|
static use<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(this: TThis, kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>;
|
|
182
|
-
static use<TThis extends typeof Error0>(this: TThis, kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>,
|
|
251
|
+
static use<TThis extends typeof Error0>(this: TThis, kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
252
|
+
static use<TThis extends typeof Error0>(this: TThis, kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
253
|
+
static use<TThis extends typeof Error0>(this: TThis, kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
183
254
|
static plugin(): PluginError0;
|
|
184
255
|
static serialize(error: unknown, isPublic?: boolean): Record<string, unknown>;
|
|
185
|
-
serialize(isPublic?: boolean):
|
|
256
|
+
serialize(isPublic?: boolean): Record<string, unknown>;
|
|
186
257
|
}
|
|
187
258
|
|
|
188
|
-
export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type
|
|
259
|
+
export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
|