@devp0nt/error0 1.0.0-next.1 → 1.0.0-next.10

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.
@@ -413,290 +413,5 @@ declare namespace Error0 {
413
413
  type JSON = ReturnType<Error0['toJSON']>;
414
414
  type Collection = Record<string, typeof Error0>;
415
415
  }
416
- declare const e0s: {
417
- Default: typeof Error0;
418
- Expected: {
419
- new (message: string): {
420
- readonly __I_AM_ERROR_0: true;
421
- readonly tag?: Error0GeneralProps["tag"];
422
- readonly code?: Error0GeneralProps["code"];
423
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
424
- readonly expected?: Error0GeneralProps["expected"];
425
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
426
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
427
- readonly cause?: Error0GeneralProps["cause"];
428
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
429
- readonly zodError?: Error0GeneralProps["zodError"];
430
- readonly axiosError?: Error0GeneralProps["axiosError"];
431
- readonly propsOriginal: Error0GeneralProps;
432
- toJSON(): {
433
- message: string;
434
- tag: string | undefined;
435
- code: string | undefined;
436
- httpStatus: number | undefined;
437
- expected: boolean | undefined;
438
- clientMessage: string | undefined;
439
- anyMessage: string | undefined;
440
- cause: unknown;
441
- meta: Meta0.ValueType;
442
- stack: string | undefined;
443
- __I_AM_ERROR_0: true;
444
- };
445
- toResponse(data?: Record<string, unknown>): undici_types.Response;
446
- name: string;
447
- message: string;
448
- stack?: string;
449
- };
450
- new (input: Error0Input): {
451
- readonly __I_AM_ERROR_0: true;
452
- readonly tag?: Error0GeneralProps["tag"];
453
- readonly code?: Error0GeneralProps["code"];
454
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
455
- readonly expected?: Error0GeneralProps["expected"];
456
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
457
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
458
- readonly cause?: Error0GeneralProps["cause"];
459
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
460
- readonly zodError?: Error0GeneralProps["zodError"];
461
- readonly axiosError?: Error0GeneralProps["axiosError"];
462
- readonly propsOriginal: Error0GeneralProps;
463
- toJSON(): {
464
- message: string;
465
- tag: string | undefined;
466
- code: string | undefined;
467
- httpStatus: number | undefined;
468
- expected: boolean | undefined;
469
- clientMessage: string | undefined;
470
- anyMessage: string | undefined;
471
- cause: unknown;
472
- meta: Meta0.ValueType;
473
- stack: string | undefined;
474
- __I_AM_ERROR_0: true;
475
- };
476
- toResponse(data?: Record<string, unknown>): undici_types.Response;
477
- name: string;
478
- message: string;
479
- stack?: string;
480
- };
481
- new (message: string, input: Error0Input): {
482
- readonly __I_AM_ERROR_0: true;
483
- readonly tag?: Error0GeneralProps["tag"];
484
- readonly code?: Error0GeneralProps["code"];
485
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
486
- readonly expected?: Error0GeneralProps["expected"];
487
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
488
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
489
- readonly cause?: Error0GeneralProps["cause"];
490
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
491
- readonly zodError?: Error0GeneralProps["zodError"];
492
- readonly axiosError?: Error0GeneralProps["axiosError"];
493
- readonly propsOriginal: Error0GeneralProps;
494
- toJSON(): {
495
- message: string;
496
- tag: string | undefined;
497
- code: string | undefined;
498
- httpStatus: number | undefined;
499
- expected: boolean | undefined;
500
- clientMessage: string | undefined;
501
- anyMessage: string | undefined;
502
- cause: unknown;
503
- meta: Meta0.ValueType;
504
- stack: string | undefined;
505
- __I_AM_ERROR_0: true;
506
- };
507
- toResponse(data?: Record<string, unknown>): undici_types.Response;
508
- name: string;
509
- message: string;
510
- stack?: string;
511
- };
512
- new (error: Error): {
513
- readonly __I_AM_ERROR_0: true;
514
- readonly tag?: Error0GeneralProps["tag"];
515
- readonly code?: Error0GeneralProps["code"];
516
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
517
- readonly expected?: Error0GeneralProps["expected"];
518
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
519
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
520
- readonly cause?: Error0GeneralProps["cause"];
521
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
522
- readonly zodError?: Error0GeneralProps["zodError"];
523
- readonly axiosError?: Error0GeneralProps["axiosError"];
524
- readonly propsOriginal: Error0GeneralProps;
525
- toJSON(): {
526
- message: string;
527
- tag: string | undefined;
528
- code: string | undefined;
529
- httpStatus: number | undefined;
530
- expected: boolean | undefined;
531
- clientMessage: string | undefined;
532
- anyMessage: string | undefined;
533
- cause: unknown;
534
- meta: Meta0.ValueType;
535
- stack: string | undefined;
536
- __I_AM_ERROR_0: true;
537
- };
538
- toResponse(data?: Record<string, unknown>): undici_types.Response;
539
- name: string;
540
- message: string;
541
- stack?: string;
542
- };
543
- new (error: Error, input: Error0Input): {
544
- readonly __I_AM_ERROR_0: true;
545
- readonly tag?: Error0GeneralProps["tag"];
546
- readonly code?: Error0GeneralProps["code"];
547
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
548
- readonly expected?: Error0GeneralProps["expected"];
549
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
550
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
551
- readonly cause?: Error0GeneralProps["cause"];
552
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
553
- readonly zodError?: Error0GeneralProps["zodError"];
554
- readonly axiosError?: Error0GeneralProps["axiosError"];
555
- readonly propsOriginal: Error0GeneralProps;
556
- toJSON(): {
557
- message: string;
558
- tag: string | undefined;
559
- code: string | undefined;
560
- httpStatus: number | undefined;
561
- expected: boolean | undefined;
562
- clientMessage: string | undefined;
563
- anyMessage: string | undefined;
564
- cause: unknown;
565
- meta: Meta0.ValueType;
566
- stack: string | undefined;
567
- __I_AM_ERROR_0: true;
568
- };
569
- toResponse(data?: Record<string, unknown>): undici_types.Response;
570
- name: string;
571
- message: string;
572
- stack?: string;
573
- };
574
- new (value: unknown): {
575
- readonly __I_AM_ERROR_0: true;
576
- readonly tag?: Error0GeneralProps["tag"];
577
- readonly code?: Error0GeneralProps["code"];
578
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
579
- readonly expected?: Error0GeneralProps["expected"];
580
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
581
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
582
- readonly cause?: Error0GeneralProps["cause"];
583
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
584
- readonly zodError?: Error0GeneralProps["zodError"];
585
- readonly axiosError?: Error0GeneralProps["axiosError"];
586
- readonly propsOriginal: Error0GeneralProps;
587
- toJSON(): {
588
- message: string;
589
- tag: string | undefined;
590
- code: string | undefined;
591
- httpStatus: number | undefined;
592
- expected: boolean | undefined;
593
- clientMessage: string | undefined;
594
- anyMessage: string | undefined;
595
- cause: unknown;
596
- meta: Meta0.ValueType;
597
- stack: string | undefined;
598
- __I_AM_ERROR_0: true;
599
- };
600
- toResponse(data?: Record<string, unknown>): undici_types.Response;
601
- name: string;
602
- message: string;
603
- stack?: string;
604
- };
605
- new (value: unknown, input: Error0Input): {
606
- readonly __I_AM_ERROR_0: true;
607
- readonly tag?: Error0GeneralProps["tag"];
608
- readonly code?: Error0GeneralProps["code"];
609
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
610
- readonly expected?: Error0GeneralProps["expected"];
611
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
612
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
613
- readonly cause?: Error0GeneralProps["cause"];
614
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
615
- readonly zodError?: Error0GeneralProps["zodError"];
616
- readonly axiosError?: Error0GeneralProps["axiosError"];
617
- readonly propsOriginal: Error0GeneralProps;
618
- toJSON(): {
619
- message: string;
620
- tag: string | undefined;
621
- code: string | undefined;
622
- httpStatus: number | undefined;
623
- expected: boolean | undefined;
624
- clientMessage: string | undefined;
625
- anyMessage: string | undefined;
626
- cause: unknown;
627
- meta: Meta0.ValueType;
628
- stack: string | undefined;
629
- __I_AM_ERROR_0: true;
630
- };
631
- toResponse(data?: Record<string, unknown>): undici_types.Response;
632
- name: string;
633
- message: string;
634
- stack?: string;
635
- };
636
- defaultMessage: string;
637
- defaultCode: string | undefined;
638
- defaultHttpStatus: number | undefined;
639
- defaultExpected: boolean | undefined;
640
- defaultClientMessage: string | undefined;
641
- defaultMeta: Meta0;
642
- defaultMaxLevel: number;
643
- _safeParseInput(error0Input: Record<string, unknown>): Error0Input;
644
- _getSelfGeneralProps({ error0Input, message, stack, }: {
645
- error0Input: Error0Input;
646
- message: string;
647
- stack: Error0GeneralProps["stack"];
648
- }): Error0GeneralProps;
649
- _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps;
650
- _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps>;
651
- _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps>;
652
- _assignError0Props(error0Props: Error0GeneralProps, extraError0Props: Partial<Error0GeneralProps>): void;
653
- _normalizeSelfExpected(error0Props: Error0GeneralProps, expectedProvided: Error0Input["expected"]): boolean | undefined;
654
- _isExpected(causesProps: Error0GeneralProps[]): boolean;
655
- _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps;
656
- _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[];
657
- _getCausesPropsFromError0Props(error0Props: Error0GeneralProps, maxLevel: number): Error0GeneralProps[];
658
- _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]> | undefined;
659
- _getFilledPropValues<TPropKey extends keyof Error0Input>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]>[];
660
- _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType;
661
- _removeConstructorStackPart(stack: Error0GeneralProps["stack"]): Error0GeneralProps["stack"];
662
- _mergeStack(prevStack: Error0GeneralProps["stack"], nextStack: Error0GeneralProps["stack"]): Error0GeneralProps["stack"];
663
- isError0(error: unknown): error is Error0;
664
- isLikelyError0(error: unknown): error is Error0;
665
- _toError0(error: unknown, inputOverride?: Error0Input): Error0;
666
- from(error: unknown, inputOverride?: Error0Input): Error0;
667
- extend(props: {
668
- defaultMessage?: Error0GeneralProps["message"];
669
- defaultCode?: Error0GeneralProps["code"];
670
- defaultHttpStatus?: Error0GeneralProps["httpStatus"];
671
- defaultExpected?: Error0GeneralProps["expected"];
672
- defaultClientMessage?: Error0GeneralProps["clientMessage"];
673
- defaultMeta?: Meta0.Meta0OrValueTypeNullish;
674
- }): /*elided*/ any;
675
- extendCollection<T extends Record<string, typeof Error0>>(classes: T, props: {
676
- defaultMessage?: Error0GeneralProps["message"];
677
- defaultCode?: Error0GeneralProps["code"];
678
- defaultHttpStatus?: Error0GeneralProps["httpStatus"];
679
- defaultExpected?: Error0GeneralProps["expected"];
680
- defaultClientMessage?: Error0GeneralProps["clientMessage"];
681
- defaultMeta?: Meta0.Meta0OrValueTypeNullish;
682
- }): T;
683
- toJSON(error: unknown, inputOverride?: Error0Input): {
684
- message: string;
685
- tag: string | undefined;
686
- code: string | undefined;
687
- httpStatus: number | undefined;
688
- expected: boolean | undefined;
689
- clientMessage: string | undefined;
690
- anyMessage: string | undefined;
691
- cause: unknown;
692
- meta: Meta0.ValueType;
693
- stack: string | undefined;
694
- __I_AM_ERROR_0: true;
695
- };
696
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
697
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
698
- stackTraceLimit: number;
699
- };
700
- };
701
416
 
702
- export { Error0, type Error0Input, e0s };
417
+ export { Error0, type Error0Input };
package/dist/cjs/index.js CHANGED
@@ -28,8 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var index_exports = {};
30
30
  __export(index_exports, {
31
- Error0: () => Error0,
32
- e0s: () => e0s
31
+ Error0: () => Error0
33
32
  });
34
33
  module.exports = __toCommonJS(index_exports);
35
34
  var import_meta0 = require("@devp0nt/meta0");
@@ -37,6 +36,25 @@ var import_axios = require("axios");
37
36
  var import_get = __toESM(require("lodash/get.js"), 1);
38
37
  var import_zod = require("zod");
39
38
  const isFilled = (value) => value !== null && value !== void 0 && value !== "";
