@devp0nt/error0 1.0.0-next.50 → 1.0.0-next.51

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 (67) hide show
  1. package/dist/cjs/index.cjs +15 -15
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +11 -2
  4. package/dist/cjs/plugins/{cause-serialize.cjs → cause.cjs} +34 -12
  5. package/dist/cjs/plugins/cause.cjs.map +1 -0
  6. package/dist/cjs/plugins/cause.d.cts +15 -0
  7. package/dist/cjs/plugins/code.cjs +10 -2
  8. package/dist/cjs/plugins/code.cjs.map +1 -1
  9. package/dist/cjs/plugins/code.d.cts +2 -1
  10. package/dist/cjs/plugins/expected.cjs +19 -6
  11. package/dist/cjs/plugins/expected.cjs.map +1 -1
  12. package/dist/cjs/plugins/expected.d.cts +4 -3
  13. package/dist/cjs/plugins/meta.cjs +3 -3
  14. package/dist/cjs/plugins/meta.cjs.map +1 -1
  15. package/dist/cjs/plugins/meta.d.cts +2 -2
  16. package/dist/cjs/plugins/stack-merge.cjs +3 -3
  17. package/dist/cjs/plugins/stack-merge.cjs.map +1 -1
  18. package/dist/cjs/plugins/stack-merge.d.cts +2 -2
  19. package/dist/cjs/plugins/status.cjs +7 -1
  20. package/dist/cjs/plugins/status.cjs.map +1 -1
  21. package/dist/cjs/plugins/status.d.cts +2 -1
  22. package/dist/cjs/plugins/tags.cjs +3 -3
  23. package/dist/cjs/plugins/tags.cjs.map +1 -1
  24. package/dist/cjs/plugins/tags.d.cts +2 -2
  25. package/dist/esm/index.d.ts +11 -2
  26. package/dist/esm/index.js +15 -15
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/plugins/cause.d.ts +15 -0
  29. package/dist/esm/plugins/cause.js +39 -0
  30. package/dist/esm/plugins/cause.js.map +1 -0
  31. package/dist/esm/plugins/code.d.ts +2 -1
  32. package/dist/esm/plugins/code.js +10 -2
  33. package/dist/esm/plugins/code.js.map +1 -1
  34. package/dist/esm/plugins/expected.d.ts +4 -3
  35. package/dist/esm/plugins/expected.js +19 -6
  36. package/dist/esm/plugins/expected.js.map +1 -1
  37. package/dist/esm/plugins/meta.d.ts +2 -2
  38. package/dist/esm/plugins/meta.js +3 -3
  39. package/dist/esm/plugins/meta.js.map +1 -1
  40. package/dist/esm/plugins/stack-merge.d.ts +2 -2
  41. package/dist/esm/plugins/stack-merge.js +3 -3
  42. package/dist/esm/plugins/stack-merge.js.map +1 -1
  43. package/dist/esm/plugins/status.d.ts +2 -1
  44. package/dist/esm/plugins/status.js +7 -1
  45. package/dist/esm/plugins/status.js.map +1 -1
  46. package/dist/esm/plugins/tags.d.ts +2 -2
  47. package/dist/esm/plugins/tags.js +3 -3
  48. package/dist/esm/plugins/tags.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/index.test.ts +9 -2
  51. package/src/index.ts +31 -16
  52. package/src/plugins/{cause-serialize.test.ts → cause.test.ts} +56 -3
  53. package/src/plugins/cause.ts +45 -0
  54. package/src/plugins/code.ts +10 -2
  55. package/src/plugins/expected.test.ts +22 -3
  56. package/src/plugins/expected.ts +23 -6
  57. package/src/plugins/meta.ts +3 -3
  58. package/src/plugins/stack-merge.test.ts +0 -7
  59. package/src/plugins/stack-merge.ts +4 -4
  60. package/src/plugins/status.ts +8 -2
  61. package/src/plugins/tags.ts +4 -4
  62. package/dist/cjs/plugins/cause-serialize.cjs.map +0 -1
  63. package/dist/cjs/plugins/cause-serialize.d.cts +0 -7
  64. package/dist/esm/plugins/cause-serialize.d.ts +0 -7
  65. package/dist/esm/plugins/cause-serialize.js +0 -17
  66. package/dist/esm/plugins/cause-serialize.js.map +0 -1
  67. package/src/plugins/cause-serialize.ts +0 -15
@@ -392,15 +392,15 @@ class Error0 extends Error {
392
392
  }
393
393
  }
394
394
  const causePlugin = plugin.cause;
