@devp0nt/error0 1.0.0-next.45 → 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.
Files changed (57) hide show
  1. package/dist/cjs/index.cjs +80 -64
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +32 -22
  4. package/dist/cjs/plugins/cause-serialize.cjs +38 -0
  5. package/dist/cjs/plugins/cause-serialize.cjs.map +1 -0
  6. package/dist/cjs/plugins/cause-serialize.d.cts +5 -0
  7. package/dist/cjs/plugins/expected.cjs +49 -0
  8. package/dist/cjs/plugins/expected.cjs.map +1 -0
  9. package/dist/cjs/plugins/expected.d.cts +5 -0
  10. package/dist/cjs/plugins/message-merge.cjs +36 -0
  11. package/dist/cjs/plugins/message-merge.cjs.map +1 -0
  12. package/dist/cjs/plugins/message-merge.d.cts +5 -0
  13. package/dist/cjs/plugins/meta.cjs +73 -0
  14. package/dist/cjs/plugins/meta.cjs.map +1 -0
  15. package/dist/cjs/plugins/meta.d.cts +5 -0
  16. package/dist/cjs/plugins/stack-merge.cjs +39 -0
  17. package/dist/cjs/plugins/stack-merge.cjs.map +1 -0
  18. package/dist/cjs/plugins/stack-merge.d.cts +5 -0
  19. package/dist/cjs/plugins/tags.cjs +48 -0
  20. package/dist/cjs/plugins/tags.cjs.map +1 -0
  21. package/dist/cjs/plugins/tags.d.cts +5 -0
  22. package/dist/esm/index.d.ts +32 -22
  23. package/dist/esm/index.js +80 -64
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/plugins/cause-serialize.d.ts +5 -0
  26. package/dist/esm/plugins/cause-serialize.js +14 -0
  27. package/dist/esm/plugins/cause-serialize.js.map +1 -0
  28. package/dist/esm/plugins/expected.d.ts +5 -0
  29. package/dist/esm/plugins/expected.js +25 -0
  30. package/dist/esm/plugins/expected.js.map +1 -0
  31. package/dist/esm/plugins/message-merge.d.ts +5 -0
  32. package/dist/esm/plugins/message-merge.js +12 -0
  33. package/dist/esm/plugins/message-merge.js.map +1 -0
  34. package/dist/esm/plugins/meta.d.ts +5 -0
  35. package/dist/esm/plugins/meta.js +49 -0
  36. package/dist/esm/plugins/meta.js.map +1 -0
  37. package/dist/esm/plugins/stack-merge.d.ts +5 -0
  38. package/dist/esm/plugins/stack-merge.js +15 -0
  39. package/dist/esm/plugins/stack-merge.js.map +1 -0
  40. package/dist/esm/plugins/tags.d.ts +5 -0
  41. package/dist/esm/plugins/tags.js +24 -0
  42. package/dist/esm/plugins/tags.js.map +1 -0
  43. package/package.json +9 -1
  44. package/src/index.test.ts +77 -100
  45. package/src/index.ts +173 -120
  46. package/src/plugins/cause-serialize.test.ts +51 -0
  47. package/src/plugins/cause-serialize.ts +11 -0
  48. package/src/plugins/expected.test.ts +47 -0
  49. package/src/plugins/expected.ts +25 -0
  50. package/src/plugins/message-merge.test.ts +32 -0
  51. package/src/plugins/message-merge.ts +15 -0
  52. package/src/plugins/meta.test.ts +32 -0
  53. package/src/plugins/meta.ts +53 -0
  54. package/src/plugins/stack-merge.test.ts +64 -0
  55. package/src/plugins/stack-merge.ts +16 -0
  56. package/src/plugins/tags.test.ts +22 -0
  57. package/src/plugins/tags.ts +21 -0
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(index_exports);
25
25
  const RESERVED_STACK_PROP_ERROR = 'Error0: "stack" is a reserved prop key. Use .stack(...) plugin API instead';
26
+ const RESERVED_MESSAGE_PROP_ERROR = 'Error0: "message" is a reserved prop key. Use .message(...) plugin API instead';
26
27
  class PluginError0 {
27
28
  _plugin;
28
29
  Infer = void 0;
@@ -32,7 +33,8 @@ class PluginError0 {
32
33
  methods: { ...plugin?.methods ?? {} },
33
34
  adapt: [...plugin?.adapt ?? []],
34
35
  stack: plugin?.stack,
35
- cause: plugin?.cause
36
+ cause: plugin?.cause,
37
+ message: plugin?.message
36
38
  };
37
39
  }