39
+ const toStringOrUndefined = (value) => {
40
+ return typeof value === "string" ? value : void 0;
41
+ };
42
+ const toNumberOrUndefined = (value) => {
43
+ if (typeof value === "number") {
44
+ return value;
45
+ }
46
+ const number = Number(value);
47
+ if (typeof value === "string" && !Number.isNaN(number)) {
48
+ return number;
49
+ }
50
+ return void 0;
51
+ };
52
+ const toBooleanOrUndefined = (value) => {
53
+ if (typeof value === "boolean") {
54
+ return value;
55
+ }
56
+ return void 0;
57
+ };
40
58
  class Error0 extends Error {
41
59
  __I_AM_ERROR_0 = true;
42
60
  tag;
@@ -117,15 +135,16 @@ class Error0 extends Error {
117
135
  message,
118
136
  stack
119
137
  }) {
120
- const meta0 = import_meta0.Meta0.extend(error0Input.meta, this.defaultMeta);
138
+ const meta0 = import_meta0.Meta0.extend(this.defaultMeta, error0Input.meta);
121
139
  const meta = meta0.getValue();
122
- const finalTag = meta0.getFinalTag(error0Input.tag);
140
+ const finalTag = import_meta0.meta0PluginTag.public.getFullTag(meta0, error0Input.tag);
141
+ delete meta.tagPrefix;
123
142
  const clientMessage = error0Input.clientMessage || this.defaultClientMessage;
124
143
  const result = {
125
144
  message: error0Input.message || this.defaultMessage,
126
145
  tag: finalTag,
127
- code: error0Input.code || meta.code || this.defaultCode,
128
- httpStatus: typeof error0Input.httpStatus === "number" ? error0Input.httpStatus : error0Input.httpStatus && typeof error0Input.httpStatus === "string" && error0Input.httpStatus in import_axios.HttpStatusCode ? import_axios.HttpStatusCode[error0Input.httpStatus] : meta.httpStatus || this.defaultHttpStatus,
146
+ code: error0Input.code || toStringOrUndefined(meta.code) || this.defaultCode,
147
+ httpStatus: typeof error0Input.httpStatus === "number" ? error0Input.httpStatus : error0Input.httpStatus && typeof error0Input.httpStatus === "string" && error0Input.httpStatus in import_axios.HttpStatusCode ? import_axios.HttpStatusCode[error0Input.httpStatus] : toNumberOrUndefined(meta.httpStatus) || this.defaultHttpStatus,
129
148
  expected: void 0,
130
149
  clientMessage,
131
150
  anyMessage: clientMessage || message,
@@ -137,7 +156,7 @@ class Error0 extends Error {
137
156
  };
138
157
  result.expected = this._normalizeSelfExpected(
139
158
  result,
140
- typeof error0Input.expected === "boolean" || typeof error0Input.expected === "function" ? error0Input.expected : meta.expected || this.defaultExpected
159
+ typeof error0Input.expected === "boolean" || typeof error0Input.expected === "function" ? error0Input.expected : toBooleanOrUndefined(meta.expected) || this.defaultExpected
141
160
  );
142
161
  result.stack = this._removeConstructorStackPart(stack);
143
162
  return result;
@@ -147,7 +166,7 @@ class Error0 extends Error {
147
166
  const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack);
148
167
  const closestTag = this._getClosestPropValue(causesProps, "tag");
149
168
  const meta = this._getMergedMetaValue(causesProps);
150
- const tag = import_meta0.Meta0.getFinalTag(meta, closestTag);
169
+ const tag = import_meta0.meta0PluginTag.public.getFullTag(meta, closestTag);
151
170
  const propsFloated = {
152
171
  message: this._getClosestPropValue(causesProps, "message"),
153
172
  tag,
@@ -383,7 +402,7 @@ class Error0 extends Error {
383
402
  static defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus;
384
403
  static defaultExpected = props.defaultExpected ?? parent.defaultExpected;
385
404
  static defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage;
386
- static defaultMeta = import_meta0.Meta0.extend(props.defaultMeta, parent.defaultMeta);
405
+ static defaultMeta = import_meta0.Meta0.extend(parent.defaultMeta, props.defaultMeta);
387
406
  };
388
407
  }
389
408
  static extendCollection(classes, props) {
@@ -421,15 +440,8 @@ class Error0 extends Error {
421
440
  );
422
441
  }
423
442
  }
424
- const e0s = {
425
- Default: Error0,
426
- Expected: Error0.extend({
427
- defaultExpected: true
428
- })
429
- };
430
443
  // Annotate the CommonJS export names for ESM import in node:
431
444
  0 && (module.exports = {
432
- Error0,
433
- e0s
445
+ Error0
434
446
  });
435
447
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { Meta0 } from '@devp0nt/meta0'\nimport { type AxiosError, HttpStatusCode, isAxiosError } from 'axios'\nimport get from 'lodash/get.js'\nimport { ZodError } from 'zod'\n\n// TODO: store tags as array from all causes\n// TODO: not use self stack if toError0\n// TODO: fix default message in extended error0, should be used in constuctor of Error0\n// TODO: remove defaults prop from getPropsFromUnknown\n// TODO: code has enum type, fn to check if code exists\n\nexport interface Error0Input {\n message?: string\n tag?: string\n code?: string\n httpStatus?: HttpStatusCode | HttpStatusCodeString\n expected?: boolean | ExpectedFn\n clientMessage?: string\n cause?: Error0Cause\n stack?: string\n meta?: Meta0.Meta0OrValueTypeNullish\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ninterface Error0GeneralProps {\n message: Error0Input['message']\n tag: Error0Input['tag']\n code: Error0Input['code']\n httpStatus: number | undefined\n expected: boolean | undefined\n clientMessage: Error0Input['clientMessage']\n anyMessage: string | undefined\n cause: Error0Input['cause']\n stack: Error['stack']\n meta: Meta0.ValueType\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ntype HttpStatusCodeString = keyof typeof HttpStatusCode\ntype Error0Cause = Error | Error0 | unknown\ntype ExpectedFn = (error: Error0GeneralProps) => boolean | undefined\n\nconst isFilled = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined && value !== ''\n\nexport class Error0 extends Error {\n public readonly __I_AM_ERROR_0: true = true\n\n public readonly tag?: Error0GeneralProps['tag']\n public readonly code?: Error0GeneralProps['code']\n public readonly httpStatus?: Error0GeneralProps['httpStatus']\n public readonly expected?: Error0GeneralProps['expected']\n public readonly clientMessage?: Error0GeneralProps['clientMessage']\n public readonly anyMessage?: Error0GeneralProps['anyMessage']\n public override readonly cause?: Error0GeneralProps['cause']\n public readonly meta?: Meta0.Meta0OrValueTypeNullish\n public readonly zodError?: Error0GeneralProps['zodError']\n public readonly axiosError?: Error0GeneralProps['axiosError']\n\n static defaultMessage = 'Unknown error'\n static defaultCode?: Error0GeneralProps['code']\n static defaultHttpStatus?: Error0GeneralProps['httpStatus']\n static defaultExpected?: Error0GeneralProps['expected']\n static defaultClientMessage?: Error0GeneralProps['clientMessage']\n static defaultMeta?: Meta0.Meta0OrValueTypeNullish\n\n public readonly propsOriginal: Error0GeneralProps\n\n constructor(message: string)\n constructor(input: Error0Input)\n constructor(message: string, input: Error0Input)\n constructor(error: Error)\n constructor(error: Error, input: Error0Input)\n constructor(value: unknown)\n constructor(value: unknown, input: Error0Input)\n constructor(...args: unknown[]) {\n const input: Partial<Error0Input> = {}\n if (args[0] instanceof Error) {\n input.cause = args[0]\n } else if (typeof args[0] === 'object' && args[0] !== null) {\n Object.assign(input, args[0])\n } else if (typeof args[0] === 'string') {\n input.message = args[0]\n }\n if (typeof args[1] === 'object' && args[1] !== null) {\n Object.assign(input, args[1])\n }\n const safeInput = Error0._safeParseInput(input)\n\n const message = safeInput.message || Error0.defaultMessage\n super(message)\n Object.setPrototypeOf(this, (this.constructor as typeof Error0).prototype)\n this.name = 'Error0'\n\n this.propsOriginal = (this.constructor as typeof Error0)._getSelfGeneralProps({\n error0Input: safeInput,\n message,\n stack: safeInput.stack || this.stack,\n })\n const causesProps = (this.constructor as typeof Error0)._getCausesPropsFromError0Props(\n this.propsOriginal,\n (this.constructor as typeof Error0).defaultMaxLevel,\n )\n const propsFloated = (this.constructor as typeof Error0)._getSelfPropsFloated(causesProps)\n this.tag = propsFloated.tag\n this.code = propsFloated.code\n this.httpStatus = propsFloated.httpStatus\n this.expected = propsFloated.expected\n this.clientMessage = propsFloated.clientMessage\n this.cause = propsFloated.cause\n this.stack = propsFloated.stack\n this.meta = propsFloated.meta\n this.zodError = propsFloated.zodError\n this.axiosError = propsFloated.axiosError\n }\n\n // settings\n\n static defaultMaxLevel = 10\n\n // props\n\n public static _safeParseInput(error0Input: Record<string, unknown>): Error0Input {\n const result: Error0Input = {}\n result.message = typeof error0Input.message === 'string' ? error0Input.message : undefined\n result.tag = typeof error0Input.tag === 'string' ? error0Input.tag : undefined\n result.code = typeof error0Input.code === 'string' ? error0Input.code : undefined\n result.httpStatus =\n typeof error0Input.httpStatus === 'number' || typeof error0Input.httpStatus === 'string'\n ? (error0Input.httpStatus as never)\n : undefined\n result.expected =\n typeof error0Input.expected === 'function' || typeof error0Input.expected === 'boolean'\n ? (error0Input.expected as never)\n : undefined\n result.clientMessage = typeof error0Input.clientMessage === 'string' ? error0Input.clientMessage : undefined\n result.cause = error0Input.cause\n result.stack = typeof error0Input.stack === 'string' ? error0Input.stack : undefined\n // result.meta0 =\n // error0Input.meta0 instanceof Meta0 ? error0Input.meta0 : undefined\n // result.meta =\n // typeof error0Input.meta === \"object\" && error0Input.meta !== null\n // ? error0Input.meta\n // : undefined\n result.meta =\n error0Input.meta instanceof Meta0\n ? error0Input.meta\n : typeof error0Input.meta === 'object' && error0Input.meta !== null\n ? (error0Input.meta as Meta0.ValueType)\n : undefined\n result.zodError = error0Input.zodError instanceof ZodError ? error0Input.zodError : undefined\n result.axiosError = isAxiosError(error0Input.axiosError) ? error0Input.axiosError : undefined\n return result\n }\n\n public static _getSelfGeneralProps({\n error0Input,\n message,\n stack,\n }: {\n error0Input: Error0Input\n message: string\n stack: Error0GeneralProps['stack']\n }): Error0GeneralProps {\n // const meta = Meta0.merge(error0Input.meta0, error0Input.meta).value\n const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)\n const meta = meta0.getValue()\n const finalTag = meta0.getFinalTag(error0Input.tag)\n const clientMessage = error0Input.clientMessage || this.defaultClientMessage\n const result: Error0GeneralProps = {\n message: error0Input.message || this.defaultMessage,\n tag: finalTag,\n code: error0Input.code || meta.code || this.defaultCode,\n httpStatus:\n typeof error0Input.httpStatus === 'number'\n ? error0Input.httpStatus\n : error0Input.httpStatus &&\n typeof error0Input.httpStatus === 'string' &&\n error0Input.httpStatus in HttpStatusCode\n ? HttpStatusCode[error0Input.httpStatus]\n : meta.httpStatus || this.defaultHttpStatus,\n expected: undefined,\n clientMessage,\n anyMessage: clientMessage || message,\n cause: error0Input.cause,\n stack: undefined,\n meta,\n zodError: error0Input.zodError,\n axiosError: error0Input.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n typeof error0Input.expected === 'boolean' || typeof error0Input.expected === 'function'\n ? error0Input.expected\n : meta.expected || this.defaultExpected,\n )\n result.stack = this._removeConstructorStackPart(stack)\n return result\n }\n\n public static _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps {\n const cause = this._getClosestPropValue(causesProps, 'cause')\n const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack)\n const closestTag = this._getClosestPropValue(causesProps, 'tag')\n const meta = this._getMergedMetaValue(causesProps)\n const tag = Meta0.getFinalTag(meta, closestTag)\n const propsFloated: Error0GeneralProps = {\n message: this._getClosestPropValue(causesProps, 'message'),\n tag,\n code: this._getClosestPropValue(causesProps, 'code'),\n httpStatus: this._getClosestPropValue(causesProps, 'httpStatus'),\n expected: this._isExpected(causesProps),\n clientMessage: this._getClosestPropValue(causesProps, 'clientMessage'),\n cause,\n stack,\n anyMessage: causesProps[0].anyMessage,\n meta,\n zodError: this._getClosestPropValue(causesProps, 'zodError'),\n axiosError: this._getClosestPropValue(causesProps, 'axiosError'),\n }\n return propsFloated\n }\n\n // sepcial\n\n public static _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps> {\n return {\n message: `Zod Validation Error: ${zodError.message}`,\n }\n }\n\n public static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps> {\n return {\n message: 'Axios Error',\n meta: {\n axiosData: (() => {\n try {\n return JSON.stringify(axiosError.response?.data)\n } catch {\n return undefined\n }\n })(),\n axiosStatus: axiosError.response?.status,\n },\n }\n }\n\n public static _assignError0Props(\n error0Props: Error0GeneralProps,\n extraError0Props: Partial<Error0GeneralProps>,\n ): void {\n const metaValue = Meta0.mergeValues(error0Props.meta, extraError0Props.meta)\n Object.assign(error0Props, extraError0Props, { meta: metaValue })\n }\n\n // expected\n\n public static _normalizeSelfExpected(\n error0Props: Error0GeneralProps,\n expectedProvided: Error0Input['expected'],\n ): boolean | undefined {\n if (typeof expectedProvided === 'function') {\n return expectedProvided(error0Props)\n }\n return expectedProvided\n }\n\n public static _isExpected(causesProps: Error0GeneralProps[]): boolean {\n let hasExpectedTrue = false\n for (const causeProps of causesProps) {\n if (causeProps.expected === false) {\n return false\n }\n if (causeProps.expected === true) {\n hasExpectedTrue = true\n }\n }\n return hasExpectedTrue\n }\n\n // getters\n\n public static _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps {\n if (typeof error !== 'object' || error === null) {\n return {\n message: undefined,\n tag: undefined,\n code: undefined,\n httpStatus: undefined,\n expected: undefined,\n clientMessage: undefined,\n anyMessage: this.defaultMessage,\n cause: undefined,\n stack: undefined,\n zodError: undefined,\n axiosError: undefined,\n meta: {},\n }\n }\n const message = 'message' in error && typeof error.message === 'string' ? error.message : undefined\n const clientMessage =\n 'clientMessage' in error && typeof error.clientMessage === 'string'\n ? error.clientMessage\n : defaults?.clientMessage || undefined\n const result: Error0GeneralProps = {\n message,\n code: 'code' in error && typeof error.code === 'string' ? error.code : defaults?.code || undefined,\n clientMessage,\n anyMessage: clientMessage || message || this.defaultMessage,\n expected: undefined,\n stack: 'stack' in error && typeof error.stack === 'string' ? error.stack : undefined,\n tag: 'tag' in error && typeof error.tag === 'string' ? error.tag : defaults?.tag || undefined,\n cause: 'cause' in error ? error.cause : defaults?.cause || undefined,\n meta:\n 'meta' in error && typeof error.meta === 'object' && error.meta !== null\n ? Meta0.getValue(error.meta as Meta0.ValueType)\n : Meta0.getValue(defaults?.meta) || {},\n httpStatus:\n 'httpStatus' in error && typeof error.httpStatus === 'number' && error.httpStatus in HttpStatusCode\n ? error.httpStatus\n : typeof defaults?.httpStatus === 'string'\n ? HttpStatusCode[defaults.httpStatus]\n : defaults?.httpStatus,\n zodError:\n 'zodError' in error && error.zodError instanceof ZodError\n ? error.zodError\n : error instanceof ZodError\n ? error\n : defaults?.zodError,\n axiosError:\n 'axiosError' in error && isAxiosError(error.axiosError)\n ? error.axiosError\n : isAxiosError(error)\n ? error\n : defaults?.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n 'expected' in error && (typeof error.expected === 'boolean' || typeof error.expected === 'function')\n ? (error.expected as ExpectedFn)\n : defaults?.expected || undefined,\n )\n if (result.zodError) {\n this._assignError0Props(result, this._getExtraError0PropsByZodError(result.zodError))\n }\n if (result.axiosError) {\n this._assignError0Props(result, this._getExtraError0PropsByAxiosError(result.axiosError))\n }\n return result\n }\n\n public static _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[] {\n if (!error) {\n return []\n }\n const causeProps = this._getPropsFromUnknown(error)\n const causesProps: Error0GeneralProps[] = [causeProps]\n if (!causeProps.cause) {\n return causesProps\n }\n if (maxLevel > 0) {\n causesProps.push(...this._getCausesPropsFromUnknown(this._getPropsFromUnknown(causeProps.cause), maxLevel - 1))\n }\n return causesProps\n }\n\n public static _getCausesPropsFromError0Props(\n error0Props: Error0GeneralProps,\n maxLevel: number,\n ): Error0GeneralProps[] {\n return [error0Props, ...this._getCausesPropsFromUnknown(error0Props.cause, maxLevel - 1)]\n }\n\n public static _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]> | undefined {\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n return propValue as NonNullable<Error0GeneralProps[TPropKey]>\n }\n }\n return undefined\n }\n\n // private static getClosestByGetter<TResult>(\n // causesProps: Error0GeneralProps[],\n // getter: (props: Error0GeneralProps) => TResult,\n // ): NonNullable<TResult> | undefined {\n // for (const causeProps of causesProps) {\n // const result = getter(causeProps)\n // if (isFilled(result)) {\n // return result\n // }\n // }\n // return undefined\n // }\n\n public static _getFilledPropValues<TPropKey extends keyof Error0Input>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]>[] {\n const values: NonNullable<Error0GeneralProps[TPropKey]>[] = []\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n values.push(propValue as NonNullable<Error0GeneralProps[TPropKey]>)\n }\n }\n return values\n }\n\n public static _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType {\n const metas = this._getFilledPropValues(causesProps, 'meta')\n if (metas.length === 0) {\n return {}\n } else if (metas.length === 1) {\n return metas[0]\n } else {\n return Meta0.mergeValues(metas[0], ...metas.slice(1))\n }\n }\n\n // stack\n\n public static _removeConstructorStackPart(stack: Error0GeneralProps['stack']): Error0GeneralProps['stack'] {\n if (!stack) {\n return stack\n }\n let lines = stack.split('\\n')\n const removeAllLinesContains = (search: string) => {\n lines = lines.filter((line) => !line.includes(search))\n }\n removeAllLinesContains('at new Error0')\n removeAllLinesContains('at _toError0')\n removeAllLinesContains('at Error0.from')\n removeAllLinesContains('at Error0._toError0')\n return lines.join('\\n')\n }\n\n public static _mergeStack(\n prevStack: Error0GeneralProps['stack'],\n nextStack: Error0GeneralProps['stack'],\n ): Error0GeneralProps['stack'] {\n return [nextStack, prevStack].filter(Boolean).join('\\n\\n') || undefined\n }\n\n // transformations\n\n static isError0(error: unknown): error is Error0 {\n return error instanceof Error0\n }\n\n static isLikelyError0(error: unknown): error is Error0 {\n if (error instanceof Error0) {\n return true\n }\n\n if (typeof error === 'object' && error !== null) {\n if ('__I_AM_ERROR_0' in error && error.__I_AM_ERROR_0 === true) {\n return true\n }\n }\n\n return false\n }\n\n public static _toError0(error: unknown, inputOverride: Error0Input = {}): Error0 {\n if (error instanceof Error0) {\n return error\n }\n\n if (typeof error === 'string') {\n return new Error0(error, inputOverride)\n }\n\n if (typeof error !== 'object' || error === null) {\n return new Error0({\n message: this.defaultMessage,\n ...inputOverride,\n })\n }\n\n const inputFromData = get(error, 'data')\n if (inputFromData) {\n if (Error0.isLikelyError0(inputFromData)) {\n return this._toError0(inputFromData, inputOverride)\n }\n }\n\n const inputFromDataError0 = get(error, 'data.error0')\n if (inputFromDataError0) {\n if (Error0.isLikelyError0(inputFromDataError0)) {\n return this._toError0(inputFromDataError0, inputOverride)\n }\n }\n\n return new Error0(this._getPropsFromUnknown(error, inputOverride))\n }\n\n static from(error: unknown, inputOverride?: Error0Input): Error0 {\n return this._toError0(error, inputOverride)\n }\n\n static extend(props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n }) {\n const parent = this\n return class Error0 extends parent {\n static override defaultMessage = props.defaultMessage ?? parent.defaultMessage\n static override defaultCode = props.defaultCode ?? parent.defaultCode\n static override defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus\n static override defaultExpected = props.defaultExpected ?? parent.defaultExpected\n static override defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage\n static override defaultMeta = Meta0.extend(props.defaultMeta, parent.defaultMeta)\n }\n }\n\n static extendCollection<T extends Record<string, typeof Error0>>(\n classes: T,\n props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n },\n ): T {\n return Object.fromEntries(Object.entries(classes).map(([name, Class]) => [name, Class.extend(props)])) as T\n }\n\n toJSON() {\n return {\n message: this.message,\n tag: this.tag,\n code: this.code,\n httpStatus: this.httpStatus,\n expected: this.expected,\n clientMessage: this.clientMessage,\n anyMessage: this.anyMessage,\n cause: this.cause,\n meta: Meta0.getValue(this.meta),\n stack: this.stack,\n __I_AM_ERROR_0: this.__I_AM_ERROR_0,\n }\n }\n static toJSON(error: unknown, inputOverride?: Error0Input) {\n const error0 = this.from(error, inputOverride)\n return error0.toJSON()\n }\n\n toResponse(data?: Record<string, unknown>) {\n return Response.json(\n {\n ...this.toJSON(),\n ...data,\n },\n {\n status: this.httpStatus,\n statusText: this.message,\n },\n )\n }\n}\n\nexport namespace Error0 {\n export type JSON = ReturnType<Error0['toJSON']>\n export type Collection = Record<string, typeof Error0>\n}\n\nexport const e0s = {\n Default: Error0,\n Expected: Error0.extend({\n defaultExpected: true,\n }),\n} satisfies Error0.Collection\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,mBAA8D;AAC9D,iBAAgB;AAChB,iBAAyB;AAyCzB,MAAM,WAAW,CAAI,UAAsC,UAAU,QAAQ,UAAU,UAAa,UAAU;AAEvG,MAAM,eAAe,MAAM;AAAA,EAChB,iBAAuB;AAAA,EAEvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,OAAO,iBAAiB;AAAA,EACxB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EAES;AAAA,EAShB,eAAe,MAAiB;AAC9B,UAAM,QAA8B,CAAC;AACrC,QAAI,KAAK,CAAC,aAAa,OAAO;AAC5B,YAAM,QAAQ,KAAK,CAAC;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SAAS,KAAK,KAAK,OAAO,aAAa;AAC7C,WAAO,OAAO,OAAO;AAAA,EACvB;AAAA,EAEA,WAAW,MAAgC;AACzC,WAAO,SAAS;AAAA,MACd;AAAA,QACE,GAAG,KAAK,OAAO;AAAA,QACf,GAAG;AAAA,MACL;AAAA,MACA;AAAA,QACE,QAAQ,KAAK;AAAA,QACb,YAAY,KAAK;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF;AAOO,MAAM,MAAM;AAAA,EACjB,SAAS;AAAA,EACT,UAAU,OAAO,OAAO;AAAA,IACtB,iBAAiB;AAAA,EACnB,CAAC;AACH;","names":["get"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { Meta0, meta0PluginTag } from '@devp0nt/meta0'\nimport { type AxiosError, HttpStatusCode, isAxiosError } from 'axios'\nimport get from 'lodash/get.js'\nimport { ZodError } from 'zod'\n\n// TODO: Зод, аксиос, это всё плагины\n// TODO: В эррор0 добавить ориджинал\n// TODO: store tags as array from all causes\n// TODO: not use self stack if toError0\n// TODO: fix default message in extended error0, should be used in constuctor of Error0\n// TODO: remove defaults prop from getPropsFromUnknown\n// TODO: code has enum type, fn to check if code exists\n\nexport interface Error0Input {\n message?: string\n tag?: string\n code?: string\n httpStatus?: HttpStatusCode | HttpStatusCodeString\n expected?: boolean | ExpectedFn\n clientMessage?: string\n cause?: Error0Cause\n stack?: string\n meta?: Meta0.Meta0OrValueTypeNullish\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ninterface Error0GeneralProps {\n message: Error0Input['message']\n tag: Error0Input['tag']\n code: Error0Input['code']\n httpStatus: number | undefined\n expected: boolean | undefined\n clientMessage: Error0Input['clientMessage']\n anyMessage: string | undefined\n cause: Error0Input['cause']\n stack: Error['stack']\n meta: Meta0.ValueType\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ntype HttpStatusCodeString = keyof typeof HttpStatusCode\ntype Error0Cause = Error | Error0 | unknown\ntype ExpectedFn = (error: Error0GeneralProps) => boolean | undefined\n\nconst isFilled = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined && value !== ''\nconst toStringOrUndefined = (value: unknown): string | undefined => {\n return typeof value === 'string' ? value : undefined\n}\nconst toNumberOrUndefined = (value: unknown): number | undefined => {\n if (typeof value === 'number') {\n return value\n }\n const number = Number(value)\n if (typeof value === 'string' && !Number.isNaN(number)) {\n return number\n }\n return undefined\n}\nconst toBooleanOrUndefined = (value: unknown): boolean | undefined => {\n if (typeof value === 'boolean') {\n return value\n }\n return undefined\n}\n\nexport class Error0 extends Error {\n public readonly __I_AM_ERROR_0: true = true\n\n public readonly tag?: Error0GeneralProps['tag']\n public readonly code?: Error0GeneralProps['code']\n public readonly httpStatus?: Error0GeneralProps['httpStatus']\n public readonly expected?: Error0GeneralProps['expected']\n public readonly clientMessage?: Error0GeneralProps['clientMessage']\n public readonly anyMessage?: Error0GeneralProps['anyMessage']\n public override readonly cause?: Error0GeneralProps['cause']\n public readonly meta?: Meta0.Meta0OrValueTypeNullish\n public readonly zodError?: Error0GeneralProps['zodError']\n public readonly axiosError?: Error0GeneralProps['axiosError']\n\n static defaultMessage = 'Unknown error'\n static defaultCode?: Error0GeneralProps['code']\n static defaultHttpStatus?: Error0GeneralProps['httpStatus']\n static defaultExpected?: Error0GeneralProps['expected']\n static defaultClientMessage?: Error0GeneralProps['clientMessage']\n static defaultMeta?: Meta0.Meta0OrValueTypeNullish\n\n public readonly propsOriginal: Error0GeneralProps\n\n constructor(message: string)\n constructor(input: Error0Input)\n constructor(message: string, input: Error0Input)\n constructor(error: Error)\n constructor(error: Error, input: Error0Input)\n constructor(value: unknown)\n constructor(value: unknown, input: Error0Input)\n constructor(...args: unknown[]) {\n const input: Partial<Error0Input> = {}\n if (args[0] instanceof Error) {\n input.cause = args[0]\n } else if (typeof args[0] === 'object' && args[0] !== null) {\n Object.assign(input, args[0])\n } else if (typeof args[0] === 'string') {\n input.message = args[0]\n }\n if (typeof args[1] === 'object' && args[1] !== null) {\n Object.assign(input, args[1])\n }\n const safeInput = Error0._safeParseInput(input)\n\n const message = safeInput.message || Error0.defaultMessage\n super(message)\n Object.setPrototypeOf(this, (this.constructor as typeof Error0).prototype)\n this.name = 'Error0'\n\n this.propsOriginal = (this.constructor as typeof Error0)._getSelfGeneralProps({\n error0Input: safeInput,\n message,\n stack: safeInput.stack || this.stack,\n })\n const causesProps = (this.constructor as typeof Error0)._getCausesPropsFromError0Props(\n this.propsOriginal,\n (this.constructor as typeof Error0).defaultMaxLevel,\n )\n const propsFloated = (this.constructor as typeof Error0)._getSelfPropsFloated(causesProps)\n this.tag = propsFloated.tag\n this.code = propsFloated.code\n this.httpStatus = propsFloated.httpStatus\n this.expected = propsFloated.expected\n this.clientMessage = propsFloated.clientMessage\n this.cause = propsFloated.cause\n this.stack = propsFloated.stack\n this.meta = propsFloated.meta\n this.zodError = propsFloated.zodError\n this.axiosError = propsFloated.axiosError\n }\n\n // settings\n\n static defaultMaxLevel = 10\n\n // props\n\n public static _safeParseInput(error0Input: Record<string, unknown>): Error0Input {\n const result: Error0Input = {}\n result.message = typeof error0Input.message === 'string' ? error0Input.message : undefined\n result.tag = typeof error0Input.tag === 'string' ? error0Input.tag : undefined\n result.code = typeof error0Input.code === 'string' ? error0Input.code : undefined\n result.httpStatus =\n typeof error0Input.httpStatus === 'number' || typeof error0Input.httpStatus === 'string'\n ? (error0Input.httpStatus as never)\n : undefined\n result.expected =\n typeof error0Input.expected === 'function' || typeof error0Input.expected === 'boolean'\n ? (error0Input.expected as never)\n : undefined\n result.clientMessage = typeof error0Input.clientMessage === 'string' ? error0Input.clientMessage : undefined\n result.cause = error0Input.cause\n result.stack = typeof error0Input.stack === 'string' ? error0Input.stack : undefined\n // result.meta0 =\n // error0Input.meta0 instanceof Meta0 ? error0Input.meta0 : undefined\n // result.meta =\n // typeof error0Input.meta === \"object\" && error0Input.meta !== null\n // ? error0Input.meta\n // : undefined\n result.meta =\n error0Input.meta instanceof Meta0\n ? error0Input.meta\n : typeof error0Input.meta === 'object' && error0Input.meta !== null\n ? (error0Input.meta as Meta0.ValueType)\n : undefined\n result.zodError = error0Input.zodError instanceof ZodError ? error0Input.zodError : undefined\n result.axiosError = isAxiosError(error0Input.axiosError) ? error0Input.axiosError : undefined\n return result\n }\n\n public static _getSelfGeneralProps({\n error0Input,\n message,\n stack,\n }: {\n error0Input: Error0Input\n message: string\n stack: Error0GeneralProps['stack']\n }): Error0GeneralProps {\n // const meta = Meta0.merge(error0Input.meta0, error0Input.meta).value\n\n // const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)\n // const defaultMetaValue =\n // this.defaultMeta && typeof this.defaultMeta === 'object' && 'getValue' in this.defaultMeta\n // ? (this.defaultMeta as any).getValue()\n // : this.defaultMeta\n\n const meta0 = Meta0.extend(this.defaultMeta, error0Input.meta)\n const meta = meta0.getValue()\n const finalTag = meta0PluginTag.public.getFullTag(meta0, error0Input.tag)\n delete meta.tagPrefix\n const clientMessage = error0Input.clientMessage || this.defaultClientMessage\n const result: Error0GeneralProps = {\n message: error0Input.message || this.defaultMessage,\n tag: finalTag,\n code: error0Input.code || toStringOrUndefined(meta.code) || this.defaultCode,\n httpStatus:\n typeof error0Input.httpStatus === 'number'\n ? error0Input.httpStatus\n : error0Input.httpStatus &&\n typeof error0Input.httpStatus === 'string' &&\n error0Input.httpStatus in HttpStatusCode\n ? HttpStatusCode[error0Input.httpStatus]\n : toNumberOrUndefined(meta.httpStatus) || this.defaultHttpStatus,\n expected: undefined,\n clientMessage,\n anyMessage: clientMessage || message,\n cause: error0Input.cause,\n stack: undefined,\n meta,\n zodError: error0Input.zodError,\n axiosError: error0Input.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n typeof error0Input.expected === 'boolean' || typeof error0Input.expected === 'function'\n ? error0Input.expected\n : toBooleanOrUndefined(meta.expected) || this.defaultExpected,\n )\n result.stack = this._removeConstructorStackPart(stack)\n return result\n }\n\n public static _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps {\n const cause = this._getClosestPropValue(causesProps, 'cause')\n const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack)\n const closestTag = this._getClosestPropValue(causesProps, 'tag')\n const meta = this._getMergedMetaValue(causesProps)\n const tag = meta0PluginTag.public.getFullTag(meta, closestTag)\n const propsFloated: Error0GeneralProps = {\n message: this._getClosestPropValue(causesProps, 'message'),\n tag,\n code: this._getClosestPropValue(causesProps, 'code'),\n httpStatus: this._getClosestPropValue(causesProps, 'httpStatus'),\n expected: this._isExpected(causesProps),\n clientMessage: this._getClosestPropValue(causesProps, 'clientMessage'),\n cause,\n stack,\n anyMessage: causesProps[0].anyMessage,\n meta,\n zodError: this._getClosestPropValue(causesProps, 'zodError'),\n axiosError: this._getClosestPropValue(causesProps, 'axiosError'),\n }\n return propsFloated\n }\n\n // sepcial\n\n public static _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps> {\n return {\n message: `Zod Validation Error: ${zodError.message}`,\n }\n }\n\n public static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps> {\n return {\n message: 'Axios Error',\n meta: {\n axiosData: (() => {\n try {\n return JSON.stringify(axiosError.response?.data)\n } catch {\n return undefined\n }\n })(),\n axiosStatus: axiosError.response?.status,\n },\n }\n }\n\n public static _assignError0Props(\n error0Props: Error0GeneralProps,\n extraError0Props: Partial<Error0GeneralProps>,\n ): void {\n const metaValue = Meta0.mergeValues(error0Props.meta, extraError0Props.meta)\n Object.assign(error0Props, extraError0Props, { meta: metaValue })\n }\n\n // expected\n\n public static _normalizeSelfExpected(\n error0Props: Error0GeneralProps,\n expectedProvided: Error0Input['expected'],\n ): boolean | undefined {\n if (typeof expectedProvided === 'function') {\n return expectedProvided(error0Props)\n }\n return expectedProvided\n }\n\n public static _isExpected(causesProps: Error0GeneralProps[]): boolean {\n let hasExpectedTrue = false\n for (const causeProps of causesProps) {\n if (causeProps.expected === false) {\n return false\n }\n if (causeProps.expected === true) {\n hasExpectedTrue = true\n }\n }\n return hasExpectedTrue\n }\n\n // getters\n\n public static _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps {\n if (typeof error !== 'object' || error === null) {\n return {\n message: undefined,\n tag: undefined,\n code: undefined,\n httpStatus: undefined,\n expected: undefined,\n clientMessage: undefined,\n anyMessage: this.defaultMessage,\n cause: undefined,\n stack: undefined,\n zodError: undefined,\n axiosError: undefined,\n meta: {},\n }\n }\n const message = 'message' in error && typeof error.message === 'string' ? error.message : undefined\n const clientMessage =\n 'clientMessage' in error && typeof error.clientMessage === 'string'\n ? error.clientMessage\n : defaults?.clientMessage || undefined\n const result: Error0GeneralProps = {\n message,\n code: 'code' in error && typeof error.code === 'string' ? error.code : defaults?.code || undefined,\n clientMessage,\n anyMessage: clientMessage || message || this.defaultMessage,\n expected: undefined,\n stack: 'stack' in error && typeof error.stack === 'string' ? error.stack : undefined,\n tag: 'tag' in error && typeof error.tag === 'string' ? error.tag : defaults?.tag || undefined,\n cause: 'cause' in error ? error.cause : defaults?.cause || undefined,\n meta:\n 'meta' in error && typeof error.meta === 'object' && error.meta !== null\n ? Meta0.getValue(error.meta as Meta0.ValueType)\n : Meta0.getValue(defaults?.meta) || {},\n httpStatus:\n 'httpStatus' in error && typeof error.httpStatus === 'number' && error.httpStatus in HttpStatusCode\n ? error.httpStatus\n : typeof defaults?.httpStatus === 'string'\n ? HttpStatusCode[defaults.httpStatus]\n : defaults?.httpStatus,\n zodError:\n 'zodError' in error && error.zodError instanceof ZodError\n ? error.zodError\n : error instanceof ZodError\n ? error\n : defaults?.zodError,\n axiosError:\n 'axiosError' in error && isAxiosError(error.axiosError)\n ? error.axiosError\n : isAxiosError(error)\n ? error\n : defaults?.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n 'expected' in error && (typeof error.expected === 'boolean' || typeof error.expected === 'function')\n ? (error.expected as ExpectedFn)\n : defaults?.expected || undefined,\n )\n if (result.zodError) {\n this._assignError0Props(result, this._getExtraError0PropsByZodError(result.zodError))\n }\n if (result.axiosError) {\n this._assignError0Props(result, this._getExtraError0PropsByAxiosError(result.axiosError))\n }\n return result\n }\n\n public static _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[] {\n if (!error) {\n return []\n }\n const causeProps = this._getPropsFromUnknown(error)\n const causesProps: Error0GeneralProps[] = [causeProps]\n if (!causeProps.cause) {\n return causesProps\n }\n if (maxLevel > 0) {\n causesProps.push(...this._getCausesPropsFromUnknown(this._getPropsFromUnknown(causeProps.cause), maxLevel - 1))\n }\n return causesProps\n }\n\n public static _getCausesPropsFromError0Props(\n error0Props: Error0GeneralProps,\n maxLevel: number,\n ): Error0GeneralProps[] {\n return [error0Props, ...this._getCausesPropsFromUnknown(error0Props.cause, maxLevel - 1)]\n }\n\n public static _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]> | undefined {\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n return propValue as NonNullable<Error0GeneralProps[TPropKey]>\n }\n }\n return undefined\n }\n\n // private static getClosestByGetter<TResult>(\n // causesProps: Error0GeneralProps[],\n // getter: (props: Error0GeneralProps) => TResult,\n // ): NonNullable<TResult> | undefined {\n // for (const causeProps of causesProps) {\n // const result = getter(causeProps)\n // if (isFilled(result)) {\n // return result\n // }\n // }\n // return undefined\n // }\n\n public static _getFilledPropValues<TPropKey extends keyof Error0Input>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]>[] {\n const values: NonNullable<Error0GeneralProps[TPropKey]>[] = []\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n values.push(propValue as NonNullable<Error0GeneralProps[TPropKey]>)\n }\n }\n return values\n }\n\n public static _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType {\n const metas = this._getFilledPropValues(causesProps, 'meta')\n if (metas.length === 0) {\n return {}\n } else if (metas.length === 1) {\n return metas[0]\n } else {\n return Meta0.mergeValues(metas[0], ...metas.slice(1))\n }\n }\n\n // stack\n\n public static _removeConstructorStackPart(stack: Error0GeneralProps['stack']): Error0GeneralProps['stack'] {\n if (!stack) {\n return stack\n }\n let lines = stack.split('\\n')\n const removeAllLinesContains = (search: string) => {\n lines = lines.filter((line) => !line.includes(search))\n }\n removeAllLinesContains('at new Error0')\n removeAllLinesContains('at _toError0')\n removeAllLinesContains('at Error0.from')\n removeAllLinesContains('at Error0._toError0')\n return lines.join('\\n')\n }\n\n public static _mergeStack(\n prevStack: Error0GeneralProps['stack'],\n nextStack: Error0GeneralProps['stack'],\n ): Error0GeneralProps['stack'] {\n return [nextStack, prevStack].filter(Boolean).join('\\n\\n') || undefined\n }\n\n // transformations\n\n static isError0(error: unknown): error is Error0 {\n return error instanceof Error0\n }\n\n static isLikelyError0(error: unknown): error is Error0 {\n if (error instanceof Error0) {\n return true\n }\n\n if (typeof error === 'object' && error !== null) {\n if ('__I_AM_ERROR_0' in error && error.__I_AM_ERROR_0 === true) {\n return true\n }\n }\n\n return false\n }\n\n public static _toError0(error: unknown, inputOverride: Error0Input = {}): Error0 {\n if (error instanceof Error0) {\n return error\n }\n\n if (typeof error === 'string') {\n return new Error0(error, inputOverride)\n }\n\n if (typeof error !== 'object' || error === null) {\n return new Error0({\n message: this.defaultMessage,\n ...inputOverride,\n })\n }\n\n const inputFromData = get(error, 'data')\n if (inputFromData) {\n if (Error0.isLikelyError0(inputFromData)) {\n return this._toError0(inputFromData, inputOverride)\n }\n }\n\n const inputFromDataError0 = get(error, 'data.error0')\n if (inputFromDataError0) {\n if (Error0.isLikelyError0(inputFromDataError0)) {\n return this._toError0(inputFromDataError0, inputOverride)\n }\n }\n\n return new Error0(this._getPropsFromUnknown(error, inputOverride))\n }\n\n static from(error: unknown, inputOverride?: Error0Input): Error0 {\n return this._toError0(error, inputOverride)\n }\n\n static extend(props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n }) {\n const parent = this\n return class Error0 extends parent {\n static override defaultMessage = props.defaultMessage ?? parent.defaultMessage\n static override defaultCode = props.defaultCode ?? parent.defaultCode\n static override defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus\n static override defaultExpected = props.defaultExpected ?? parent.defaultExpected\n static override defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage\n static override defaultMeta = Meta0.extend(parent.defaultMeta, props.defaultMeta)\n }\n }\n\n static extendCollection<T extends Record<string, typeof Error0>>(\n classes: T,\n props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n },\n ): T {\n return Object.fromEntries(Object.entries(classes).map(([name, Class]) => [name, Class.extend(props)])) as T\n }\n\n toJSON() {\n return {\n message: this.message,\n tag: this.tag,\n code: this.code,\n httpStatus: this.httpStatus,\n expected: this.expected,\n clientMessage: this.clientMessage,\n anyMessage: this.anyMessage,\n cause: this.cause,\n meta: Meta0.getValue(this.meta),\n stack: this.stack,\n __I_AM_ERROR_0: this.__I_AM_ERROR_0,\n }\n }\n static toJSON(error: unknown, inputOverride?: Error0Input) {\n const error0 = this.from(error, inputOverride)\n return error0.toJSON()\n }\n\n toResponse(data?: Record<string, unknown>) {\n return Response.json(\n {\n ...this.toJSON(),\n ...data,\n },\n {\n status: this.httpStatus,\n statusText: this.message,\n },\n )\n }\n}\n\nexport namespace Error0 {\n export type JSON = ReturnType<Error0['toJSON']>\n export type Collection = Record<string, typeof Error0>\n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ACf,GAAG;AAAA,MACL;AAAA,MACA;AAAA,QACE,QAAQ,KAAK;AAAA,QACb,YAAY,KAAK;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF;","names":["get"]}
@@ -413,290 +413,5 @@ declare namespace Error0 {
413
413
  type JSON = ReturnType<Error0['toJSON']>;
414
414
  type Collection = Record<string, typeof Error0>;
415
415
  }
416
- declare const e0s: {
417
- Default: typeof Error0;
418
- Expected: {
419
- new (message: string): {
420
- readonly __I_AM_ERROR_0: true;
421
- readonly tag?: Error0GeneralProps["tag"];
422
- readonly code?: Error0GeneralProps["code"];
423
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
424
- readonly expected?: Error0GeneralProps["expected"];
425
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
426
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
427
- readonly cause?: Error0GeneralProps["cause"];
428
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
429
- readonly zodError?: Error0GeneralProps["zodError"];
430
- readonly axiosError?: Error0GeneralProps["axiosError"];
431
- readonly propsOriginal: Error0GeneralProps;
432
- toJSON(): {
433
- message: string;
434
- tag: string | undefined;
435
- code: string | undefined;
436
- httpStatus: number | undefined;
437
- expected: boolean | undefined;
438
- clientMessage: string | undefined;
439
- anyMessage: string | undefined;
440
- cause: unknown;
441
- meta: Meta0.ValueType;
442
- stack: string | undefined;
443
- __I_AM_ERROR_0: true;
444
- };
445
- toResponse(data?: Record<string, unknown>): undici_types.Response;
446
- name: string;
447
- message: string;
448
- stack?: string;
449
- };
450
- new (input: Error0Input): {
451
- readonly __I_AM_ERROR_0: true;
452
- readonly tag?: Error0GeneralProps["tag"];
453
- readonly code?: Error0GeneralProps["code"];
454
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
455
- readonly expected?: Error0GeneralProps["expected"];
456
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
457
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
458
- readonly cause?: Error0GeneralProps["cause"];
459
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
460
- readonly zodError?: Error0GeneralProps["zodError"];
461
- readonly axiosError?: Error0GeneralProps["axiosError"];
462
- readonly propsOriginal: Error0GeneralProps;
463
- toJSON(): {
464
- message: string;
465
- tag: string | undefined;
466
- code: string | undefined;
467
- httpStatus: number | undefined;
468
- expected: boolean | undefined;
469
- clientMessage: string | undefined;
470
- anyMessage: string | undefined;
471
- cause: unknown;
472
- meta: Meta0.ValueType;
473
- stack: string | undefined;
474
- __I_AM_ERROR_0: true;
475
- };
476
- toResponse(data?: Record<string, unknown>): undici_types.Response;
477
- name: string;
478
- message: string;
479
- stack?: string;
480
- };
481
- new (message: string, input: Error0Input): {
482
- readonly __I_AM_ERROR_0: true;
483
- readonly tag?: Error0GeneralProps["tag"];
484
- readonly code?: Error0GeneralProps["code"];
485
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
486
- readonly expected?: Error0GeneralProps["expected"];
487
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
488
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
489
- readonly cause?: Error0GeneralProps["cause"];
490
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
491
- readonly zodError?: Error0GeneralProps["zodError"];
492
- readonly axiosError?: Error0GeneralProps["axiosError"];
493
- readonly propsOriginal: Error0GeneralProps;
494
- toJSON(): {
495
- message: string;
496
- tag: string | undefined;
497
- code: string | undefined;
498
- httpStatus: number | undefined;
499
- expected: boolean | undefined;
500
- clientMessage: string | undefined;
501
- anyMessage: string | undefined;
502
- cause: unknown;
503
- meta: Meta0.ValueType;
504
- stack: string | undefined;
505
- __I_AM_ERROR_0: true;
506
- };
507
- toResponse(data?: Record<string, unknown>): undici_types.Response;
508
- name: string;
509
- message: string;
510
- stack?: string;
511
- };
512
- new (error: Error): {
513
- readonly __I_AM_ERROR_0: true;
514
- readonly tag?: Error0GeneralProps["tag"];
515
- readonly code?: Error0GeneralProps["code"];
516
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
517
- readonly expected?: Error0GeneralProps["expected"];
518
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
519
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
520
- readonly cause?: Error0GeneralProps["cause"];
521
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
522
- readonly zodError?: Error0GeneralProps["zodError"];
523
- readonly axiosError?: Error0GeneralProps["axiosError"];
524
- readonly propsOriginal: Error0GeneralProps;
525
- toJSON(): {
526
- message: string;
527
- tag: string | undefined;
528
- code: string | undefined;
529
- httpStatus: number | undefined;
530
- expected: boolean | undefined;
531
- clientMessage: string | undefined;
532
- anyMessage: string | undefined;
533
- cause: unknown;
534
- meta: Meta0.ValueType;
535
- stack: string | undefined;
536
- __I_AM_ERROR_0: true;
537
- };
538
- toResponse(data?: Record<string, unknown>): undici_types.Response;
539
- name: string;
540
- message: string;
541
- stack?: string;
542
- };
543
- new (error: Error, input: Error0Input): {
544
- readonly __I_AM_ERROR_0: true;
545
- readonly tag?: Error0GeneralProps["tag"];
546
- readonly code?: Error0GeneralProps["code"];
547
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
548
- readonly expected?: Error0GeneralProps["expected"];
549
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
550
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
551
- readonly cause?: Error0GeneralProps["cause"];
552
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
553
- readonly zodError?: Error0GeneralProps["zodError"];
554
- readonly axiosError?: Error0GeneralProps["axiosError"];
555
- readonly propsOriginal: Error0GeneralProps;
556
- toJSON(): {
557
- message: string;
558
- tag: string | undefined;
559
- code: string | undefined;
560
- httpStatus: number | undefined;
561
- expected: boolean | undefined;
562
- clientMessage: string | undefined;
563
- anyMessage: string | undefined;
564
- cause: unknown;
565
- meta: Meta0.ValueType;
566
- stack: string | undefined;
567
- __I_AM_ERROR_0: true;
568
- };
569
- toResponse(data?: Record<string, unknown>): undici_types.Response;
570
- name: string;
571
- message: string;
572
- stack?: string;
573
- };
574
- new (value: unknown): {
575
- readonly __I_AM_ERROR_0: true;
576
- readonly tag?: Error0GeneralProps["tag"];
577
- readonly code?: Error0GeneralProps["code"];
578
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
579
- readonly expected?: Error0GeneralProps["expected"];
580
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
581
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
582
- readonly cause?: Error0GeneralProps["cause"];
583
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
584
- readonly zodError?: Error0GeneralProps["zodError"];
585
- readonly axiosError?: Error0GeneralProps["axiosError"];
586
- readonly propsOriginal: Error0GeneralProps;
587
- toJSON(): {
588
- message: string;
589
- tag: string | undefined;
590
- code: string | undefined;
591
- httpStatus: number | undefined;
592
- expected: boolean | undefined;
593
- clientMessage: string | undefined;
594
- anyMessage: string | undefined;
595
- cause: unknown;
596
- meta: Meta0.ValueType;
597
- stack: string | undefined;
598
- __I_AM_ERROR_0: true;
599
- };
600
- toResponse(data?: Record<string, unknown>): undici_types.Response;
601
- name: string;
602
- message: string;
603
- stack?: string;
604
- };
605
- new (value: unknown, input: Error0Input): {
606
- readonly __I_AM_ERROR_0: true;
607
- readonly tag?: Error0GeneralProps["tag"];
608
- readonly code?: Error0GeneralProps["code"];
609
- readonly httpStatus?: Error0GeneralProps["httpStatus"];
610
- readonly expected?: Error0GeneralProps["expected"];
611
- readonly clientMessage?: Error0GeneralProps["clientMessage"];
612
- readonly anyMessage?: Error0GeneralProps["anyMessage"];
613
- readonly cause?: Error0GeneralProps["cause"];
614
- readonly meta?: Meta0.Meta0OrValueTypeNullish;
615
- readonly zodError?: Error0GeneralProps["zodError"];
616
- readonly axiosError?: Error0GeneralProps["axiosError"];
617
- readonly propsOriginal: Error0GeneralProps;
618
- toJSON(): {
619
- message: string;
620
- tag: string | undefined;
621
- code: string | undefined;
622
- httpStatus: number | undefined;
623
- expected: boolean | undefined;
624
- clientMessage: string | undefined;
625
- anyMessage: string | undefined;
626
- cause: unknown;
627
- meta: Meta0.ValueType;
628
- stack: string | undefined;
629
- __I_AM_ERROR_0: true;
630
- };
631
- toResponse(data?: Record<string, unknown>): undici_types.Response;
632
- name: string;
633
- message: string;
634
- stack?: string;
635
- };
636
- defaultMessage: string;
637
- defaultCode: string | undefined;
638
- defaultHttpStatus: number | undefined;
639
- defaultExpected: boolean | undefined;
640
- defaultClientMessage: string | undefined;
641
- defaultMeta: Meta0;
642
- defaultMaxLevel: number;
643
- _safeParseInput(error0Input: Record<string, unknown>): Error0Input;
644
- _getSelfGeneralProps({ error0Input, message, stack, }: {
645
- error0Input: Error0Input;
646
- message: string;
647
- stack: Error0GeneralProps["stack"];
648
- }): Error0GeneralProps;
649
- _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps;
650
- _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps>;
651
- _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps>;
652
- _assignError0Props(error0Props: Error0GeneralProps, extraError0Props: Partial<Error0GeneralProps>): void;
653
- _normalizeSelfExpected(error0Props: Error0GeneralProps, expectedProvided: Error0Input["expected"]): boolean | undefined;
654
- _isExpected(causesProps: Error0GeneralProps[]): boolean;
655
- _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps;
656
- _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[];
657
- _getCausesPropsFromError0Props(error0Props: Error0GeneralProps, maxLevel: number): Error0GeneralProps[];
658
- _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]> | undefined;
659
- _getFilledPropValues<TPropKey extends keyof Error0Input>(causesProps: Error0GeneralProps[], propKey: TPropKey): NonNullable<Error0GeneralProps[TPropKey]>[];
660
- _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType;
661
- _removeConstructorStackPart(stack: Error0GeneralProps["stack"]): Error0GeneralProps["stack"];
662
- _mergeStack(prevStack: Error0GeneralProps["stack"], nextStack: Error0GeneralProps["stack"]): Error0GeneralProps["stack"];
663
- isError0(error: unknown): error is Error0;
664
- isLikelyError0(error: unknown): error is Error0;
665
- _toError0(error: unknown, inputOverride?: Error0Input): Error0;
666
- from(error: unknown, inputOverride?: Error0Input): Error0;
667
- extend(props: {
668
- defaultMessage?: Error0GeneralProps["message"];
669
- defaultCode?: Error0GeneralProps["code"];
670
- defaultHttpStatus?: Error0GeneralProps["httpStatus"];
671
- defaultExpected?: Error0GeneralProps["expected"];
672
- defaultClientMessage?: Error0GeneralProps["clientMessage"];
673
- defaultMeta?: Meta0.Meta0OrValueTypeNullish;
674
- }): /*elided*/ any;
675
- extendCollection<T extends Record<string, typeof Error0>>(classes: T, props: {
676
- defaultMessage?: Error0GeneralProps["message"];
677
- defaultCode?: Error0GeneralProps["code"];
678
- defaultHttpStatus?: Error0GeneralProps["httpStatus"];
679
- defaultExpected?: Error0GeneralProps["expected"];
680
- defaultClientMessage?: Error0GeneralProps["clientMessage"];
681
- defaultMeta?: Meta0.Meta0OrValueTypeNullish;
682
- }): T;
683
- toJSON(error: unknown, inputOverride?: Error0Input): {
684
- message: string;
685
- tag: string | undefined;
686
- code: string | undefined;
687
- httpStatus: number | undefined;
688
- expected: boolean | undefined;
689
- clientMessage: string | undefined;
690
- anyMessage: string | undefined;
691
- cause: unknown;
692
- meta: Meta0.ValueType;
693
- stack: string | undefined;
694
- __I_AM_ERROR_0: true;
695
- };
696
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
697
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
698
- stackTraceLimit: number;
699
- };
700
- };
701
416
 