395
- if (causePlugin?.serialize && "cause" in errorRecord) {
395
+ if (causePlugin && "cause" in errorRecord) {
396
396
  try {
397
- if (this.isSerialized(errorRecord.cause)) {
398
- ;
399
- recreated.cause = this._fromSerialized(errorRecord.cause);
400
- } else {
401
- ;
402
- recreated.cause = errorRecord.cause;
403
- }
397
+ ;
398
+ recreated.cause = causePlugin.deserialize({
399
+ cause: errorRecord.cause,
400
+ error: errorRecord,
401
+ isSerialized: (serializedCause) => this.isSerialized(serializedCause),
402
+ fromSerialized: (serializedCause) => this._fromSerialized(serializedCause)
403
+ });
404
404
  } catch {
405
405
  console.error("Error0: failed to deserialize cause", errorRecord);
406
406
  }
@@ -471,8 +471,8 @@ class Error0 extends Error {
471
471
  if (typeof key === "undefined") {
472
472
  throw new Error('Error0.use("cause", value) requires cause plugin value');
473
473
  }
474
- if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
475
- throw new Error('Error0.use("cause", value) expects { serialize: function }');
474
+ if (typeof key !== "object" || key === null || typeof key.serialize !== "function" || typeof key.deserialize !== "function") {
475
+ throw new Error('Error0.use("cause", value) expects { serialize: function, deserialize: function }');
476
476
  }
477
477
  return this._useWithPlugin({
478
478
  cause: key
@@ -534,8 +534,6 @@ class Error0 extends Error {
534
534
  }
535
535
  const json = {
536
536
  name: error0.name
537
- // we do not serialize causes, it is enough that we have floated props and adapt helper
538
- // cause: error0.cause,
539
537
  };
540
538
  if (serializedMessage !== void 0) {
541
539
  json.message = serializedMessage;
@@ -572,7 +570,7 @@ class Error0 extends Error {
572
570
  if (stackPlugin) {
573
571
  serializedStack = stackPlugin.serialize({ value: error0.stack, error: error0, isPublic });
574
572
  } else {
575
- serializedStack = error0.stack;
573
+ serializedStack = isPublic ? void 0 : error0.stack;
576
574
  }
577
575
  if (serializedStack !== void 0) {
578
576
  json.stack = serializedStack;
@@ -584,9 +582,11 @@ class Error0 extends Error {
584
582
  if (causePlugin?.serialize) {
585
583
  try {
586
584
  const serializedCause = causePlugin.serialize({
587
- value: error0.cause,
585
+ cause: error0.cause,
588
586
  error: error0,
589
- isPublic
587
+ isPublic,
588
+ is: (cause) => this.is(cause),
589
+ serialize: (cause) => this.serialize(cause, isPublic)
590
590
  });
591
591
  if (serializedCause !== void 0) {
592
592
  json.cause = serializedCause;
@@ -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 ErrorPluginPropSerializeOptions<\n TOutputValue,\n TError extends Error0,\n TResolveValue extends TOutputValue | undefined,\n> = {\n own: TOutputValue | undefined\n flow: Array<TOutputValue | undefined>\n resolved: TResolveValue\n error: TError\n isPublic: boolean\n}\ntype ErrorPluginPropSerialize<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> =\n | ((options: ErrorPluginPropSerializeOptions<TOutputValue, TError, TResolveValue>) => unknown)\n | false\ntype ErrorPluginPropDeserialize<TOutputValue> =\n | ((options: { value: unknown; record: Record<string, unknown> }) => TOutputValue | undefined)\n | false\ntype ErrorPluginPropOptionsResolveOptions<TOutputValue, TError extends Error0> = {\n own: TOutputValue | undefined\n flow: Array<TOutputValue | undefined>\n error: TError\n}\ntype ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {\n resolve: (options: ErrorPluginPropOptionsResolveOptions<TOutputValue, TError>) => TResolveValue\n serialize: ErrorPluginPropSerialize<TOutputValue, TError, TResolveValue>\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\ntype ErrorPluginAnyMethodFn = (error: any, ...args: any[]) => any\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 = { fn: ErrorPluginAnyMethodFn }\n\nexport type ErrorPluginProps = { [key: string]: ErrorPluginPropOptions<any, any> }\nexport type ErrorPluginMethods = { [key: string]: ErrorPluginAnyMethodFn }\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 TMethod extends ErrorPluginAnyMethodFn,\n> = TMethods & Record<TKey, TMethod>\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 BindInstanceMethod<TMethod> = TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n (error: any, ...args: infer TArgs4): infer TOutput4\n}\n ? {\n (...args: TArgs1): TOutput1\n (...args: TArgs2): TOutput2\n (...args: TArgs3): TOutput3\n (...args: TArgs4): TOutput4\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n }\n ? {\n (...args: TArgs1): TOutput1\n (...args: TArgs2): TOutput2\n (...args: TArgs3): TOutput3\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n }\n ? {\n (...args: TArgs1): TOutput1\n (...args: TArgs2): TOutput2\n }\n : TMethod extends (error: any, ...args: infer TArgs) => infer TOutput\n ? (...args: TArgs) => TOutput\n : never\ntype BindStaticMethod<TMethod> = TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n (error: any, ...args: infer TArgs4): infer TOutput4\n}\n ? {\n (error: unknown, ...args: TArgs1): TOutput1\n (error: unknown, ...args: TArgs2): TOutput2\n (error: unknown, ...args: TArgs3): TOutput3\n (error: unknown, ...args: TArgs4): TOutput4\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n }\n ? {\n (error: unknown, ...args: TArgs1): TOutput1\n (error: unknown, ...args: TArgs2): TOutput2\n (error: unknown, ...args: TArgs3): TOutput3\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n }\n ? {\n (error: unknown, ...args: TArgs1): TOutput1\n (error: unknown, ...args: TArgs2): TOutput2\n }\n : TMethod extends (error: any, ...args: infer TArgs) => infer TOutput\n ? (error: unknown, ...args: TArgs) => TOutput\n : never\ntype ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: BindInstanceMethod<TPluginsMap['methods'][TKey]['fn']>\n}\nexport type ErrorResolved<TPluginsMap extends ErrorPluginsMap> = ErrorResolvedProps<TPluginsMap> &\n ErrorMethods<TPluginsMap>\n\ntype ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: BindStaticMethod<TPluginsMap['methods'][TKey]['fn']>\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 propKeys: string[]\n propEntries: Array<[string, ErrorPluginPropOptions<unknown>]>\n methodEntries: Array<[string, ErrorPluginMethodFn<unknown>]>\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']>]: {\n fn: NonNullable<TPlugin['methods']>[TKey] extends ErrorPluginAnyMethodFn\n ? NonNullable<TPlugin['methods']>[TKey]\n : never\n }\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 TMethod extends ErrorPluginAnyMethodFn,\n> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<never, never>, Record<TKey, TMethod>>>\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 &\n ErrorResolved<TMap> &\n ErrorOwnMethods<TMap> &\n ErrorResolveMethods<TMap> & { readonly __pluginsMap?: TMap }\ntype BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 &\n ErrorResolved<PluginsMapFromParts<TProps, TMethods>> &\n ErrorOwnMethods<PluginsMapFromParts<TProps, TMethods>> &\n ErrorResolveMethods<PluginsMapFromParts<TProps, TMethods>> & {\n readonly __pluginsMap?: PluginsMapFromParts<TProps, TMethods>\n }\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, TMethod extends (error: BuilderError0<TProps, TMethods>, ...args: any[]) => any>(\n key: TKey,\n value: TMethod,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TMethod>> {\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, TMethod extends (error: BuilderError0<TProps, TMethods>, ...args: any[]) => any>(\n kind: 'method',\n key: TKey,\n value: TMethod,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TMethod>>\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\nconst OWN_SYMBOL: unique symbol = Symbol('Error0.own')\ntype ErrorOwnStore = Record<string, unknown>\n\nexport type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {\n MAX_CAUSES_DEPTH: number\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 round: (\n error: unknown,\n isPublic?: boolean,\n ) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>\n causes: {\n (error: unknown, instancesOnly?: false): unknown[]\n (\n error: unknown,\n instancesOnly: true,\n ): Array<Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>>\n }\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, TMethod extends (error: ErrorInstanceOfMap<TPluginsMap>, ...args: any[]) => any>(\n // key: TKey,\n // value: TMethod,\n // ) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TMethod>>\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, TMethod extends (error: ErrorInstanceOfMap<TPluginsMap>, ...args: any[]) => any>(\n kind: 'method',\n key: TKey,\n value: TMethod,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TMethod>>\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 static MAX_CAUSES_DEPTH = 99\n protected static _plugins: ErrorPlugin[] = []\n protected static _resolvedPlugin?: ErrorPluginResolved\n\n private static readonly _emptyPlugin: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n stack: undefined,\n cause: undefined,\n message: undefined,\n propKeys: [],\n propEntries: [],\n methodEntries: [],\n }\n\n private static _indexResolvedPlugin(\n resolved: Omit<ErrorPluginResolved, 'propKeys' | 'propEntries' | 'methodEntries'>,\n ): ErrorPluginResolved {\n return {\n ...resolved,\n propKeys: Object.keys(resolved.props),\n propEntries: Object.entries(resolved.props),\n methodEntries: Object.entries(resolved.methods),\n }\n }\n\n private static _applyPlugin(\n resolved: Omit<ErrorPluginResolved, 'propKeys' | 'propEntries' | 'methodEntries'>,\n plugin: ErrorPlugin,\n ): void {\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\n private static _mergeResolvedPlugin(\n this: typeof Error0,\n base: ErrorPluginResolved,\n plugin: ErrorPlugin,\n ): ErrorPluginResolved {\n const merged: Omit<ErrorPluginResolved, 'propKeys' | 'propEntries' | 'methodEntries'> = {\n props: { ...base.props },\n methods: { ...base.methods },\n adapt: [...base.adapt],\n stack: base.stack,\n cause: base.cause,\n message: base.message,\n }\n this._applyPlugin(merged, plugin)\n return this._indexResolvedPlugin(merged)\n }\n\n private static _getResolvedPlugin(this: typeof Error0): ErrorPluginResolved {\n if (Object.prototype.hasOwnProperty.call(this, '_resolvedPlugin') && this._resolvedPlugin) {\n return this._resolvedPlugin\n }\n const resolved: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n propKeys: [],\n propEntries: [],\n methodEntries: [],\n }\n for (const plugin of this._plugins) {\n this._applyPlugin(resolved, plugin)\n }\n const indexed = this._indexResolvedPlugin(resolved)\n Object.defineProperty(this, '_resolvedPlugin', {\n value: indexed,\n writable: true,\n enumerable: false,\n configurable: true,\n })\n return indexed\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 const ownStore = Object.create(null) as ErrorOwnStore\n Object.defineProperty(this, OWN_SYMBOL, { value: ownStore, writable: true, enumerable: false, configurable: true })\n\n for (const [key, prop] of plugin.propEntries) {\n if (key === 'stack') {\n continue\n }\n Object.defineProperty(this, key, {\n get: () =>\n prop.resolve({\n own: ownStore[key],\n flow: this.flow(key as never),\n error: this,\n }),\n set: (value) => {\n ownStore[key] = value\n },\n enumerable: true,\n configurable: true,\n })\n if (key in input) {\n const ownValue = (input as Record<string, unknown>)[key]\n ownStore[key] = typeof prop.init === 'function' ? prop.init(ownValue) : ownValue\n }\n }\n }\n\n private static _getOwnStore(object: object): ErrorOwnStore | undefined {\n const record = object as Record<string | symbol, unknown>\n const existing = record[OWN_SYMBOL]\n if (existing && typeof existing === 'object') {\n return existing as ErrorOwnStore\n }\n return undefined\n }\n\n private static readonly isOwnProperty = (object: object, key: string): boolean => {\n const ownStore = this._getOwnStore(object)\n if (ownStore) {\n return Object.prototype.hasOwnProperty.call(ownStore, key)\n }\n return !!Object.getOwnPropertyDescriptor(object, key)\n }\n private static _ownByKey(error: object, key: string): unknown {\n const ownStore = this._getOwnStore(error)\n if (ownStore) {\n return ownStore[key]\n }\n return (error as Record<string, unknown>)[key]\n }\n private static _flowByKey(error: object, key: string): unknown[] {\n const causes = this.causes(error, true)\n const values = new Array<unknown>(causes.length)\n for (let i = 0; i < causes.length; i += 1) {\n values[i] = this._ownByKey(causes[i], key)\n }\n return values\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 plugin.propKeys) {\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 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 const ctor = this.constructor as typeof Error0\n return ctor._flowByKey(this, key)\n }\n\n static _resolveByKey(error: Error0, key: string, plugin: ErrorPluginResolved): unknown {\n try {\n const options = {\n get own() {\n return error.own(key as never)\n },\n get flow() {\n return error.flow(key as never)\n },\n error,\n }\n const prop = plugin.props[key]\n const resolver = prop.resolve\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!resolver) {\n return (error as any)[key]\n }\n return resolver(options as ErrorPluginPropOptionsResolveOptions<any, any>)\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to resolve property ${key}`, error)\n return undefined\n }\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 of plugin.propKeys) {\n resolved[key] = this._resolveByKey(error0, key, plugin)\n }\n return resolved\n }\n resolve<TThis extends Error0>(this: TThis): ErrorResolvedProps<PluginsMapOfInstance<TThis>>\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 seen = new Set<unknown>()\n let depth = 0\n while (depth < this.MAX_CAUSES_DEPTH) {\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 depth += 1\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 static round(error: unknown, isPublic = false): Error0 {\n return this.from(this.serialize(error, isPublic))\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 for (const [key, prop] of plugin.propEntries) {\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], record: 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 const resolved = this._mergeResolvedPlugin(Base._getResolvedPlugin(), plugin)\n ;(Error0Extended as typeof Error0)._resolvedPlugin = resolved\n for (const [key, method] of resolved.methodEntries) {\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, TMethod extends (error: ErrorInstanceOfMap<PluginsMapOf<TThis>>, ...args: any[]) => any>(\n // this: TThis,\n // key: TKey,\n // value: TMethod,\n // ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TMethod>> {\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<\n TThis extends typeof Error0,\n TKey extends string,\n TMethod extends (error: ErrorInstanceOfMap<PluginsMapOf<TThis>>, ...args: any[]) => any,\n >(\n this: TThis,\n kind: 'method',\n key: TKey,\n value: TMethod,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TMethod>>\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 plugin = this._getResolvedPlugin()\n const resolveByKey = (targetError: Error0, key: string, targetPlugin: ErrorPluginResolved): unknown =>\n this._resolveByKey(targetError, key, targetPlugin)\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 // we do not serialize causes, it is enough that we have floated props and adapt helper\n // cause: error0.cause,\n }\n if (serializedMessage !== undefined) {\n json.message = serializedMessage\n }\n\n for (const [key, prop] of plugin.propEntries) {\n if (prop.serialize === false) {\n continue\n }\n try {\n const options = {\n get own() {\n return error0.own(key as never)\n },\n get flow() {\n return error0.flow(key as never)\n },\n get resolved() {\n return resolveByKey(error0, key, plugin)\n },\n error: error0,\n isPublic,\n }\n const jsonValue = prop.serialize(options as ErrorPluginPropSerializeOptions<any, any, any>)\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}`, error0)\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 json\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 round<TThis extends Error0>(this: TThis, isPublic = true): TThis {\n const ctor = this.constructor as typeof Error0\n return ctor.round(this, isPublic) as TThis\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2PA,MAAM,4BAA4B;AAClC,MAAM,8BAA8B;AA4E7B,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,OACyE;AACzE,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,OAA4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AA,MACf;AAAA,IACF,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;AAAA,EACT;AAAA,EAEA,UAAU,WAAW,MAA+B;AAClD,UAAM,OAAO,KAAK;AAClB,WAAO,KAAK,UAAU,MAAM,QAAQ;AAAA,EACtC;AAAA,EAEA,MAAyC,WAAW,MAAa;AAC/D,UAAM,OAAO,KAAK;AAClB,WAAO,KAAK,MAAM,MAAM,QAAQ;AAAA,EAClC;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 ErrorPluginPropSerializeOptions<\n TOutputValue,\n TError extends Error0,\n TResolveValue extends TOutputValue | undefined,\n> = {\n own: TOutputValue | undefined\n flow: Array<TOutputValue | undefined>\n resolved: TResolveValue\n error: TError\n isPublic: boolean\n}\ntype ErrorPluginPropSerialize<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> =\n | ((options: ErrorPluginPropSerializeOptions<TOutputValue, TError, TResolveValue>) => unknown)\n | false\ntype ErrorPluginPropDeserialize<TOutputValue> =\n | ((options: { value: unknown; record: Record<string, unknown> }) => TOutputValue | undefined)\n | false\ntype ErrorPluginPropOptionsResolveOptions<TOutputValue, TError extends Error0> = {\n own: TOutputValue | undefined\n flow: Array<TOutputValue | undefined>\n error: TError\n}\ntype ErrorPluginPropOptionsBase<TOutputValue, TError extends Error0, TResolveValue extends TOutputValue | undefined> = {\n resolve: (options: ErrorPluginPropOptionsResolveOptions<TOutputValue, TError>) => TResolveValue\n serialize: ErrorPluginPropSerialize<TOutputValue, TError, TResolveValue>\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\ntype ErrorPluginAnyMethodFn = (error: any, ...args: any[]) => any\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 cause: unknown\n error: TError\n isPublic: boolean\n is: (cause: unknown) => boolean\n serialize: (cause: unknown) => Record<string, unknown>\n}) => unknown\nexport type ErrorPluginCauseDeserialize = (options: {\n cause: unknown\n error: Record<string, unknown>\n isSerialized: (serializedCause: unknown) => boolean\n fromSerialized: (serializedCause: unknown) => Error0\n}) => unknown\nexport type ErrorPluginCause<TError extends Error0 = Error0> = {\n serialize: ErrorPluginCauseSerialize<TError>\n deserialize: ErrorPluginCauseDeserialize\n}\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 = { fn: ErrorPluginAnyMethodFn }\n\nexport type ErrorPluginProps = { [key: string]: ErrorPluginPropOptions<any, any> }\nexport type ErrorPluginMethods = { [key: string]: ErrorPluginAnyMethodFn }\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 TMethod extends ErrorPluginAnyMethodFn,\n> = TMethods & Record<TKey, TMethod>\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 BindInstanceMethod<TMethod> = TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n (error: any, ...args: infer TArgs4): infer TOutput4\n}\n ? {\n (...args: TArgs1): TOutput1\n (...args: TArgs2): TOutput2\n (...args: TArgs3): TOutput3\n (...args: TArgs4): TOutput4\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n }\n ? {\n (...args: TArgs1): TOutput1\n (...args: TArgs2): TOutput2\n (...args: TArgs3): TOutput3\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n }\n ? {\n (...args: TArgs1): TOutput1\n (...args: TArgs2): TOutput2\n }\n : TMethod extends (error: any, ...args: infer TArgs) => infer TOutput\n ? (...args: TArgs) => TOutput\n : never\ntype BindStaticMethod<TMethod> = TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n (error: any, ...args: infer TArgs4): infer TOutput4\n}\n ? {\n (error: unknown, ...args: TArgs1): TOutput1\n (error: unknown, ...args: TArgs2): TOutput2\n (error: unknown, ...args: TArgs3): TOutput3\n (error: unknown, ...args: TArgs4): TOutput4\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n (error: any, ...args: infer TArgs3): infer TOutput3\n }\n ? {\n (error: unknown, ...args: TArgs1): TOutput1\n (error: unknown, ...args: TArgs2): TOutput2\n (error: unknown, ...args: TArgs3): TOutput3\n }\n : TMethod extends {\n (error: any, ...args: infer TArgs1): infer TOutput1\n (error: any, ...args: infer TArgs2): infer TOutput2\n }\n ? {\n (error: unknown, ...args: TArgs1): TOutput1\n (error: unknown, ...args: TArgs2): TOutput2\n }\n : TMethod extends (error: any, ...args: infer TArgs) => infer TOutput\n ? (error: unknown, ...args: TArgs) => TOutput\n : never\ntype ErrorMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: BindInstanceMethod<TPluginsMap['methods'][TKey]['fn']>\n}\nexport type ErrorResolved<TPluginsMap extends ErrorPluginsMap> = ErrorResolvedProps<TPluginsMap> &\n ErrorMethods<TPluginsMap>\n\ntype ErrorStaticMethods<TPluginsMap extends ErrorPluginsMap> = {\n [TKey in keyof TPluginsMap['methods']]: BindStaticMethod<TPluginsMap['methods'][TKey]['fn']>\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 propKeys: string[]\n propEntries: Array<[string, ErrorPluginPropOptions<unknown>]>\n methodEntries: Array<[string, ErrorPluginMethodFn<unknown>]>\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']>]: {\n fn: NonNullable<TPlugin['methods']>[TKey] extends ErrorPluginAnyMethodFn\n ? NonNullable<TPlugin['methods']>[TKey]\n : never\n }\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 TMethod extends ErrorPluginAnyMethodFn,\n> = ExtendErrorPluginsMap<TMap, ErrorPlugin<Record<never, never>, Record<TKey, TMethod>>>\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 &\n ErrorResolved<TMap> &\n ErrorOwnMethods<TMap> &\n ErrorResolveMethods<TMap> & { readonly __pluginsMap?: TMap }\ntype BuilderError0<TProps extends ErrorPluginProps, TMethods extends ErrorPluginMethods> = Error0 &\n ErrorResolved<PluginsMapFromParts<TProps, TMethods>> &\n ErrorOwnMethods<PluginsMapFromParts<TProps, TMethods>> &\n ErrorResolveMethods<PluginsMapFromParts<TProps, TMethods>> & {\n readonly __pluginsMap?: PluginsMapFromParts<TProps, TMethods>\n }\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, TMethod extends (error: BuilderError0<TProps, TMethods>, ...args: any[]) => any>(\n key: TKey,\n value: TMethod,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TMethod>> {\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, TMethod extends (error: BuilderError0<TProps, TMethods>, ...args: any[]) => any>(\n kind: 'method',\n key: TKey,\n value: TMethod,\n ): PluginError0<TProps, AddMethodToPluginMethods<TMethods, TKey, TMethod>>\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\nconst OWN_SYMBOL: unique symbol = Symbol('Error0.own')\ntype ErrorOwnStore = Record<string, unknown>\n\nexport type ClassError0<TPluginsMap extends ErrorPluginsMap = EmptyPluginsMap> = {\n MAX_CAUSES_DEPTH: number\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 round: (\n error: unknown,\n isPublic?: boolean,\n ) => Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>\n causes: {\n (error: unknown, instancesOnly?: false): unknown[]\n (\n error: unknown,\n instancesOnly: true,\n ): Array<Error0 & ErrorResolved<TPluginsMap> & ErrorOwnMethods<TPluginsMap> & ErrorResolveMethods<TPluginsMap>>\n }\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, TMethod extends (error: ErrorInstanceOfMap<TPluginsMap>, ...args: any[]) => any>(\n // key: TKey,\n // value: TMethod,\n // ) => ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TMethod>>\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, TMethod extends (error: ErrorInstanceOfMap<TPluginsMap>, ...args: any[]) => any>(\n kind: 'method',\n key: TKey,\n value: TMethod,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<TPluginsMap, TKey, TMethod>>\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 static MAX_CAUSES_DEPTH = 99\n protected static _plugins: ErrorPlugin[] = []\n protected static _resolvedPlugin?: ErrorPluginResolved\n\n private static readonly _emptyPlugin: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n stack: undefined,\n cause: undefined,\n message: undefined,\n propKeys: [],\n propEntries: [],\n methodEntries: [],\n }\n\n private static _indexResolvedPlugin(\n resolved: Omit<ErrorPluginResolved, 'propKeys' | 'propEntries' | 'methodEntries'>,\n ): ErrorPluginResolved {\n return {\n ...resolved,\n propKeys: Object.keys(resolved.props),\n propEntries: Object.entries(resolved.props),\n methodEntries: Object.entries(resolved.methods),\n }\n }\n\n private static _applyPlugin(\n resolved: Omit<ErrorPluginResolved, 'propKeys' | 'propEntries' | 'methodEntries'>,\n plugin: ErrorPlugin,\n ): void {\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\n private static _mergeResolvedPlugin(\n this: typeof Error0,\n base: ErrorPluginResolved,\n plugin: ErrorPlugin,\n ): ErrorPluginResolved {\n const merged: Omit<ErrorPluginResolved, 'propKeys' | 'propEntries' | 'methodEntries'> = {\n props: { ...base.props },\n methods: { ...base.methods },\n adapt: [...base.adapt],\n stack: base.stack,\n cause: base.cause,\n message: base.message,\n }\n this._applyPlugin(merged, plugin)\n return this._indexResolvedPlugin(merged)\n }\n\n private static _getResolvedPlugin(this: typeof Error0): ErrorPluginResolved {\n if (Object.prototype.hasOwnProperty.call(this, '_resolvedPlugin') && this._resolvedPlugin) {\n return this._resolvedPlugin\n }\n const resolved: ErrorPluginResolved = {\n props: {},\n methods: {},\n adapt: [],\n propKeys: [],\n propEntries: [],\n methodEntries: [],\n }\n for (const plugin of this._plugins) {\n this._applyPlugin(resolved, plugin)\n }\n const indexed = this._indexResolvedPlugin(resolved)\n Object.defineProperty(this, '_resolvedPlugin', {\n value: indexed,\n writable: true,\n enumerable: false,\n configurable: true,\n })\n return indexed\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 const ownStore = Object.create(null) as ErrorOwnStore\n Object.defineProperty(this, OWN_SYMBOL, { value: ownStore, writable: true, enumerable: false, configurable: true })\n\n for (const [key, prop] of plugin.propEntries) {\n if (key === 'stack') {\n continue\n }\n Object.defineProperty(this, key, {\n get: () =>\n prop.resolve({\n own: ownStore[key],\n flow: this.flow(key as never),\n error: this,\n }),\n set: (value) => {\n ownStore[key] = value\n },\n enumerable: true,\n configurable: true,\n })\n if (key in input) {\n const ownValue = (input as Record<string, unknown>)[key]\n ownStore[key] = typeof prop.init === 'function' ? prop.init(ownValue) : ownValue\n }\n }\n }\n\n private static _getOwnStore(object: object): ErrorOwnStore | undefined {\n const record = object as Record<string | symbol, unknown>\n const existing = record[OWN_SYMBOL]\n if (existing && typeof existing === 'object') {\n return existing as ErrorOwnStore\n }\n return undefined\n }\n\n private static readonly isOwnProperty = (object: object, key: string): boolean => {\n const ownStore = this._getOwnStore(object)\n if (ownStore) {\n return Object.prototype.hasOwnProperty.call(ownStore, key)\n }\n return !!Object.getOwnPropertyDescriptor(object, key)\n }\n private static _ownByKey(error: object, key: string): unknown {\n const ownStore = this._getOwnStore(error)\n if (ownStore) {\n return ownStore[key]\n }\n return (error as Record<string, unknown>)[key]\n }\n private static _flowByKey(error: object, key: string): unknown[] {\n const causes = this.causes(error, true)\n const values = new Array<unknown>(causes.length)\n for (let i = 0; i < causes.length; i += 1) {\n values[i] = this._ownByKey(causes[i], key)\n }\n return values\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 plugin.propKeys) {\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 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 const ctor = this.constructor as typeof Error0\n return ctor._flowByKey(this, key)\n }\n\n static _resolveByKey(error: Error0, key: string, plugin: ErrorPluginResolved): unknown {\n try {\n const options = {\n get own() {\n return error.own(key as never)\n },\n get flow() {\n return error.flow(key as never)\n },\n error,\n }\n const prop = plugin.props[key]\n const resolver = prop.resolve\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!resolver) {\n return (error as any)[key]\n }\n return resolver(options as ErrorPluginPropOptionsResolveOptions<any, any>)\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error0: failed to resolve property ${key}`, error)\n return undefined\n }\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 of plugin.propKeys) {\n resolved[key] = this._resolveByKey(error0, key, plugin)\n }\n return resolved\n }\n resolve<TThis extends Error0>(this: TThis): ErrorResolvedProps<PluginsMapOfInstance<TThis>>\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 seen = new Set<unknown>()\n let depth = 0\n while (depth < this.MAX_CAUSES_DEPTH) {\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 depth += 1\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 static round(error: unknown, isPublic = false): Error0 {\n return this.from(this.serialize(error, isPublic))\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 for (const [key, prop] of plugin.propEntries) {\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], record: 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 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 && 'cause' in errorRecord) {\n try {\n ;(recreated as { cause?: unknown }).cause = causePlugin.deserialize({\n cause: errorRecord.cause,\n error: errorRecord,\n isSerialized: (serializedCause) => this.isSerialized(serializedCause),\n fromSerialized: (serializedCause) => this._fromSerialized(serializedCause),\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 const resolved = this._mergeResolvedPlugin(Base._getResolvedPlugin(), plugin)\n ;(Error0Extended as typeof Error0)._resolvedPlugin = resolved\n for (const [key, method] of resolved.methodEntries) {\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, TMethod extends (error: ErrorInstanceOfMap<PluginsMapOf<TThis>>, ...args: any[]) => any>(\n // this: TThis,\n // key: TKey,\n // value: TMethod,\n // ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TMethod>> {\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<\n TThis extends typeof Error0,\n TKey extends string,\n TMethod extends (error: ErrorInstanceOfMap<PluginsMapOf<TThis>>, ...args: any[]) => any,\n >(\n this: TThis,\n kind: 'method',\n key: TKey,\n value: TMethod,\n ): ClassError0<ExtendErrorPluginsMapWithMethod<PluginsMapOf<TThis>, TKey, TMethod>>\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 (\n typeof key !== 'object' ||\n key === null ||\n typeof (key as { serialize?: unknown }).serialize !== 'function' ||\n typeof (key as { deserialize?: unknown }).deserialize !== 'function'\n ) {\n throw new Error('Error0.use(\"cause\", value) expects { serialize: function, deserialize: 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 plugin = this._getResolvedPlugin()\n const resolveByKey = (targetError: Error0, key: string, targetPlugin: ErrorPluginResolved): unknown =>\n this._resolveByKey(targetError, key, targetPlugin)\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 }\n if (serializedMessage !== undefined) {\n json.message = serializedMessage\n }\n\n for (const [key, prop] of plugin.propEntries) {\n if (prop.serialize === false) {\n continue\n }\n try {\n const options = {\n get own() {\n return error0.own(key as never)\n },\n get flow() {\n return error0.flow(key as never)\n },\n get resolved() {\n return resolveByKey(error0, key, plugin)\n },\n error: error0,\n isPublic,\n }\n const jsonValue = prop.serialize(options as ErrorPluginPropSerializeOptions<any, any, any>)\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}`, error0)\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 = isPublic ? undefined : 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 cause: (error0 as { cause?: unknown }).cause,\n error: error0,\n isPublic,\n is: (cause) => this.is(cause),\n serialize: (cause) => this.serialize(cause, 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 json\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 round<TThis extends Error0>(this: TThis, isPublic = true): TThis {\n const ctor = this.constructor as typeof Error0\n return ctor.round(this, isPublic) as TThis\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsQA,MAAM,4BAA4B;AAClC,MAAM,8BAA8B;AA4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AAEN,gBAAQ,MAAM,qCAAqC,MAAM;AAAA,MAC3D;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,WAAW,MAA+B;AAClD,UAAM,OAAO,KAAK;AAClB,WAAO,KAAK,UAAU,MAAM,QAAQ;AAAA,EACtC;AAAA,EAEA,MAAyC,WAAW,MAAa;AAC/D,UAAM,OAAO,KAAK;AAClB,WAAO,KAAK,MAAM,MAAM,QAAQ;AAAA,EAClC;AACF;","names":[]}
@@ -48,12 +48,21 @@ type ErrorPluginStack<TError extends Error0 = Error0> = {
48
48
  serialize: ErrorPluginStackSerialize<TError>;
49
49
  };
50
50
  type ErrorPluginCauseSerialize<TError extends Error0> = (options: {
51
- value: unknown;
51
+ cause: unknown;
52
52
  error: TError;
53
53
  isPublic: boolean;
54
+ is: (cause: unknown) => boolean;
55
+ serialize: (cause: unknown) => Record<string, unknown>;
56
+ }) => unknown;
57
+ type ErrorPluginCauseDeserialize = (options: {
58
+ cause: unknown;
59
+ error: Record<string, unknown>;
60
+ isSerialized: (serializedCause: unknown) => boolean;
61
+ fromSerialized: (serializedCause: unknown) => Error0;
54
62
  }) => unknown;
55
63
  type ErrorPluginCause<TError extends Error0 = Error0> = {
56
64
  serialize: ErrorPluginCauseSerialize<TError>;
65
+ deserialize: ErrorPluginCauseDeserialize;
57
66
  };
58
67
  type ErrorPluginMessageSerialize<TError extends Error0> = (options: {
59
68
  value: string;
@@ -340,4 +349,4 @@ declare class Error0 extends Error {
340
349
  round<TThis extends Error0>(this: TThis, isPublic?: boolean): TThis;
341
350
  }
342
351
 
343
- export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseSerialize, type ErrorPluginMessage, type ErrorPluginMessageSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
352
+ export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseDeserialize, type ErrorPluginCauseSerialize, type ErrorPluginMessage, type ErrorPluginMessageSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
@@ -16,26 +16,48 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var cause_serialize_exports = {};
20
- __export(cause_serialize_exports, {
21
- causeSerializePlugin: () => causeSerializePlugin
19
+ var cause_exports = {};
20
+ __export(cause_exports, {
21
+ causePlugin: () => causePlugin
22
22
  });
23
- module.exports = __toCommonJS(cause_serialize_exports);
23
+ module.exports = __toCommonJS(cause_exports);
24
24
  var import__ = require('../index.cjs');
25
- const causeSerializePlugin = ({ hideWhenPublic = true } = {}) => import__.Error0.plugin().cause({
26
- serialize: ({ value, error, isPublic }) => {
27
- if (hideWhenPublic && isPublic) {
25
+ const causePlugin = ({
26
+ isPublic = false,
27
+ variants = void 0
28
+ } = {}) => import__.Error0.plugin().cause({
29
+ serialize: ({ cause, isPublic: _isPublic, is, serialize }) => {
30
+ if (!isPublic && _isPublic) {
28
31
  return void 0;
29
32
  }
30
- const ctor = error.constructor;
31
- if (ctor.is(value)) {
32
- return ctor.serialize(value, isPublic);
33
+ if (variants) {
34
+ for (const variant of Object.values(variants)) {
35
+ if (cause instanceof variant) {
36
+ return variant.serialize(cause);
37
+ }
38
+ }
39
+ }
40
+ if (is(cause)) {
41
+ return serialize(cause);
33
42
  }
34
43
  return void 0;
44
+ },
45
+ deserialize: ({ cause, fromSerialized, isSerialized }) => {
46
+ if (variants) {
47
+ for (const variant of Object.values(variants)) {
48
+ if (variant.isSerialized(cause)) {
49
+ return variant.from(cause);
50
+ }
51
+ }
52
+ }
53
+ if (isSerialized(cause)) {
54
+ return fromSerialized(cause);
55
+ }
56
+ return cause;
35
57
  }
36
58
  });
37
59
  // Annotate the CommonJS export names for ESM import in node:
38
60
  0 && (module.exports = {
39
- causeSerializePlugin
61
+ causePlugin
40
62
  });
41
- //# sourceMappingURL=cause-serialize.cjs.map
63
+ //# sourceMappingURL=cause.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/plugins/cause.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\ntype Variant = {\n new (...args: any[]): unknown\n [Symbol.hasInstance]: (value: any) => boolean\n isSerialized: (serializedCause: any) => boolean\n serialize: (error: any) => unknown\n from: (error: any) => unknown\n}\n\nexport const causePlugin = <TVariants extends Record<string, Variant> = Record<never, Variant>>({\n isPublic = false,\n variants = undefined,\n}: { isPublic?: boolean; variants?: TVariants } = {}) =>\n Error0.plugin().cause({\n serialize: ({ cause, isPublic: _isPublic, is, serialize }) => {\n if (!isPublic && _isPublic) {\n return undefined\n }\n if (variants) {\n for (const variant of Object.values(variants)) {\n if (cause instanceof variant) {\n return variant.serialize(cause)\n }\n }\n }\n if (is(cause)) {\n return serialize(cause)\n }\n return undefined\n },\n deserialize: ({ cause, fromSerialized, isSerialized }) => {\n if (variants) {\n for (const variant of Object.values(variants)) {\n if (variant.isSerialized(cause)) {\n return variant.from(cause)\n }\n }\n }\n if (isSerialized(cause)) {\n return fromSerialized(cause)\n }\n return cause\n },\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAUhB,MAAM,cAAc,CAAqE;AAAA,EAC9F,WAAW;AAAA,EACX,WAAW;AACb,IAAkD,CAAC,MACjD,gBAAO,OAAO,EAAE,MAAM;AAAA,EACpB,WAAW,CAAC,EAAE,OAAO,UAAU,WAAW,IAAI,UAAU,MAAM;AAC5D,QAAI,CAAC,YAAY,WAAW;AAC1B,aAAO;AAAA,IACT;AACA,QAAI,UAAU;AACZ,iBAAW,WAAW,OAAO,OAAO,QAAQ,GAAG;AAC7C,YAAI,iBAAiB,SAAS;AAC5B,iBAAO,QAAQ,UAAU,KAAK;AAAA,QAChC;AAAA,MACF;AAAA,IACF;AACA,QAAI,GAAG,KAAK,GAAG;AACb,aAAO,UAAU,KAAK;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AAAA,EACA,aAAa,CAAC,EAAE,OAAO,gBAAgB,aAAa,MAAM;AACxD,QAAI,UAAU;AACZ,iBAAW,WAAW,OAAO,OAAO,QAAQ,GAAG;AAC7C,YAAI,QAAQ,aAAa,KAAK,GAAG;AAC/B,iBAAO,QAAQ,KAAK,KAAK;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AACA,QAAI,aAAa,KAAK,GAAG;AACvB,aAAO,eAAe,KAAK;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AACF,CAAC;","names":[]}
@@ -0,0 +1,15 @@
1
+ import { PluginError0 } from '../index.cjs';
2
+
3
+ type Variant = {
4
+ new (...args: any[]): unknown;
5
+ [Symbol.hasInstance]: (value: any) => boolean;
6
+ isSerialized: (serializedCause: any) => boolean;
7
+ serialize: (error: any) => unknown;
8
+ from: (error: any) => unknown;
9
+ };
10
+ declare const causePlugin: <TVariants extends Record<string, Variant> = Record<never, Variant>>({ isPublic, variants, }?: {
11
+ isPublic?: boolean;
12
+ variants?: TVariants;
13
+ }) => PluginError0<Record<never, never>, Record<never, never>>;
14
+
15
+ export { causePlugin };
@@ -22,12 +22,20 @@ __export(code_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(code_exports);
24
24
  var import__ = require('../index.cjs');
25
- const codePlugin = ({ codes } = {}) => {
25
+ const codePlugin = ({
26
+ codes,
27
+ isPublic = false
28
+ } = {}) => {
26
29
  const isCode = (value) => typeof value === "string" && (!codes || codes.includes(value));
27
30
  return import__.Error0.plugin().prop("code", {
28
31
  init: (code) => code,
29
32
  resolve: ({ flow }) => flow.find(Boolean),
30
- serialize: ({ resolved, isPublic }) => resolved,
33
+ serialize: ({ resolved, isPublic: _isPublic }) => {
34
+ if (!isPublic && _isPublic) {
35
+ return void 0;
36
+ }
37
+ return resolved;
38
+ },
31
39
  deserialize: ({ value, record }) => isCode(value) ? value : void 0
32
40
  });
33
41
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/code.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const codePlugin = <TCode extends string>({ codes }: { codes?: TCode[] } = {}) => {\n const isCode = (value: unknown): value is TCode =>\n typeof value === 'string' && (!codes || codes.includes(value as TCode))\n return Error0.plugin().prop('code', {\n init: (code: TCode) => code,\n resolve: ({ flow }) => flow.find(Boolean),\n serialize: ({ resolved, isPublic }) => resolved,\n deserialize: ({ value, record }) => (isCode(value) ? value : undefined),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAEhB,MAAM,aAAa,CAAuB,EAAE,MAAM,IAAyB,CAAC,MAAM;AACvF,QAAM,SAAS,CAAC,UACd,OAAO,UAAU,aAAa,CAAC,SAAS,MAAM,SAAS,KAAc;AACvE,SAAO,gBAAO,OAAO,EAAE,KAAK,QAAQ;AAAA,IAClC,MAAM,CAAC,SAAgB;AAAA,IACvB,SAAS,CAAC,EAAE,KAAK,MAAM,KAAK,KAAK,OAAO;AAAA,IACxC,WAAW,CAAC,EAAE,UAAU,SAAS,MAAM;AAAA,IACvC,aAAa,CAAC,EAAE,OAAO,OAAO,MAAO,OAAO,KAAK,IAAI,QAAQ;AAAA,EAC/D,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/plugins/code.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const codePlugin = <TCode extends string>({\n codes,\n isPublic = false,\n}: { codes?: TCode[]; isPublic?: boolean } = {}) => {\n const isCode = (value: unknown): value is TCode =>\n typeof value === 'string' && (!codes || codes.includes(value as TCode))\n return Error0.plugin().prop('code', {\n init: (code: TCode) => code,\n resolve: ({ flow }) => flow.find(Boolean),\n serialize: ({ resolved, isPublic: _isPublic }) => {\n if (!isPublic && _isPublic) {\n return undefined\n }\n return resolved\n },\n deserialize: ({ value, record }) => (isCode(value) ? value : undefined),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAEhB,MAAM,aAAa,CAAuB;AAAA,EAC/C;AAAA,EACA,WAAW;AACb,IAA6C,CAAC,MAAM;AAClD,QAAM,SAAS,CAAC,UACd,OAAO,UAAU,aAAa,CAAC,SAAS,MAAM,SAAS,KAAc;AACvE,SAAO,gBAAO,OAAO,EAAE,KAAK,QAAQ;AAAA,IAClC,MAAM,CAAC,SAAgB;AAAA,IACvB,SAAS,CAAC,EAAE,KAAK,MAAM,KAAK,KAAK,OAAO;AAAA,IACxC,WAAW,CAAC,EAAE,UAAU,UAAU,UAAU,MAAM;AAChD,UAAI,CAAC,YAAY,WAAW;AAC1B,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,IACA,aAAa,CAAC,EAAE,OAAO,OAAO,MAAO,OAAO,KAAK,IAAI,QAAQ;AAAA,EAC/D,CAAC;AACH;","names":[]}
@@ -1,7 +1,8 @@
1
1
  import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.cjs';
2
2
 
3
- declare const codePlugin: <TCode extends string>({ codes }?: {
3
+ declare const codePlugin: <TCode extends string>({ codes, isPublic, }?: {
4
4
  codes?: TCode[];
5
+ isPublic?: boolean;
5
6
  }) => PluginError0<Record<never, never> & Record<"code", ErrorPluginPropOptions<TCode, TCode, Error0, TCode | undefined>>, Record<never, never>>;
6
7
 
7
8
  export { codePlugin };
@@ -22,7 +22,17 @@ __export(expected_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(expected_exports);
24
24
  var import__ = require('../index.cjs');
25
- const isExpected = (flow) => {
25
+ const isExpected = ({
26
+ flow,
27
+ error,
28
+ override
29
+ }) => {
30
+ if (override) {
31
+ const overridden = override(error);
32
+ if (overridden !== void 0) {
33
+ return overridden;
34
+ }
35
+ }
26
36
  let expected = false;
27
37
  for (const value of flow) {
28
38
  if (value === false) {
@@ -34,18 +44,21 @@ const isExpected = (flow) => {
34
44
  }
35
45
  return expected;
36
46
  };
37
- const expectedPlugin = ({ hideWhenPublic = true } = {}) => import__.Error0.plugin().prop("expected", {
47
+ const expectedPlugin = ({
48
+ isPublic = false,
49
+ override
50
+ } = {}) => import__.Error0.plugin().prop("expected", {
38
51
  init: (input) => input,
39
- resolve: ({ flow }) => isExpected(flow),
40
- serialize: ({ resolved, isPublic }) => {
41
- if (hideWhenPublic && isPublic) {
52
+ resolve: ({ flow, error }) => isExpected({ flow, error, override }),
53
+ serialize: ({ resolved, isPublic: _isPublic }) => {
54
+ if (isPublic && _isPublic) {
42
55
  return void 0;
43
56
  }
44
57
  return resolved;
45
58
  },
46
59
  deserialize: ({ value }) => typeof value === "boolean" ? value : void 0
47
60
  }).method("isExpected", (error) => {
48
- return isExpected(error.flow("expected"));
61
+ return isExpected({ flow: error.flow("expected"), error, override });
49
62
  });
50
63
  // Annotate the CommonJS export names for ESM import in node:
51
64
  0 && (module.exports = {
@@ -1 +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 = ({ hideWhenPublic = true }: { hideWhenPublic?: boolean } = {}) =>\n Error0.plugin()\n .prop('expected', {\n init: (input: boolean) => input,\n resolve: ({ flow }) => isExpected(flow),\n serialize: ({ resolved, isPublic }) => {\n if (hideWhenPublic && isPublic) {\n return undefined\n }\n return resolved\n },\n deserialize: ({ value }) => (typeof value === 'boolean' ? value : undefined),\n })\n .method('isExpected', (error) => {\n return isExpected(error.flow('expected'))\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;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,CAAC,EAAE,iBAAiB,KAAK,IAAkC,CAAC,MACxF,gBAAO,OAAO,EACX,KAAK,YAAY;AAAA,EAChB,MAAM,CAAC,UAAmB;AAAA,EAC1B,SAAS,CAAC,EAAE,KAAK,MAAM,WAAW,IAAI;AAAA,EACtC,WAAW,CAAC,EAAE,UAAU,SAAS,MAAM;AACrC,QAAI,kBAAkB,UAAU;AAC9B,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EACA,aAAa,CAAC,EAAE,MAAM,MAAO,OAAO,UAAU,YAAY,QAAQ;AACpE,CAAC,EACA,OAAO,cAAc,CAAC,UAAU;AAC/B,SAAO,WAAW,MAAM,KAAK,UAAU,CAAC;AAC1C,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../../src/plugins/expected.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nconst isExpected = ({\n flow,\n error,\n override,\n}: {\n flow: unknown[]\n error: Error0\n override?: (error: any) => boolean | undefined\n}) => {\n if (override) {\n const overridden = override(error)\n if (overridden !== undefined) {\n return overridden\n }\n }\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 = <TError extends Error0>({\n isPublic = false,\n override,\n}: { isPublic?: boolean; override?: (error: TError) => boolean | undefined } = {}) =>\n Error0.plugin()\n .prop('expected', {\n init: (input: boolean) => input,\n resolve: ({ flow, error }) => isExpected({ flow, error, override }),\n serialize: ({ resolved, isPublic: _isPublic }) => {\n if (isPublic && _isPublic) {\n return undefined\n }\n return resolved\n },\n deserialize: ({ value }) => (typeof value === 'boolean' ? value : undefined),\n })\n .method('isExpected', (error) => {\n return isExpected({ flow: error.flow('expected'), error, override })\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAEvB,MAAM,aAAa,CAAC;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AACF,MAIM;AACJ,MAAI,UAAU;AACZ,UAAM,aAAa,SAAS,KAAK;AACjC,QAAI,eAAe,QAAW;AAC5B,aAAO;AAAA,IACT;AAAA,EACF;AACA,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,CAAwB;AAAA,EACpD,WAAW;AAAA,EACX;AACF,IAA+E,CAAC,MAC9E,gBAAO,OAAO,EACX,KAAK,YAAY;AAAA,EAChB,MAAM,CAAC,UAAmB;AAAA,EAC1B,SAAS,CAAC,EAAE,MAAM,MAAM,MAAM,WAAW,EAAE,MAAM,OAAO,SAAS,CAAC;AAAA,EAClE,WAAW,CAAC,EAAE,UAAU,UAAU,UAAU,MAAM;AAChD,QAAI,YAAY,WAAW;AACzB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EACA,aAAa,CAAC,EAAE,MAAM,MAAO,OAAO,UAAU,YAAY,QAAQ;AACpE,CAAC,EACA,OAAO,cAAc,CAAC,UAAU;AAC/B,SAAO,WAAW,EAAE,MAAM,MAAM,KAAK,UAAU,GAAG,OAAO,SAAS,CAAC;AACrE,CAAC;","names":[]}
@@ -1,7 +1,8 @@
1
- import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.cjs';
1
+ import { Error0, PluginError0, ErrorPluginPropOptions } from '../index.cjs';
2
2
 
3
- declare const expectedPlugin: ({ hideWhenPublic }?: {
4
- hideWhenPublic?: boolean;
3
+ declare const expectedPlugin: <TError extends Error0>({ isPublic, override, }?: {
4
+ isPublic?: boolean;
5
+ override?: (error: TError) => boolean | undefined;
5
6
  }) => PluginError0<Record<never, never> & Record<"expected", ErrorPluginPropOptions<boolean, boolean, Error0, boolean>>, Record<never, never> & Record<"isExpected", (error: Error0 & {
6
7
  expected: boolean;
7
8
  } & {} & {