38
40
  prop(key, value) {
@@ -50,17 +52,24 @@ class PluginError0 {
50
52
  cause(value) {
51
53
  return this.use("cause", value);
52
54
  }
55
+ message(value) {
56
+ return this.use("message", value);
57
+ }
53
58
  use(kind, keyOrValue, value) {
54
59
  const nextProps = { ...this._plugin.props ?? {} };
55
60
  const nextMethods = { ...this._plugin.methods ?? {} };
56
61
  const nextAdapt = [...this._plugin.adapt ?? []];
57
62
  let nextStack = this._plugin.stack;
58
63
  let nextCause = this._plugin.cause;
64
+ let nextMessage = this._plugin.message;
59
65
  if (kind === "prop") {
60
66
  const key = keyOrValue;
61
67
  if (key === "stack") {
62
68
  throw new Error(RESERVED_STACK_PROP_ERROR);
63
69
  }
70
+ if (key === "message") {
71
+ throw new Error(RESERVED_MESSAGE_PROP_ERROR);
72
+ }
64
73
  if (value === void 0) {
65
74
  throw new Error('PluginError0.use("prop", key, value) requires value');
66
75
  }
@@ -75,27 +84,32 @@ class PluginError0 {
75
84
  nextAdapt.push(keyOrValue);
76
85
  } else if (kind === "stack") {
77
86
  nextStack = keyOrValue;
78
- } else {
87
+ } else if (kind === "cause") {
79
88
  nextCause = keyOrValue;
89
+ } else {
90
+ nextMessage = keyOrValue;
80
91
  }
81
92
  return new PluginError0({
82
93
  props: nextProps,
83
94
  methods: nextMethods,
84
95
  adapt: nextAdapt,
85
96
  stack: nextStack,
86
- cause: nextCause
97
+ cause: nextCause,
98
+ message: nextMessage
87
99
  });
88
100
  }
89
101
  }
90
102
  class Error0 extends Error {
91
103
  static __pluginsMap;
104
+ __pluginsMap;
92
105
  static _plugins = [];
93
106
  static _emptyPlugin = {
94
107
  props: {},
95
108
  methods: {},
96
109
  adapt: [],
97
110
  stack: void 0,
98
- cause: void 0
111
+ cause: void 0,
112
+ message: void 0
99
113
  };
100
114
  static _getResolvedPlugin() {
101
115
  const resolved = {
@@ -107,6 +121,9 @@ class Error0 extends Error {
107
121
  if (plugin.props && "stack" in plugin.props) {
108
122
  throw new Error(RESERVED_STACK_PROP_ERROR);
109
123
  }
124
+ if (plugin.props && "message" in plugin.props) {
125
+ throw new Error(RESERVED_MESSAGE_PROP_ERROR);
126
+ }
110
127
  Object.assign(resolved.props, plugin.props ?? this._emptyPlugin.props);
111
128
  Object.assign(resolved.methods, plugin.methods ?? this._emptyPlugin.methods);
112
129
  resolved.adapt.push(...plugin.adapt ?? this._emptyPlugin.adapt);
@@ -116,6 +133,9 @@ class Error0 extends Error {
116
133
  if (typeof plugin.cause !== "undefined") {
117
134
  resolved.cause = plugin.cause;
118
135
  }
136
+ if (typeof plugin.message !== "undefined") {
137
+ resolved.message = plugin.message;
138
+ }
119
139
  }
120
140
  return resolved;
121
141
  }
@@ -311,8 +331,7 @@ class Error0 extends Error {
311
331
  console.error(`Error0: failed to deserialize property ${key}`, errorRecord);
312
332
  }
313
333
  }
314
- const stackPlugin = plugin.stack;
315
- if (stackPlugin !== false && "stack" in errorRecord) {
334
+ if ("stack" in errorRecord) {
316
335
  try {
317
336
  if (typeof errorRecord.stack === "string") {
318
337
  recreated.stack = errorRecord.stack;
@@ -321,8 +340,8 @@ class Error0 extends Error {
321
340
  console.error("Error0: failed to deserialize stack", errorRecord);
322
341
  }
323
342
  }
324
- const causePlugin = plugin.cause ?? false;
325
- if (causePlugin && "cause" in errorRecord) {
343
+ const causePlugin = plugin.cause;
344
+ if (causePlugin?.serialize && "cause" in errorRecord) {
326
345
  try {
327
346
  if (this.isSerialized(errorRecord.cause)) {
328
347
  ;
@@ -377,24 +396,10 @@ class Error0 extends Error {
377
396
  methods: { ...pluginRecord._plugin.methods ?? {} },
378
397
  adapt: [...pluginRecord._plugin.adapt ?? []],
379
398
  stack: pluginRecord._plugin.stack,
380
- cause: pluginRecord._plugin.cause
399
+ cause: pluginRecord._plugin.cause,
400
+ message: pluginRecord._plugin.message
381
401
  };
382
402
  }
383
- static prop(key, value) {
384
- return this.use("prop", key, value);
385
- }
386
- static method(key, value) {
387
- return this.use("method", key, value);
388
- }
389
- static adapt(value) {
390
- return this.use("adapt", value);
391
- }
392
- static stack(value) {
393
- return this.use("stack", value);
394
- }
395
- static cause(value) {
396
- return this.use("cause", value);
397
- }
398
403
  static use(first, key, value) {
399
404
  if (first instanceof PluginError0) {
400
405
  return this._useWithPlugin(this._pluginFromBuilder(first));
@@ -403,8 +408,8 @@ class Error0 extends Error {
403
408
  if (typeof key === "undefined") {
404
409
  throw new Error('Error0.use("stack", value) requires stack plugin value');
405
410
  }
406
- if (key !== "merge" && typeof key !== "boolean" && typeof key !== "function") {
407
- throw new Error('Error0.use("stack", value) expects function | boolean | "merge"');
411
+ if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
412
+ throw new Error('Error0.use("stack", value) expects { serialize: function }');
408
413
  }
409
414
  return this._useWithPlugin({
410
415
  stack: key
@@ -414,13 +419,24 @@ class Error0 extends Error {
414
419
  if (typeof key === "undefined") {
415
420
  throw new Error('Error0.use("cause", value) requires cause plugin value');
416
421
  }
417
- if (typeof key !== "boolean" && typeof key !== "function") {
418
- throw new Error('Error0.use("cause", value) expects function | boolean');
422
+ if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
423
+ throw new Error('Error0.use("cause", value) expects { serialize: function }');
419
424
  }
420
425
  return this._useWithPlugin({
421
426
  cause: key
422
427
  });
423
428
  }
429
+ if (first === "message") {
430
+ if (typeof key === "undefined") {
431
+ throw new Error('Error0.use("message", value) requires message plugin value');
432
+ }
433
+ if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
434
+ throw new Error('Error0.use("message", value) expects { serialize: function }');
435
+ }
436
+ return this._useWithPlugin({
437
+ message: key
438
+ });
439
+ }
424
440
  if (first === "adapt") {
425
441
  if (typeof key !== "function") {
426
442
  throw new Error('Error0.use("adapt", value) requires adapt function');
@@ -436,6 +452,9 @@ class Error0 extends Error {
436
452
  if (key === "stack") {
437
453
  throw new Error(RESERVED_STACK_PROP_ERROR);
438
454
  }
455
+ if (key === "message") {
456
+ throw new Error(RESERVED_MESSAGE_PROP_ERROR);
457
+ }
439
458
  return this._useWithPlugin({
440
459
  props: { [key]: value }
441
460
  });
@@ -451,13 +470,23 @@ class Error0 extends Error {
451
470
  const error0 = this.from(error);
452
471
  const resolvedProps = this.resolve(error0);
453
472
  const resolvedRecord = resolvedProps;
473
+ const plugin = this._getResolvedPlugin();
474
+ const messagePlugin = plugin.message;
475
+ let serializedMessage = error0.message;
476
+ try {
477
+ if (messagePlugin) {
478
+ serializedMessage = messagePlugin.serialize({ value: error0.message, error: error0, isPublic });
479
+ }
480
+ } catch {
481
+ console.error("Error0: failed to serialize message", error0);
482
+ serializedMessage = error0.message;
483
+ }
454
484
  const json = {
455
485
  name: error0.name,
456
- message: error0.message
486
+ message: serializedMessage
457
487
  // we do not serialize causes, it is enough that we have floated props and adapt helper
458
488
  // cause: error0.cause,
459
489
  };
460
- const plugin = this._getResolvedPlugin();
461
490
  const propsEntries = Object.entries(plugin.props);
462
491
  for (const [key, prop] of propsEntries) {
463
492
  if (prop.serialize === false) {
@@ -473,43 +502,30 @@ class Error0 extends Error {
473
502
  console.error(`Error0: failed to serialize property ${key}`, resolvedRecord);
474
503
  }
475
504
  }
476
- const stackSerialize = plugin.stack;
477
- if (stackSerialize !== false) {
478
- try {
479
- let serializedStack;
480
- if (stackSerialize === "merge") {
481
- serializedStack = error0.causes().map((cause) => {
482
- return cause instanceof Error ? cause.stack : void 0;
483
- }).filter((value) => typeof value === "string").join("\n");
484
- } else if (typeof stackSerialize === "function") {
485
- serializedStack = stackSerialize({ value: error0.stack, error: error0, isPublic });
486
- } else {
487
- serializedStack = error0.stack;
488
- }
489
- if (serializedStack !== void 0) {
490
- json.stack = serializedStack;
491
- }
492
- } catch {
493
- console.error("Error0: failed to serialize stack", error0);
505
+ const stackPlugin = plugin.stack;
506
+ try {
507
+ let serializedStack;
508
+ if (stackPlugin) {
509
+ serializedStack = stackPlugin.serialize({ value: error0.stack, error: error0, isPublic });
510
+ } else {
511
+ serializedStack = error0.stack;
494
512
  }
513
+ if (serializedStack !== void 0) {
514
+ json.stack = serializedStack;
515
+ }
516
+ } catch {
517
+ console.error("Error0: failed to serialize stack", error0);
495
518
  }
496
- const causeSerialize = plugin.cause ?? false;
497
- if (causeSerialize) {
519
+ const causePlugin = plugin.cause;
520
+ if (causePlugin?.serialize) {
498
521
  try {
499
- if (causeSerialize === true) {
500
- const causeValue = error0.cause;
501
- if (this.is(causeValue)) {
502
- json.cause = this.serialize(causeValue, isPublic);
503
- }
504
- } else {
505
- const serializedCause = causeSerialize({
506
- value: error0.cause,
507
- error: error0,
508
- isPublic
509
- });
510
- if (serializedCause !== void 0) {
511
- json.cause = serializedCause;
512
- }
522
+ const serializedCause = causePlugin.serialize({
523
+ value: error0.cause,
524
+ error: error0,
525
+ isPublic
526
+ });
527
+ if (serializedCause !== void 0) {
528
+ json.cause = serializedCause;
513
529
  }
514
530
  } catch {
515
531
  console.error("Error0: failed to serialize cause", error0);
@@ -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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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ACF;AACA,UAAM,iBAAiB,OAAO,SAAS;AACvC,QAAI,gBAAgB;AAClB,UAAI;AACF,YAAI,mBAAmB,MAAM;AAC3B,gBAAM,aAAc,OAA+B;AACnD,cAAI,KAAK,GAAG,UAAU,GAAG;AACvB,iBAAK,QAAQ,KAAK,UAAU,YAAY,QAAQ;AAAA,UAClD;AAAA,QACF,OAAO;AACL,gBAAM,kBAAkB,eAAe;AAAA,YACrC,OAAQ,OAA+B;AAAA,YACvC,OAAO;AAAA,YACP;AAAA,UACF,CAAC;AACD,cAAI,oBAAoB,QAAW;AACjC,iBAAK,QAAQ;AAAA,UACf;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":[]}
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,KAME,KACA,OACsG;AACtG,WAAO,KAAK,IAAI,QAAQ,KAAK,KAAK;AAAA,EACpC;AAAA,EAEA,OACE,KACA,OACqF;AACrF,WAAO,KAAK,IAAI,UAAU,KAAK,KAAK;AAAA,EACtC;AAAA,EAEA,MACE,OACgC;AAChC,WAAO,KAAK,IAAI,SAAS,KAAK;AAAA,EAChC;AAAA,EAEA,MAAM,OAA0F;AAC9F,WAAO,KAAK,IAAI,SAAS,KAAK;AAAA,EAChC;AAAA,EAEA,MAAM,OAA0F;AAC9F,WAAO,KAAK,IAAI,SAAS,KAAK;AAAA,EAChC;AAAA,EAEA,QAAQ,OAA4F;AAClG,WAAO,KAAK,IAAI,WAAW,KAAK;AAAA,EAClC;AAAA,EAwBA,IACE,MACA,YACA,OACwB;AACxB,UAAM,YAA8B,EAAE,GAAI,KAAK,QAAQ,SAAS,CAAC,EAAG;AACpE,UAAM,cAAkC,EAAE,GAAI,KAAK,QAAQ,WAAW,CAAC,EAAG;AAC1E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