702
- export { Error0, type Error0Input, e0s };
417
+ export { Error0, type Error0Input };
package/dist/esm/index.js CHANGED
@@ -1,8 +1,27 @@
1
- import { Meta0 } from "@devp0nt/meta0";
1
+ import { Meta0, meta0PluginTag } from "@devp0nt/meta0";
2
2
  import { HttpStatusCode, isAxiosError } from "axios";
3
3
  import get from "lodash/get.js";
4
4
  import { ZodError } from "zod";
5
5
  const isFilled = (value) => value !== null && value !== void 0 && value !== "";
6
+ const toStringOrUndefined = (value) => {
7
+ return typeof value === "string" ? value : void 0;
8
+ };
9
+ const toNumberOrUndefined = (value) => {
10
+ if (typeof value === "number") {
11
+ return value;
12
+ }
13
+ const number = Number(value);
14
+ if (typeof value === "string" && !Number.isNaN(number)) {
15
+ return number;
16
+ }
17
+ return void 0;
18
+ };
19
+ const toBooleanOrUndefined = (value) => {
20
+ if (typeof value === "boolean") {
21
+ return value;
22
+ }
23
+ return void 0;
24
+ };
6
25
  class Error0 extends Error {
7
26
  __I_AM_ERROR_0 = true;
8
27
  tag;
@@ -83,15 +102,16 @@ class Error0 extends Error {
83
102
  message,
84
103
  stack
85
104
  }) {
86
- const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta);
105
+ const meta0 = Meta0.extend(this.defaultMeta, error0Input.meta);
87
106
  const meta = meta0.getValue();
