@devp0nt/error0 1.0.0-next.46 → 1.0.0-next.47
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 +80 -49
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +32 -12
- package/dist/cjs/plugins/cause-serialize.cjs +38 -0
- package/dist/cjs/plugins/cause-serialize.cjs.map +1 -0
- package/dist/cjs/plugins/cause-serialize.d.cts +5 -0
- package/dist/cjs/plugins/expected.cjs +49 -0
- package/dist/cjs/plugins/expected.cjs.map +1 -0
- package/dist/cjs/plugins/expected.d.cts +5 -0
- package/dist/cjs/plugins/message-merge.cjs +36 -0
- package/dist/cjs/plugins/message-merge.cjs.map +1 -0
- package/dist/cjs/plugins/message-merge.d.cts +5 -0
- package/dist/cjs/plugins/meta.cjs +73 -0
- package/dist/cjs/plugins/meta.cjs.map +1 -0
- package/dist/cjs/plugins/meta.d.cts +5 -0
- package/dist/cjs/plugins/stack-merge.cjs +39 -0
- package/dist/cjs/plugins/stack-merge.cjs.map +1 -0
- package/dist/cjs/plugins/stack-merge.d.cts +5 -0
- package/dist/cjs/plugins/tags.cjs +48 -0
- package/dist/cjs/plugins/tags.cjs.map +1 -0
- package/dist/cjs/plugins/tags.d.cts +5 -0
- package/dist/esm/index.d.ts +32 -12
- package/dist/esm/index.js +80 -49
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/plugins/cause-serialize.d.ts +5 -0
- package/dist/esm/plugins/cause-serialize.js +14 -0
- package/dist/esm/plugins/cause-serialize.js.map +1 -0
- package/dist/esm/plugins/expected.d.ts +5 -0
- package/dist/esm/plugins/expected.js +25 -0
- package/dist/esm/plugins/expected.js.map +1 -0
- package/dist/esm/plugins/message-merge.d.ts +5 -0
- package/dist/esm/plugins/message-merge.js +12 -0
- package/dist/esm/plugins/message-merge.js.map +1 -0
- package/dist/esm/plugins/meta.d.ts +5 -0
- package/dist/esm/plugins/meta.js +49 -0
- package/dist/esm/plugins/meta.js.map +1 -0
- package/dist/esm/plugins/stack-merge.d.ts +5 -0
- package/dist/esm/plugins/stack-merge.js +15 -0
- package/dist/esm/plugins/stack-merge.js.map +1 -0
- package/dist/esm/plugins/tags.d.ts +5 -0
- package/dist/esm/plugins/tags.js +24 -0
- package/dist/esm/plugins/tags.js.map +1 -0
- package/package.json +9 -1
- package/src/index.test.ts +56 -79
- package/src/index.ts +117 -64
- package/src/plugins/cause-serialize.test.ts +51 -0
- package/src/plugins/cause-serialize.ts +11 -0
- package/src/plugins/expected.test.ts +47 -0
- package/src/plugins/expected.ts +25 -0
- package/src/plugins/message-merge.test.ts +32 -0
- package/src/plugins/message-merge.ts +15 -0
- package/src/plugins/meta.test.ts +32 -0
- package/src/plugins/meta.ts +53 -0
- package/src/plugins/stack-merge.test.ts +64 -0
- package/src/plugins/stack-merge.ts +16 -0
- package/src/plugins/tags.test.ts +22 -0
- package/src/plugins/tags.ts +21 -0
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const RESERVED_STACK_PROP_ERROR = 'Error0: "stack" is a reserved prop key. Use .stack(...) plugin API instead';
|
|
2
|
+
const RESERVED_MESSAGE_PROP_ERROR = 'Error0: "message" is a reserved prop key. Use .message(...) plugin API instead';
|
|
2
3
|
class PluginError0 {
|
|
3
4
|
_plugin;
|
|
4
5
|
Infer = void 0;
|
|
@@ -8,7 +9,8 @@ class PluginError0 {
|
|
|
8
9
|
methods: { ...plugin?.methods ?? {} },
|
|
9
10
|
adapt: [...plugin?.adapt ?? []],
|
|
10
11
|
stack: plugin?.stack,
|
|
11
|
-
cause: plugin?.cause
|
|
12
|
+
cause: plugin?.cause,
|
|
13
|
+
message: plugin?.message
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
16
|
prop(key, value) {
|
|
@@ -26,17 +28,24 @@ class PluginError0 {
|
|
|
26
28
|
cause(value) {
|
|
27
29
|
return this.use("cause", value);
|
|
28
30
|
}
|
|
31
|
+
message(value) {
|
|
32
|
+
return this.use("message", value);
|
|
33
|
+
}
|
|
29
34
|
use(kind, keyOrValue, value) {
|
|
30
35
|
const nextProps = { ...this._plugin.props ?? {} };
|
|
31
36
|
const nextMethods = { ...this._plugin.methods ?? {} };
|
|
32
37
|
const nextAdapt = [...this._plugin.adapt ?? []];
|
|
33
38
|
let nextStack = this._plugin.stack;
|
|
34
39
|
let nextCause = this._plugin.cause;
|
|
40
|
+
let nextMessage = this._plugin.message;
|
|
35
41
|
if (kind === "prop") {
|
|
36
42
|
const key = keyOrValue;
|
|
37
43
|
if (key === "stack") {
|
|
38
44
|
throw new Error(RESERVED_STACK_PROP_ERROR);
|
|
39
45
|
}
|
|
46
|
+
if (key === "message") {
|
|
47
|
+
throw new Error(RESERVED_MESSAGE_PROP_ERROR);
|
|
48
|
+
}
|
|
40
49
|
if (value === void 0) {
|
|
41
50
|
throw new Error('PluginError0.use("prop", key, value) requires value');
|
|
42
51
|
}
|
|
@@ -51,27 +60,32 @@ class PluginError0 {
|
|
|
51
60
|
nextAdapt.push(keyOrValue);
|
|
52
61
|
} else if (kind === "stack") {
|
|
53
62
|
nextStack = keyOrValue;
|
|
54
|
-
} else {
|
|
63
|
+
} else if (kind === "cause") {
|
|
55
64
|
nextCause = keyOrValue;
|
|
65
|
+
} else {
|
|
66
|
+
nextMessage = keyOrValue;
|
|
56
67
|
}
|
|
57
68
|
return new PluginError0({
|
|
58
69
|
props: nextProps,
|
|
59
70
|
methods: nextMethods,
|
|
60
71
|
adapt: nextAdapt,
|
|
61
72
|
stack: nextStack,
|
|
62
|
-
cause: nextCause
|
|
73
|
+
cause: nextCause,
|
|
74
|
+
message: nextMessage
|
|
63
75
|
});
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
class Error0 extends Error {
|
|
67
79
|
static __pluginsMap;
|
|
80
|
+
__pluginsMap;
|
|
68
81
|
static _plugins = [];
|
|
69
82
|
static _emptyPlugin = {
|
|
70
83
|
props: {},
|
|
71
84
|
methods: {},
|
|
72
85
|
adapt: [],
|
|
73
86
|
stack: void 0,
|
|
74
|
-
cause: void 0
|
|
87
|
+
cause: void 0,
|
|
88
|
+
message: void 0
|
|
75
89
|
};
|
|
76
90
|
static _getResolvedPlugin() {
|
|
77
91
|
const resolved = {
|
|
@@ -83,6 +97,9 @@ class Error0 extends Error {
|
|
|
83
97
|
if (plugin.props && "stack" in plugin.props) {
|
|
84
98
|
throw new Error(RESERVED_STACK_PROP_ERROR);
|
|
85
99
|
}
|
|
100
|
+
if (plugin.props && "message" in plugin.props) {
|
|
101
|
+
throw new Error(RESERVED_MESSAGE_PROP_ERROR);
|
|
102
|
+
}
|
|
86
103
|
Object.assign(resolved.props, plugin.props ?? this._emptyPlugin.props);
|
|
87
104
|
Object.assign(resolved.methods, plugin.methods ?? this._emptyPlugin.methods);
|
|
88
105
|
resolved.adapt.push(...plugin.adapt ?? this._emptyPlugin.adapt);
|
|
@@ -92,6 +109,9 @@ class Error0 extends Error {
|
|
|
92
109
|
if (typeof plugin.cause !== "undefined") {
|
|
93
110
|
resolved.cause = plugin.cause;
|
|
94
111
|
}
|
|
112
|
+
if (typeof plugin.message !== "undefined") {
|
|
113
|
+
resolved.message = plugin.message;
|
|
114
|
+
}
|
|
95
115
|
}
|
|
96
116
|
return resolved;
|
|
97
117
|
}
|
|
@@ -287,8 +307,7 @@ class Error0 extends Error {
|
|
|
287
307
|
console.error(`Error0: failed to deserialize property ${key}`, errorRecord);
|
|
288
308
|
}
|
|
289
309
|
}
|
|
290
|
-
|
|
291
|
-
if (stackPlugin !== false && "stack" in errorRecord) {
|
|
310
|
+
if ("stack" in errorRecord) {
|
|
292
311
|
try {
|
|
293
312
|
if (typeof errorRecord.stack === "string") {
|
|
294
313
|
recreated.stack = errorRecord.stack;
|
|
@@ -297,8 +316,8 @@ class Error0 extends Error {
|
|
|
297
316
|
console.error("Error0: failed to deserialize stack", errorRecord);
|
|
298
317
|
}
|
|
299
318
|
}
|
|
300
|
-
const causePlugin = plugin.cause
|
|
301
|
-
if (causePlugin && "cause" in errorRecord) {
|
|
319
|
+
const causePlugin = plugin.cause;
|
|
320
|
+
if (causePlugin?.serialize && "cause" in errorRecord) {
|
|
302
321
|
try {
|
|
303
322
|
if (this.isSerialized(errorRecord.cause)) {
|
|
304
323
|
;
|
|
@@ -353,7 +372,8 @@ class Error0 extends Error {
|
|
|
353
372
|
methods: { ...pluginRecord._plugin.methods ?? {} },
|
|
354
373
|
adapt: [...pluginRecord._plugin.adapt ?? []],
|
|
355
374
|
stack: pluginRecord._plugin.stack,
|
|
356
|
-
cause: pluginRecord._plugin.cause
|
|
375
|
+
cause: pluginRecord._plugin.cause,
|
|
376
|
+
message: pluginRecord._plugin.message
|
|
357
377
|
};
|
|
358
378
|
}
|
|
359
379
|
static use(first, key, value) {
|
|
@@ -364,8 +384,8 @@ class Error0 extends Error {
|
|
|
364
384
|
if (typeof key === "undefined") {
|
|
365
385
|
throw new Error('Error0.use("stack", value) requires stack plugin value');
|
|
366
386
|
}
|
|
367
|
-
if (key !== "
|
|
368
|
-
throw new Error('Error0.use("stack", value) expects
|
|
387
|
+
if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
|
|
388
|
+
throw new Error('Error0.use("stack", value) expects { serialize: function }');
|
|
369
389
|
}
|
|
370
390
|
return this._useWithPlugin({
|
|
371
391
|
stack: key
|
|
@@ -375,13 +395,24 @@ class Error0 extends Error {
|
|
|
375
395
|
if (typeof key === "undefined") {
|
|
376
396
|
throw new Error('Error0.use("cause", value) requires cause plugin value');
|
|
377
397
|
}
|
|
378
|
-
if (typeof key !== "
|
|
379
|
-
throw new Error('Error0.use("cause", value) expects function
|
|
398
|
+
if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
|
|
399
|
+
throw new Error('Error0.use("cause", value) expects { serialize: function }');
|
|
380
400
|
}
|
|
381
401
|
return this._useWithPlugin({
|
|
382
402
|
cause: key
|
|
383
403
|
});
|
|
384
404
|
}
|
|
405
|
+
if (first === "message") {
|
|
406
|
+
if (typeof key === "undefined") {
|
|
407
|
+
throw new Error('Error0.use("message", value) requires message plugin value');
|
|
408
|
+
}
|
|
409
|
+
if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
|
|
410
|
+
throw new Error('Error0.use("message", value) expects { serialize: function }');
|
|
411
|
+
}
|
|
412
|
+
return this._useWithPlugin({
|
|
413
|
+
message: key
|
|
414
|
+
});
|
|
415
|
+
}
|
|
385
416
|
if (first === "adapt") {
|
|
386
417
|
if (typeof key !== "function") {
|
|
387
418
|
throw new Error('Error0.use("adapt", value) requires adapt function');
|
|
@@ -397,6 +428,9 @@ class Error0 extends Error {
|
|
|
397
428
|
if (key === "stack") {
|
|
398
429
|
throw new Error(RESERVED_STACK_PROP_ERROR);
|
|
399
430
|
}
|
|
431
|
+
if (key === "message") {
|
|
432
|
+
throw new Error(RESERVED_MESSAGE_PROP_ERROR);
|
|
433
|
+
}
|
|
400
434
|
return this._useWithPlugin({
|
|
401
435
|
props: { [key]: value }
|
|
402
436
|
});
|
|
@@ -412,13 +446,23 @@ class Error0 extends Error {
|
|
|
412
446
|
const error0 = this.from(error);
|
|
413
447
|
const resolvedProps = this.resolve(error0);
|
|
414
448
|
const resolvedRecord = resolvedProps;
|
|
449
|
+
const plugin = this._getResolvedPlugin();
|
|
450
|
+
const messagePlugin = plugin.message;
|
|
451
|
+
let serializedMessage = error0.message;
|
|
452
|
+
try {
|
|
453
|
+
if (messagePlugin) {
|
|
454
|
+
serializedMessage = messagePlugin.serialize({ value: error0.message, error: error0, isPublic });
|
|
455
|
+
}
|
|
456
|
+
} catch {
|
|
457
|
+
console.error("Error0: failed to serialize message", error0);
|
|
458
|
+
serializedMessage = error0.message;
|
|
459
|
+
}
|
|
415
460
|
const json = {
|
|
416
461
|
name: error0.name,
|
|
417
|
-
message:
|
|
462
|
+
message: serializedMessage
|
|
418
463
|
// we do not serialize causes, it is enough that we have floated props and adapt helper
|
|
419
464
|
// cause: error0.cause,
|
|
420
465
|
};
|
|
421
|
-
const plugin = this._getResolvedPlugin();
|
|
422
466
|
const propsEntries = Object.entries(plugin.props);
|
|
423
467
|
for (const [key, prop] of propsEntries) {
|
|
424
468
|
if (prop.serialize === false) {
|
|
@@ -434,43 +478,30 @@ class Error0 extends Error {
|
|
|
434
478
|
console.error(`Error0: failed to serialize property ${key}`, resolvedRecord);
|
|
435
479
|
}
|
|
436
480
|
}
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}).filter((value) => typeof value === "string").join("\n");
|
|
445
|
-
} else if (typeof stackSerialize === "function") {
|
|
446
|
-
serializedStack = stackSerialize({ value: error0.stack, error: error0, isPublic });
|
|
447
|
-
} else {
|
|
448
|
-
serializedStack = error0.stack;
|
|
449
|
-
}
|
|
450
|
-
if (serializedStack !== void 0) {
|
|
451
|
-
json.stack = serializedStack;
|
|
452
|
-
}
|
|
453
|
-
} catch {
|
|
454
|
-
console.error("Error0: failed to serialize stack", error0);
|
|
481
|
+
const stackPlugin = plugin.stack;
|
|
482
|
+
try {
|
|
483
|
+
let serializedStack;
|
|
484
|
+
if (stackPlugin) {
|
|
485
|
+
serializedStack = stackPlugin.serialize({ value: error0.stack, error: error0, isPublic });
|
|
486
|
+
} else {
|
|
487
|
+
serializedStack = error0.stack;
|
|
455
488
|
}
|
|
489
|
+
if (serializedStack !== void 0) {
|
|
490
|
+
json.stack = serializedStack;
|
|
491
|
+
}
|
|
492
|
+
} catch {
|
|
493
|
+
console.error("Error0: failed to serialize stack", error0);
|
|
456
494
|
}
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
495
|
+
const causePlugin = plugin.cause;
|
|
496
|
+
if (causePlugin?.serialize) {
|
|
459
497
|
try {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
value: error0.cause,
|
|
468
|
-
error: error0,
|
|
469
|
-
isPublic
|
|
470
|
-
});
|
|
471
|
-
if (serializedCause !== void 0) {
|
|
472
|
-
json.cause = serializedCause;
|
|
473
|
-
}
|
|
498
|
+
const serializedCause = causePlugin.serialize({
|
|
499
|
+
value: error0.cause,
|
|
500
|
+
error: error0,
|
|
501
|
+
isPublic
|
|
502
|
+
});
|
|
503
|
+
if (serializedCause !== void 0) {
|
|
504
|
+
json.cause = serializedCause;
|
|
474
505
|
}
|
|
475
506
|
} catch {
|
|
476
507
|
console.error("Error0: failed to serialize cause", error0);
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false\ntype NormalizeUnknownToUndefined<T> = IsUnknown<T> extends true ? undefined : T\ntype IsOnlyUndefined<T> = [Exclude<T, undefined>] extends [never] ? true : false\ntype InferFirstArg<TFn> = TFn extends (...args: infer TArgs) => unknown\n ? TArgs extends [infer TFirst, ...unknown[]]\n ? TFirst\n : undefined\n : undefined\ntype InferPluginPropInput<TProp extends ErrorPluginPropOptions<any, any, any, any>> = TProp extends {\n init: infer TInit\n}\n ? NormalizeUnknownToUndefined<InferFirstArg<TInit>>\n : undefined\ntype ErrorPluginPropInit<TInputValue, TOutputValue> = ((input: TInputValue) => TOutputValue) | (() => TOutputValue)\ntype ErrorPluginPropSerialize<TOutputValue, TError extends Error0> =\n | ((options: { value: TOutputValue; error: TError; isPublic: boolean }) => unknown)\n | false\ntype ErrorPluginPropDeserialize<TOutputValue> =\n | ((options: { value: unknown; serialized: Record<string, unknown> }) => TOutputValue | undefined)\n | false\ntype ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {\n resolve: (options: {\n own: TOutputValue | undefined\n flow: Array<TOutputValue | undefined>\n error: TError\n }) => TResolveValue\n serialize: ErrorPluginPropSerialize<TResolveValue, TError>\n deserialize: ErrorPluginPropDeserialize<TOutputValue>\n}\ntype ErrorPluginPropOptionsWithInit<\n TInputValue,\n TOutputValue,\n TError extends Error0,\n TResolveValue extends TOutputValue | undefined,\n> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {\n init: ErrorPluginPropInit<TInputValue, TOutputValue>\n}\ntype ErrorPluginPropOptionsWithoutInit<\n TOutputValue,\n TError extends Error0,\n TResolveValue extends TOutputValue | undefined,\n> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {\n init?: undefined\n}\nexport type ErrorPluginPropOptions<\n TInputValue = undefined,\n TOutputValue = unknown,\n TError extends Error0 = Error0,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n> =\n | ErrorPluginPropOptionsWithInit<TInputValue, TOutputValue, TError, TResolveValue>\n | ErrorPluginPropOptionsWithoutInit<TOutputValue, TError, TResolveValue>\nexport type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (\n error: TError,\n ...args: TArgs\n) => TOutputValue\nexport type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined\nexport type ErrorPluginAdaptFn<\n TError extends Error0 = Error0,\n TOutputProps extends Record<string, unknown> = Record<never, never>,\n> = ((error: TError) => void) | ((error: TError) => ErrorPluginAdaptResult<TOutputProps>)\nexport type ErrorPluginStackSerialize<TError extends Error0> =\n | ((options: { value: string | undefined; error: TError; isPublic: boolean }) => unknown)\n | boolean\n | 'merge'\nexport type ErrorPluginStack<TError extends Error0 = Error0> = ErrorPluginStackSerialize<TError>\nexport type ErrorPluginCauseSerialize<TError extends Error0> =\n | ((options: { value: unknown; error: TError; isPublic: boolean }) => unknown)\n | boolean\nexport type ErrorPluginCause<TError extends Error0 = Error0> = ErrorPluginCauseSerialize<TError>\ntype ErrorMethodRecord = {\n args: unknown[]\n output: unknown\n}\n\nexport type ErrorPluginProps = { [key: string]: ErrorPluginPropOptions<any, any> }\nexport type ErrorPluginMethods = { [key: string]: ErrorPluginMethodFn<any, any[]> }\n\nexport type ErrorPlugin<\n TProps extends ErrorPluginProps = Record<never, never>,\n TMethods extends ErrorPluginMethods = Record<never, never>,\n> = {\n props?: TProps\n methods?: TMethods\n adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>\n stack?: ErrorPluginStack\n cause?: ErrorPluginCause\n}\ntype AddPropToPluginProps<\n TProps extends ErrorPluginProps,\n TKey extends string,\n TInputValue,\n TOutputValue,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>\ntype AddMethodToPluginMethods<\n TMethods extends ErrorPluginMethods,\n TKey extends string,\n TArgs extends unknown[],\n TOutputValue,\n> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>\ntype PluginOutputProps<TProps extends ErrorPluginProps> = {\n [TKey in keyof TProps]: TProps[TKey] extends ErrorPluginPropOptions<any, any, any, infer TResolveValue>\n ? TResolveValue\n : never\n}\nexport type ErrorPluginsMap = {\n props: Record<string, { init: unknown; output: unknown; resolve: unknown }>\n methods: Record<string, ErrorMethodRecord>\n}\nexport type IsEmptyObject<T> = keyof T extends never ? true : false\nexport type ErrorInputBase = {\n cause?: unknown\n}\ntype ErrorInputPluginProps<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['props'] as IsOnlyUndefined<TPluginsMap['props'][TKey]['init']> extends true\n ? never\n : TKey]?: TPluginsMap['props'][TKey]['init']\n}\nexport type ErrorInput<TPluginsMap extends ErrorPluginsMap> =\n IsEmptyObject<TPluginsMap['props']> extends true\n ? ErrorInputBase\n : ErrorInputBase & ErrorInputPluginProps<TPluginsMap>\n\ntype ErrorResolvedProps<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve']\n}\ntype ErrorOwnProps<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['output'] | undefined\n}\ntype ErrorOwnMethods<TPluginsMap extends ErrorPluginsMap> = {\n own: {\n (): ErrorOwnProps<TPluginsMap>\n <TKey extends keyof TPluginsMap['props'] & string>(key: TKey): ErrorOwnProps<TPluginsMap>[TKey]\n }\n flow: <TKey extends keyof TPluginsMap['props'] & string>(key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>\n}\ntype ErrorResolveMethods<TPluginsMap extends ErrorPluginsMap> = {\n resolve: () => ErrorResolvedProps<TPluginsMap>\n}\ntype ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {\n args: infer TArgs extends unknown[]\n output: infer TOutput\n }\n ? (...args: TArgs) => TOutput\n : never\n}\nexport type ErrorResolved<TPluginsMap extends ErrorPluginsMap> = ErrorResolvedProps<TPluginsMap> &\n ErrorMethods<TPluginsMap>\n\ntype ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {\n args: infer TArgs extends unknown[]\n output: infer TOutput\n }\n ? (error: unknown, ...args: TArgs) => TOutput\n : never\n}\n\ntype EmptyPluginsMap = {\n props: Record<never, { init: never; output: never; resolve: never }>\n methods: Record<never, ErrorMethodRecord>\n}\n\ntype ErrorPluginResolved = {\n props: Record<string, ErrorPluginPropOptions<unknown>>\n methods: Record<string, ErrorPluginMethodFn<unknown>>\n adapt: Array<ErrorPluginAdaptFn<Error0, Record<string, unknown>>>\n stack?: ErrorPluginStack\n cause?: ErrorPluginCause\n}\nconst RESERVED_STACK_PROP_ERROR = 'Error0: \"stack\" is a reserved prop key. Use .stack(...) plugin API instead'\n\ntype PluginPropsMapOf<TPlugin extends ErrorPlugin> = {\n [TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<\n any,\n infer TOutputValue,\n any,\n infer TResolveValue\n >\n ? {\n init: InferPluginPropInput<NonNullable<TPlugin['props']>[TKey]>\n output: TOutputValue\n resolve: TResolveValue\n }\n : never\n}\ntype PluginMethodsMapOf<TPlugin extends ErrorPlugin> = {\n [TKey in keyof NonNullable<TPlugin['methods']>]: NonNullable<TPlugin['methods']>[TKey] extends (\n error: Error0,\n ...args: infer TArgs extends unknown[]\n ) => infer TOutput\n ? { args: TArgs; output: TOutput }\n : never\n}\ntype ErrorPluginsMapOfPlugin<TPlugin extends ErrorPlugin> = {\n props: PluginPropsMapOf<TPlugin>\n methods: PluginMethodsMapOf<TPlugin>\n}\ntype ExtendErrorPluginsMap<TMap extends ErrorPluginsMap, TPlugin extends ErrorPlugin> = {\n props: TMap['props'] & ErrorPluginsMapOfPlugin<TPlugin>['props']\n methods: TMap['methods'] & ErrorPluginsMapOfPlugin<TPlugin>['methods']\n}\ntype ExtendErrorPluginsMapWithProp<\n TMap extends ErrorPluginsMap,\n TKey extends string,\n TInputValue,\n TOutputValue,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n> = ExtendErrorPluginsMap<\n TMap,\n ErrorPlugin<Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>>\n>\ntype ExtendErrorPluginsMapWithMethod<\n TMap extends ErrorPluginsMap,\n TKey extends string,\n TArgs extends unknown[],\n TOutputValue,\n> = ExtendErrorPluginsMap<\n TMap,\n ErrorPlugin<Record<never, never>, Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>>\n>\n\ntype PluginsMapOf<TClass> = TClass extends { __pluginsMap?: infer TPluginsMap }\n ? TPluginsMap extends ErrorPluginsMap\n ? TPluginsMap\n : EmptyPluginsMap\n : EmptyPluginsMap\ntype PluginsMapOfInstance<TInstance> = TInstance extends { constructor: { __pluginsMap?: infer TPluginsMap } }\n ? TPluginsMap extends ErrorPluginsMap\n ? TPluginsMap\n : EmptyPluginsMap\n : EmptyPluginsMap\n\ntype PluginsMapFromParts<\n TProps extends ErrorPluginProps,\n TMethods extends ErrorPluginMethods,\n> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>\ntype ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TMap>\ntype BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 &\n ErrorResolved<PluginsMapFromParts<TProps, TMethods>>\n\ntype PluginOfBuilder<TBuilder> =\n TBuilder extends PluginError0<infer TProps, infer TMethods> ? ErrorPlugin<TProps, TMethods> : never\n\nexport class PluginError0<\n TProps extends ErrorPluginProps = Record<never, never>,\n TMethods extends ErrorPluginMethods = Record<never, never>,\n> {\n private readonly _plugin: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>\n\n readonly Infer = undefined as unknown as {\n props: TProps\n methods: TMethods\n }\n\n constructor(plugin?: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>) {\n this._plugin = {\n props: { ...(plugin?.props ?? {}) },\n methods: { ...(plugin?.methods ?? {}) },\n adapt: [...(plugin?.adapt ?? [])],\n stack: plugin?.stack,\n cause: plugin?.cause,\n }\n }\n\n prop<\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>,\n ): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods> {\n return this.use('prop', key, value)\n }\n\n method<TKey extends string, TArgs extends unknown[], TOutputValue>(\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>> {\n return this.use('method', key, value)\n }\n\n adapt(\n value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>,\n ): PluginError0<TProps, TMethods> {\n return this.use('adapt', value)\n }\n\n stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods> {\n return this.use('stack', value)\n }\n\n cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods> {\n return this.use('cause', value)\n }\n\n use<\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n kind: 'prop',\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>,\n ): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>\n use<TKey extends string, TArgs extends unknown[], TOutputValue>(\n kind: 'method',\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>>\n use(\n kind: 'adapt',\n value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>,\n ): PluginError0<TProps, TMethods>\n use(kind: 'stack', value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>\n use(kind: 'cause', value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>\n use(\n kind: 'prop' | 'method' | 'adapt' | 'stack' | 'cause',\n keyOrValue: unknown,\n value?: ErrorPluginPropOptions<unknown, unknown, any> | ErrorPluginMethodFn<unknown, unknown[], any>,\n ): PluginError0<any, any> {\n const nextProps: ErrorPluginProps = { ...(this._plugin.props ?? {}) }\n const nextMethods: ErrorPluginMethods = { ...(this._plugin.methods ?? {}) }\n const nextAdapt: Array<ErrorPluginAdaptFn<Error0, Record<string, unknown>>> = [...(this._plugin.adapt ?? [])]\n let nextStack: ErrorPluginStack | undefined = this._plugin.stack\n let nextCause: ErrorPluginCause | undefined = this._plugin.cause\n if (kind === 'prop') {\n const key = keyOrValue as string\n if (key === 'stack') {\n throw new Error(RESERVED_STACK_PROP_ERROR)\n }\n if (value === undefined) {\n throw new Error('PluginError0.use(\"prop\", key, value) requires value')\n }\n nextProps[key] = value as ErrorPluginPropOptions<any, any>\n } else if (kind === 'method') {\n const key = keyOrValue as string\n if (value === undefined) {\n throw new Error('PluginError0.use(\"method\", key, value) requires value')\n }\n nextMethods[key] = value as ErrorPluginMethodFn<any, any[]>\n } else if (kind === 'adapt') {\n nextAdapt.push(keyOrValue as ErrorPluginAdaptFn<Error0, Record<string, unknown>>)\n } else if (kind === 'stack') {\n nextStack = keyOrValue as ErrorPluginStack\n } else {\n nextCause = keyOrValue as ErrorPluginCause\n }\n return new PluginError0({\n props: nextProps,\n methods: nextMethods,\n adapt: nextAdapt,\n stack: nextStack,\n cause: nextCause,\n })\n }\n}\n\nexport type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {\n new (\n message: string,\n input?: ErrorInput<TPluginsMap>,\n ): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>\n new (\n input: { message: string } & ErrorInput<TPluginsMap>,\n ): Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>\n readonly __pluginsMap?: TPluginsMap\n from: (\n error: unknown,\n ) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>\n resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>\n serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>\n own: {\n (error: object): ErrorOwnProps<TPluginsMap>\n <TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey): ErrorOwnProps<TPluginsMap>[TKey]\n }\n flow: <TKey extends keyof TPluginsMap['props'] & string>(\n error: object,\n key: TKey,\n ) => Array<ErrorOwnProps<TPluginsMap>[TKey]>\n // prop: <\n // TKey extends string,\n // TInputValue = undefined,\n // TOutputValue = unknown,\n // TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n // >(\n // key: TKey,\n // value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>,\n // ) => ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>\n // method: <TKey extends string, TArgs extends unknown[], TOutputValue>(\n // key: TKey,\n // value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>,\n // ) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>\n // adapt: (\n // value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>,\n // ) => ClassError0<TPluginsMap>\n // stack: (value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>\n // cause: (value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>\n use: {\n <TBuilder extends PluginError0>(\n plugin: TBuilder,\n ): ClassError0<ExtendErrorPluginsMap<TPluginsMap, PluginOfBuilder<TBuilder>>>\n <\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n kind: 'prop',\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>,\n ): ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>\n <TKey extends string, TArgs extends unknown[], TOutputValue>(\n kind: 'method',\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>\n (\n kind: 'adapt',\n value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>,\n ): ClassError0<TPluginsMap>\n (kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>\n (kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>\n }\n plugin: () => PluginError0\n} & ErrorStaticMethods<TPluginsMap>\n\nexport class Error0 extends Error {\n static readonly __pluginsMap?: EmptyPluginsMap\n protected static _plugins: ErrorPlugin[] = []\n\n private static readonly _emptyPlugin: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n stack: undefined,\n cause: undefined,\n }\n\n private static _getResolvedPlugin(this: typeof Error0): ErrorPluginResolved {\n const resolved: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n }\n for (const plugin of this._plugins) {\n if (plugin.props && 'stack' in plugin.props) {\n throw new Error(RESERVED_STACK_PROP_ERROR)\n }\n Object.assign(resolved.props, plugin.props ?? this._emptyPlugin.props)\n Object.assign(resolved.methods, plugin.methods ?? this._emptyPlugin.methods)\n resolved.adapt.push(...(plugin.adapt ?? this._emptyPlugin.adapt))\n if (typeof plugin.stack !== 'undefined') {\n resolved.stack = plugin.stack\n }\n if (typeof plugin.cause !== 'undefined') {\n resolved.cause = plugin.cause\n }\n }\n return resolved\n }\n\n constructor(message: string, input?: ErrorInput<EmptyPluginsMap>)\n constructor(input: { message: string } & ErrorInput<EmptyPluginsMap>)\n constructor(\n ...args:\n | [message: string, input?: ErrorInput<EmptyPluginsMap>]\n | [{ message: string } & ErrorInput<EmptyPluginsMap>]\n ) {\n const [first, second] = args\n const input = typeof first === 'string' ? { message: first, ...(second ?? {}) } : first\n\n super(input.message, { cause: input.cause })\n this.name = 'Error0'\n\n const ctor = this.constructor as typeof Error0\n const plugin = ctor._getResolvedPlugin()\n\n for (const [key, prop] of Object.entries(plugin.props)) {\n if (key === 'stack') {\n continue\n }\n if (key in input) {\n const ownValue = (input as Record<string, unknown>)[key]\n if (typeof prop.init === 'function') {\n ;(this as Record<string, unknown>)[key] = prop.init(ownValue)\n } else {\n ;(this as Record<string, unknown>)[key] = ownValue\n }\n } else {\n Object.defineProperty(this, key, {\n get: () => prop.resolve({ own: undefined, flow: this.flow(key), error: this }),\n set: (value) => {\n Object.defineProperty(this, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n })\n },\n enumerable: true,\n configurable: true,\n })\n }\n }\n }\n\n private static readonly isSelfProperty = (object: object, key: string): boolean => {\n const d = Object.getOwnPropertyDescriptor(object, key)\n if (!d) return false\n if (typeof d.get === 'function' || typeof d.set === 'function') {\n if ('name' in object && object.name === 'Error0') {\n return false\n } else {\n return true\n }\n }\n return true\n }\n private static _ownByKey(error: object, key: string): unknown {\n if (this.isSelfProperty(error, key)) {\n return (error as Record<string, unknown>)[key]\n }\n return undefined\n }\n private static _flowByKey(error: object, key: string): unknown[] {\n return this.causes(error, true).map((cause) => {\n return this._ownByKey(cause, key)\n })\n }\n\n static own<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorOwnProps<PluginsMapOf<TThis>>\n static own<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(\n this: TThis,\n error: unknown,\n key: TKey,\n ): ErrorOwnProps<PluginsMapOf<TThis>>[TKey]\n static own(error: unknown, key?: string): unknown {\n const error0 = this.from(error)\n if (key === undefined) {\n const ownValues: Record<string, unknown> = {}\n const plugin = this._getResolvedPlugin()\n for (const ownKey of Object.keys(plugin.props)) {\n ownValues[ownKey] = this._ownByKey(error0, ownKey)\n }\n return ownValues\n }\n return this._ownByKey(error0, key)\n }\n own<TThis extends Error0>(this: TThis): ErrorOwnProps<PluginsMapOfInstance<TThis>>\n own<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(\n this: TThis,\n key: TKey,\n ): ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey]\n own(key?: string): unknown {\n const ctor = this.constructor as typeof Error0\n if (key === undefined) {\n return ctor.own(this)\n }\n return ctor._ownByKey(this, key)\n }\n\n static flow<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(\n this: TThis,\n error: unknown,\n key: TKey,\n ): Array<ErrorOwnProps<PluginsMapOf<TThis>>[TKey]>\n static flow(error: unknown, key: string): unknown[]\n static flow(error: unknown, key: string): unknown[] {\n const error0 = this.from(error)\n return this._flowByKey(error0, key)\n }\n flow<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(\n this: TThis,\n key: TKey,\n ): Array<ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey]>\n flow(key: string): unknown[]\n flow(key: string): unknown[] {\n const ctor = this.constructor as typeof Error0\n return ctor._flowByKey(this, key)\n }\n\n static resolve<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorResolvedProps<PluginsMapOf<TThis>>\n static resolve(error: unknown): Record<string, unknown>\n static resolve(error: unknown): Record<string, unknown> {\n const error0 = this.from(error)\n const resolved: Record<string, unknown> = {}\n const plugin = this._getResolvedPlugin()\n for (const [key, prop] of Object.entries(plugin.props)) {\n try {\n // resolved[key] = (error0 as unknown as Record<string, unknown>)[key]\n const options = Object.defineProperties(\n {\n error: error0,\n },\n {\n own: {\n get: () => error0.own(key as never),\n },\n flow: {\n get: () => error0.flow(key),\n },\n },\n )\n resolved[key] = prop.resolve(options as never)\n // resolved[key] = prop.resolve({ own: error0.own(key as never), flow: error0.flow(key), error: error0 })\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to resolve property ${key}`, error0)\n }\n }\n return resolved\n }\n resolve<TThis extends Error0>(this: TThis): ErrorResolvedProps<PluginsMapOfInstance<TThis>>\n resolve(): Record<string, unknown>\n resolve(): Record<string, unknown> {\n const ctor = this.constructor as typeof Error0\n return ctor.resolve(this)\n }\n\n static causes(error: unknown, instancesOnly?: false): unknown[]\n static causes<T extends typeof Error0>(this: T, error: unknown, instancesOnly: true): Array<InstanceType<T>>\n static causes(error: unknown, instancesOnly?: boolean): unknown[] {\n const causes: unknown[] = []\n let current: unknown = error\n const maxDepth = 99\n const seen = new Set<unknown>()\n for (let depth = 0; depth < maxDepth; depth += 1) {\n if (seen.has(current)) {\n break\n }\n seen.add(current)\n if (!instancesOnly || this.is(current)) {\n causes.push(current)\n }\n if (!current || typeof current !== 'object') {\n break\n }\n current = (current as { cause?: unknown }).cause\n }\n return causes\n }\n causes<TThis extends Error0>(this: TThis, instancesOnly?: false): [TThis, ...unknown[]]\n causes<TThis extends Error0>(this: TThis, instancesOnly: true): [TThis, ...TThis[]]\n causes(instancesOnly?: boolean): unknown[] {\n const ctor = this.constructor as typeof Error0\n if (instancesOnly) {\n return ctor.causes(this, true)\n }\n return ctor.causes(this)\n }\n\n static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T> {\n return error instanceof this\n }\n\n static isSerialized(error: unknown): error is Record<string, unknown> {\n return !this.is(error) && typeof error === 'object' && error !== null && 'name' in error && error.name === 'Error0'\n }\n\n static from(error: unknown): Error0 {\n if (this.is(error)) {\n return error\n }\n if (this.isSerialized(error)) {\n return this._fromSerialized(error)\n }\n return this._fromNonError0(error)\n }\n\n private static _applyAdapt(error: Error0): Error0 {\n const plugin = this._getResolvedPlugin()\n for (const adapt of plugin.adapt) {\n const adapted = adapt(error as any)\n if (adapted && typeof adapted === 'object') {\n Object.assign(error as unknown as Record<string, unknown>, adapted)\n }\n }\n return error\n }\n\n private static _fromSerialized(error: unknown): Error0 {\n const message = this._extractMessage(error)\n if (typeof error !== 'object' || error === null) {\n return this._applyAdapt(new this(message, { cause: error }))\n }\n const errorRecord = error as Record<string, unknown>\n const recreated = new this(message)\n const plugin = this._getResolvedPlugin()\n const propsEntries = Object.entries(plugin.props)\n for (const [key, prop] of propsEntries) {\n if (prop.deserialize === false) {\n continue\n }\n if (!(key in errorRecord)) {\n continue\n }\n try {\n const value = prop.deserialize({ value: errorRecord[key], serialized: errorRecord })\n ;(recreated as unknown as Record<string, unknown>)[key] = value\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to deserialize property ${key}`, errorRecord)\n }\n }\n // we do not serialize causes\n // ;(recreated as unknown as { cause?: unknown }).cause = errorRecord.cause\n const stackPlugin = plugin.stack\n if (stackPlugin !== false && 'stack' in errorRecord) {\n try {\n if (typeof errorRecord.stack === 'string') {\n recreated.stack = errorRecord.stack\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to deserialize stack', errorRecord)\n }\n }\n const causePlugin = plugin.cause ?? false\n if (causePlugin && 'cause' in errorRecord) {\n try {\n if (this.isSerialized(errorRecord.cause)) {\n ;(recreated as { cause?: unknown }).cause = this._fromSerialized(errorRecord.cause)\n } else {\n ;(recreated as { cause?: unknown }).cause = errorRecord.cause\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to deserialize cause', errorRecord)\n }\n }\n return recreated\n }\n\n private static _fromNonError0(error: unknown): Error0 {\n const message = this._extractMessage(error)\n return this._applyAdapt(new this(message, { cause: error }))\n }\n\n private static _extractMessage(error: unknown): string {\n return (\n (typeof error === 'string'\n ? error\n : typeof error === 'object' && error !== null && 'message' in error && typeof error.message === 'string'\n ? error.message\n : undefined) || 'Unknown error'\n )\n }\n\n private static _useWithPlugin(\n this: typeof Error0,\n plugin: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>,\n ): ClassError0 {\n const Base = this as unknown as typeof Error0\n const Error0Extended = class Error0 extends Base {}\n ;(Error0Extended as typeof Error0)._plugins = [...Base._plugins, plugin]\n\n const resolved = (Error0Extended as typeof Error0)._getResolvedPlugin()\n for (const [key, method] of Object.entries(resolved.methods)) {\n Object.defineProperty((Error0Extended as typeof Error0).prototype, key, {\n value: function (...args: unknown[]) {\n return method(this as Error0, ...args)\n },\n writable: true,\n enumerable: true,\n configurable: true,\n })\n Object.defineProperty(Error0Extended, key, {\n value: function (error: unknown, ...args: unknown[]) {\n return method(this.from(error), ...args)\n },\n writable: true,\n enumerable: true,\n configurable: true,\n })\n }\n\n return Error0Extended as unknown as ClassError0\n }\n\n private static _pluginFromBuilder(plugin: PluginError0): ErrorPlugin<ErrorPluginProps, ErrorPluginMethods> {\n const pluginRecord = plugin as unknown as {\n _plugin: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>\n }\n return {\n props: { ...(pluginRecord._plugin.props ?? {}) },\n methods: { ...(pluginRecord._plugin.methods ?? {}) },\n adapt: [...(pluginRecord._plugin.adapt ?? [])],\n stack: pluginRecord._plugin.stack,\n cause: pluginRecord._plugin.cause,\n }\n }\n\n // static prop<\n // TThis extends typeof Error0,\n // TKey extends string,\n // TInputValue = undefined,\n // TOutputValue = unknown,\n // TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n // >(\n // this: TThis,\n // key: TKey,\n // value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>,\n // ): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>> {\n // return this.use('prop', key, value)\n // }\n\n // static method<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(\n // this: TThis,\n // key: TKey,\n // value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n // ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>> {\n // return this.use('method', key, value)\n // }\n\n // static adapt<TThis extends typeof Error0>(\n // this: TThis,\n // value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>,\n // ): ClassError0<PluginsMapOf<TThis>> {\n // return this.use('adapt', value)\n // }\n\n // static stack<TThis extends typeof Error0>(\n // this: TThis,\n // value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n // ): ClassError0<PluginsMapOf<TThis>> {\n // return this.use('stack', value)\n // }\n\n // static cause<TThis extends typeof Error0>(\n // this: TThis,\n // value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n // ): ClassError0<PluginsMapOf<TThis>> {\n // return this.use('cause', value)\n // }\n\n static use<TThis extends typeof Error0, TBuilder extends PluginError0>(\n this: TThis,\n plugin: TBuilder,\n ): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>\n static use<\n TThis extends typeof Error0,\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n this: TThis,\n kind: 'prop',\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>,\n ): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>\n static use<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(\n this: TThis,\n kind: 'method',\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>\n static use<TThis extends typeof Error0>(\n this: TThis,\n kind: 'adapt',\n value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>,\n ): ClassError0<PluginsMapOf<TThis>>\n static use<TThis extends typeof Error0>(\n this: TThis,\n kind: 'stack',\n value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n ): ClassError0<PluginsMapOf<TThis>>\n static use<TThis extends typeof Error0>(\n this: TThis,\n kind: 'cause',\n value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n ): ClassError0<PluginsMapOf<TThis>>\n static use(\n this: typeof Error0,\n first: PluginError0 | 'prop' | 'method' | 'adapt' | 'stack' | 'cause',\n key?: unknown,\n value?: ErrorPluginPropOptions<unknown> | ErrorPluginMethodFn<unknown>,\n ): ClassError0 {\n if (first instanceof PluginError0) {\n return this._useWithPlugin(this._pluginFromBuilder(first))\n }\n if (first === 'stack') {\n if (typeof key === 'undefined') {\n throw new Error('Error0.use(\"stack\", value) requires stack plugin value')\n }\n if (key !== 'merge' && typeof key !== 'boolean' && typeof key !== 'function') {\n throw new Error('Error0.use(\"stack\", value) expects function | boolean | \"merge\"')\n }\n return this._useWithPlugin({\n stack: key as ErrorPluginStack,\n })\n }\n if (first === 'cause') {\n if (typeof key === 'undefined') {\n throw new Error('Error0.use(\"cause\", value) requires cause plugin value')\n }\n if (typeof key !== 'boolean' && typeof key !== 'function') {\n throw new Error('Error0.use(\"cause\", value) expects function | boolean')\n }\n return this._useWithPlugin({\n cause: key as ErrorPluginCause,\n })\n }\n if (first === 'adapt') {\n if (typeof key !== 'function') {\n throw new Error('Error0.use(\"adapt\", value) requires adapt function')\n }\n return this._useWithPlugin({\n adapt: [key as ErrorPluginAdaptFn<Error0, Record<string, unknown>>],\n })\n }\n if (typeof key !== 'string' || value === undefined) {\n throw new Error('Error0.use(kind, key, value) requires key and value')\n }\n\n if (first === 'prop') {\n if (key === 'stack') {\n throw new Error(RESERVED_STACK_PROP_ERROR)\n }\n return this._useWithPlugin({\n props: { [key]: value as ErrorPluginPropOptions<unknown> },\n })\n }\n return this._useWithPlugin({\n methods: { [key]: value as ErrorPluginMethodFn<unknown> },\n })\n }\n\n static plugin(): PluginError0 {\n return new PluginError0()\n }\n\n static serialize(error: unknown, isPublic = true): Record<string, unknown> {\n const error0 = this.from(error)\n const resolvedProps = this.resolve(error0)\n const resolvedRecord = resolvedProps as Record<string, unknown>\n const json: Record<string, unknown> = {\n name: error0.name,\n message: error0.message,\n // we do not serialize causes, it is enough that we have floated props and adapt helper\n // cause: error0.cause,\n }\n\n const plugin = this._getResolvedPlugin()\n const propsEntries = Object.entries(plugin.props)\n for (const [key, prop] of propsEntries) {\n if (prop.serialize === false) {\n continue\n }\n try {\n const value = resolvedRecord[key]\n const jsonValue = prop.serialize({ value, error: error0, isPublic })\n if (jsonValue !== undefined) {\n json[key] = jsonValue\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to serialize property ${key}`, resolvedRecord)\n }\n }\n const stackSerialize = plugin.stack\n if (stackSerialize !== false) {\n try {\n let serializedStack: unknown\n if (stackSerialize === 'merge') {\n serializedStack = error0\n .causes()\n .map((cause) => {\n return cause instanceof Error ? cause.stack : undefined\n })\n .filter((value): value is string => typeof value === 'string')\n .join('\\n')\n } else if (typeof stackSerialize === 'function') {\n serializedStack = stackSerialize({ value: error0.stack, error: error0, isPublic })\n } else {\n serializedStack = error0.stack\n }\n if (serializedStack !== undefined) {\n json.stack = serializedStack\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to serialize stack', error0)\n }\n }\n const causeSerialize = plugin.cause ?? false\n if (causeSerialize) {\n try {\n if (causeSerialize === true) {\n const causeValue = (error0 as { cause?: unknown }).cause\n if (this.is(causeValue)) {\n json.cause = this.serialize(causeValue, isPublic)\n }\n } else {\n const serializedCause = causeSerialize({\n value: (error0 as { cause?: unknown }).cause,\n error: error0,\n isPublic,\n })\n if (serializedCause !== undefined) {\n json.cause = serializedCause\n }\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to serialize cause', error0)\n }\n }\n return Object.fromEntries(Object.entries(json).filter(([, value]) => value !== undefined)) as Record<\n string,\n unknown\n >\n }\n\n serialize(isPublic = true): Record<string, unknown> {\n const ctor = this.constructor as typeof Error0\n return ctor.serialize(this, isPublic)\n }\n}\n"],"mappings":"AA4KA,MAAM,4BAA4B;AA0E3B,MAAM,aAGX;AAAA,EACiB;AAAA,EAER,QAAQ;AAAA,EAKjB,YAAY,QAA4D;AACtE,SAAK,UAAU;AAA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,EAAE,KAAK,MAAM,UAAU,MAAS,CAAC;AAAA,EAI3F;AAAA,EAEA,UAAU,WAAW,MAA+B;AAClD,UAAM,OAAO,KAAK;AAClB,WAAO,KAAK,UAAU,MAAM,QAAQ;AAAA,EACtC;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false\ntype NormalizeUnknownToUndefined<T> = IsUnknown<T> extends true ? undefined : T\ntype IsOnlyUndefined<T> = [Exclude<T, undefined>] extends [never] ? true : false\ntype InferFirstArg<TFn> = TFn extends (...args: infer TArgs) => unknown\n ? TArgs extends [infer TFirst, ...unknown[]]\n ? TFirst\n : undefined\n : undefined\ntype InferPluginPropInput<TProp extends ErrorPluginPropOptions<any, any, any, any>> = TProp extends {\n init: infer TInit\n}\n ? NormalizeUnknownToUndefined<InferFirstArg<TInit>>\n : undefined\ntype ErrorPluginPropInit<TInputValue, TOutputValue> = ((input: TInputValue) => TOutputValue) | (() => TOutputValue)\ntype ErrorPluginPropSerialize<TOutputValue, TError extends Error0> =\n | ((options: { value: TOutputValue; error: TError; isPublic: boolean }) => unknown)\n | false\ntype ErrorPluginPropDeserialize<TOutputValue> =\n | ((options: { value: unknown; serialized: Record<string, unknown> }) => TOutputValue | undefined)\n | false\ntype ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {\n resolve: (options: {\n own: TOutputValue | undefined\n flow: Array<TOutputValue | undefined>\n error: TError\n }) => TResolveValue\n serialize: ErrorPluginPropSerialize<TResolveValue, TError>\n deserialize: ErrorPluginPropDeserialize<TOutputValue>\n}\ntype ErrorPluginPropOptionsWithInit<\n TInputValue,\n TOutputValue,\n TError extends Error0,\n TResolveValue extends TOutputValue | undefined,\n> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {\n init: ErrorPluginPropInit<TInputValue, TOutputValue>\n}\ntype ErrorPluginPropOptionsWithoutInit<\n TOutputValue,\n TError extends Error0,\n TResolveValue extends TOutputValue | undefined,\n> = ErrorPluginPropOptionsBase<TOutputValue, TError, TResolveValue> & {\n init?: undefined\n}\nexport type ErrorPluginPropOptions<\n TInputValue = undefined,\n TOutputValue = unknown,\n TError extends Error0 = Error0,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n> =\n | ErrorPluginPropOptionsWithInit<TInputValue, TOutputValue, TError, TResolveValue>\n | ErrorPluginPropOptionsWithoutInit<TOutputValue, TError, TResolveValue>\nexport type ErrorPluginMethodFn<TOutputValue, TArgs extends unknown[] = unknown[], TError extends Error0 = Error0> = (\n error: TError,\n ...args: TArgs\n) => TOutputValue\nexport type ErrorPluginAdaptResult<TOutputProps extends Record<string, unknown>> = Partial<TOutputProps> | undefined\nexport type ErrorPluginAdaptFn<\n TError extends Error0 = Error0,\n TOutputProps extends Record<string, unknown> = Record<never, never>,\n> = ((error: TError) => void) | ((error: TError) => ErrorPluginAdaptResult<TOutputProps>)\nexport type ErrorPluginStackSerialize<TError extends Error0> = (options: {\n value: string | undefined\n error: TError\n isPublic: boolean\n}) => unknown\nexport type ErrorPluginStack<TError extends Error0 = Error0> = { serialize: ErrorPluginStackSerialize<TError> }\nexport type ErrorPluginCauseSerialize<TError extends Error0> = (options: {\n value: unknown\n error: TError\n isPublic: boolean\n}) => unknown\nexport type ErrorPluginCause<TError extends Error0 = Error0> = { serialize: ErrorPluginCauseSerialize<TError> }\nexport type ErrorPluginMessageSerialize<TError extends Error0> = (options: {\n value: string\n error: TError\n isPublic: boolean\n}) => unknown\nexport type ErrorPluginMessage<TError extends Error0 = Error0> = { serialize: ErrorPluginMessageSerialize<TError> }\ntype ErrorMethodRecord = {\n args: unknown[]\n output: unknown\n}\n\nexport type ErrorPluginProps = { [key: string]: ErrorPluginPropOptions<any, any> }\nexport type ErrorPluginMethods = { [key: string]: ErrorPluginMethodFn<any, any[]> }\n\nexport type ErrorPlugin<\n TProps extends ErrorPluginProps = Record<never, never>,\n TMethods extends ErrorPluginMethods = Record<never, never>,\n> = {\n props?: TProps\n methods?: TMethods\n adapt?: Array<ErrorPluginAdaptFn<Error0, PluginOutputProps<TProps>>>\n stack?: ErrorPluginStack\n cause?: ErrorPluginCause\n message?: ErrorPluginMessage\n}\ntype AddPropToPluginProps<\n TProps extends ErrorPluginProps,\n TKey extends string,\n TInputValue,\n TOutputValue,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n> = TProps & Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>\ntype AddMethodToPluginMethods<\n TMethods extends ErrorPluginMethods,\n TKey extends string,\n TArgs extends unknown[],\n TOutputValue,\n> = TMethods & Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>\ntype PluginOutputProps<TProps extends ErrorPluginProps> = {\n [TKey in keyof TProps]: TProps[TKey] extends ErrorPluginPropOptions<any, any, any, infer TResolveValue>\n ? TResolveValue\n : never\n}\nexport type ErrorPluginsMap = {\n props: Record<string, { init: unknown; output: unknown; resolve: unknown }>\n methods: Record<string, ErrorMethodRecord>\n}\nexport type IsEmptyObject<T> = keyof T extends never ? true : false\nexport type ErrorInputBase = {\n cause?: unknown\n}\ntype ErrorInputPluginProps<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['props'] as IsOnlyUndefined<TPluginsMap['props'][TKey]['init']> extends true\n ? never\n : TKey]?: TPluginsMap['props'][TKey]['init']\n}\nexport type ErrorInput<TPluginsMap extends ErrorPluginsMap> =\n IsEmptyObject<TPluginsMap['props']> extends true\n ? ErrorInputBase\n : ErrorInputBase & ErrorInputPluginProps<TPluginsMap>\n\ntype ErrorResolvedProps<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['resolve']\n}\ntype ErrorOwnProps<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['props']]: TPluginsMap['props'][TKey]['output'] | undefined\n}\ntype ErrorOwnMethods<TPluginsMap extends ErrorPluginsMap> = {\n own: {\n (): ErrorOwnProps<TPluginsMap>\n <TKey extends keyof TPluginsMap['props'] & string>(key: TKey): ErrorOwnProps<TPluginsMap>[TKey]\n }\n flow: <TKey extends keyof TPluginsMap['props'] & string>(key: TKey) => Array<ErrorOwnProps<TPluginsMap>[TKey]>\n}\ntype ErrorResolveMethods<TPluginsMap extends ErrorPluginsMap> = {\n resolve: () => ErrorResolvedProps<TPluginsMap>\n}\ntype ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {\n args: infer TArgs extends unknown[]\n output: infer TOutput\n }\n ? (...args: TArgs) => TOutput\n : never\n}\nexport type ErrorResolved<TPluginsMap extends ErrorPluginsMap> = ErrorResolvedProps<TPluginsMap> &\n ErrorMethods<TPluginsMap>\n\ntype ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: TPluginsMap['methods'][TKey] extends {\n args: infer TArgs extends unknown[]\n output: infer TOutput\n }\n ? (error: unknown, ...args: TArgs) => TOutput\n : never\n}\n\ntype EmptyPluginsMap = {\n props: Record<never, { init: never; output: never; resolve: never }>\n methods: Record<never, ErrorMethodRecord>\n}\n\ntype ErrorPluginResolved = {\n props: Record<string, ErrorPluginPropOptions<unknown>>\n methods: Record<string, ErrorPluginMethodFn<unknown>>\n adapt: Array<ErrorPluginAdaptFn<Error0, Record<string, unknown>>>\n stack?: ErrorPluginStack\n cause?: ErrorPluginCause\n message?: ErrorPluginMessage\n}\nconst RESERVED_STACK_PROP_ERROR = 'Error0: \"stack\" is a reserved prop key. Use .stack(...) plugin API instead'\nconst RESERVED_MESSAGE_PROP_ERROR = 'Error0: \"message\" is a reserved prop key. Use .message(...) plugin API instead'\n\ntype PluginPropsMapOf<TPlugin extends ErrorPlugin> = {\n [TKey in keyof NonNullable<TPlugin['props']>]: NonNullable<TPlugin['props']>[TKey] extends ErrorPluginPropOptions<\n any,\n infer TOutputValue,\n any,\n infer TResolveValue\n >\n ? {\n init: InferPluginPropInput<NonNullable<TPlugin['props']>[TKey]>\n output: TOutputValue\n resolve: TResolveValue\n }\n : never\n}\ntype PluginMethodsMapOf<TPlugin extends ErrorPlugin> = {\n [TKey in keyof NonNullable<TPlugin['methods']>]: NonNullable<TPlugin['methods']>[TKey] extends (\n error: Error0,\n ...args: infer TArgs extends unknown[]\n ) => infer TOutput\n ? { args: TArgs; output: TOutput }\n : never\n}\ntype ErrorPluginsMapOfPlugin<TPlugin extends ErrorPlugin> = {\n props: PluginPropsMapOf<TPlugin>\n methods: PluginMethodsMapOf<TPlugin>\n}\ntype ExtendErrorPluginsMap<TMap extends ErrorPluginsMap, TPlugin extends ErrorPlugin> = {\n props: TMap['props'] & ErrorPluginsMapOfPlugin<TPlugin>['props']\n methods: TMap['methods'] & ErrorPluginsMapOfPlugin<TPlugin>['methods']\n}\ntype ExtendErrorPluginsMapWithProp<\n TMap extends ErrorPluginsMap,\n TKey extends string,\n TInputValue,\n TOutputValue,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n> = ExtendErrorPluginsMap<\n TMap,\n ErrorPlugin<Record<TKey, ErrorPluginPropOptions<TInputValue, TOutputValue, Error0, TResolveValue>>>\n>\ntype ExtendErrorPluginsMapWithMethod<\n TMap extends ErrorPluginsMap,\n TKey extends string,\n TArgs extends unknown[],\n TOutputValue,\n> = ExtendErrorPluginsMap<\n TMap,\n ErrorPlugin<Record<never, never>, Record<TKey, ErrorPluginMethodFn<TOutputValue, TArgs>>>\n>\n\ntype PluginsMapOf<TClass> = TClass extends { __pluginsMap?: infer TPluginsMap }\n ? TPluginsMap extends ErrorPluginsMap\n ? TPluginsMap\n : EmptyPluginsMap\n : EmptyPluginsMap\ntype PluginsMapOfInstance<TInstance> = TInstance extends { __pluginsMap?: infer TPluginsMap }\n ? TPluginsMap extends ErrorPluginsMap\n ? TPluginsMap\n : EmptyPluginsMap\n : EmptyPluginsMap\n\ntype PluginsMapFromParts<\n TProps extends ErrorPluginProps,\n TMethods extends ErrorPluginMethods,\n> = ErrorPluginsMapOfPlugin<ErrorPlugin<TProps, TMethods>>\ntype ErrorInstanceOfMap<TMap extends ErrorPluginsMap> = Error0 & ErrorResolved<TMap>\ntype BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 &\n ErrorResolved<PluginsMapFromParts<TProps, TMethods>>\n\ntype PluginOfBuilder<TBuilder> =\n TBuilder extends PluginError0<infer TProps, infer TMethods> ? ErrorPlugin<TProps, TMethods> : never\n\nexport class PluginError0<\n TProps extends ErrorPluginProps = Record<never, never>,\n TMethods extends ErrorPluginMethods = Record<never, never>,\n> {\n private readonly _plugin: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>\n\n readonly Infer = undefined as unknown as {\n props: TProps\n methods: TMethods\n }\n\n constructor(plugin?: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>) {\n this._plugin = {\n props: { ...(plugin?.props ?? {}) },\n methods: { ...(plugin?.methods ?? {}) },\n adapt: [...(plugin?.adapt ?? [])],\n stack: plugin?.stack,\n cause: plugin?.cause,\n message: plugin?.message,\n }\n }\n\n prop<\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>,\n ): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods> {\n return this.use('prop', key, value)\n }\n\n method<TKey extends string, TArgs extends unknown[], TOutputValue>(\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>> {\n return this.use('method', key, value)\n }\n\n adapt(\n value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>,\n ): PluginError0<TProps, TMethods> {\n return this.use('adapt', value)\n }\n\n stack(value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods> {\n return this.use('stack', value)\n }\n\n cause(value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods> {\n return this.use('cause', value)\n }\n\n message(value: ErrorPluginMessage<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods> {\n return this.use('message', value)\n }\n\n use<\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n kind: 'prop',\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, BuilderError0<TProps, TMethods>, TResolveValue>,\n ): PluginError0<AddPropToPluginProps<TProps, TKey, TInputValue, TOutputValue, TResolveValue>, TMethods>\n use<TKey extends string, TArgs extends unknown[], TOutputValue>(\n kind: 'method',\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, BuilderError0<TProps, TMethods>>,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TArgs, TOutputValue>>\n use(\n kind: 'adapt',\n value: ErrorPluginAdaptFn<BuilderError0<TProps, TMethods>, PluginOutputProps<TProps>>,\n ): PluginError0<TProps, TMethods>\n use(kind: 'stack', value: ErrorPluginStack<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>\n use(kind: 'cause', value: ErrorPluginCause<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>\n use(kind: 'message', value: ErrorPluginMessage<BuilderError0<TProps, TMethods>>): PluginError0<TProps, TMethods>\n use(\n kind: 'prop' | 'method' | 'adapt' | 'stack' | 'cause' | 'message',\n keyOrValue: unknown,\n value?: ErrorPluginPropOptions<unknown, unknown, any> | ErrorPluginMethodFn<unknown, unknown[], any>,\n ): PluginError0<any, any> {\n const nextProps: ErrorPluginProps = { ...(this._plugin.props ?? {}) }\n const nextMethods: ErrorPluginMethods = { ...(this._plugin.methods ?? {}) }\n const nextAdapt: Array<ErrorPluginAdaptFn<Error0, Record<string, unknown>>> = [...(this._plugin.adapt ?? [])]\n let nextStack: ErrorPluginStack | undefined = this._plugin.stack\n let nextCause: ErrorPluginCause | undefined = this._plugin.cause\n let nextMessage: ErrorPluginMessage | undefined = this._plugin.message\n if (kind === 'prop') {\n const key = keyOrValue as string\n if (key === 'stack') {\n throw new Error(RESERVED_STACK_PROP_ERROR)\n }\n if (key === 'message') {\n throw new Error(RESERVED_MESSAGE_PROP_ERROR)\n }\n if (value === undefined) {\n throw new Error('PluginError0.use(\"prop\", key, value) requires value')\n }\n nextProps[key] = value as ErrorPluginPropOptions<any, any>\n } else if (kind === 'method') {\n const key = keyOrValue as string\n if (value === undefined) {\n throw new Error('PluginError0.use(\"method\", key, value) requires value')\n }\n nextMethods[key] = value as ErrorPluginMethodFn<any, any[]>\n } else if (kind === 'adapt') {\n nextAdapt.push(keyOrValue as ErrorPluginAdaptFn<Error0, Record<string, unknown>>)\n } else if (kind === 'stack') {\n nextStack = keyOrValue as ErrorPluginStack\n } else if (kind === 'cause') {\n nextCause = keyOrValue as ErrorPluginCause\n } else {\n nextMessage = keyOrValue as ErrorPluginMessage\n }\n return new PluginError0({\n props: nextProps,\n methods: nextMethods,\n adapt: nextAdapt,\n stack: nextStack,\n cause: nextCause,\n message: nextMessage,\n })\n }\n}\n\nexport type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {\n new (\n message: string,\n input?: ErrorInput<TPluginsMap>,\n ): Error0 &\n ErrorResolved<TPluginsMap> &\n ErrorOwnMethods<TPluginsMap> &\n ErrorResolveMethods<TPluginsMap> & { readonly __pluginsMap?: TPluginsMap }\n new (\n input: { message: string } & ErrorInput<TPluginsMap>,\n ): Error0 &\n ErrorResolved<TPluginsMap> &\n ErrorOwnMethods<TPluginsMap> &\n ErrorResolveMethods<TPluginsMap> & { readonly __pluginsMap?: TPluginsMap }\n readonly __pluginsMap?: TPluginsMap\n from: (\n error: unknown,\n ) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>\n resolve: (error: unknown) => ErrorResolvedProps<TPluginsMap>\n serialize: (error: unknown, isPublic?: boolean) => Record<string, unknown>\n own: {\n (error: object): ErrorOwnProps<TPluginsMap>\n <TKey extends keyof TPluginsMap['props'] & string>(error: object, key: TKey): ErrorOwnProps<TPluginsMap>[TKey]\n }\n flow: <TKey extends keyof TPluginsMap['props'] & string>(\n error: object,\n key: TKey,\n ) => Array<ErrorOwnProps<TPluginsMap>[TKey]>\n // prop: <\n // TKey extends string,\n // TInputValue = undefined,\n // TOutputValue = unknown,\n // TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n // >(\n // key: TKey,\n // value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>,\n // ) => ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>\n // method: <TKey extends string, TArgs extends unknown[], TOutputValue>(\n // key: TKey,\n // value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>,\n // ) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>\n // adapt: (\n // value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>,\n // ) => ClassError0<TPluginsMap>\n // stack: (value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>\n // cause: (value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>) => ClassError0<TPluginsMap>\n use: {\n <TBuilder extends PluginError0>(\n plugin: TBuilder,\n ): ClassError0<ExtendErrorPluginsMap<TPluginsMap, PluginOfBuilder<TBuilder>>>\n <\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n kind: 'prop',\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<TPluginsMap>, TResolveValue>,\n ): ClassError0<ExtendErrorPluginsMapWithProp<TPluginsMap, TKey, TInputValue, TOutputValue, TResolveValue>>\n <TKey extends string, TArgs extends unknown[], TOutputValue>(\n kind: 'method',\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<TPluginsMap>>,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TArgs, TOutputValue>>\n (\n kind: 'adapt',\n value: ErrorPluginAdaptFn<ErrorInstanceOfMap<TPluginsMap>, ErrorResolvedProps<TPluginsMap>>,\n ): ClassError0<TPluginsMap>\n (kind: 'stack', value: ErrorPluginStack<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>\n (kind: 'cause', value: ErrorPluginCause<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>\n (kind: 'message', value: ErrorPluginMessage<ErrorInstanceOfMap<TPluginsMap>>): ClassError0<TPluginsMap>\n }\n plugin: () => PluginError0\n} & ErrorStaticMethods<TPluginsMap>\n\nexport class Error0 extends Error {\n static readonly __pluginsMap?: EmptyPluginsMap\n readonly __pluginsMap?: EmptyPluginsMap\n protected static _plugins: ErrorPlugin[] = []\n\n private static readonly _emptyPlugin: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n stack: undefined,\n cause: undefined,\n message: undefined,\n }\n\n private static _getResolvedPlugin(this: typeof Error0): ErrorPluginResolved {\n const resolved: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n }\n for (const plugin of this._plugins) {\n if (plugin.props && 'stack' in plugin.props) {\n throw new Error(RESERVED_STACK_PROP_ERROR)\n }\n if (plugin.props && 'message' in plugin.props) {\n throw new Error(RESERVED_MESSAGE_PROP_ERROR)\n }\n Object.assign(resolved.props, plugin.props ?? this._emptyPlugin.props)\n Object.assign(resolved.methods, plugin.methods ?? this._emptyPlugin.methods)\n resolved.adapt.push(...(plugin.adapt ?? this._emptyPlugin.adapt))\n if (typeof plugin.stack !== 'undefined') {\n resolved.stack = plugin.stack\n }\n if (typeof plugin.cause !== 'undefined') {\n resolved.cause = plugin.cause\n }\n if (typeof plugin.message !== 'undefined') {\n resolved.message = plugin.message\n }\n }\n return resolved\n }\n\n constructor(message: string, input?: ErrorInput<EmptyPluginsMap>)\n constructor(input: { message: string } & ErrorInput<EmptyPluginsMap>)\n constructor(\n ...args:\n | [message: string, input?: ErrorInput<EmptyPluginsMap>]\n | [{ message: string } & ErrorInput<EmptyPluginsMap>]\n ) {\n const [first, second] = args\n const input = typeof first === 'string' ? { message: first, ...(second ?? {}) } : first\n\n super(input.message, { cause: input.cause })\n this.name = 'Error0'\n\n const ctor = this.constructor as typeof Error0\n const plugin = ctor._getResolvedPlugin()\n\n for (const [key, prop] of Object.entries(plugin.props)) {\n if (key === 'stack') {\n continue\n }\n if (key in input) {\n const ownValue = (input as Record<string, unknown>)[key]\n if (typeof prop.init === 'function') {\n ;(this as Record<string, unknown>)[key] = prop.init(ownValue)\n } else {\n ;(this as Record<string, unknown>)[key] = ownValue\n }\n } else {\n Object.defineProperty(this, key, {\n get: () => prop.resolve({ own: undefined, flow: this.flow(key), error: this }),\n set: (value) => {\n Object.defineProperty(this, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n })\n },\n enumerable: true,\n configurable: true,\n })\n }\n }\n }\n\n private static readonly isSelfProperty = (object: object, key: string): boolean => {\n const d = Object.getOwnPropertyDescriptor(object, key)\n if (!d) return false\n if (typeof d.get === 'function' || typeof d.set === 'function') {\n if ('name' in object && object.name === 'Error0') {\n return false\n } else {\n return true\n }\n }\n return true\n }\n private static _ownByKey(error: object, key: string): unknown {\n if (this.isSelfProperty(error, key)) {\n return (error as Record<string, unknown>)[key]\n }\n return undefined\n }\n private static _flowByKey(error: object, key: string): unknown[] {\n return this.causes(error, true).map((cause) => {\n return this._ownByKey(cause, key)\n })\n }\n\n static own<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorOwnProps<PluginsMapOf<TThis>>\n static own<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(\n this: TThis,\n error: unknown,\n key: TKey,\n ): ErrorOwnProps<PluginsMapOf<TThis>>[TKey]\n static own(error: unknown, key?: string): unknown {\n const error0 = this.from(error)\n if (key === undefined) {\n const ownValues: Record<string, unknown> = {}\n const plugin = this._getResolvedPlugin()\n for (const ownKey of Object.keys(plugin.props)) {\n ownValues[ownKey] = this._ownByKey(error0, ownKey)\n }\n return ownValues\n }\n return this._ownByKey(error0, key)\n }\n own<TThis extends Error0>(this: TThis): ErrorOwnProps<PluginsMapOfInstance<TThis>>\n own<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(\n this: TThis,\n key: TKey,\n ): ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey]\n own(key?: string): unknown {\n const ctor = this.constructor as typeof Error0\n if (key === undefined) {\n return ctor.own(this)\n }\n return ctor._ownByKey(this, key)\n }\n\n static flow<TThis extends typeof Error0, TKey extends keyof PluginsMapOf<TThis>['props'] & string>(\n this: TThis,\n error: unknown,\n key: TKey,\n ): Array<ErrorOwnProps<PluginsMapOf<TThis>>[TKey]>\n static flow(error: unknown, key: string): unknown[]\n static flow(error: unknown, key: string): unknown[] {\n const error0 = this.from(error)\n return this._flowByKey(error0, key)\n }\n flow<TThis extends Error0, TKey extends keyof PluginsMapOfInstance<TThis>['props'] & string>(\n this: TThis,\n key: TKey,\n ): Array<ErrorOwnProps<PluginsMapOfInstance<TThis>>[TKey]>\n flow(key: string): unknown[]\n flow(key: string): unknown[] {\n const ctor = this.constructor as typeof Error0\n return ctor._flowByKey(this, key)\n }\n\n static resolve<TThis extends typeof Error0>(this: TThis, error: unknown): ErrorResolvedProps<PluginsMapOf<TThis>>\n static resolve(error: unknown): Record<string, unknown>\n static resolve(error: unknown): Record<string, unknown> {\n const error0 = this.from(error)\n const resolved: Record<string, unknown> = {}\n const plugin = this._getResolvedPlugin()\n for (const [key, prop] of Object.entries(plugin.props)) {\n try {\n // resolved[key] = (error0 as unknown as Record<string, unknown>)[key]\n const options = Object.defineProperties(\n {\n error: error0,\n },\n {\n own: {\n get: () => error0.own(key as never),\n },\n flow: {\n get: () => error0.flow(key),\n },\n },\n )\n resolved[key] = prop.resolve(options as never)\n // resolved[key] = prop.resolve({ own: error0.own(key as never), flow: error0.flow(key), error: error0 })\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to resolve property ${key}`, error0)\n }\n }\n return resolved\n }\n resolve<TThis extends Error0>(this: TThis): ErrorResolvedProps<PluginsMapOfInstance<TThis>>\n resolve(): Record<string, unknown>\n resolve(): Record<string, unknown> {\n const ctor = this.constructor as typeof Error0\n return ctor.resolve(this)\n }\n\n static causes(error: unknown, instancesOnly?: false): unknown[]\n static causes<T extends typeof Error0>(this: T, error: unknown, instancesOnly: true): Array<InstanceType<T>>\n static causes(error: unknown, instancesOnly?: boolean): unknown[] {\n const causes: unknown[] = []\n let current: unknown = error\n const maxDepth = 99\n const seen = new Set<unknown>()\n for (let depth = 0; depth < maxDepth; depth += 1) {\n if (seen.has(current)) {\n break\n }\n seen.add(current)\n if (!instancesOnly || this.is(current)) {\n causes.push(current)\n }\n if (!current || typeof current !== 'object') {\n break\n }\n current = (current as { cause?: unknown }).cause\n }\n return causes\n }\n causes<TThis extends Error0>(this: TThis, instancesOnly?: false): [TThis, ...unknown[]]\n causes<TThis extends Error0>(this: TThis, instancesOnly: true): [TThis, ...TThis[]]\n causes(instancesOnly?: boolean): unknown[] {\n const ctor = this.constructor as typeof Error0\n if (instancesOnly) {\n return ctor.causes(this, true)\n }\n return ctor.causes(this)\n }\n\n static is<T extends typeof Error0>(this: T, error: unknown): error is InstanceType<T> {\n return error instanceof this\n }\n\n static isSerialized(error: unknown): error is Record<string, unknown> {\n return !this.is(error) && typeof error === 'object' && error !== null && 'name' in error && error.name === 'Error0'\n }\n\n static from(error: unknown): Error0 {\n if (this.is(error)) {\n return error\n }\n if (this.isSerialized(error)) {\n return this._fromSerialized(error)\n }\n return this._fromNonError0(error)\n }\n\n private static _applyAdapt(error: Error0): Error0 {\n const plugin = this._getResolvedPlugin()\n for (const adapt of plugin.adapt) {\n const adapted = adapt(error as any)\n if (adapted && typeof adapted === 'object') {\n Object.assign(error as unknown as Record<string, unknown>, adapted)\n }\n }\n return error\n }\n\n private static _fromSerialized(error: unknown): Error0 {\n const message = this._extractMessage(error)\n if (typeof error !== 'object' || error === null) {\n return this._applyAdapt(new this(message, { cause: error }))\n }\n const errorRecord = error as Record<string, unknown>\n const recreated = new this(message)\n const plugin = this._getResolvedPlugin()\n const propsEntries = Object.entries(plugin.props)\n for (const [key, prop] of propsEntries) {\n if (prop.deserialize === false) {\n continue\n }\n if (!(key in errorRecord)) {\n continue\n }\n try {\n const value = prop.deserialize({ value: errorRecord[key], serialized: errorRecord })\n ;(recreated as unknown as Record<string, unknown>)[key] = value\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to deserialize property ${key}`, errorRecord)\n }\n }\n // we do not serialize causes\n // ;(recreated as unknown as { cause?: unknown }).cause = errorRecord.cause\n if ('stack' in errorRecord) {\n try {\n if (typeof errorRecord.stack === 'string') {\n recreated.stack = errorRecord.stack\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to deserialize stack', errorRecord)\n }\n }\n const causePlugin = plugin.cause\n if (causePlugin?.serialize && 'cause' in errorRecord) {\n try {\n if (this.isSerialized(errorRecord.cause)) {\n ;(recreated as { cause?: unknown }).cause = this._fromSerialized(errorRecord.cause)\n } else {\n ;(recreated as { cause?: unknown }).cause = errorRecord.cause\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to deserialize cause', errorRecord)\n }\n }\n return recreated\n }\n\n private static _fromNonError0(error: unknown): Error0 {\n const message = this._extractMessage(error)\n return this._applyAdapt(new this(message, { cause: error }))\n }\n\n private static _extractMessage(error: unknown): string {\n return (\n (typeof error === 'string'\n ? error\n : typeof error === 'object' && error !== null && 'message' in error && typeof error.message === 'string'\n ? error.message\n : undefined) || 'Unknown error'\n )\n }\n\n private static _useWithPlugin(\n this: typeof Error0,\n plugin: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>,\n ): ClassError0 {\n const Base = this as unknown as typeof Error0\n const Error0Extended = class Error0 extends Base {}\n ;(Error0Extended as typeof Error0)._plugins = [...Base._plugins, plugin]\n\n const resolved = (Error0Extended as typeof Error0)._getResolvedPlugin()\n for (const [key, method] of Object.entries(resolved.methods)) {\n Object.defineProperty((Error0Extended as typeof Error0).prototype, key, {\n value: function (...args: unknown[]) {\n return method(this as Error0, ...args)\n },\n writable: true,\n enumerable: true,\n configurable: true,\n })\n Object.defineProperty(Error0Extended, key, {\n value: function (error: unknown, ...args: unknown[]) {\n return method(this.from(error), ...args)\n },\n writable: true,\n enumerable: true,\n configurable: true,\n })\n }\n\n return Error0Extended as unknown as ClassError0\n }\n\n private static _pluginFromBuilder(plugin: PluginError0): ErrorPlugin<ErrorPluginProps, ErrorPluginMethods> {\n const pluginRecord = plugin as unknown as {\n _plugin: ErrorPlugin<ErrorPluginProps, ErrorPluginMethods>\n }\n return {\n props: { ...(pluginRecord._plugin.props ?? {}) },\n methods: { ...(pluginRecord._plugin.methods ?? {}) },\n adapt: [...(pluginRecord._plugin.adapt ?? [])],\n stack: pluginRecord._plugin.stack,\n cause: pluginRecord._plugin.cause,\n message: pluginRecord._plugin.message,\n }\n }\n\n // static prop<\n // TThis extends typeof Error0,\n // TKey extends string,\n // TInputValue = undefined,\n // TOutputValue = unknown,\n // TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n // >(\n // this: TThis,\n // key: TKey,\n // value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>,\n // ): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>> {\n // return this.use('prop', key, value)\n // }\n\n // static method<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(\n // this: TThis,\n // key: TKey,\n // value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n // ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>> {\n // return this.use('method', key, value)\n // }\n\n // static adapt<TThis extends typeof Error0>(\n // this: TThis,\n // value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>,\n // ): ClassError0<PluginsMapOf<TThis>> {\n // return this.use('adapt', value)\n // }\n\n // static stack<TThis extends typeof Error0>(\n // this: TThis,\n // value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n // ): ClassError0<PluginsMapOf<TThis>> {\n // return this.use('stack', value)\n // }\n\n // static cause<TThis extends typeof Error0>(\n // this: TThis,\n // value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n // ): ClassError0<PluginsMapOf<TThis>> {\n // return this.use('cause', value)\n // }\n\n static use<TThis extends typeof Error0, TBuilder extends PluginError0>(\n this: TThis,\n plugin: TBuilder,\n ): ClassError0<ExtendErrorPluginsMap<PluginsMapOf<TThis>, PluginOfBuilder<TBuilder>>>\n static use<\n TThis extends typeof Error0,\n TKey extends string,\n TInputValue = undefined,\n TOutputValue = unknown,\n TResolveValue extends TOutputValue | undefined = TOutputValue | undefined,\n >(\n this: TThis,\n kind: 'prop',\n key: TKey,\n value: ErrorPluginPropOptions<TInputValue, TOutputValue, ErrorInstanceOfMap<PluginsMapOf<TThis>>, TResolveValue>,\n ): ClassError0<ExtendErrorPluginsMapWithProp<PluginsMapOf<TThis>, TKey, TInputValue, TOutputValue, TResolveValue>>\n static use<TThis extends typeof Error0, TKey extends string, TArgs extends unknown[], TOutputValue>(\n this: TThis,\n kind: 'method',\n key: TKey,\n value: ErrorPluginMethodFn<TOutputValue, TArgs, ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TArgs, TOutputValue>>\n static use<TThis extends typeof Error0>(\n this: TThis,\n kind: 'adapt',\n value: ErrorPluginAdaptFn<ErrorInstanceOfMap<PluginsMapOf<TThis>>, ErrorResolvedProps<PluginsMapOf<TThis>>>,\n ): ClassError0<PluginsMapOf<TThis>>\n static use<TThis extends typeof Error0>(\n this: TThis,\n kind: 'stack',\n value: ErrorPluginStack<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n ): ClassError0<PluginsMapOf<TThis>>\n static use<TThis extends typeof Error0>(\n this: TThis,\n kind: 'cause',\n value: ErrorPluginCause<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n ): ClassError0<PluginsMapOf<TThis>>\n static use<TThis extends typeof Error0>(\n this: TThis,\n kind: 'message',\n value: ErrorPluginMessage<ErrorInstanceOfMap<PluginsMapOf<TThis>>>,\n ): ClassError0<PluginsMapOf<TThis>>\n static use(\n this: typeof Error0,\n first: PluginError0 | 'prop' | 'method' | 'adapt' | 'stack' | 'cause' | 'message',\n key?: unknown,\n value?: ErrorPluginPropOptions<unknown> | ErrorPluginMethodFn<unknown>,\n ): ClassError0 {\n if (first instanceof PluginError0) {\n return this._useWithPlugin(this._pluginFromBuilder(first))\n }\n if (first === 'stack') {\n if (typeof key === 'undefined') {\n throw new Error('Error0.use(\"stack\", value) requires stack plugin value')\n }\n if (typeof key !== 'object' || key === null || typeof (key as { serialize?: unknown }).serialize !== 'function') {\n throw new Error('Error0.use(\"stack\", value) expects { serialize: function }')\n }\n return this._useWithPlugin({\n stack: key as ErrorPluginStack,\n })\n }\n if (first === 'cause') {\n if (typeof key === 'undefined') {\n throw new Error('Error0.use(\"cause\", value) requires cause plugin value')\n }\n if (typeof key !== 'object' || key === null || typeof (key as { serialize?: unknown }).serialize !== 'function') {\n throw new Error('Error0.use(\"cause\", value) expects { serialize: function }')\n }\n return this._useWithPlugin({\n cause: key as ErrorPluginCause,\n })\n }\n if (first === 'message') {\n if (typeof key === 'undefined') {\n throw new Error('Error0.use(\"message\", value) requires message plugin value')\n }\n if (typeof key !== 'object' || key === null || typeof (key as { serialize?: unknown }).serialize !== 'function') {\n throw new Error('Error0.use(\"message\", value) expects { serialize: function }')\n }\n return this._useWithPlugin({\n message: key as ErrorPluginMessage,\n })\n }\n if (first === 'adapt') {\n if (typeof key !== 'function') {\n throw new Error('Error0.use(\"adapt\", value) requires adapt function')\n }\n return this._useWithPlugin({\n adapt: [key as ErrorPluginAdaptFn<Error0, Record<string, unknown>>],\n })\n }\n if (typeof key !== 'string' || value === undefined) {\n throw new Error('Error0.use(kind, key, value) requires key and value')\n }\n\n if (first === 'prop') {\n if (key === 'stack') {\n throw new Error(RESERVED_STACK_PROP_ERROR)\n }\n if (key === 'message') {\n throw new Error(RESERVED_MESSAGE_PROP_ERROR)\n }\n return this._useWithPlugin({\n props: { [key]: value as ErrorPluginPropOptions<unknown> },\n })\n }\n return this._useWithPlugin({\n methods: { [key]: value as ErrorPluginMethodFn<unknown> },\n })\n }\n\n static plugin(): PluginError0 {\n return new PluginError0()\n }\n\n static serialize(error: unknown, isPublic = true): Record<string, unknown> {\n const error0 = this.from(error)\n const resolvedProps = this.resolve(error0)\n const resolvedRecord = resolvedProps as Record<string, unknown>\n const plugin = this._getResolvedPlugin()\n const messagePlugin = plugin.message\n let serializedMessage: unknown = error0.message\n try {\n if (messagePlugin) {\n serializedMessage = messagePlugin.serialize({ value: error0.message, error: error0, isPublic })\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to serialize message', error0)\n serializedMessage = error0.message\n }\n const json: Record<string, unknown> = {\n name: error0.name,\n message: serializedMessage,\n // we do not serialize causes, it is enough that we have floated props and adapt helper\n // cause: error0.cause,\n }\n\n const propsEntries = Object.entries(plugin.props)\n for (const [key, prop] of propsEntries) {\n if (prop.serialize === false) {\n continue\n }\n try {\n const value = resolvedRecord[key]\n const jsonValue = prop.serialize({ value, error: error0, isPublic })\n if (jsonValue !== undefined) {\n json[key] = jsonValue\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to serialize property ${key}`, resolvedRecord)\n }\n }\n const stackPlugin = plugin.stack\n try {\n let serializedStack: unknown\n if (stackPlugin) {\n serializedStack = stackPlugin.serialize({ value: error0.stack, error: error0, isPublic })\n } else {\n serializedStack = error0.stack\n }\n if (serializedStack !== undefined) {\n json.stack = serializedStack\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to serialize stack', error0)\n }\n const causePlugin = plugin.cause\n if (causePlugin?.serialize) {\n try {\n const serializedCause = causePlugin.serialize({\n value: (error0 as { cause?: unknown }).cause,\n error: error0,\n isPublic,\n })\n if (serializedCause !== undefined) {\n json.cause = serializedCause\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error('Error0: failed to serialize cause', error0)\n }\n }\n return Object.fromEntries(Object.entries(json).filter(([, value]) => value !== undefined)) as Record<\n string,\n unknown\n >\n }\n\n serialize(isPublic = true): Record<string, unknown> {\n const ctor = this.constructor as typeof Error0\n return ctor.serialize(this, isPublic)\n }\n}\n"],"mappings":"AAuLA,MAAM,4BAA4B;AAClC,MAAM,8BAA8B;AA0E7B,MAAM,aAGX;AAAA,EACiB;AAAA,EAER,QAAQ;AAAA,EAKjB,YAAY,QAA4D;AACtE,SAAK,UAAU;AAAA,MACb,OAAO,EAAE,GAAI,QAAQ,SAAS,CAAC,EAAG;AAAA,MAClC,SAAS,EAAE,GAAI,QAAQ,WAAW,CAAC,EAAG;AAAA,MACtC,OAAO,CAAC,GAAI,QAAQ,SAAS,CAAC,CAAE;AAAA,MAChC,OAAO,QAAQ;AAAA,MACf,OAAO,QAAQ;AAAA,MACf,SAAS,QAAQ;AAA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F,QAAQ;AAEN,cAAQ,MAAM,qCAAqC,MAAM;AAAA,IAC3D;AACA,UAAM,cAAc,OAAO;AAC3B,QAAI,aAAa,WAAW;AAC1B,UAAI;AACF,cAAM,kBAAkB,YAAY,UAAU;AAAA,UAC5C,OAAQ,OAA+B;AAAA,UACvC,OAAO;AAAA,UACP;AAAA,QACF,CAAC;AACD,YAAI,oBAAoB,QAAW;AACjC,eAAK,QAAQ;AAAA,QACf;AAAA,MACF,QAAQ;AAEN,gBAAQ,MAAM,qCAAqC,MAAM;AAAA,MAC3D;AAAA,IACF;AACA,WAAO,OAAO,YAAY,OAAO,QAAQ,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS,CAAC;AAAA,EAI3F;AAAA,EAEA,UAAU,WAAW,MAA+B;AAClD,UAAM,OAAO,KAAK;AAClB,WAAO,KAAK,UAAU,MAAM,QAAQ;AAAA,EACtC;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Error0 } from "../index.js";
|
|
2
|
+
const causeSerializePlugin = Error0.plugin().use("cause", {
|
|
3
|
+
serialize: ({ value, error, isPublic }) => {
|
|
4
|
+
const ctor = error.constructor;
|
|
5
|
+
if (ctor.is(value)) {
|
|
6
|
+
return ctor.serialize(value, isPublic);
|
|
7
|
+
}
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export {
|
|
12
|
+
causeSerializePlugin
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=cause-serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/cause-serialize.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const causeSerializePlugin = Error0.plugin().use('cause', {\n serialize: ({ value, error, isPublic }) => {\n const ctor = error.constructor as typeof Error0\n if (ctor.is(value)) {\n return ctor.serialize(value, isPublic)\n }\n return undefined\n },\n})\n"],"mappings":"AAAA,SAAS,cAAc;AAEhB,MAAM,uBAAuB,OAAO,OAAO,EAAE,IAAI,SAAS;AAAA,EAC/D,WAAW,CAAC,EAAE,OAAO,OAAO,SAAS,MAAM;AACzC,UAAM,OAAO,MAAM;AACnB,QAAI,KAAK,GAAG,KAAK,GAAG;AAClB,aAAO,KAAK,UAAU,OAAO,QAAQ;AAAA,IACvC;AACA,WAAO;AAAA,EACT;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PluginError0, ErrorPluginPropOptions, Error0, ErrorPluginMethodFn } from '../index.js';
|
|
2
|
+
|
|
3
|
+
declare const expectedPlugin: PluginError0<Record<never, never> & Record<"expected", ErrorPluginPropOptions<boolean, boolean, Error0, boolean>>, Record<never, never> & Record<"isExpected", ErrorPluginMethodFn<boolean, [], Error0>>>;
|
|
4
|
+
|
|
5
|
+
export { expectedPlugin };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Error0 } from "../index.js";
|
|
2
|
+
const isExpected = (flow) => {
|
|
3
|
+
let expected = false;
|
|
4
|
+
for (const value of flow) {
|
|
5
|
+
if (value === false) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (value === true) {
|
|
9
|
+
expected = true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return expected;
|
|
13
|
+
};
|
|
14
|
+
const expectedPlugin = Error0.plugin().use("prop", "expected", {
|
|
15
|
+
init: (input) => input,
|
|
16
|
+
resolve: ({ flow }) => isExpected(flow),
|
|
17
|
+
serialize: ({ value }) => value,
|
|
18
|
+
deserialize: ({ value }) => typeof value === "boolean" ? value : void 0
|
|
19
|
+
}).use("method", "isExpected", (error) => {
|
|
20
|
+
return isExpected(error.flow("expected"));
|
|
21
|
+
});
|
|
22
|
+
export {
|
|
23
|
+
expectedPlugin
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=expected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/expected.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nconst isExpected = (flow: unknown[]) => {\n let expected = false\n for (const value of flow) {\n if (value === false) {\n return false\n }\n if (value === true) {\n expected = true\n }\n }\n return expected\n}\n\nexport const expectedPlugin = Error0.plugin()\n .use('prop', 'expected', {\n init: (input: boolean) => input,\n resolve: ({ flow }) => isExpected(flow),\n serialize: ({ value }) => value,\n deserialize: ({ value }) => (typeof value === 'boolean' ? value : undefined),\n })\n .use('method', 'isExpected', (error) => {\n return isExpected(error.flow('expected'))\n })\n"],"mappings":"AAAA,SAAS,cAAc;AAEvB,MAAM,aAAa,CAAC,SAAoB;AACtC,MAAI,WAAW;AACf,aAAW,SAAS,MAAM;AACxB,QAAI,UAAU,OAAO;AACnB,aAAO;AAAA,IACT;AACA,QAAI,UAAU,MAAM;AAClB,iBAAW;AAAA,IACb;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,iBAAiB,OAAO,OAAO,EACzC,IAAI,QAAQ,YAAY;AAAA,EACvB,MAAM,CAAC,UAAmB;AAAA,EAC1B,SAAS,CAAC,EAAE,KAAK,MAAM,WAAW,IAAI;AAAA,EACtC,WAAW,CAAC,EAAE,MAAM,MAAM;AAAA,EAC1B,aAAa,CAAC,EAAE,MAAM,MAAO,OAAO,UAAU,YAAY,QAAQ;AACpE,CAAC,EACA,IAAI,UAAU,cAAc,CAAC,UAAU;AACtC,SAAO,WAAW,MAAM,KAAK,UAAU,CAAC;AAC1C,CAAC;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Error0 } from "../index.js";
|
|
2
|
+
const messageMergePlugin = Error0.plugin().use("message", {
|
|
3
|
+
serialize: ({ error }) => {
|
|
4
|
+
return error.causes().map((cause) => {
|
|
5
|
+
return cause instanceof Error ? cause.message : void 0;
|
|
6
|
+
}).filter((value) => typeof value === "string").join(": ") || "Unknown error";
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export {
|
|
10
|
+
messageMergePlugin
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=message-merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/message-merge.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const messageMergePlugin = Error0.plugin().use('message', {\n serialize: ({ error }) => {\n return (\n error\n .causes()\n .map((cause) => {\n return cause instanceof Error ? cause.message : undefined\n })\n .filter((value): value is string => typeof value === 'string')\n .join(': ') || 'Unknown error'\n )\n },\n})\n"],"mappings":"AAAA,SAAS,cAAc;AAEhB,MAAM,qBAAqB,OAAO,OAAO,EAAE,IAAI,WAAW;AAAA,EAC/D,WAAW,CAAC,EAAE,MAAM,MAAM;AACxB,WACE,MACG,OAAO,EACP,IAAI,CAAC,UAAU;AACd,aAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,IAClD,CAAC,EACA,OAAO,CAAC,UAA2B,OAAO,UAAU,QAAQ,EAC5D,KAAK,IAAI,KAAK;AAAA,EAErB;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.js';
|
|
2
|
+
|
|
3
|
+
declare const metaPlugin: PluginError0<Record<never, never> & Record<"meta", ErrorPluginPropOptions<Record<string, unknown>, Record<string, unknown>, Error0, Record<string, unknown> | undefined>>, Record<never, never>>;
|
|
4
|
+
|
|
5
|
+
export { metaPlugin };
|