@devp0nt/error0 1.0.0-next.43 → 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.
@@ -17,7 +17,7 @@ type ErrorPluginPropDeserialize<TOutputValue> = ((options: {
17
17
  }) => TOutputValue | undefined) | false;
18
18
  type ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {
19
19
  resolve: (options: {
20
- value: TOutputValue | undefined;
20
+ own: TOutputValue | undefined;
21
21
  flow: Array<TOutputValue | undefined>;
22
22
  error: TError;
23
23
  }) => TResolveValue;
@@ -34,6 +34,18 @@ type ErrorPluginPropOptions<TInputValue = undefined, TOutputValue = unknown, TEr
34
34
  type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
35
35
  type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
36
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>;
37
49
  type ErrorMethodRecord = {
38
50
  args: unknown[];
39
51
  output: unknown;
@@ -48,6 +60,8 @@ type ErrorPlugin<TProps extends ErrorPluginProps = Record<never, never>, TMethod
48
60
  props?: TProps;
49
61
  methods?: TMethods;
50
62
  adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>;
63
+ stack?: ErrorPluginStack;
64
+ cause?: ErrorPluginCause;
51
65
  };
52
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>>;
53
67
  type AddMethodToPluginMethods<TMethods extends ErrorPluginMethods, TKey extends string, TArgs extends unknown[], TOutputValue> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>;
@@ -57,6 +71,7 @@ type PluginOutputProps<TProps extends ErrorPluginProps> = {
57
71
  type ErrorPluginsMap = {
58
72
  props: Record<string, {
59
73
  init: unknown;
74
+ output: unknown;
60
75
  resolve: unknown;
61
76
  }>;
62
77
  methods: Record<string, ErrorMethodRecord>;
@@ -72,6 +87,19 @@ type ErrorInput<TPluginsMap extends ErrorPluginsMap> = IsEmptyObject<TPluginsMap
72
87
  type ErrorResolvedProps<TPluginsMap extends ErrorPluginsMap> = {
73
88
  [TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve'];
74
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]>;
99
+ };
100
+ type ErrorResolveMethods<TPluginsMap extends ErrorPluginsMap> = {
101
+ resolve: () => ErrorResolvedProps<TPluginsMap>;
102
+ };
75
103
  type ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {
76
104
  [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
77
105
  args: infer TArgs extends unknown[];
@@ -88,13 +116,15 @@ type ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {
88
116
  type EmptyPluginsMap = {
89
117
  props: Record<never, {
90
118
  init: never;
119
+ output: never;
91
120
  resolve: never;
92
121
  }>;
93
122
  methods: Record<never, ErrorMethodRecord>;
94
123
  };
95
124
  type PluginPropsMapOf<TPlugin extends ErrorPlugin> = {
96
- [TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, any, any, infer TResolveValue> ? {
125
+ [TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue, any, infer TResolveValue> ? {
97
126
  init: InferPluginPropInput<NonNullable<TPlugin['props']>[TKey]>;
127
+ output: TOutputValue;
98
128
  resolve: TResolveValue;
99
129
  } : never;
100
130
  };
@@ -117,6 +147,11 @@ type ExtendErrorPluginsMapWithMethod<TMap extends ErrorPluginsMap, TKey extends
117
147
  type PluginsMapOf<TClass> = TClass extends {
118
148
  __pluginsMap?: infer TPluginsMap;
119
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;
120
155
  type PluginsMapFromParts<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>;
121
156
  type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TMap>;
122
157
  type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 & ErrorResolved<PluginsMapFromParts<TProps, TMethods>>;
@@ -131,26 +166,40 @@ declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never
131
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>;
132
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>>;
133
168
  adapt(value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
169
+ stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
170
+ cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
134
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>;
135
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>>;
136
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>;
137
176
  }
138
177
  type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
139
- new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap>;
178
+ new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
140
179
  new (input: {
141
180
  message: string;
142
- } & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap>;
181
+ } & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
143
182
  readonly __pluginsMap?: TPluginsMap;
144
- from: (error: unknown) => Error0 & ErrorResolved<TPluginsMap>;
183
+ from: (error: unknown) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
184
+ resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>;
145
185
  serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>;
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]>;
146
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>>;
147
192
  method: <TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
148
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>;
149
196
  use: {
150
197
  <TBuilder extends PluginError0>(plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<TPluginsMap, PluginOfBuilder<TBuilder>>>;
151
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>>;
152
199
  <TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
153
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>;
154
203
  };
155
204
  plugin: () => PluginError0;
156
205
  } & ErrorStaticMethods<TPluginsMap>;
@@ -164,14 +213,24 @@ declare class Error0 extends Error {
164
213
  message: string;
165
214
  } & ErrorInput<EmptyPluginsMap>);
166
215
  private static readonly isSelfProperty;
167
- static own(error: object, key: string): unknown;
168
- own(key: string): unknown;
169
- static flow(error: object, key: string): unknown[];
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]>;
170
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>;
171
230
  static causes(error: unknown, instancesOnly?: false): unknown[];
172
231
  static causes<T extends typeof Error0>(this: T, error: unknown, instancesOnly: true): Array<InstanceType<T>>;
173
- causes<T extends typeof Error0>(this: T, instancesOnly?: false): [InstanceType<T>, ...unknown[]];
174
- causes<T extends typeof Error0>(this: T, instancesOnly: true): [InstanceType<T>, ...Array<InstanceType<T>>];
232
+ causes<TThis extends Error0>(this: TThis, instancesOnly?: false): [TThis, ...unknown[]];
233
+ causes<TThis extends Error0>(this: TThis, instancesOnly: true): [TThis, ...TThis[]];
175
234
  static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T>;
176
235
  static isSerialized(error: unknown): error is Record<string, unknown>;
177
236
  static from(error: unknown): Error0;
@@ -184,13 +243,17 @@ declare class Error0 extends Error {
184
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>>;
185
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>>;
186
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>>;
187
248
  static use<TThis extends typeof Error0, TBuilder extends PluginError0>(this: TThis, plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>;
188
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>>;
189
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>>;
190
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>>;
191
254
  static plugin(): PluginError0;
192
255
  static serialize(error: unknown, isPublic?: boolean): Record<string, unknown>;
193
- serialize(isPublic?: boolean): object;
256
+ serialize(isPublic?: boolean): Record<string, unknown>;
194
257
  }
195
258
 
196
- export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
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 };
@@ -17,7 +17,7 @@ type ErrorPluginPropDeserialize<TOutputValue> = ((options: {
17
17
  }) => TOutputValue | undefined) | false;
18
18
  type ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {
19
19
  resolve: (options: {
20
- value: TOutputValue | undefined;
20
+ own: TOutputValue | undefined;
21
21
  flow: Array<TOutputValue | undefined>;
22
22
  error: TError;
23
23
  }) => TResolveValue;
@@ -34,6 +34,18 @@ type ErrorPluginPropOptions<TInputValue = undefined, TOutputValue = unknown, TEr
34
34
  type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
35
35
  type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
36
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>;
37
49
  type ErrorMethodRecord = {
38
50
  args: unknown[];
39
51
  output: unknown;
@@ -48,6 +60,8 @@ type ErrorPlugin<TProps extends ErrorPluginProps = Record<never, never>, TMethod
48
60
  props?: TProps;
49
61
  methods?: TMethods;
50
62
  adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>;
63
+ stack?: ErrorPluginStack;
64
+ cause?: ErrorPluginCause;
51
65
  };
52
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>>;
53
67
  type AddMethodToPluginMethods<TMethods extends ErrorPluginMethods, TKey extends string, TArgs extends unknown[], TOutputValue> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>;
@@ -57,6 +71,7 @@ type PluginOutputProps<TProps extends ErrorPluginProps> = {
57
71
  type ErrorPluginsMap = {
58
72
  props: Record<string, {
59
73
  init: unknown;
74
+ output: unknown;
60
75
  resolve: unknown;
61
76
  }>;
62
77
  methods: Record<string, ErrorMethodRecord>;
@@ -72,6 +87,19 @@ type ErrorInput<TPluginsMap extends ErrorPluginsMap> = IsEmptyObject<TPluginsMap
72
87
  type ErrorResolvedProps<TPluginsMap extends ErrorPluginsMap> = {
73
88
  [TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve'];
74
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]>;
99
+ };
100
+ type ErrorResolveMethods<TPluginsMap extends ErrorPluginsMap> = {
101
+ resolve: () => ErrorResolvedProps<TPluginsMap>;
102
+ };
75
103
  type ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {
76
104
  [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
77
105
  args: infer TArgs extends unknown[];
@@ -88,13 +116,15 @@ type ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {
88
116
  type EmptyPluginsMap = {
89
117
  props: Record<never, {
90
118
  init: never;
119
+ output: never;
91
120
  resolve: never;
92
121
  }>;
93
122
  methods: Record<never, ErrorMethodRecord>;
94
123
  };
95
124
  type PluginPropsMapOf<TPlugin extends ErrorPlugin> = {
96
- [TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, any, any, infer TResolveValue> ? {
125
+ [TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue, any, infer TResolveValue> ? {
97
126
  init: InferPluginPropInput<NonNullable<TPlugin['props']>[TKey]>;
127
+ output: TOutputValue;
98
128
  resolve: TResolveValue;
99
129
  } : never;
100
130
  };
@@ -117,6 +147,11 @@ type ExtendErrorPluginsMapWithMethod<TMap extends ErrorPluginsMap, TKey extends
117
147
  type PluginsMapOf<TClass> = TClass extends {
118
148
  __pluginsMap?: infer TPluginsMap;
119
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;
120
155
  type PluginsMapFromParts<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>;
121
156
  type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TMap>;
122
157
  type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 & ErrorResolved<PluginsMapFromParts<TProps, TMethods>>;
@@ -131,26 +166,40 @@ declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never
131
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>;
132
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>>;
133
168
  adapt(value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
169
+ stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
170
+ cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
134
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>;
135
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>>;
136
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>;
137
176
  }
138
177
  type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
139
- new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap>;
178
+ new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
140
179
  new (input: {
141
180
  message: string;
142
- } & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap>;
181
+ } & ErrorInput<TPluginsMap>): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
143
182
  readonly __pluginsMap?: TPluginsMap;
144
- from: (error: unknown) => Error0 & ErrorResolved<TPluginsMap>;
183
+ from: (error: unknown) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
184
+ resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>;
145
185
  serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>;
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]>;
146
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>>;
147
192
  method: <TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
148
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>;
149
196
  use: {
150
197
  <TBuilder extends PluginError0>(plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<TPluginsMap, PluginOfBuilder<TBuilder>>>;
151
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>>;
152
199
  <TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>;
153
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>;
154
203
  };
155
204
  plugin: () => PluginError0;
156
205
  } & ErrorStaticMethods<TPluginsMap>;
@@ -164,14 +213,24 @@ declare class Error0 extends Error {
164
213
  message: string;
165
214
  } & ErrorInput<EmptyPluginsMap>);
166
215
  private static readonly isSelfProperty;
167
- static own(error: object, key: string): unknown;
168
- own(key: string): unknown;
169
- static flow(error: object, key: string): unknown[];
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]>;
170
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>;
171
230
  static causes(error: unknown, instancesOnly?: false): unknown[];
172
231
  static causes<T extends typeof Error0>(this: T, error: unknown, instancesOnly: true): Array<InstanceType<T>>;
173
- causes<T extends typeof Error0>(this: T, instancesOnly?: false): [InstanceType<T>, ...unknown[]];
174
- causes<T extends typeof Error0>(this: T, instancesOnly: true): [InstanceType<T>, ...Array<InstanceType<T>>];
232
+ causes<TThis extends Error0>(this: TThis, instancesOnly?: false): [TThis, ...unknown[]];
233
+ causes<TThis extends Error0>(this: TThis, instancesOnly: true): [TThis, ...TThis[]];
175
234
  static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T>;
176
235
  static isSerialized(error: unknown): error is Record<string, unknown>;
177
236
  static from(error: unknown): Error0;
@@ -184,13 +243,17 @@ declare class Error0 extends Error {
184
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>>;
185
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>>;
186
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>>;
187
248
  static use<TThis extends typeof Error0, TBuilder extends PluginError0>(this: TThis, plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>;
188
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>>;
189
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>>;
190
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>>;
191
254
  static plugin(): PluginError0;
192
255
  static serialize(error: unknown, isPublic?: boolean): Record<string, unknown>;
193
- serialize(isPublic?: boolean): object;
256
+ serialize(isPublic?: boolean): Record<string, unknown>;
194
257
  }
195
258
 
196
- export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
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 };