88
- const finalTag = meta0.getFinalTag(error0Input.tag);
107
+ const finalTag = meta0PluginTag.public.getFullTag(meta0, error0Input.tag);
108
+ delete meta.tagPrefix;
89
109
  const clientMessage = error0Input.clientMessage || this.defaultClientMessage;
90
110
  const result = {
91
111
  message: error0Input.message || this.defaultMessage,
92
112
  tag: finalTag,
93
- code: error0Input.code || meta.code || this.defaultCode,
94
- httpStatus: typeof error0Input.httpStatus === "number" ? error0Input.httpStatus : error0Input.httpStatus && typeof error0Input.httpStatus === "string" && error0Input.httpStatus in HttpStatusCode ? HttpStatusCode[error0Input.httpStatus] : meta.httpStatus || this.defaultHttpStatus,
113
+ code: error0Input.code || toStringOrUndefined(meta.code) || this.defaultCode,
114
+ httpStatus: typeof error0Input.httpStatus === "number" ? error0Input.httpStatus : error0Input.httpStatus && typeof error0Input.httpStatus === "string" && error0Input.httpStatus in HttpStatusCode ? HttpStatusCode[error0Input.httpStatus] : toNumberOrUndefined(meta.httpStatus) || this.defaultHttpStatus,
95
115
  expected: void 0,
96
116
  clientMessage,
97
117
  anyMessage: clientMessage || message,
@@ -103,7 +123,7 @@ class Error0 extends Error {
103
123
  };
104
124
  result.expected = this._normalizeSelfExpected(
105
125
  result,
106
- typeof error0Input.expected === "boolean" || typeof error0Input.expected === "function" ? error0Input.expected : meta.expected || this.defaultExpected
126
+ typeof error0Input.expected === "boolean" || typeof error0Input.expected === "function" ? error0Input.expected : toBooleanOrUndefined(meta.expected) || this.defaultExpected
107
127
  );
108
128
  result.stack = this._removeConstructorStackPart(stack);
109
129
  return result;
@@ -113,7 +133,7 @@ class Error0 extends Error {
113
133
  const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack);
114
134
  const closestTag = this._getClosestPropValue(causesProps, "tag");
115
135
  const meta = this._getMergedMetaValue(causesProps);
116
- const tag = Meta0.getFinalTag(meta, closestTag);
136
+ const tag = meta0PluginTag.public.getFullTag(meta, closestTag);
117
137
  const propsFloated = {
118
138
  message: this._getClosestPropValue(causesProps, "message"),
119
139
  tag,
@@ -349,7 +369,7 @@ class Error0 extends Error {
349
369
  static defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus;
350
370
  static defaultExpected = props.defaultExpected ?? parent.defaultExpected;
351
371
  static defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage;
352
- static defaultMeta = Meta0.extend(props.defaultMeta, parent.defaultMeta);
372
+ static defaultMeta = Meta0.extend(parent.defaultMeta, props.defaultMeta);
353
373
  };
354
374
  }
355
375
  static extendCollection(classes, props) {
@@ -387,14 +407,7 @@ class Error0 extends Error {
387
407
  );
388
408
  }
389
409
  }
