@devp0nt/error0 1.0.0-next.40 → 1.0.0-next.42

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.
@@ -1,183 +1,188 @@
1
- type ErrorExtensionPropOptions<TInputValue, TOutputValue, TError extends Error0 = Error0> = {
2
- input: (value: TInputValue) => TOutputValue;
3
- output: (error: TError) => TOutputValue;
4
- serialize: (value: TOutputValue, error: TError, isPublic: boolean) => unknown;
5
- };
6
- type ErrorExtensionCopmputedFn<TOutputValue, TError extends Error0 = Error0> = (error: TError) => TOutputValue;
7
- type ErrorExtensionMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
8
- type ErrorExtensionRefineResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
9
- type ErrorExtensionRefineFn<TError extends Error0 = Error0, TOutputProps extends Record<string, unknown> = Record<never, never>> = ((error: TError) => void) | ((error: TError) => ErrorExtensionRefineResult<TOutputProps>);
1
+ type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false;
2
+ type NormalizeUnknownToUndefined<T> = IsUnknown<T> extends true ? undefined : T;
3
+ type IsOnlyUndefined<T> = [Exclude<T, undefined>] extends [never] ? true : false;
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>> = NormalizeUnknownToUndefined<InferFirstArg<TProp['init']>>;
6
+ type ErrorPluginPropInit<TInputValue, TOutputValue> = ((input: TInputValue) => TOutputValue) | (() => TOutputValue);
7
+ type ErrorPluginPropSerialize<TOutputValue, TError extends Error0> = ((options: {
8
+ value: TOutputValue;
9
+ error: TError;
10
+ isPublic: boolean;
11
+ }) => unknown) | false;
12
+ type ErrorPluginPropDeserialize<TOutputValue> = ((options: {
13
+ value: unknown;
14
+ serialized: Record<string, unknown>;
15
+ }) => TOutputValue | undefined) | false;
16
+ type ErrorPluginPropOptions<TInputValue, TOutputValue, TError extends Error0 = Error0> = {
17
+ init: ErrorPluginPropInit<TInputValue, TOutputValue>;
18
+ resolve: (options: {
19
+ value: TOutputValue | undefined;
20
+ flow: Array<TOutputValue | undefined>;
21
+ error: TError;
22
+ }) => TOutputValue | undefined;
23
+ serialize: ErrorPluginPropSerialize<TOutputValue, TError>;
24
+ deserialize: ErrorPluginPropDeserialize<TOutputValue>;
25
+ };
26
+ type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
27
+ type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
28
+ type ErrorPluginAdaptFn<TError extends Error0 = Error0, TOutputProps extends Record<string, unknown> = Record<never, never>> = ((error: TError) => void) | ((error: TError) => ErrorPluginAdaptResult<TOutputProps>);
10
29
  type ErrorMethodRecord = {
11
30
  args: unknown[];
12
31
  output: unknown;
13
32
  };
