@devp0nt/error0 1.0.0-next.53 → 1.0.0-next.54
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 +109 -105
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +42 -35
- package/dist/cjs/plugins/code.d.cts +40 -2
- package/dist/cjs/plugins/expected.d.cts +53 -11
- package/dist/cjs/plugins/meta.d.cts +40 -2
- package/dist/cjs/plugins/stack-merge.cjs +3 -3
- package/dist/cjs/plugins/stack-merge.cjs.map +1 -1
- package/dist/cjs/plugins/status.d.cts +40 -2
- package/dist/cjs/plugins/tags.d.cts +53 -11
- package/dist/esm/index.d.ts +42 -35
- package/dist/esm/index.js +109 -105
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/plugins/code.d.ts +40 -2
- package/dist/esm/plugins/expected.d.ts +53 -11
- package/dist/esm/plugins/meta.d.ts +40 -2
- package/dist/esm/plugins/stack-merge.js +3 -3
- package/dist/esm/plugins/stack-merge.js.map +1 -1
- package/dist/esm/plugins/status.d.ts +40 -2
- package/dist/esm/plugins/tags.d.ts +53 -11
- package/package.json +4 -2
- package/src/index.test.ts +187 -5
- package/src/index.ts +256 -246
- package/src/plugins/stack-merge.ts +2 -3
- package/src/plugins/tags.test.ts +1 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -35,6 +35,18 @@ type ErrorPluginPropOptionsWithoutInit<TOutputValue, TError extends Error0, TRes
|
|
|
35
35
|
init?: undefined;
|
|
36
36
|
};
|
|
37
37
|
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>;
|
|
38
|
+
type ErrorPluginPropOptionsBaseDefinition<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {
|
|
39
|
+
resolve?: ((options: ErrorPluginPropOptionsResolveOptions<TOutputValue, TError>) => TResolveValue) | boolean;
|
|
40
|
+
serialize?: ErrorPluginPropSerialize<TOutputValue, TError, TResolveValue>;
|
|
41
|
+
deserialize?: ErrorPluginPropDeserialize<TOutputValue>;
|
|
42
|
+
};
|
|
43
|
+
type ErrorPluginPropOptionsWithInitDefinition<TInputValue, TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = ErrorPluginPropOptionsBaseDefinition<TOutputValue, TError, TResolveValue> & {
|
|
44
|
+
init: ErrorPluginPropInit<TInputValue, TOutputValue>;
|
|
45
|
+
};
|
|
46
|
+
type ErrorPluginPropOptionsWithoutInitDefinition<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = ErrorPluginPropOptionsBaseDefinition<TOutputValue, TError, TResolveValue> & {
|
|
47
|
+
init?: undefined;
|
|
48
|
+
};
|
|
49
|
+
type ErrorPluginPropOptionsDefinition<TInputValue = undefined, TOutputValue = unknown, TError extends Error0 = Error0, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined> = ErrorPluginPropOptionsWithInitDefinition<TInputValue, TOutputValue, TError, TResolveValue> | ErrorPluginPropOptionsWithoutInitDefinition<TOutputValue, TError, TResolveValue>;
|
|
38
50
|
type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (error: TError, ...args: TArgs) => TOutputValue;
|
|
39
51
|
type ErrorPluginAnyMethodFn = (error: any, ...args: any[]) => any;
|
|
40
52
|
type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined;
|
|
@@ -116,15 +128,17 @@ type ErrorResolvedProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
|
116
128
|
type ErrorOwnProps<TPluginsMap extends ErrorPluginsMap> = {
|
|
117
129
|
[TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['output'] | undefined;
|
|
118
130
|
};
|
|
131
|
+
type ErrorResolveMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
132
|
+
resolve: () => ErrorResolvedProps<TPluginsMap>;
|
|
133
|
+
};
|
|
134
|
+
type Error0ResolvedInstance<TPluginsMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TPluginsMap> & ErrorResolveMethods<TPluginsMap>;
|
|
119
135
|
type ErrorOwnMethods<TPluginsMap extends ErrorPluginsMap> = {
|
|
120
|
-
own
|
|
121
|
-
(): ErrorOwnProps<TPluginsMap>;
|
|
122
|
-
<TKey extends keyof TPluginsMap['props'] & string>(key: TKey): ErrorOwnProps<TPluginsMap>[TKey];
|
|
123
|
-
};
|
|
136
|
+
own?: Partial<ErrorOwnProps<TPluginsMap>>;
|
|
124
137
|
flow: <TKey extends keyof TPluginsMap['props'] & string>(key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>;
|
|
138
|
+
assign: (props: Partial<ErrorOwnProps<TPluginsMap>>) => Error0ResolvedInstance<TPluginsMap>;
|
|
125
139
|
};
|
|
126
|
-
type
|
|
127
|
-
|
|
140
|
+
type InstanceError0<TPluginsMap extends ErrorPluginsMap> = Error0ResolvedInstance<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & {
|
|
141
|
+
readonly __pluginsMap?: TPluginsMap;
|
|
128
142
|
};
|
|
129
143
|
type BindInstanceMethod<TMethod> = TMethod extends (error: any, ...args: infer TArgs) => infer TOutput ? (...args: TArgs) => TOutput : never;
|
|
130
144
|
type BindStaticMethod<TMethod> = TMethod extends (error: any, ...args: infer TArgs) => infer TOutput ? (error: unknown, ...args: TArgs) => TOutput : never;
|
|
@@ -183,12 +197,8 @@ type PluginsMapOfInstance<TInstance> = TInstance extends {
|
|
|
183
197
|
__pluginsMap?: infer TPluginsMap;
|
|
184
198
|
} ? TPluginsMap extends ErrorPluginsMap ? TPluginsMap : EmptyPluginsMap : EmptyPluginsMap;
|
|
185
199
|
type PluginsMapFromParts<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>;
|
|
186
|
-
type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> =
|
|
187
|
-
|
|
188
|
-
};
|
|
189
|
-
type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 & ErrorResolved<PluginsMapFromParts<TProps, TMethods>> & ErrorOwnMethods<PluginsMapFromParts<TProps, TMethods>> & ErrorResolveMethods<PluginsMapFromParts<TProps, TMethods>> & {
|
|
190
|
-
readonly __pluginsMap?: PluginsMapFromParts<TProps, TMethods>;
|
|
191
|
-
};
|
|
200
|
+
type ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = InstanceError0<TMap>;
|
|
201
|
+
type BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = InstanceError0<PluginsMapFromParts<TProps, TMethods>>;
|
|
192
202
|
type PluginOfBuilder<TBuilder> = TBuilder extends PluginError0<infer TProps, infer TMethods> ? ErrorPlugin<TProps, TMethods> : never;
|
|
193
203
|
declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never>, TMethods extends ErrorPluginMethods = Record<never, never>> {
|
|
194
204
|
private readonly _plugin;
|
|
@@ -197,38 +207,36 @@ declare class PluginError0<TProps extends ErrorPluginProps = Record<never, never
|
|
|
197
207
|
methods: TMethods;
|
|
198
208
|
};
|
|
199
209
|
constructor(plugin?: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>);
|
|
200
|
-
prop<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(key: TKey, value:
|
|
210
|
+
prop<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(key: TKey, value: ErrorPluginPropOptionsDefinition<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>;
|
|
201
211
|
method<TKey extends string, TMethod extends (error: BuilderError0<TProps, TMethods>, ...args: any[]) => any>(key: TKey, value: TMethod): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TMethod>>;
|
|
202
212
|
adapt(value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
|
|
203
213
|
stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
204
214
|
cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
205
215
|
message(value: ErrorPluginMessage<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
206
|
-
use<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value:
|
|
216
|
+
use<TKey extends string, TInputValue = undefined, TOutputValue = unknown, TResolveValue extends TOutputValue | undefined = TOutputValue | undefined>(kind: 'prop', key: TKey, value: ErrorPluginPropOptionsDefinition<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>;
|
|
207
217
|
use<TKey extends string, TMethod extends (error: BuilderError0<TProps, TMethods>, ...args: any[]) => any>(kind: 'method', key: TKey, value: TMethod): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TMethod>>;
|
|
208
218
|
use(kind: 'adapt', value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>): PluginError0<TProps, TMethods>;
|
|
209
219
|
use(kind: 'stack', value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
210
220
|
use(kind: 'cause', value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
211
221
|
use(kind: 'message', value: ErrorPluginMessage<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>;
|
|
212
222
|
}
|
|
223
|
+
type ErrorOwnStore = Record<string, unknown>;
|
|
213
224
|
type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {
|
|
214
225
|
MAX_CAUSES_DEPTH: number;
|
|
215
|
-
new (message: string, input?: ErrorInput<TPluginsMap>):
|
|
216
|
-
readonly __pluginsMap?: TPluginsMap;
|
|
217
|
-
};
|
|
226
|
+
new (message: string, input?: ErrorInput<TPluginsMap>): InstanceError0<TPluginsMap>;
|
|
218
227
|
new (input: {
|
|
219
228
|
message: string;
|
|
220
|
-
} & ErrorInput<TPluginsMap>):
|
|
221
|
-
readonly __pluginsMap?: TPluginsMap;
|
|
222
|
-
};
|
|
229
|
+
} & ErrorInput<TPluginsMap>): InstanceError0<TPluginsMap>;
|
|
223
230
|
readonly __pluginsMap?: TPluginsMap;
|
|
224
|
-
from: (error: unknown) =>
|
|
225
|
-
round: (error: unknown, isPublic?: boolean) =>
|
|
231
|
+
from: <TThis extends ClassError0<any>>(this: TThis, error: unknown) => InstanceType<TThis>;
|
|
232
|
+
round: <TThis extends ClassError0<any>>(this: TThis, error: unknown, isPublic?: boolean) => InstanceType<TThis>;
|
|
226
233
|
causes: {
|
|
227
234
|
(error: unknown, instancesOnly?: false): unknown[];
|
|
228
|
-
(error: unknown, instancesOnly: true): Array<
|
|
235
|
+
(error: unknown, instancesOnly: true): Array<InstanceError0<TPluginsMap>>;
|
|
229
236
|
};
|
|
230
237
|
resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>;
|
|
231
238
|
serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>;
|
|
239
|
+
assign: <TThis extends ClassError0<any>>(this: TThis, error: unknown, props: Partial<ErrorOwnProps<PluginsMapOf<TThis>>>) => InstanceError0<PluginsMapOf<TThis>>;
|
|
232
240
|
own: {
|
|
233
241
|
(error: object): ErrorOwnProps<TPluginsMap>;
|
|
234
242
|
<TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey): ErrorOwnProps<TPluginsMap>[TKey];
|
|
@@ -251,6 +259,7 @@ declare class Error0 extends Error {
|
|
|
251
259
|
static MAX_CAUSES_DEPTH: number;
|
|
252
260
|
protected static _plugins: ErrorPlugin[];
|
|
253
261
|
protected static _resolvedPlugin?: ErrorPluginResolved;
|
|
262
|
+
own?: ErrorOwnStore;
|
|
254
263
|
private static readonly _emptyPlugin;
|
|
255
264
|
private static _indexResolvedPlugin;
|
|
256
265
|
private static _applyPlugin;
|
|
@@ -260,17 +269,13 @@ declare class Error0 extends Error {
|
|
|
260
269
|
constructor(input: {
|
|
261
270
|
message: string;
|
|
262
271
|
} & ErrorInput<EmptyPluginsMap>);
|
|
263
|
-
private static
|
|
264
|
-
private static readonly isOwnProperty;
|
|
265
|
-
private static _ownByKey;
|
|
266
|
-
private static _flowByKey;
|
|
272
|
+
private static fixStack;
|
|
267
273
|
static own<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorOwnProps<PluginsMapOf<TThis>>;
|
|
268
274
|
static own<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(this: TThis, error: unknown, key: TKey): ErrorOwnProps<PluginsMapOf<TThis>>[TKey];
|
|
269
|
-
own<TThis extends Error0>(this: TThis): ErrorOwnProps<PluginsMapOfInstance<TThis>>;
|
|
270
|
-
own<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(this: TThis, key: TKey): ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey];
|
|
271
275
|
static flow<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(this: TThis, error: unknown, key: TKey): Array<ErrorOwnProps<PluginsMapOf<TThis>>[TKey]>;
|
|
272
276
|
flow<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(this: TThis, key: TKey): Array<ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey]>;
|
|
273
|
-
|
|
277
|
+
private readonly _resolveByKeyCache;
|
|
278
|
+
private _resolveByKey;
|
|
274
279
|
static resolve<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorResolvedProps<PluginsMapOf<TThis>>;
|
|
275
280
|
static resolve(error: unknown): Record<string, unknown>;
|
|
276
281
|
resolve<TThis extends Error0>(this: TThis): ErrorResolvedProps<PluginsMapOfInstance<TThis>>;
|
|
@@ -280,8 +285,11 @@ declare class Error0 extends Error {
|
|
|
280
285
|
causes<TThis extends Error0>(this: TThis, instancesOnly: true): [TThis, ...TThis[]];
|
|
281
286
|
static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T>;
|
|
282
287
|
static isSerialized(error: unknown): error is Record<string, unknown>;
|
|
283
|
-
static from(error: unknown):
|
|
284
|
-
static round(error: unknown, isPublic?: boolean):
|
|
288
|
+
static from<TThis extends typeof Error0>(this: TThis, error: unknown): InstanceType<TThis>;
|
|
289
|
+
static round<TThis extends typeof Error0>(this: TThis, error: unknown, isPublic?: boolean): InstanceType<TThis>;
|
|
290
|
+
round<TThis extends Error0>(this: TThis, isPublic?: boolean): TThis;
|
|
291
|
+
static assign<TThis extends typeof Error0>(this: TThis, error: unknown, props: Partial<ErrorOwnProps<PluginsMapOf<TThis>>>): InstanceType<TThis>;
|
|
292
|
+
assign<TThis extends Error0>(this: TThis, props: Partial<ErrorOwnProps<PluginsMapOfInstance<TThis>>>): TThis;
|
|
285
293
|
private static _applyAdapt;
|
|
286
294
|
private static _fromSerialized;
|
|
287
295
|
private static _fromNonError0;
|
|
@@ -289,7 +297,7 @@ declare class Error0 extends Error {
|
|
|
289
297
|
private static _useWithPlugin;
|
|
290
298
|
private static _pluginFromBuilder;
|
|
291
299
|
static use<TThis extends typeof Error0, TBuilder extends PluginError0>(this: TThis, plugin: TBuilder): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>;
|
|
292
|
-
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:
|
|
300
|
+
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: ErrorPluginPropOptionsDefinition<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>;
|
|
293
301
|
static use<TThis extends typeof Error0, TKey extends string, TMethod extends (error: ErrorInstanceOfMap<PluginsMapOf<TThis>>, ...args: any[]) => any>(this: TThis, kind: 'method', key: TKey, value: TMethod): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TMethod>>;
|
|
294
302
|
static use<TThis extends typeof Error0>(this: TThis, kind: 'adapt', value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
295
303
|
static use<TThis extends typeof Error0>(this: TThis, kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>): ClassError0<PluginsMapOf<TThis>>;
|
|
@@ -298,7 +306,6 @@ declare class Error0 extends Error {
|
|
|
298
306
|
static plugin(): PluginError0;
|
|
299
307
|
static serialize(error: unknown, isPublic?: boolean): Record<string, unknown>;
|
|
300
308
|
serialize(isPublic?: boolean): Record<string, unknown>;
|
|
301
|
-
round<TThis extends Error0>(this: TThis, isPublic?: boolean): TThis;
|
|
302
309
|
}
|
|
303
310
|
|
|
304
|
-
export { type ClassError0, Error0, type
|
|
311
|
+
export { type ClassError0, Error0, type ErrorPlugin, type InstanceError0, PluginError0 };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
const RESERVED_STACK_PROP_ERROR = 'Error0: "stack" is a reserved prop key. Use .stack(...) plugin API instead';
|
|
2
2
|
const RESERVED_MESSAGE_PROP_ERROR = 'Error0: "message" is a reserved prop key. Use .message(...) plugin API instead';
|
|
3
|
+
const fromPropOptionsDefinition = (options) => {
|
|
4
|
+
let resolver;
|
|
5
|
+
if (!options.resolve) {
|
|
6
|
+
resolver = (options2) => options2.own;
|
|
7
|
+
} else if (options.resolve === true) {
|
|
8
|
+
resolver = (options2) => options2.flow.find((v) => v !== void 0);
|
|
9
|
+
} else if (typeof options.resolve === "function") {
|
|
10
|
+
resolver = options.resolve;
|
|
11
|
+
} else {
|
|
12
|
+
throw new Error("Invalid resolve option");
|
|
13
|
+
}
|
|
14
|
+
const serializer = options.serialize ?? false;
|
|
15
|
+
const deserializer = options.deserialize ?? false;
|
|
16
|
+
return {
|
|
17
|
+
...options,
|
|
18
|
+
resolve: resolver,
|
|
19
|
+
serialize: serializer,
|
|
20
|
+
deserialize: deserializer
|
|
21
|
+
};
|
|
22
|
+
};
|
|
3
23
|
class PluginError0 {
|
|
4
24
|
_plugin;
|
|
5
25
|
Infer = void 0;
|
|
@@ -49,7 +69,7 @@ class PluginError0 {
|
|
|
49
69
|
if (value === void 0) {
|
|
50
70
|
throw new Error('PluginError0.use("prop", key, value) requires value');
|
|
51
71
|
}
|
|
52
|
-
nextProps[key] = value;
|
|
72
|
+
nextProps[key] = fromPropOptionsDefinition(value);
|
|
53
73
|
} else if (kind === "method") {
|
|
54
74
|
const key = keyOrValue;
|
|
55
75
|
if (value === void 0) {
|
|
@@ -75,10 +95,8 @@ class PluginError0 {
|
|
|
75
95
|
});
|
|
76
96
|
}
|
|
77
97
|
}
|
|
78
|
-
const OWN_SYMBOL = Symbol("Error0.own");
|
|
79
98
|
class Error0 extends Error {
|
|
80
99
|
static __pluginsMap;
|
|
81
|
-
__pluginsMap;
|
|
82
100
|
static MAX_CAUSES_DEPTH = 99;
|
|
83
101
|
static _plugins = [];
|
|
84
102
|
static _resolvedPlugin;
|
|
@@ -164,122 +182,102 @@ class Error0 extends Error {
|
|
|
164
182
|
this.name = "Error0";
|
|
165
183
|
const ctor = this.constructor;
|
|
166
184
|
const plugin = ctor._getResolvedPlugin();
|
|
167
|
-
const ownStore = /* @__PURE__ */ Object.create(null);
|
|
168
|
-
Object.defineProperty(this, OWN_SYMBOL, { value: ownStore, writable: true, enumerable: false, configurable: true });
|
|
169
185
|
for (const [key, prop] of plugin.propEntries) {
|
|
170
186
|
if (key === "stack") {
|
|
171
187
|
continue;
|
|
172
188
|
}
|
|
173
189
|
Object.defineProperty(this, key, {
|
|
174
|
-
get: () =>
|
|
175
|
-
own: ownStore[key],
|
|
176
|
-
flow: this.flow(key),
|
|
177
|
-
error: this
|
|
178
|
-
}),
|
|
190
|
+
get: () => this._resolveByKey(key, plugin),
|
|
179
191
|
set: (value) => {
|
|
180
|
-
|
|
192
|
+
this.assign({ [key]: value });
|
|
181
193
|
},
|
|
182
194
|
enumerable: true,
|
|
183
195
|
configurable: true
|
|
184
196
|
});
|
|
185
197
|
if (key in input) {
|
|
186
|
-
const
|
|
187
|
-
|
|
198
|
+
const inputValue = input[key];
|
|
199
|
+
const ownValue = typeof prop.init === "function" ? prop.init(inputValue) : inputValue;
|
|
200
|
+
this.assign({ [key]: ownValue });
|
|
188
201
|
}
|
|
189
202
|
}
|
|
203
|
+
Error0.fixStack(input.cause);
|
|
190
204
|
}
|
|
191
|
-
static
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
};
|
|
206
|
-
static _ownByKey(error, key) {
|
|
207
|
-
const ownStore = this._getOwnStore(error);
|
|
208
|
-
if (ownStore) {
|
|
209
|
-
return ownStore[key];
|
|
210
|
-
}
|
|
211
|
-
return error[key];
|
|
212
|
-
}
|
|
213
|
-
static _flowByKey(error, key) {
|
|
214
|
-
const causes = this.causes(error, true);
|
|
215
|
-
const values = new Array(causes.length);
|
|
216
|
-
for (let i = 0; i < causes.length; i += 1) {
|
|
217
|
-
values[i] = this._ownByKey(causes[i], key);
|
|
205
|
+
static fixStack(cause) {
|
|
206
|
+
try {
|
|
207
|
+
if (process.env.NODE_ENV !== "production") {
|
|
208
|
+
let nextCause = cause;
|
|
209
|
+
let depth = 0;
|
|
210
|
+
const maxDepth = 99;
|
|
211
|
+
while (nextCause && depth < maxDepth) {
|
|
212
|
+
;
|
|
213
|
+
globalThis.__ERROR0_FIX_STACKTRACE__(nextCause);
|
|
214
|
+
nextCause = nextCause.cause;
|
|
215
|
+
depth++;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} catch {
|
|
218
219
|
}
|
|
219
|
-
return values;
|
|
220
220
|
}
|
|
221
221
|
static own(error, key) {
|
|
222
222
|
const error0 = this.from(error);
|
|
223
223
|
if (key === void 0) {
|
|
224
|
-
|
|
225
|
-
const plugin = this._getResolvedPlugin();
|
|
226
|
-
for (const ownKey of plugin.propKeys) {
|
|
227
|
-
ownValues[ownKey] = this._ownByKey(error0, ownKey);
|
|
228
|
-
}
|
|
229
|
-
return ownValues;
|
|
224
|
+
return error0.own ?? {};
|
|
230
225
|
}
|
|
231
|
-
return
|
|
232
|
-
}
|
|
233
|
-
own(key) {
|
|
234
|
-
const ctor = this.constructor;
|
|
235
|
-
if (key === void 0) {
|
|
236
|
-
return ctor.own(this);
|
|
237
|
-
}
|
|
238
|
-
return ctor._ownByKey(this, key);
|
|
226
|
+
return error0.own?.[key];
|
|
239
227
|
}
|
|
240
228
|
static flow(error, key) {
|
|
241
229
|
const error0 = this.from(error);
|
|
242
|
-
return
|
|
230
|
+
return error0.flow(key);
|
|
243
231
|
}
|
|
244
232
|
flow(key) {
|
|
245
|
-
const
|
|
246
|
-
|
|
233
|
+
const causes = this.causes(true);
|
|
234
|
+
const values = new Array(causes.length);
|
|
235
|
+
for (let i = 0; i < causes.length; i += 1) {
|
|
236
|
+
values[i] = causes[i].own?.[key];
|
|
237
|
+
}
|
|
238
|
+
return values;
|
|
247
239
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
},
|
|
254
|
-
get flow() {
|
|
255
|
-
return error.flow(key);
|
|
256
|
-
},
|
|
257
|
-
error
|
|
258
|
-
};
|
|
259
|
-
const prop = plugin.props[key];
|
|
260
|
-
const resolver = prop.resolve;
|
|
261
|
-
if (!resolver) {
|
|
262
|
-
return error[key];
|
|
263
|
-
}
|
|
264
|
-
return resolver(options);
|
|
265
|
-
} catch {
|
|
266
|
-
console.error(`Error0: failed to resolve property ${key}`, error);
|
|
267
|
-
return void 0;
|
|
240
|
+
_resolveByKeyCache = /* @__PURE__ */ new Map();
|
|
241
|
+
_resolveByKey(key, plugin) {
|
|
242
|
+
const error = this;
|
|
243
|
+
if (this._resolveByKeyCache.has(key)) {
|
|
244
|
+
return this._resolveByKeyCache.get(key);
|
|
268
245
|
}
|
|
246
|
+
const value = (() => {
|
|
247
|
+
try {
|
|
248
|
+
const options = {
|
|
249
|
+
get flow() {
|
|
250
|
+
return error.flow(key);
|
|
251
|
+
},
|
|
252
|
+
own: error.own?.[key],
|
|
253
|
+
error
|
|
254
|
+
};
|
|
255
|
+
const prop = plugin.props[key];
|
|
256
|
+
const resolver = prop.resolve;
|
|
257
|
+
if (!resolver) {
|
|
258
|
+
return error[key];
|
|
259
|
+
}
|
|
260
|
+
return resolver(options);
|
|
261
|
+
} catch {
|
|
262
|
+
console.error(`Error0: failed to resolve property ${key}`, error);
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
})();
|
|
266
|
+
this._resolveByKeyCache.set(key, value);
|
|
267
|
+
return value;
|
|
269
268
|
}
|
|
270
269
|
static resolve(error) {
|
|
271
|
-
|
|
270
|
+
return this.from(error).resolve();
|
|
271
|
+
}
|
|
272
|
+
resolve() {
|
|
273
|
+
const ctor = this.constructor;
|
|
274
|
+
const plugin = ctor._getResolvedPlugin();
|
|
272
275
|
const resolved = {};
|
|
273
|
-
const plugin = this._getResolvedPlugin();
|
|
274
276
|
for (const key of plugin.propKeys) {
|
|
275
|
-
resolved[key] = this._resolveByKey(
|
|
277
|
+
resolved[key] = this._resolveByKey(key, plugin);
|
|
276
278
|
}
|
|
277
279
|
return resolved;
|
|
278
280
|
}
|
|
279
|
-
resolve() {
|
|
280
|
-
const ctor = this.constructor;
|
|
281
|
-
return ctor.resolve(this);
|
|
282
|
-
}
|
|
283
281
|
static causes(error, instancesOnly) {
|
|
284
282
|
const causes = [];
|
|
285
283
|
let current = error;
|
|
@@ -324,14 +322,27 @@ class Error0 extends Error {
|
|
|
324
322
|
return this._fromNonError0(error);
|
|
325
323
|
}
|
|
326
324
|
static round(error, isPublic = false) {
|
|
327
|
-
return this.from(
|
|
325
|
+
return this.from(error).round(isPublic);
|
|
326
|
+
}
|
|
327
|
+
round(isPublic = true) {
|
|
328
|
+
const ctor = this.constructor;
|
|
329
|
+
return ctor.from(this.serialize(isPublic));
|
|
330
|
+
}
|
|
331
|
+
static assign(error, props) {
|
|
332
|
+
const error0 = this.from(error);
|
|
333
|
+
return error0.assign(props);
|
|
334
|
+
}
|
|
335
|
+
assign(props) {
|
|
336
|
+
this.own = Object.assign(this.own ?? {}, props);
|
|
337
|
+
this._resolveByKeyCache.clear();
|
|
338
|
+
return this;
|
|
328
339
|
}
|
|
329
340
|
static _applyAdapt(error) {
|
|
330
341
|
const plugin = this._getResolvedPlugin();
|
|
331
342
|
for (const adapt of plugin.adapt) {
|
|
332
343
|
const adapted = adapt(error);
|
|
333
344
|
if (adapted && typeof adapted === "object") {
|
|
334
|
-
|
|
345
|
+
error.assign(adapted);
|
|
335
346
|
}
|
|
336
347
|
}
|
|
337
348
|
return error;
|
|
@@ -478,7 +489,7 @@ class Error0 extends Error {
|
|
|
478
489
|
throw new Error(RESERVED_MESSAGE_PROP_ERROR);
|
|
479
490
|
}
|
|
480
491
|
return this._useWithPlugin({
|
|
481
|
-
props: { [key]: value }
|
|
492
|
+
props: { [key]: fromPropOptionsDefinition(value) }
|
|
482
493
|
});
|
|
483
494
|
}
|
|
484
495
|
return this._useWithPlugin({
|
|
@@ -489,9 +500,12 @@ class Error0 extends Error {
|
|
|
489
500
|
return new PluginError0();
|
|
490
501
|
}
|
|
491
502
|
static serialize(error, isPublic = true) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
503
|
+
return this.from(error).serialize(isPublic);
|
|
504
|
+
}
|
|
505
|
+
serialize(isPublic = true) {
|
|
506
|
+
const error0 = this;
|
|
507
|
+
const ctor = error0.constructor;
|
|
508
|
+
const plugin = ctor._getResolvedPlugin();
|
|
495
509
|
const messagePlugin = plugin.message;
|
|
496
510
|
let serializedMessage = error0.message;
|
|
497
511
|
try {
|
|
@@ -514,15 +528,13 @@ class Error0 extends Error {
|
|
|
514
528
|
}
|
|
515
529
|
try {
|
|
516
530
|
const options = {
|
|
517
|
-
get own() {
|
|
518
|
-
return error0.own(key);
|
|
519
|
-
},
|
|
520
531
|
get flow() {
|
|
521
532
|
return error0.flow(key);
|
|
522
533
|
},
|
|
523
534
|
get resolved() {
|
|
524
|
-
return
|
|
535
|
+
return error0._resolveByKey(key, plugin);
|
|
525
536
|
},
|
|
537
|
+
own: error0.own?.[key],
|
|
526
538
|
error: error0,
|
|
527
539
|
isPublic
|
|
528
540
|
};
|
|
@@ -555,8 +567,8 @@ class Error0 extends Error {
|
|
|
555
567
|
cause: error0.cause,
|
|
556
568
|
error: error0,
|
|
557
569
|
isPublic,
|
|
558
|
-
is: (cause) =>
|
|
559
|
-
serialize: (cause) =>
|
|
570
|
+
is: (cause) => ctor.is(cause),
|
|
571
|
+
serialize: (cause) => ctor.serialize(cause, isPublic)
|
|
560
572
|
});
|
|
561
573
|
if (serializedCause !== void 0) {
|
|
562
574
|
json.cause = serializedCause;
|
|
@@ -567,14 +579,6 @@ class Error0 extends Error {
|
|
|
567
579
|
}
|
|
568
580
|
return json;
|
|
569
581
|
}
|
|
570
|
-
serialize(isPublic = true) {
|
|
571
|
-
const ctor = this.constructor;
|
|
572
|
-
return ctor.serialize(this, isPublic);
|
|
573
|
-
}
|
|
574
|
-
round(isPublic = true) {
|
|
575
|
-
const ctor = this.constructor;
|
|
576
|
-
return ctor.round(this, isPublic);
|
|
577
|
-
}
|
|
578
582
|
}
|
|
579
583
|
export {
|
|
580
584
|
Error0,
|