390
- const e0s = {
391
- Default: Error0,
392
- Expected: Error0.extend({
393
- defaultExpected: true
394
- })
395
- };
396
410
  export {
397
- Error0,
398
- e0s
411
+ Error0
399
412
  };
400
413
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { Meta0 } from '@devp0nt/meta0'\nimport { type AxiosError, HttpStatusCode, isAxiosError } from 'axios'\nimport get from 'lodash/get.js'\nimport { ZodError } from 'zod'\n\n// TODO: store tags as array from all causes\n// TODO: not use self stack if toError0\n// TODO: fix default message in extended error0, should be used in constuctor of Error0\n// TODO: remove defaults prop from getPropsFromUnknown\n// TODO: code has enum type, fn to check if code exists\n\nexport interface Error0Input {\n message?: string\n tag?: string\n code?: string\n httpStatus?: HttpStatusCode | HttpStatusCodeString\n expected?: boolean | ExpectedFn\n clientMessage?: string\n cause?: Error0Cause\n stack?: string\n meta?: Meta0.Meta0OrValueTypeNullish\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ninterface Error0GeneralProps {\n message: Error0Input['message']\n tag: Error0Input['tag']\n code: Error0Input['code']\n httpStatus: number | undefined\n expected: boolean | undefined\n clientMessage: Error0Input['clientMessage']\n anyMessage: string | undefined\n cause: Error0Input['cause']\n stack: Error['stack']\n meta: Meta0.ValueType\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ntype HttpStatusCodeString = keyof typeof HttpStatusCode\ntype Error0Cause = Error | Error0 | unknown\ntype ExpectedFn = (error: Error0GeneralProps) => boolean | undefined\n\nconst isFilled = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined && value !== ''\n\nexport class Error0 extends Error {\n public readonly __I_AM_ERROR_0: true = true\n\n public readonly tag?: Error0GeneralProps['tag']\n public readonly code?: Error0GeneralProps['code']\n public readonly httpStatus?: Error0GeneralProps['httpStatus']\n public readonly expected?: Error0GeneralProps['expected']\n public readonly clientMessage?: Error0GeneralProps['clientMessage']\n public readonly anyMessage?: Error0GeneralProps['anyMessage']\n public override readonly cause?: Error0GeneralProps['cause']\n public readonly meta?: Meta0.Meta0OrValueTypeNullish\n public readonly zodError?: Error0GeneralProps['zodError']\n public readonly axiosError?: Error0GeneralProps['axiosError']\n\n static defaultMessage = 'Unknown error'\n static defaultCode?: Error0GeneralProps['code']\n static defaultHttpStatus?: Error0GeneralProps['httpStatus']\n static defaultExpected?: Error0GeneralProps['expected']\n static defaultClientMessage?: Error0GeneralProps['clientMessage']\n static defaultMeta?: Meta0.Meta0OrValueTypeNullish\n\n public readonly propsOriginal: Error0GeneralProps\n\n constructor(message: string)\n constructor(input: Error0Input)\n constructor(message: string, input: Error0Input)\n constructor(error: Error)\n constructor(error: Error, input: Error0Input)\n constructor(value: unknown)\n constructor(value: unknown, input: Error0Input)\n constructor(...args: unknown[]) {\n const input: Partial<Error0Input> = {}\n if (args[0] instanceof Error) {\n input.cause = args[0]\n } else if (typeof args[0] === 'object' && args[0] !== null) {\n Object.assign(input, args[0])\n } else if (typeof args[0] === 'string') {\n input.message = args[0]\n }\n if (typeof args[1] === 'object' && args[1] !== null) {\n Object.assign(input, args[1])\n }\n const safeInput = Error0._safeParseInput(input)\n\n const message = safeInput.message || Error0.defaultMessage\n super(message)\n Object.setPrototypeOf(this, (this.constructor as typeof Error0).prototype)\n this.name = 'Error0'\n\n this.propsOriginal = (this.constructor as typeof Error0)._getSelfGeneralProps({\n error0Input: safeInput,\n message,\n stack: safeInput.stack || this.stack,\n })\n const causesProps = (this.constructor as typeof Error0)._getCausesPropsFromError0Props(\n this.propsOriginal,\n (this.constructor as typeof Error0).defaultMaxLevel,\n )\n const propsFloated = (this.constructor as typeof Error0)._getSelfPropsFloated(causesProps)\n this.tag = propsFloated.tag\n this.code = propsFloated.code\n this.httpStatus = propsFloated.httpStatus\n this.expected = propsFloated.expected\n this.clientMessage = propsFloated.clientMessage\n this.cause = propsFloated.cause\n this.stack = propsFloated.stack\n this.meta = propsFloated.meta\n this.zodError = propsFloated.zodError\n this.axiosError = propsFloated.axiosError\n }\n\n // settings\n\n static defaultMaxLevel = 10\n\n // props\n\n public static _safeParseInput(error0Input: Record<string, unknown>): Error0Input {\n const result: Error0Input = {}\n result.message = typeof error0Input.message === 'string' ? error0Input.message : undefined\n result.tag = typeof error0Input.tag === 'string' ? error0Input.tag : undefined\n result.code = typeof error0Input.code === 'string' ? error0Input.code : undefined\n result.httpStatus =\n typeof error0Input.httpStatus === 'number' || typeof error0Input.httpStatus === 'string'\n ? (error0Input.httpStatus as never)\n : undefined\n result.expected =\n typeof error0Input.expected === 'function' || typeof error0Input.expected === 'boolean'\n ? (error0Input.expected as never)\n : undefined\n result.clientMessage = typeof error0Input.clientMessage === 'string' ? error0Input.clientMessage : undefined\n result.cause = error0Input.cause\n result.stack = typeof error0Input.stack === 'string' ? error0Input.stack : undefined\n // result.meta0 =\n // error0Input.meta0 instanceof Meta0 ? error0Input.meta0 : undefined\n // result.meta =\n // typeof error0Input.meta === \"object\" && error0Input.meta !== null\n // ? error0Input.meta\n // : undefined\n result.meta =\n error0Input.meta instanceof Meta0\n ? error0Input.meta\n : typeof error0Input.meta === 'object' && error0Input.meta !== null\n ? (error0Input.meta as Meta0.ValueType)\n : undefined\n result.zodError = error0Input.zodError instanceof ZodError ? error0Input.zodError : undefined\n result.axiosError = isAxiosError(error0Input.axiosError) ? error0Input.axiosError : undefined\n return result\n }\n\n public static _getSelfGeneralProps({\n error0Input,\n message,\n stack,\n }: {\n error0Input: Error0Input\n message: string\n stack: Error0GeneralProps['stack']\n }): Error0GeneralProps {\n // const meta = Meta0.merge(error0Input.meta0, error0Input.meta).value\n const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)\n const meta = meta0.getValue()\n const finalTag = meta0.getFinalTag(error0Input.tag)\n const clientMessage = error0Input.clientMessage || this.defaultClientMessage\n const result: Error0GeneralProps = {\n message: error0Input.message || this.defaultMessage,\n tag: finalTag,\n code: error0Input.code || meta.code || this.defaultCode,\n httpStatus:\n typeof error0Input.httpStatus === 'number'\n ? error0Input.httpStatus\n : error0Input.httpStatus &&\n typeof error0Input.httpStatus === 'string' &&\n error0Input.httpStatus in HttpStatusCode\n ? HttpStatusCode[error0Input.httpStatus]\n : meta.httpStatus || this.defaultHttpStatus,\n expected: undefined,\n clientMessage,\n anyMessage: clientMessage || message,\n cause: error0Input.cause,\n stack: undefined,\n meta,\n zodError: error0Input.zodError,\n axiosError: error0Input.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n typeof error0Input.expected === 'boolean' || typeof error0Input.expected === 'function'\n ? error0Input.expected\n : meta.expected || this.defaultExpected,\n )\n result.stack = this._removeConstructorStackPart(stack)\n return result\n }\n\n public static _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps {\n const cause = this._getClosestPropValue(causesProps, 'cause')\n const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack)\n const closestTag = this._getClosestPropValue(causesProps, 'tag')\n const meta = this._getMergedMetaValue(causesProps)\n const tag = Meta0.getFinalTag(meta, closestTag)\n const propsFloated: Error0GeneralProps = {\n message: this._getClosestPropValue(causesProps, 'message'),\n tag,\n code: this._getClosestPropValue(causesProps, 'code'),\n httpStatus: this._getClosestPropValue(causesProps, 'httpStatus'),\n expected: this._isExpected(causesProps),\n clientMessage: this._getClosestPropValue(causesProps, 'clientMessage'),\n cause,\n stack,\n anyMessage: causesProps[0].anyMessage,\n meta,\n zodError: this._getClosestPropValue(causesProps, 'zodError'),\n axiosError: this._getClosestPropValue(causesProps, 'axiosError'),\n }\n return propsFloated\n }\n\n // sepcial\n\n public static _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps> {\n return {\n message: `Zod Validation Error: ${zodError.message}`,\n }\n }\n\n public static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps> {\n return {\n message: 'Axios Error',\n meta: {\n axiosData: (() => {\n try {\n return JSON.stringify(axiosError.response?.data)\n } catch {\n return undefined\n }\n })(),\n axiosStatus: axiosError.response?.status,\n },\n }\n }\n\n public static _assignError0Props(\n error0Props: Error0GeneralProps,\n extraError0Props: Partial<Error0GeneralProps>,\n ): void {\n const metaValue = Meta0.mergeValues(error0Props.meta, extraError0Props.meta)\n Object.assign(error0Props, extraError0Props, { meta: metaValue })\n }\n\n // expected\n\n public static _normalizeSelfExpected(\n error0Props: Error0GeneralProps,\n expectedProvided: Error0Input['expected'],\n ): boolean | undefined {\n if (typeof expectedProvided === 'function') {\n return expectedProvided(error0Props)\n }\n return expectedProvided\n }\n\n public static _isExpected(causesProps: Error0GeneralProps[]): boolean {\n let hasExpectedTrue = false\n for (const causeProps of causesProps) {\n if (causeProps.expected === false) {\n return false\n }\n if (causeProps.expected === true) {\n hasExpectedTrue = true\n }\n }\n return hasExpectedTrue\n }\n\n // getters\n\n public static _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps {\n if (typeof error !== 'object' || error === null) {\n return {\n message: undefined,\n tag: undefined,\n code: undefined,\n httpStatus: undefined,\n expected: undefined,\n clientMessage: undefined,\n anyMessage: this.defaultMessage,\n cause: undefined,\n stack: undefined,\n zodError: undefined,\n axiosError: undefined,\n meta: {},\n }\n }\n const message = 'message' in error && typeof error.message === 'string' ? error.message : undefined\n const clientMessage =\n 'clientMessage' in error && typeof error.clientMessage === 'string'\n ? error.clientMessage\n : defaults?.clientMessage || undefined\n const result: Error0GeneralProps = {\n message,\n code: 'code' in error && typeof error.code === 'string' ? error.code : defaults?.code || undefined,\n clientMessage,\n anyMessage: clientMessage || message || this.defaultMessage,\n expected: undefined,\n stack: 'stack' in error && typeof error.stack === 'string' ? error.stack : undefined,\n tag: 'tag' in error && typeof error.tag === 'string' ? error.tag : defaults?.tag || undefined,\n cause: 'cause' in error ? error.cause : defaults?.cause || undefined,\n meta:\n 'meta' in error && typeof error.meta === 'object' && error.meta !== null\n ? Meta0.getValue(error.meta as Meta0.ValueType)\n : Meta0.getValue(defaults?.meta) || {},\n httpStatus:\n 'httpStatus' in error && typeof error.httpStatus === 'number' && error.httpStatus in HttpStatusCode\n ? error.httpStatus\n : typeof defaults?.httpStatus === 'string'\n ? HttpStatusCode[defaults.httpStatus]\n : defaults?.httpStatus,\n zodError:\n 'zodError' in error && error.zodError instanceof ZodError\n ? error.zodError\n : error instanceof ZodError\n ? error\n : defaults?.zodError,\n axiosError:\n 'axiosError' in error && isAxiosError(error.axiosError)\n ? error.axiosError\n : isAxiosError(error)\n ? error\n : defaults?.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n 'expected' in error && (typeof error.expected === 'boolean' || typeof error.expected === 'function')\n ? (error.expected as ExpectedFn)\n : defaults?.expected || undefined,\n )\n if (result.zodError) {\n this._assignError0Props(result, this._getExtraError0PropsByZodError(result.zodError))\n }\n if (result.axiosError) {\n this._assignError0Props(result, this._getExtraError0PropsByAxiosError(result.axiosError))\n }\n return result\n }\n\n public static _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[] {\n if (!error) {\n return []\n }\n const causeProps = this._getPropsFromUnknown(error)\n const causesProps: Error0GeneralProps[] = [causeProps]\n if (!causeProps.cause) {\n return causesProps\n }\n if (maxLevel > 0) {\n causesProps.push(...this._getCausesPropsFromUnknown(this._getPropsFromUnknown(causeProps.cause), maxLevel - 1))\n }\n return causesProps\n }\n\n public static _getCausesPropsFromError0Props(\n error0Props: Error0GeneralProps,\n maxLevel: number,\n ): Error0GeneralProps[] {\n return [error0Props, ...this._getCausesPropsFromUnknown(error0Props.cause, maxLevel - 1)]\n }\n\n public static _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]> | undefined {\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n return propValue as NonNullable<Error0GeneralProps[TPropKey]>\n }\n }\n return undefined\n }\n\n // private static getClosestByGetter<TResult>(\n // causesProps: Error0GeneralProps[],\n // getter: (props: Error0GeneralProps) => TResult,\n // ): NonNullable<TResult> | undefined {\n // for (const causeProps of causesProps) {\n // const result = getter(causeProps)\n // if (isFilled(result)) {\n // return result\n // }\n // }\n // return undefined\n // }\n\n public static _getFilledPropValues<TPropKey extends keyof Error0Input>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]>[] {\n const values: NonNullable<Error0GeneralProps[TPropKey]>[] = []\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n values.push(propValue as NonNullable<Error0GeneralProps[TPropKey]>)\n }\n }\n return values\n }\n\n public static _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType {\n const metas = this._getFilledPropValues(causesProps, 'meta')\n if (metas.length === 0) {\n return {}\n } else if (metas.length === 1) {\n return metas[0]\n } else {\n return Meta0.mergeValues(metas[0], ...metas.slice(1))\n }\n }\n\n // stack\n\n public static _removeConstructorStackPart(stack: Error0GeneralProps['stack']): Error0GeneralProps['stack'] {\n if (!stack) {\n return stack\n }\n let lines = stack.split('\\n')\n const removeAllLinesContains = (search: string) => {\n lines = lines.filter((line) => !line.includes(search))\n }\n removeAllLinesContains('at new Error0')\n removeAllLinesContains('at _toError0')\n removeAllLinesContains('at Error0.from')\n removeAllLinesContains('at Error0._toError0')\n return lines.join('\\n')\n }\n\n public static _mergeStack(\n prevStack: Error0GeneralProps['stack'],\n nextStack: Error0GeneralProps['stack'],\n ): Error0GeneralProps['stack'] {\n return [nextStack, prevStack].filter(Boolean).join('\\n\\n') || undefined\n }\n\n // transformations\n\n static isError0(error: unknown): error is Error0 {\n return error instanceof Error0\n }\n\n static isLikelyError0(error: unknown): error is Error0 {\n if (error instanceof Error0) {\n return true\n }\n\n if (typeof error === 'object' && error !== null) {\n if ('__I_AM_ERROR_0' in error && error.__I_AM_ERROR_0 === true) {\n return true\n }\n }\n\n return false\n }\n\n public static _toError0(error: unknown, inputOverride: Error0Input = {}): Error0 {\n if (error instanceof Error0) {\n return error\n }\n\n if (typeof error === 'string') {\n return new Error0(error, inputOverride)\n }\n\n if (typeof error !== 'object' || error === null) {\n return new Error0({\n message: this.defaultMessage,\n ...inputOverride,\n })\n }\n\n const inputFromData = get(error, 'data')\n if (inputFromData) {\n if (Error0.isLikelyError0(inputFromData)) {\n return this._toError0(inputFromData, inputOverride)\n }\n }\n\n const inputFromDataError0 = get(error, 'data.error0')\n if (inputFromDataError0) {\n if (Error0.isLikelyError0(inputFromDataError0)) {\n return this._toError0(inputFromDataError0, inputOverride)\n }\n }\n\n return new Error0(this._getPropsFromUnknown(error, inputOverride))\n }\n\n static from(error: unknown, inputOverride?: Error0Input): Error0 {\n return this._toError0(error, inputOverride)\n }\n\n static extend(props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n }) {\n const parent = this\n return class Error0 extends parent {\n static override defaultMessage = props.defaultMessage ?? parent.defaultMessage\n static override defaultCode = props.defaultCode ?? parent.defaultCode\n static override defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus\n static override defaultExpected = props.defaultExpected ?? parent.defaultExpected\n static override defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage\n static override defaultMeta = Meta0.extend(props.defaultMeta, parent.defaultMeta)\n }\n }\n\n static extendCollection<T extends Record<string, typeof Error0>>(\n classes: T,\n props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n },\n ): T {\n return Object.fromEntries(Object.entries(classes).map(([name, Class]) => [name, Class.extend(props)])) as T\n }\n\n toJSON() {\n return {\n message: this.message,\n tag: this.tag,\n code: this.code,\n httpStatus: this.httpStatus,\n expected: this.expected,\n clientMessage: this.clientMessage,\n anyMessage: this.anyMessage,\n cause: this.cause,\n meta: Meta0.getValue(this.meta),\n stack: this.stack,\n __I_AM_ERROR_0: this.__I_AM_ERROR_0,\n }\n }\n static toJSON(error: unknown, inputOverride?: Error0Input) {\n const error0 = this.from(error, inputOverride)\n return error0.toJSON()\n }\n\n toResponse(data?: Record<string, unknown>) {\n return Response.json(\n {\n ...this.toJSON(),\n ...data,\n },\n {\n status: this.httpStatus,\n statusText: this.message,\n },\n )\n }\n}\n\nexport namespace Error0 {\n export type JSON = ReturnType<Error0['toJSON']>\n export type Collection = Record<string, typeof Error0>\n}\n\nexport const e0s = {\n Default: Error0,\n Expected: Error0.extend({\n defaultExpected: true,\n }),\n} satisfies Error0.Collection\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAA0B,gBAAgB,oBAAoB;AAC9D,OAAO,SAAS;AAChB,SAAS,gBAAgB;AAyCzB,MAAM,WAAW,CAAI,UAAsC,UAAU,QAAQ,UAAU,UAAa,UAAU;AAEvG,MAAM,eAAe,MAAM;AAAA,EAChB,iBAAuB;AAAA,EAEvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,OAAO,iBAAiB;AAAA,EACxB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EAES;AAAA,EAShB,eAAe,MAAiB;AAC9B,UAAM,QAA8B,CAAC;AACrC,QAAI,KAAK,CAAC,aAAa,OAAO;AAC5B,YAAM,QAAQ,KAAK,CAAC;AAAA,IACtB,WAAW,OAAO,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,MAAM,MAAM;AAC1D,aAAO,OAAO,OAAO,KAAK,CAAC,CAAC;AAAA,IAC9B,WAAW,OAAO,KAAK,CAAC,MAAM,UAAU;AACtC,YAAM,UAAU,KAAK,CAAC;AAAA,IACxB;AACA,QAAI,OAAO,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,MAAM,MAAM;AACnD,aAAO,OAAO,OAAO,KAAK,CAAC,CAAC;AAAA,IAC9B;AACA,UAAM,YAAY,OAA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":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { Meta0, meta0PluginTag } from '@devp0nt/meta0'\nimport { type AxiosError, HttpStatusCode, isAxiosError } from 'axios'\nimport get from 'lodash/get.js'\nimport { ZodError } from 'zod'\n\n// TODO: Зод, аксиос, это всё плагины\n// TODO: В эррор0 добавить ориджинал\n// TODO: store tags as array from all causes\n// TODO: not use self stack if toError0\n// TODO: fix default message in extended error0, should be used in constuctor of Error0\n// TODO: remove defaults prop from getPropsFromUnknown\n// TODO: code has enum type, fn to check if code exists\n\nexport interface Error0Input {\n message?: string\n tag?: string\n code?: string\n httpStatus?: HttpStatusCode | HttpStatusCodeString\n expected?: boolean | ExpectedFn\n clientMessage?: string\n cause?: Error0Cause\n stack?: string\n meta?: Meta0.Meta0OrValueTypeNullish\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ninterface Error0GeneralProps {\n message: Error0Input['message']\n tag: Error0Input['tag']\n code: Error0Input['code']\n httpStatus: number | undefined\n expected: boolean | undefined\n clientMessage: Error0Input['clientMessage']\n anyMessage: string | undefined\n cause: Error0Input['cause']\n stack: Error['stack']\n meta: Meta0.ValueType\n zodError?: ZodError\n axiosError?: AxiosError\n}\n\ntype HttpStatusCodeString = keyof typeof HttpStatusCode\ntype Error0Cause = Error | Error0 | unknown\ntype ExpectedFn = (error: Error0GeneralProps) => boolean | undefined\n\nconst isFilled = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined && value !== ''\nconst toStringOrUndefined = (value: unknown): string | undefined => {\n return typeof value === 'string' ? value : undefined\n}\nconst toNumberOrUndefined = (value: unknown): number | undefined => {\n if (typeof value === 'number') {\n return value\n }\n const number = Number(value)\n if (typeof value === 'string' && !Number.isNaN(number)) {\n return number\n }\n return undefined\n}\nconst toBooleanOrUndefined = (value: unknown): boolean | undefined => {\n if (typeof value === 'boolean') {\n return value\n }\n return undefined\n}\n\nexport class Error0 extends Error {\n public readonly __I_AM_ERROR_0: true = true\n\n public readonly tag?: Error0GeneralProps['tag']\n public readonly code?: Error0GeneralProps['code']\n public readonly httpStatus?: Error0GeneralProps['httpStatus']\n public readonly expected?: Error0GeneralProps['expected']\n public readonly clientMessage?: Error0GeneralProps['clientMessage']\n public readonly anyMessage?: Error0GeneralProps['anyMessage']\n public override readonly cause?: Error0GeneralProps['cause']\n public readonly meta?: Meta0.Meta0OrValueTypeNullish\n public readonly zodError?: Error0GeneralProps['zodError']\n public readonly axiosError?: Error0GeneralProps['axiosError']\n\n static defaultMessage = 'Unknown error'\n static defaultCode?: Error0GeneralProps['code']\n static defaultHttpStatus?: Error0GeneralProps['httpStatus']\n static defaultExpected?: Error0GeneralProps['expected']\n static defaultClientMessage?: Error0GeneralProps['clientMessage']\n static defaultMeta?: Meta0.Meta0OrValueTypeNullish\n\n public readonly propsOriginal: Error0GeneralProps\n\n constructor(message: string)\n constructor(input: Error0Input)\n constructor(message: string, input: Error0Input)\n constructor(error: Error)\n constructor(error: Error, input: Error0Input)\n constructor(value: unknown)\n constructor(value: unknown, input: Error0Input)\n constructor(...args: unknown[]) {\n const input: Partial<Error0Input> = {}\n if (args[0] instanceof Error) {\n input.cause = args[0]\n } else if (typeof args[0] === 'object' && args[0] !== null) {\n Object.assign(input, args[0])\n } else if (typeof args[0] === 'string') {\n input.message = args[0]\n }\n if (typeof args[1] === 'object' && args[1] !== null) {\n Object.assign(input, args[1])\n }\n const safeInput = Error0._safeParseInput(input)\n\n const message = safeInput.message || Error0.defaultMessage\n super(message)\n Object.setPrototypeOf(this, (this.constructor as typeof Error0).prototype)\n this.name = 'Error0'\n\n this.propsOriginal = (this.constructor as typeof Error0)._getSelfGeneralProps({\n error0Input: safeInput,\n message,\n stack: safeInput.stack || this.stack,\n })\n const causesProps = (this.constructor as typeof Error0)._getCausesPropsFromError0Props(\n this.propsOriginal,\n (this.constructor as typeof Error0).defaultMaxLevel,\n )\n const propsFloated = (this.constructor as typeof Error0)._getSelfPropsFloated(causesProps)\n this.tag = propsFloated.tag\n this.code = propsFloated.code\n this.httpStatus = propsFloated.httpStatus\n this.expected = propsFloated.expected\n this.clientMessage = propsFloated.clientMessage\n this.cause = propsFloated.cause\n this.stack = propsFloated.stack\n this.meta = propsFloated.meta\n this.zodError = propsFloated.zodError\n this.axiosError = propsFloated.axiosError\n }\n\n // settings\n\n static defaultMaxLevel = 10\n\n // props\n\n public static _safeParseInput(error0Input: Record<string, unknown>): Error0Input {\n const result: Error0Input = {}\n result.message = typeof error0Input.message === 'string' ? error0Input.message : undefined\n result.tag = typeof error0Input.tag === 'string' ? error0Input.tag : undefined\n result.code = typeof error0Input.code === 'string' ? error0Input.code : undefined\n result.httpStatus =\n typeof error0Input.httpStatus === 'number' || typeof error0Input.httpStatus === 'string'\n ? (error0Input.httpStatus as never)\n : undefined\n result.expected =\n typeof error0Input.expected === 'function' || typeof error0Input.expected === 'boolean'\n ? (error0Input.expected as never)\n : undefined\n result.clientMessage = typeof error0Input.clientMessage === 'string' ? error0Input.clientMessage : undefined\n result.cause = error0Input.cause\n result.stack = typeof error0Input.stack === 'string' ? error0Input.stack : undefined\n // result.meta0 =\n // error0Input.meta0 instanceof Meta0 ? error0Input.meta0 : undefined\n // result.meta =\n // typeof error0Input.meta === \"object\" && error0Input.meta !== null\n // ? error0Input.meta\n // : undefined\n result.meta =\n error0Input.meta instanceof Meta0\n ? error0Input.meta\n : typeof error0Input.meta === 'object' && error0Input.meta !== null\n ? (error0Input.meta as Meta0.ValueType)\n : undefined\n result.zodError = error0Input.zodError instanceof ZodError ? error0Input.zodError : undefined\n result.axiosError = isAxiosError(error0Input.axiosError) ? error0Input.axiosError : undefined\n return result\n }\n\n public static _getSelfGeneralProps({\n error0Input,\n message,\n stack,\n }: {\n error0Input: Error0Input\n message: string\n stack: Error0GeneralProps['stack']\n }): Error0GeneralProps {\n // const meta = Meta0.merge(error0Input.meta0, error0Input.meta).value\n\n // const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)\n // const defaultMetaValue =\n // this.defaultMeta && typeof this.defaultMeta === 'object' && 'getValue' in this.defaultMeta\n // ? (this.defaultMeta as any).getValue()\n // : this.defaultMeta\n\n const meta0 = Meta0.extend(this.defaultMeta, error0Input.meta)\n const meta = meta0.getValue()\n const finalTag = meta0PluginTag.public.getFullTag(meta0, error0Input.tag)\n delete meta.tagPrefix\n const clientMessage = error0Input.clientMessage || this.defaultClientMessage\n const result: Error0GeneralProps = {\n message: error0Input.message || this.defaultMessage,\n tag: finalTag,\n code: error0Input.code || toStringOrUndefined(meta.code) || this.defaultCode,\n httpStatus:\n typeof error0Input.httpStatus === 'number'\n ? error0Input.httpStatus\n : error0Input.httpStatus &&\n typeof error0Input.httpStatus === 'string' &&\n error0Input.httpStatus in HttpStatusCode\n ? HttpStatusCode[error0Input.httpStatus]\n : toNumberOrUndefined(meta.httpStatus) || this.defaultHttpStatus,\n expected: undefined,\n clientMessage,\n anyMessage: clientMessage || message,\n cause: error0Input.cause,\n stack: undefined,\n meta,\n zodError: error0Input.zodError,\n axiosError: error0Input.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n typeof error0Input.expected === 'boolean' || typeof error0Input.expected === 'function'\n ? error0Input.expected\n : toBooleanOrUndefined(meta.expected) || this.defaultExpected,\n )\n result.stack = this._removeConstructorStackPart(stack)\n return result\n }\n\n public static _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps {\n const cause = this._getClosestPropValue(causesProps, 'cause')\n const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack)\n const closestTag = this._getClosestPropValue(causesProps, 'tag')\n const meta = this._getMergedMetaValue(causesProps)\n const tag = meta0PluginTag.public.getFullTag(meta, closestTag)\n const propsFloated: Error0GeneralProps = {\n message: this._getClosestPropValue(causesProps, 'message'),\n tag,\n code: this._getClosestPropValue(causesProps, 'code'),\n httpStatus: this._getClosestPropValue(causesProps, 'httpStatus'),\n expected: this._isExpected(causesProps),\n clientMessage: this._getClosestPropValue(causesProps, 'clientMessage'),\n cause,\n stack,\n anyMessage: causesProps[0].anyMessage,\n meta,\n zodError: this._getClosestPropValue(causesProps, 'zodError'),\n axiosError: this._getClosestPropValue(causesProps, 'axiosError'),\n }\n return propsFloated\n }\n\n // sepcial\n\n public static _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps> {\n return {\n message: `Zod Validation Error: ${zodError.message}`,\n }\n }\n\n public static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps> {\n return {\n message: 'Axios Error',\n meta: {\n axiosData: (() => {\n try {\n return JSON.stringify(axiosError.response?.data)\n } catch {\n return undefined\n }\n })(),\n axiosStatus: axiosError.response?.status,\n },\n }\n }\n\n public static _assignError0Props(\n error0Props: Error0GeneralProps,\n extraError0Props: Partial<Error0GeneralProps>,\n ): void {\n const metaValue = Meta0.mergeValues(error0Props.meta, extraError0Props.meta)\n Object.assign(error0Props, extraError0Props, { meta: metaValue })\n }\n\n // expected\n\n public static _normalizeSelfExpected(\n error0Props: Error0GeneralProps,\n expectedProvided: Error0Input['expected'],\n ): boolean | undefined {\n if (typeof expectedProvided === 'function') {\n return expectedProvided(error0Props)\n }\n return expectedProvided\n }\n\n public static _isExpected(causesProps: Error0GeneralProps[]): boolean {\n let hasExpectedTrue = false\n for (const causeProps of causesProps) {\n if (causeProps.expected === false) {\n return false\n }\n if (causeProps.expected === true) {\n hasExpectedTrue = true\n }\n }\n return hasExpectedTrue\n }\n\n // getters\n\n public static _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps {\n if (typeof error !== 'object' || error === null) {\n return {\n message: undefined,\n tag: undefined,\n code: undefined,\n httpStatus: undefined,\n expected: undefined,\n clientMessage: undefined,\n anyMessage: this.defaultMessage,\n cause: undefined,\n stack: undefined,\n zodError: undefined,\n axiosError: undefined,\n meta: {},\n }\n }\n const message = 'message' in error && typeof error.message === 'string' ? error.message : undefined\n const clientMessage =\n 'clientMessage' in error && typeof error.clientMessage === 'string'\n ? error.clientMessage\n : defaults?.clientMessage || undefined\n const result: Error0GeneralProps = {\n message,\n code: 'code' in error && typeof error.code === 'string' ? error.code : defaults?.code || undefined,\n clientMessage,\n anyMessage: clientMessage || message || this.defaultMessage,\n expected: undefined,\n stack: 'stack' in error && typeof error.stack === 'string' ? error.stack : undefined,\n tag: 'tag' in error && typeof error.tag === 'string' ? error.tag : defaults?.tag || undefined,\n cause: 'cause' in error ? error.cause : defaults?.cause || undefined,\n meta:\n 'meta' in error && typeof error.meta === 'object' && error.meta !== null\n ? Meta0.getValue(error.meta as Meta0.ValueType)\n : Meta0.getValue(defaults?.meta) || {},\n httpStatus:\n 'httpStatus' in error && typeof error.httpStatus === 'number' && error.httpStatus in HttpStatusCode\n ? error.httpStatus\n : typeof defaults?.httpStatus === 'string'\n ? HttpStatusCode[defaults.httpStatus]\n : defaults?.httpStatus,\n zodError:\n 'zodError' in error && error.zodError instanceof ZodError\n ? error.zodError\n : error instanceof ZodError\n ? error\n : defaults?.zodError,\n axiosError:\n 'axiosError' in error && isAxiosError(error.axiosError)\n ? error.axiosError\n : isAxiosError(error)\n ? error\n : defaults?.axiosError,\n }\n result.expected = this._normalizeSelfExpected(\n result,\n 'expected' in error && (typeof error.expected === 'boolean' || typeof error.expected === 'function')\n ? (error.expected as ExpectedFn)\n : defaults?.expected || undefined,\n )\n if (result.zodError) {\n this._assignError0Props(result, this._getExtraError0PropsByZodError(result.zodError))\n }\n if (result.axiosError) {\n this._assignError0Props(result, this._getExtraError0PropsByAxiosError(result.axiosError))\n }\n return result\n }\n\n public static _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[] {\n if (!error) {\n return []\n }\n const causeProps = this._getPropsFromUnknown(error)\n const causesProps: Error0GeneralProps[] = [causeProps]\n if (!causeProps.cause) {\n return causesProps\n }\n if (maxLevel > 0) {\n causesProps.push(...this._getCausesPropsFromUnknown(this._getPropsFromUnknown(causeProps.cause), maxLevel - 1))\n }\n return causesProps\n }\n\n public static _getCausesPropsFromError0Props(\n error0Props: Error0GeneralProps,\n maxLevel: number,\n ): Error0GeneralProps[] {\n return [error0Props, ...this._getCausesPropsFromUnknown(error0Props.cause, maxLevel - 1)]\n }\n\n public static _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]> | undefined {\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n return propValue as NonNullable<Error0GeneralProps[TPropKey]>\n }\n }\n return undefined\n }\n\n // private static getClosestByGetter<TResult>(\n // causesProps: Error0GeneralProps[],\n // getter: (props: Error0GeneralProps) => TResult,\n // ): NonNullable<TResult> | undefined {\n // for (const causeProps of causesProps) {\n // const result = getter(causeProps)\n // if (isFilled(result)) {\n // return result\n // }\n // }\n // return undefined\n // }\n\n public static _getFilledPropValues<TPropKey extends keyof Error0Input>(\n causesProps: Error0GeneralProps[],\n propKey: TPropKey,\n ): NonNullable<Error0GeneralProps[TPropKey]>[] {\n const values: NonNullable<Error0GeneralProps[TPropKey]>[] = []\n for (const causeProps of causesProps) {\n const propValue = causeProps[propKey]\n if (isFilled(propValue)) {\n values.push(propValue as NonNullable<Error0GeneralProps[TPropKey]>)\n }\n }\n return values\n }\n\n public static _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType {\n const metas = this._getFilledPropValues(causesProps, 'meta')\n if (metas.length === 0) {\n return {}\n } else if (metas.length === 1) {\n return metas[0]\n } else {\n return Meta0.mergeValues(metas[0], ...metas.slice(1))\n }\n }\n\n // stack\n\n public static _removeConstructorStackPart(stack: Error0GeneralProps['stack']): Error0GeneralProps['stack'] {\n if (!stack) {\n return stack\n }\n let lines = stack.split('\\n')\n const removeAllLinesContains = (search: string) => {\n lines = lines.filter((line) => !line.includes(search))\n }\n removeAllLinesContains('at new Error0')\n removeAllLinesContains('at _toError0')\n removeAllLinesContains('at Error0.from')\n removeAllLinesContains('at Error0._toError0')\n return lines.join('\\n')\n }\n\n public static _mergeStack(\n prevStack: Error0GeneralProps['stack'],\n nextStack: Error0GeneralProps['stack'],\n ): Error0GeneralProps['stack'] {\n return [nextStack, prevStack].filter(Boolean).join('\\n\\n') || undefined\n }\n\n // transformations\n\n static isError0(error: unknown): error is Error0 {\n return error instanceof Error0\n }\n\n static isLikelyError0(error: unknown): error is Error0 {\n if (error instanceof Error0) {\n return true\n }\n\n if (typeof error === 'object' && error !== null) {\n if ('__I_AM_ERROR_0' in error && error.__I_AM_ERROR_0 === true) {\n return true\n }\n }\n\n return false\n }\n\n public static _toError0(error: unknown, inputOverride: Error0Input = {}): Error0 {\n if (error instanceof Error0) {\n return error\n }\n\n if (typeof error === 'string') {\n return new Error0(error, inputOverride)\n }\n\n if (typeof error !== 'object' || error === null) {\n return new Error0({\n message: this.defaultMessage,\n ...inputOverride,\n })\n }\n\n const inputFromData = get(error, 'data')\n if (inputFromData) {\n if (Error0.isLikelyError0(inputFromData)) {\n return this._toError0(inputFromData, inputOverride)\n }\n }\n\n const inputFromDataError0 = get(error, 'data.error0')\n if (inputFromDataError0) {\n if (Error0.isLikelyError0(inputFromDataError0)) {\n return this._toError0(inputFromDataError0, inputOverride)\n }\n }\n\n return new Error0(this._getPropsFromUnknown(error, inputOverride))\n }\n\n static from(error: unknown, inputOverride?: Error0Input): Error0 {\n return this._toError0(error, inputOverride)\n }\n\n static extend(props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n }) {\n const parent = this\n return class Error0 extends parent {\n static override defaultMessage = props.defaultMessage ?? parent.defaultMessage\n static override defaultCode = props.defaultCode ?? parent.defaultCode\n static override defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus\n static override defaultExpected = props.defaultExpected ?? parent.defaultExpected\n static override defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage\n static override defaultMeta = Meta0.extend(parent.defaultMeta, props.defaultMeta)\n }\n }\n\n static extendCollection<T extends Record<string, typeof Error0>>(\n classes: T,\n props: {\n defaultMessage?: Error0GeneralProps['message']\n defaultCode?: Error0GeneralProps['code']\n defaultHttpStatus?: Error0GeneralProps['httpStatus']\n defaultExpected?: Error0GeneralProps['expected']\n defaultClientMessage?: Error0GeneralProps['clientMessage']\n defaultMeta?: Meta0.Meta0OrValueTypeNullish\n },\n ): T {\n return Object.fromEntries(Object.entries(classes).map(([name, Class]) => [name, Class.extend(props)])) as T\n }\n\n toJSON() {\n return {\n message: this.message,\n tag: this.tag,\n code: this.code,\n httpStatus: this.httpStatus,\n expected: this.expected,\n clientMessage: this.clientMessage,\n anyMessage: this.anyMessage,\n cause: this.cause,\n meta: Meta0.getValue(this.meta),\n stack: this.stack,\n __I_AM_ERROR_0: this.__I_AM_ERROR_0,\n }\n }\n static toJSON(error: unknown, inputOverride?: Error0Input) {\n const error0 = this.from(error, inputOverride)\n return error0.toJSON()\n }\n\n toResponse(data?: Record<string, unknown>) {\n return Response.json(\n {\n ...this.toJSON(),\n ...data,\n },\n {\n status: this.httpStatus,\n statusText: this.message,\n },\n )\n }\n}\n\nexport namespace Error0 {\n export type JSON = ReturnType<Error0['toJSON']>\n export type Collection = Record<string, typeof Error0>\n}\n"],"mappings":"AAAA,SAAS,OAAO,sBAAsB;AACtC,SAA0B,gBAAgB,oBAAoB;AAC9D,OAAO,SAAS;AAChB,SAAS,gBAAgB;AA2CzB,MAAM,WAAW,CAAI,UAAsC,UAAU,QAAQ,UAAU,UAAa,UAAU;AAC9G,MAAM,sBAAsB,CAAC,UAAuC;AAClE,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AACA,MAAM,sBAAsB,CAAC,UAAuC;AAClE,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AACA,QAAM,SAAS,OAAO,KAAK;AAC3B,MAAI,OAAO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Ac,MAAM,OAAO,OAAO,aAAa,MAAM,WAAW;AAAA,IAClF;AAAA,EACF;AAAA,EAEA,OAAO,iBACL,SACA,OAQG;AACH,WAAO,OAAO,YAAY,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,KAAK,CAAC,CAAC,CAAC;AAAA,EACvG;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,MACL,SAAS,KAAK;AAAA,MACd,KAAK,KAAK;AAAA,MACV,MAAM,KAAK;AAAA,MACX,YAAY,KAAK;AAAA,MACjB,UAAU,KAAK;AAAA,MACf,eAAe,KAAK;AAAA,MACpB,YAAY,KAAK;AAAA,MACjB,OAAO,KAAK;AAAA,MACZ,MAAM,MAAM,SAAS,KAAK,IAAI;AAAA,MAC9B,OAAO,KAAK;AAAA,MACZ,gBAAgB,KAAK;AAAA,IACvB;AAAA,EACF;AAAA,EACA,OAAO,OAAO,OAAgB,eAA6B;AACzD,UAAM,SAAS,KAAK,KAAK,OAAO,aAAa;AAC7C,WAAO,OAAO,OAAO;AAAA,EACvB;AAAA,EAEA,WAAW,MAAgC;AACzC,WAAO,SAAS;AAAA,MACd;AAAA,QACE,GAAG,KAAK,OAAO;AAAA,QACf,GAAG;AAAA,MACL;AAAA,MACA;AAAA,QACE,QAAQ,KAAK;AAAA,QACb,YAAY,KAAK;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -41,6 +41,7 @@
41
41
  "build:test:watch": "bun run build:test:esm:watch & bun run build:test:cjs:watch",