14
- type ErrorExtensionProps = {
15
- [key: string]: ErrorExtensionPropOptions<any, any>;
33
+ type ErrorPluginProps = {
34
+ [key: string]: ErrorPluginPropOptions<any, any>;
16
35
  };
17
- type ErrorExtensionComputed = {
18
- [key: string]: ErrorExtensionCopmputedFn<any>;
36
+ type ErrorPluginMethods = {
37
+ [key: string]: ErrorPluginMethodFn<any, any[]>;
19
38
  };
20
- type ErrorExtensionMethods = {
21
- [key: string]: ErrorExtensionMethodFn<any, any[]>;
22
- };
23
- type ErrorExtension<TProps extends ErrorExtensionProps = Record<never, never>, TComputed extends ErrorExtensionComputed = Record<never, never>, TMethods extends ErrorExtensionMethods = Record<never, never>> = {
39
+ type ErrorPlugin<TProps extends ErrorPluginProps = Record<never, never>, TMethods extends ErrorPluginMethods = Record<never, never>> = {
24
40
  props?: TProps;
25
- computed?: TComputed;
26
41
  methods?: TMethods;
27
- refine?: Array<ErrorExtensionRefineFn<Error0, ExtensionOutputProps<TProps>>>;
42
+ adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>;
28
43
  };
29
- type AddPropToExtensionProps<TProps extends ErrorExtensionProps, TKey extends string, TInputValue, TOutputValue> = TProps & Record<TKey, ErrorExtensionPropOptions<TInputValue, TOutputValue>>;
30
- type AddComputedToExtensionComputed<TComputed extends ErrorExtensionComputed, TKey extends string, TOutputValue> = TComputed & Record<TKey, ErrorExtensionCopmputedFn<TOutputValue>>;
31
- type AddMethodToExtensionMethods<TMethods extends ErrorExtensionMethods, TKey extends string, TArgs extends unknown[], TOutputValue> = TMethods & Record<TKey, ErrorExtensionMethodFn<TOutputValue, TArgs>>;
32
- type ExtensionOutputProps<TProps extends ErrorExtensionProps> = {
33
- [TKey in keyof TProps]: TProps[TKey] extends ErrorExtensionPropOptions<any, infer TOutputValue> ? TOutputValue : never;
44
+ type AddPropToPluginProps<TProps extends ErrorPluginProps, TKey extends string, TInputValue, TOutputValue> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue>>;
45
+ type AddMethodToPluginMethods<TMethods extends ErrorPluginMethods, TKey extends string, TArgs extends unknown[], TOutputValue> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>;
46
+ type PluginOutputProps<TProps extends ErrorPluginProps> = {
47
+ [TKey in keyof TProps]: TProps[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue> ? TOutputValue : never;
34
48
  };
35
- type ErrorExtensionsMap = {
49
+ type ErrorPluginsMap = {
36
50
  props: Record<string, {
37
- input: unknown;
38
- output: unknown;
51
+ init: unknown;
52
+ resolve: unknown;
39
53
  }>;
40
- computed: Record<string, unknown>;
41
54
  methods: Record<string, ErrorMethodRecord>;
42
55
  };
43
56
  type IsEmptyObject<T> = keyof T extends never ? true : false;
44
57
  type ErrorInputBase = {
45
58
  cause?: unknown;
46
59
  };
47
- type ErrorInput<TExtensionsMap extends ErrorExtensionsMap> = IsEmptyObject<TExtensionsMap['props']> extends true ? ErrorInputBase : ErrorInputBase & Partial<{
48
- [TKey in keyof TExtensionsMap['props']]: TExtensionsMap['props'][TKey]['input'];
49
- }>;
50
- type ErrorOutputProps<TExtensionsMap extends ErrorExtensionsMap> = {
51
- [TKey in keyof TExtensionsMap['props']]: TExtensionsMap['props'][TKey]['output'];
60
+ type ErrorInputPluginProps<TPluginsMap extends ErrorPluginsMap> = {
61
+ [TKey in keyof TPluginsMap['props'] as IsOnlyUndefined<TPluginsMap['props'][TKey]['init']> extends true ? never : TKey]?: TPluginsMap['props'][TKey]['init'];
52
62
  };
53
- type ErrorOutputComputed<TExtensionsMap extends ErrorExtensionsMap> = {
54
- [TKey in keyof TExtensionsMap['computed']]: TExtensionsMap['computed'][TKey];
63
+ type ErrorInput<TPluginsMap extends ErrorPluginsMap> = IsEmptyObject<TPluginsMap['props']> extends true ? ErrorInputBase : ErrorInputBase & ErrorInputPluginProps<TPluginsMap>;
64
+ type ErrorOutputProps<TPluginsMap extends ErrorPluginsMap> = {
65
+ [TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve'] | undefined;
55
66
  };
56
- type ErrorOutputMethods<TExtensionsMap extends ErrorExtensionsMap> = {
57
- [TKey in keyof TExtensionsMap['methods']]: TExtensionsMap['methods'][TKey] extends {
67
+ type ErrorOutputMethods<TPluginsMap extends ErrorPluginsMap> = {
68
+ [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
58
69
  args: infer TArgs extends unknown[];
59
70
  output: infer TOutput;
60
71
  } ? (...args: TArgs) => TOutput : never;
61
72
  };
62
- type ErrorOutput<TExtensionsMap extends ErrorExtensionsMap> = ErrorOutputProps<TExtensionsMap> & ErrorOutputComputed<TExtensionsMap> & ErrorOutputMethods<TExtensionsMap>;
63
- type ErrorStaticMethods<TExtensionsMap extends ErrorExtensionsMap> = {
64
- [TKey in keyof TExtensionsMap['methods']]: TExtensionsMap['methods'][TKey] extends {
73
+ type ErrorOutput<TPluginsMap extends ErrorPluginsMap> = ErrorOutputProps<TPluginsMap> & ErrorOutputMethods<TPluginsMap>;
74
+ type ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {
75
+ [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {
65
76
  args: infer TArgs extends unknown[];
66
77
  output: infer TOutput;
67
78
  } ? (error: unknown, ...args: TArgs) => TOutput : never;
68
79
  };
69
- type EmptyExtensionsMap = {
80
+ type EmptyPluginsMap = {
70
81
  props: Record<never, {
71
- input: never;
72
- output: never;
82
+ init: never;
83
+ resolve: never;
73
84
  }>;
74
- computed: Record<never, never>;
75
85
  methods: Record<never, ErrorMethodRecord>;
76
86
  };
77
- type ExtensionPropsMapOf<TExtension extends ErrorExtension> = {
78
- [TKey in keyof NonNullable<TExtension['props']>]: NonNullable<TExtension['props']>[TKey] extends ErrorExtensionPropOptions<infer TInputValue, infer TOutputValue> ? {
79
- input: TInputValue;
80
- output: TOutputValue;
87
+ type PluginPropsMapOf<TPlugin extends ErrorPlugin> = {
88
+ [TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<any, infer TOutputValue> ? {
89
+ init: InferPluginPropInput<NonNullable<TPlugin['props']>[TKey]>;
90
+ resolve: TOutputValue;
81
91
  } : never;
82
92
  };
83
- type ExtensionComputedMapOf<TExtension extends ErrorExtension> = {
84
- [TKey in keyof NonNullable<TExtension['computed']>]: NonNullable<TExtension['computed']>[TKey] extends ErrorExtensionCopmputedFn<infer TOutputValue> ? TOutputValue : never;
85
- };
86
- type ExtensionMethodsMapOf<TExtension extends ErrorExtension> = {
87
- [TKey in keyof NonNullable<TExtension['methods']>]: NonNullable<TExtension['methods']>[TKey] extends (error: Error0, ...args: infer TArgs extends unknown[]) => infer TOutput ? {
93
+ type PluginMethodsMapOf<TPlugin extends ErrorPlugin> = {
94
+ [TKey in keyof NonNullable<TPlugin['methods']>]: NonNullable<TPlugin['methods']>[TKey] extends (error: Error0, ...args: infer TArgs extends unknown[]) => infer TOutput ? {
88
95
  args: TArgs;
89
96
  output: TOutput;
90
97
  } : never;
91
98
  };
92
- type ErrorExtensionsMapOfExtension<TExtension extends ErrorExtension> = {
93
- props: ExtensionPropsMapOf<TExtension>;
94
- computed: ExtensionComputedMapOf<TExtension>;
95
- methods: ExtensionMethodsMapOf<TExtension>;
96
- };
97
- type ExtendErrorExtensionsMap<TMap extends ErrorExtensionsMap, TExtension extends ErrorExtension> = {
98
- props: TMap['props'] & ErrorExtensionsMapOfExtension<TExtension>['props'];
99
- computed: TMap['computed'] & ErrorExtensionsMapOfExtension<TExtension>['computed'];
100
- methods: TMap['methods'] & ErrorExtensionsMapOfExtension<TExtension>['methods'];
101
- };
102
- type ExtendErrorExtensionsMapWithProp<TMap extends ErrorExtensionsMap, TKey extends string, TInputValue, TOutputValue> = ExtendErrorExtensionsMap<TMap, ErrorExtension<Record<TKey, ErrorExtensionPropOptions<TInputValue, TOutputValue>>>>;
103
- type ExtendErrorExtensionsMapWithComputed<TMap extends ErrorExtensionsMap, TKey extends string, TOutputValue> = ExtendErrorExtensionsMap<TMap, ErrorExtension<Record<never, never>, Record<TKey, ErrorExtensionCopmputedFn<TOutputValue>>>>;
104
- type ExtendErrorExtensionsMapWithMethod<TMap extends ErrorExtensionsMap, TKey extends string, TArgs extends unknown[], TOutputValue> = ExtendErrorExtensionsMap<TMap, ErrorExtension<Record<never, never>, Record<never, never>, Record<TKey, ErrorExtensionMethodFn<TOutputValue, TArgs>>>>;
105
- type ExtensionsMapOf<TClass> = TClass extends {
106
- __extensionsMap?: infer TExtensionsMap;
107
- } ? TExtensionsMap extends ErrorExtensionsMap ? TExtensionsMap : EmptyExtensionsMap : EmptyExtensionsMap;
108
- type ExtensionsMapFromParts<TProps extends ErrorExtensionProps, TComputed extends ErrorExtensionComputed, TMethods extends ErrorExtensionMethods> = ErrorExtensionsMapOfExtension<ErrorExtension<TProps, TComputed, TMethods>>;
109
- type ErrorInstanceOfMap<TMap extends ErrorExtensionsMap> = Error0 & ErrorOutput<TMap>;
110
- type BuilderError0<TProps extends ErrorExtensionProps, TComputed extends ErrorExtensionComputed, TMethods extends ErrorExtensionMethods> = Error0 & ErrorOutput<ExtensionsMapFromParts<TProps, TComputed, TMethods>>;
111
- type ExtensionOfBuilder<TBuilder> = TBuilder extends ExtensionError0<infer TProps, infer TComputed, infer TMethods> ? ErrorExtension<TProps, TComputed, TMethods> : never;
112
- type ErrorFlowPolicy = 'instance' | 'error0' | 'likeError0' | 'all';
113
- declare class ExtensionError0<TProps extends ErrorExtensionProps = Record<never, never>, TComputed extends ErrorExtensionComputed = Record<never, never>, TMethods extends ErrorExtensionMethods = Record<never, never>> {
114
- private readonly _extension;
99
+ type ErrorPluginsMapOfPlugin<TPlugin extends ErrorPlugin> = {
100
+ props: PluginPropsMapOf<TPlugin>;
101
+ methods: PluginMethodsMapOf<TPlugin>;
102
+ };
103
+ type ExtendErrorPluginsMap<TMap extends ErrorPluginsMap, TPlugin extends ErrorPlugin> = {
104
+ props: TMap['props'] & ErrorPluginsMapOfPlugin<TPlugin>['props'];
105
+ methods: TMap['methods'] & ErrorPluginsMapOfPlugin<TPlugin>['methods'];
106
+ };
107
+ type ExtendErrorPluginsMapWithProp<TMap extends ErrorPluginsMap, TKey extends string, TInputValue, TOutputValue> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue>>>>;
108
+ type ExtendErrorPluginsMapWithMethod<TMap extends ErrorPluginsMap, TKey extends string, TArgs extends unknown[], TOutputValue> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<never, never>, Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>>>;
109
+ type PluginsMapOf<TClass> = TClass extends {
110
+ __pluginsMap?: infer TPluginsMap;
111
+ } ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
112
+ type PluginsMapFromParts<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>;
113
+ type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorOutput<TMap>;
114
+ type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 & ErrorOutput<PluginsMapFromParts<TProps, TMethods>>;
115
+ type PluginOfBuilder<TBuilder> = TBuilder extends PluginError0<infer TProps, infer TMethods> ? ErrorPlugin<TProps, TMethods> : never;
116
+ declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never>, TMethods extends ErrorPluginMethods = Record<never, never>> {
117
+ private readonly _plugin;
115
118
  readonly Infer: {
116
119
  props: TProps;
117
- computed: TComputed;
118
120
  methods: TMethods;
119
121
  };
120
- constructor(extension?: ErrorExtension<ErrorExtensionProps, ErrorExtensionComputed, ErrorExtensionMethods>);
121
- prop<TKey extends string, TInputValue, TOutputValue>(key: TKey, value: ErrorExtensionPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TComputed, TMethods>>): ExtensionError0<AddPropToExtensionProps<TProps, TKey, TInputValue, TOutputValue>, TComputed, TMethods>;
122
- computed<TKey extends string, TOutputValue>(key: TKey, value: ErrorExtensionCopmputedFn<TOutputValue, BuilderError0<TProps, TComputed, TMethods>>): ExtensionError0<TProps, AddComputedToExtensionComputed<TComputed, TKey, TOutputValue>, TMethods>;
123
- method<TKey extends string, TArgs extends unknown[], TOutputValue>(key: TKey, value: ErrorExtensionMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TComputed, TMethods>>): ExtensionError0<TProps, TComputed, AddMethodToExtensionMethods<TMethods, TKey, TArgs, TOutputValue>>;
124
- refine(value: ErrorExtensionRefineFn<BuilderError0<TProps, TComputed, TMethods>, ExtensionOutputProps<TProps>>): ExtensionError0<TProps, TComputed, TMethods>;
125
- extend<TKey extends string, TInputValue, TOutputValue>(kind: 'prop', key: TKey, value: ErrorExtensionPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TComputed, TMethods>>): ExtensionError0<AddPropToExtensionProps<TProps, TKey, TInputValue, TOutputValue>, TComputed, TMethods>;
126
- extend<TKey extends string, TOutputValue>(kind: 'computed', key: TKey, value: ErrorExtensionCopmputedFn<TOutputValue, BuilderError0<TProps, TComputed, TMethods>>): ExtensionError0<TProps, AddComputedToExtensionComputed<TComputed, TKey, TOutputValue>, TMethods>;
127
- extend<TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorExtensionMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TComputed, TMethods>>): ExtensionError0<TProps, TComputed, AddMethodToExtensionMethods<TMethods, TKey, TArgs, TOutputValue>>;
128
- extend(kind: 'refine', value: ErrorExtensionRefineFn<BuilderError0<TProps, TComputed, TMethods>, ExtensionOutputProps<TProps>>): ExtensionError0<TProps, TComputed, TMethods>;
122
+ constructor(plugin?: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>);
123
+ prop<TKey extends string, TInputValue, TOutputValue>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue>, TMethods>;
124
+ 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
+ adapt(value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
126
+ use<TKey extends string, TInputValue, TOutputValue>(kind: 'prop', key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue>, TMethods>;
127
+ 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
+ use(kind: 'adapt', value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
129
129
  }
130
- type ClassError0<TExtensionsMap extends ErrorExtensionsMap = EmptyExtensionsMap> = {
131
- new (message: string, input?: ErrorInput<TExtensionsMap>): Error0 & ErrorOutput<TExtensionsMap>;
130
+ type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
131
+ new (message: string, input?: ErrorInput<TPluginsMap>): Error0 & ErrorOutput<TPluginsMap>;
132
132
  new (input: {
133
133
  message: string;
134
- } & ErrorInput<TExtensionsMap>): Error0 & ErrorOutput<TExtensionsMap>;
135
- readonly __extensionsMap?: TExtensionsMap;
136
- from: (error: unknown) => Error0 & ErrorOutput<TExtensionsMap>;
137
- serialize: (error: unknown, isPublic?: boolean) => object;
138
- extend: {
139
- <TBuilder extends ExtensionError0>(extension: TBuilder): ClassError0<ExtendErrorExtensionsMap<TExtensionsMap, ExtensionOfBuilder<TBuilder>>>;
140
- <TKey extends string, TInputValue, TOutputValue>(kind: 'prop', key: TKey, value: ErrorExtensionPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TExtensionsMap>>): ClassError0<ExtendErrorExtensionsMapWithProp<TExtensionsMap, TKey, TInputValue, TOutputValue>>;
141
- <TKey extends string, TOutputValue>(kind: 'computed', key: TKey, value: ErrorExtensionCopmputedFn<TOutputValue, ErrorInstanceOfMap<TExtensionsMap>>): ClassError0<ExtendErrorExtensionsMapWithComputed<TExtensionsMap, TKey, TOutputValue>>;
142
- <TKey extends string, TArgs extends unknown[], TOutputValue>(kind: 'method', key: TKey, value: ErrorExtensionMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TExtensionsMap>>): ClassError0<ExtendErrorExtensionsMapWithMethod<TExtensionsMap, TKey, TArgs, TOutputValue>>;
143
- (kind: 'refine', value: ErrorExtensionRefineFn<ErrorInstanceOfMap<TExtensionsMap>, ErrorOutputProps<TExtensionsMap>>): ClassError0<TExtensionsMap>;
134
+ } & ErrorInput<TPluginsMap>): Error0 & ErrorOutput<TPluginsMap>;
135
+ readonly __pluginsMap?: TPluginsMap;
136
+ from: (error: unknown) => Error0 & ErrorOutput<TPluginsMap>;
137
+ serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>;
138
+ prop: <TKey extends string, TInputValue, TOutputValue>(key: TKey, value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue>>;
139
+ 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>, ErrorOutputProps<TPluginsMap>>) => ClassError0<TPluginsMap>;
141
+ use: {
142
+ <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>>): ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue>>;
144
+ <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>, ErrorOutputProps<TPluginsMap>>): ClassError0<TPluginsMap>;
144
146
  };
145
- extension: () => ExtensionError0;
146
- } & ErrorStaticMethods<TExtensionsMap>;
147
+ plugin: () => PluginError0;
148
+ } & ErrorStaticMethods<TPluginsMap>;
147
149
  declare class Error0 extends Error {
148
- static readonly __extensionsMap?: EmptyExtensionsMap;
149
- protected static _extensions: ErrorExtension[];
150
- private static readonly _emptyExtension;
151
- private static _getResolvedExtension;
152
- constructor(message: string, input?: ErrorInput<EmptyExtensionsMap>);
150
+ static readonly __pluginsMap?: EmptyPluginsMap;
151
+ protected static _plugins: ErrorPlugin[];
152
+ private static readonly _emptyPlugin;
153
+ private static _getResolvedPlugin;
154
+ constructor(message: string, input?: ErrorInput<EmptyPluginsMap>);
153
155
  constructor(input: {
154
156
  message: string;
155
- } & ErrorInput<EmptyExtensionsMap>);
157
+ } & ErrorInput<EmptyPluginsMap>);
156
158
  private static readonly isSelfProperty;
157
159
  static own(error: object, key: string): unknown;
158
160
  own(key: string): unknown;
159
- static flow(error: object, key: string, policy?: ErrorFlowPolicy): unknown[];
160
- flow(key: string, policy?: ErrorFlowPolicy): unknown[];
161
- static causes(error: object, policy?: ErrorFlowPolicy): object[];
162
- causes(policy?: ErrorFlowPolicy): object[];
163
- static is(error: unknown): error is Error0;
164
- static isError0(error: unknown): error is Error0;
165
- static isLikeError0(error: unknown): error is Error0 | object;
161
+ static flow(error: object, key: string): unknown[];
162
+ flow(key: string): unknown[];
163
+ static causes(error: unknown, instancesOnly?: false): unknown[];
164
+ static causes<T extends typeof Error0>(this: T, error: unknown, instancesOnly: true): Array<InstanceType<T>>;
165
+ causes<T extends typeof Error0>(this: T, instancesOnly?: false): [InstanceType<T>, ...unknown[]];
166
+ causes<T extends typeof Error0>(this: T, instancesOnly: true): [InstanceType<T>, ...Array<InstanceType<T>>];
167
+ static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T>;
168
+ static isSerialized(error: unknown): error is Record<string, unknown>;
166
169
  static from(error: unknown): Error0;
167
- private static _applyRefine;
168
- private static _fromLikeError0;
170
+ private static _applyAdapt;
171
+ private static _fromSerialized;
169
172
  private static _fromNonError0;
170
173
  private static _extractMessage;
171
- private static _extendWithExtension;
172
- private static _extensionFromBuilder;
173
- static extend<TThis extends typeof Error0, TBuilder extends ExtensionError0>(this: TThis, extension: TBuilder): ClassError0<ExtendErrorExtensionsMap<ExtensionsMapOf<TThis>, ExtensionOfBuilder<TBuilder>>>;
174
- static extend<TThis extends typeof Error0, TKey extends string, TInputValue, TOutputValue>(this: TThis, kind: 'prop', key: TKey, value: ErrorExtensionPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<ExtensionsMapOf<TThis>>>): ClassError0<ExtendErrorExtensionsMapWithProp<ExtensionsMapOf<TThis>, TKey, TInputValue, TOutputValue>>;
175
- static extend<TThis extends typeof Error0, TKey extends string, TOutputValue>(this: TThis, kind: 'computed', key: TKey, value: ErrorExtensionCopmputedFn<TOutputValue, ErrorInstanceOfMap<ExtensionsMapOf<TThis>>>): ClassError0<ExtendErrorExtensionsMapWithComputed<ExtensionsMapOf<TThis>, TKey, TOutputValue>>;
176
- static extend<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(this: TThis, kind: 'method', key: TKey, value: ErrorExtensionMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<ExtensionsMapOf<TThis>>>): ClassError0<ExtendErrorExtensionsMapWithMethod<ExtensionsMapOf<TThis>, TKey, TArgs, TOutputValue>>;
177
- static extend<TThis extends typeof Error0>(this: TThis, kind: 'refine', value: ErrorExtensionRefineFn<ErrorInstanceOfMap<ExtensionsMapOf<TThis>>, ErrorOutputProps<ExtensionsMapOf<TThis>>>): ClassError0<ExtensionsMapOf<TThis>>;
178
- static extension(): ExtensionError0;
179
- static serialize(error: unknown, isPublic?: boolean): object;
174
+ private static _useWithPlugin;
175
+ 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>>>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue>>;
177
+ 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>>, ErrorOutputProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
179
+ 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>>>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue>>;
181
+ 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>>, ErrorOutputProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
183
+ static plugin(): PluginError0;
184
+ static serialize(error: unknown, isPublic?: boolean): Record<string, unknown>;
180
185
  serialize(isPublic?: boolean): object;
181
186
  }
182
187
 
183
- export { type ClassError0, Error0, type ErrorExtension, type ErrorExtensionComputed, type ErrorExtensionCopmputedFn, type ErrorExtensionMethodFn, type ErrorExtensionMethods, type ErrorExtensionPropOptions, type ErrorExtensionProps, type ErrorExtensionRefineFn, type ErrorExtensionRefineResult, type ErrorExtensionsMap, type ErrorFlowPolicy, type ErrorInput, type ErrorInputBase, type ErrorOutput, ExtensionError0, type IsEmptyObject };
188
+ export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorOutput, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginsMap, type IsEmptyObject, PluginError0 };