42
42
  "build:all": "bun run build && bun run build:test",
43
43
  "test": "bun test src",
44
+ "test:us": "bun test src --update-snapshots",
44
45
  "test:watch": "bun test --watch",
45
46
  "test:coverage": "bun test --coverage",
46
47
  "test:dist:esm": "bun test dist-test/esm",
@@ -63,8 +64,9 @@
63
64
  "pack:dry": "npm pack --dry-run",
64
65
  "prepare": "husky"
65
66
  },
66
- "dependencies": {
67
- "@devp0nt/meta0": "^1.0.0-next.2",
67
+ "dependencies": {},
68
+ "peerDependencies": {
69
+ "@devp0nt/meta0": "^1.0.0-next.11",
68
70
  "axios": "^1.12.2",
69
71
  "zod": "^4.1.9"
70
72
  },
@@ -93,5 +95,5 @@
93
95
  "publishConfig": {
94
96
  "access": "public"
95
97
  },
96
- "version": "1.0.0-next.1"
98
+ "version": "1.0.0-next.10"
97
99
  }
package/src/index.test.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import { describe, expect, it } from 'bun:test'
2
2
  import { type AxiosError, isAxiosError } from 'axios'
3
3
  import z, { ZodError } from 'zod'
4
- import { Error0, e0s } from './index.js'
4
+ import { Error0 } from './index.js'
5
+
6
+ const e0s = {
7
+ Default: Error0,
8
+ Expected: Error0.extend({
9
+ defaultExpected: true,
10
+ }) as typeof Error0,
11
+ } satisfies Error0.Collection
5
12
 
6
13
  // TODO: test expected
7
14
 
@@ -418,9 +425,10 @@ describe('error0', () => {
418
425
  defaultMessage: 'nested error',
419
426
  defaultMeta: {
420
427
  tagPrefix: 'nested',
428
+ x: 1,
421
429
  },
422
430
  })
423
- const error0 = new e0s1.Default('nested error')
431
+ const error0 = new e0s1.Default('nested error', { tag: 'x' })
424
432
  expect(error0).toBeInstanceOf(e0s1.Default)
425
433
  expect(error0).toBeInstanceOf(e0s.Default)
426
434
  expect(error0).toBeInstanceOf(Error0)
@@ -435,13 +443,13 @@ describe('error0', () => {
435
443
  "httpStatus": undefined,
436
444
  "message": "nested error",
437
445
  "meta": {
438
- "tagPrefix": "nested",
446
+ "x": 1,
439
447
  },
440
448
  "stack":
441
449
  "Error0: nested error
442
450
  at <anonymous> (...)"
443
451
  ,
444
- "tag": "nested:nested",
452
+ "tag": "nested:x",
445
453
  }
446
454
  `)
447
455
 
@@ -461,13 +469,13 @@ describe('error0', () => {
461
469
  "httpStatus": undefined,
462
470
  "message": "nested error 1",
463
471
  "meta": {
464
- "tagPrefix": "nested",
472
+ "x": 1,
465
473
  },
466
474
  "stack":
467
475
  "Error0: nested error 1
468
476
  at <anonymous> (...)"
469
477
  ,
470
- "tag": "nested:nested",
478
+ "tag": "nested",
471
479
  }
472
480
  `)
473
481
  })
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { Meta0 } from '@devp0nt/meta0'
1
+ import { Meta0, meta0PluginTag } from '@devp0nt/meta0'
2
2
  import { type AxiosError, HttpStatusCode, isAxiosError } from 'axios'
3
3
  import get from 'lodash/get.js'
4
4
  import { ZodError } from 'zod'
5
5
 
6
+ // TODO: Зод, аксиос, это всё плагины
7
+ // TODO: В эррор0 добавить ориджинал
6
8
  // TODO: store tags as array from all causes
7
9
  // TODO: not use self stack if toError0
8
10
  // TODO: fix default message in extended error0, should be used in constuctor of Error0
@@ -43,6 +45,25 @@ type Error0Cause = Error | Error0 | unknown
43
45
  type ExpectedFn = (error: Error0GeneralProps) => boolean | undefined
44
46
 
45
47
  const isFilled = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined && value !== ''
48
+ const toStringOrUndefined = (value: unknown): string | undefined => {
49
+ return typeof value === 'string' ? value : undefined
50
+ }
51
+ const toNumberOrUndefined = (value: unknown): number | undefined => {
52
+ if (typeof value === 'number') {
53
+ return value
54
+ }
55
+ const number = Number(value)
56
+ if (typeof value === 'string' && !Number.isNaN(number)) {
57
+ return number
58
+ }
59
+ return undefined
60
+ }
61
+ const toBooleanOrUndefined = (value: unknown): boolean | undefined => {
62
+ if (typeof value === 'boolean') {
63
+ return value
64
+ }
65
+ return undefined
66
+ }
46
67
 
47
68
  export class Error0 extends Error {
48
69
  public readonly __I_AM_ERROR_0: true = true
@@ -164,14 +185,22 @@ export class Error0 extends Error {
164
185
  stack: Error0GeneralProps['stack']
165
186
  }): Error0GeneralProps {
166
187
  // const meta = Meta0.merge(error0Input.meta0, error0Input.meta).value
167
- const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)
188
+
189
+ // const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)
190
+ // const defaultMetaValue =
191
+ // this.defaultMeta && typeof this.defaultMeta === 'object' && 'getValue' in this.defaultMeta
192
+ // ? (this.defaultMeta as any).getValue()
193
+ // : this.defaultMeta
194
+
195
+ const meta0 = Meta0.extend(this.defaultMeta, error0Input.meta)
168
196
  const meta = meta0.getValue()
169
- const finalTag = meta0.getFinalTag(error0Input.tag)
197
+ const finalTag = meta0PluginTag.public.getFullTag(meta0, error0Input.tag)
198
+ delete meta.tagPrefix
170
199
  const clientMessage = error0Input.clientMessage || this.defaultClientMessage
171
200
  const result: Error0GeneralProps = {
172
201
  message: error0Input.message || this.defaultMessage,
173
202
  tag: finalTag,
174
- code: error0Input.code || meta.code || this.defaultCode,
203
+ code: error0Input.code || toStringOrUndefined(meta.code) || this.defaultCode,
175
204
  httpStatus:
176
205
  typeof error0Input.httpStatus === 'number'
177
206
  ? error0Input.httpStatus
@@ -179,7 +208,7 @@ export class Error0 extends Error {
179
208
  typeof error0Input.httpStatus === 'string' &&
180
209
  error0Input.httpStatus in HttpStatusCode
181
210
  ? HttpStatusCode[error0Input.httpStatus]
182
- : meta.httpStatus || this.defaultHttpStatus,
211
+ : toNumberOrUndefined(meta.httpStatus) || this.defaultHttpStatus,
183
212
  expected: undefined,
184
213
  clientMessage,
185
214
  anyMessage: clientMessage || message,
@@ -193,7 +222,7 @@ export class Error0 extends Error {
193
222
  result,
194
223
  typeof error0Input.expected === 'boolean' || typeof error0Input.expected === 'function'
195
224
  ? error0Input.expected
196
- : meta.expected || this.defaultExpected,
225
+ : toBooleanOrUndefined(meta.expected) || this.defaultExpected,
197
226
  )
198
227
  result.stack = this._removeConstructorStackPart(stack)
199
228
  return result
@@ -204,7 +233,7 @@ export class Error0 extends Error {
204
233
  const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack)
205
234
  const closestTag = this._getClosestPropValue(causesProps, 'tag')
206
235
  const meta = this._getMergedMetaValue(causesProps)
207
- const tag = Meta0.getFinalTag(meta, closestTag)
236
+ const tag = meta0PluginTag.public.getFullTag(meta, closestTag)
208
237
  const propsFloated: Error0GeneralProps = {
209
238
  message: this._getClosestPropValue(causesProps, 'message'),
210
239
  tag,
@@ -519,7 +548,7 @@ export class Error0 extends Error {
519
548
  static override defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus
520
549
  static override defaultExpected = props.defaultExpected ?? parent.defaultExpected
521
550
  static override defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage
522
- static override defaultMeta = Meta0.extend(props.defaultMeta, parent.defaultMeta)
551
+ static override defaultMeta = Meta0.extend(parent.defaultMeta, props.defaultMeta)
523
552
  }
524
553
  }
525
554
 
@@ -575,10 +604,3 @@ export namespace Error0 {
575
604
  export type JSON = ReturnType<Error0['toJSON']>
576
605
  export type Collection = Record<string, typeof Error0>
577
606
  }
578
-
579
- export const e0s = {
580
- Default: Error0,
581
- Expected: Error0.extend({
582
- defaultExpected: true,
583
- }),
584
- } satisfies Error0.Collection