@devp0nt/error0 1.0.0-next.50 → 1.0.0-next.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +17 -23
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +11 -2
- package/dist/cjs/plugins/cause.cjs +63 -0
- package/dist/cjs/plugins/cause.cjs.map +1 -0
- package/dist/cjs/plugins/cause.d.cts +15 -0
- package/dist/cjs/plugins/code.cjs +10 -2
- package/dist/cjs/plugins/code.cjs.map +1 -1
- package/dist/cjs/plugins/code.d.cts +2 -1
- package/dist/cjs/plugins/expected.cjs +19 -6
- package/dist/cjs/plugins/expected.cjs.map +1 -1
- package/dist/cjs/plugins/expected.d.cts +4 -3
- package/dist/cjs/plugins/{cause-serialize.cjs → flat-original.cjs} +15 -17
- package/dist/cjs/plugins/flat-original.cjs.map +1 -0
- package/dist/cjs/plugins/flat-original.d.cts +7 -0
- package/dist/cjs/plugins/meta.cjs +3 -3
- package/dist/cjs/plugins/meta.cjs.map +1 -1
- package/dist/cjs/plugins/meta.d.cts +2 -2
- package/dist/cjs/plugins/stack-merge.cjs +3 -3
- package/dist/cjs/plugins/stack-merge.cjs.map +1 -1
- package/dist/cjs/plugins/stack-merge.d.cts +2 -2
- package/dist/cjs/plugins/status.cjs +7 -1
- package/dist/cjs/plugins/status.cjs.map +1 -1
- package/dist/cjs/plugins/status.d.cts +2 -1
- package/dist/cjs/plugins/tags.cjs +3 -3
- package/dist/cjs/plugins/tags.cjs.map +1 -1
- package/dist/cjs/plugins/tags.d.cts +2 -2
- package/dist/esm/index.d.ts +11 -2
- package/dist/esm/index.js +17 -23
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/plugins/cause.d.ts +15 -0
- package/dist/esm/plugins/cause.js +39 -0
- package/dist/esm/plugins/cause.js.map +1 -0
- package/dist/esm/plugins/code.d.ts +2 -1
- package/dist/esm/plugins/code.js +10 -2
- package/dist/esm/plugins/code.js.map +1 -1
- package/dist/esm/plugins/expected.d.ts +4 -3
- package/dist/esm/plugins/expected.js +19 -6
- package/dist/esm/plugins/expected.js.map +1 -1
- package/dist/esm/plugins/flat-original.d.ts +7 -0
- package/dist/esm/plugins/flat-original.js +15 -0
- package/dist/esm/plugins/flat-original.js.map +1 -0
- package/dist/esm/plugins/meta.d.ts +2 -2
- package/dist/esm/plugins/meta.js +3 -3
- package/dist/esm/plugins/meta.js.map +1 -1
- package/dist/esm/plugins/stack-merge.d.ts +2 -2
- package/dist/esm/plugins/stack-merge.js +3 -3
- package/dist/esm/plugins/stack-merge.js.map +1 -1
- package/dist/esm/plugins/status.d.ts +2 -1
- package/dist/esm/plugins/status.js +7 -1
- package/dist/esm/plugins/status.js.map +1 -1
- package/dist/esm/plugins/tags.d.ts +2 -2
- package/dist/esm/plugins/tags.js +3 -3
- package/dist/esm/plugins/tags.js.map +1 -1
- package/package.json +1 -1
- package/src/index.test.ts +9 -2
- package/src/index.ts +33 -25
- package/src/plugins/{cause-serialize.test.ts → cause.test.ts} +56 -3
- package/src/plugins/cause.ts +45 -0
- package/src/plugins/code.ts +10 -2
- package/src/plugins/expected.test.ts +22 -3
- package/src/plugins/expected.ts +23 -6
- package/src/plugins/flat-original.test.ts +45 -0
- package/src/plugins/flat-original.ts +12 -0
- package/src/plugins/meta.ts +3 -3
- package/src/plugins/stack-merge.test.ts +0 -7
- package/src/plugins/stack-merge.ts +4 -4
- package/src/plugins/status.ts +8 -2
- package/src/plugins/tags.ts +4 -4
- package/dist/cjs/plugins/cause-serialize.cjs.map +0 -1
- package/dist/cjs/plugins/cause-serialize.d.cts +0 -7
- package/dist/esm/plugins/cause-serialize.d.ts +0 -7
- package/dist/esm/plugins/cause-serialize.js +0 -17
- package/dist/esm/plugins/cause-serialize.js.map +0 -1
- package/src/plugins/cause-serialize.ts +0 -15
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.js';
|
|
2
2
|
|
|
3
|
-
declare const statusPlugin: <TStatuses extends Record<string, number> = Record<never, number>>({ statuses, strict, }?: {
|
|
3
|
+
declare const statusPlugin: <TStatuses extends Record<string, number> = Record<never, number>>({ isPublic, statuses, strict, }?: {
|
|
4
|
+
isPublic?: boolean;
|
|
4
5
|
statuses?: TStatuses;
|
|
5
6
|
strict?: boolean;
|
|
6
7
|
}) => PluginError0<Record<never, never> & Record<"status", ErrorPluginPropOptions<number | Extract<keyof TStatuses, string>, number | undefined, Error0, number | undefined>>, Record<never, never>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Error0 } from "../index.js";
|
|
2
2
|
const statusPlugin = ({
|
|
3
|
+
isPublic = false,
|
|
3
4
|
statuses,
|
|
4
5
|
strict = false
|
|
5
6
|
} = {}) => {
|
|
@@ -20,7 +21,12 @@ const statusPlugin = ({
|
|
|
20
21
|
return Error0.plugin().prop("status", {
|
|
21
22
|
init: (status) => convertStatusValue(status),
|
|
22
23
|
resolve: ({ flow }) => flow.find(Boolean),
|
|
23
|
-
serialize: ({ resolved }) =>
|
|
24
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
25
|
+
if (!isPublic && _isPublic) {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
return resolved;
|
|
29
|
+
},
|
|
24
30
|
deserialize: ({ value }) => typeof value === "number" ? value : void 0
|
|
25
31
|
});
|
|
26
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/status.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const statusPlugin = <TStatuses extends Record<string, number> = Record<never, number>>({\n statuses,\n strict = false,\n}: { statuses?: TStatuses; strict?: boolean } = {}) => {\n const statusValues = statuses ? Object.values(statuses) : undefined\n const isStatusValue = (value: unknown): value is number =>\n typeof value === 'number' && (!statusValues || !strict || statusValues.includes(value))\n const normalizeStatusValue = (value: unknown): number | undefined => {\n return isStatusValue(value) ? value : undefined\n }\n const convertStatusValue = (value: number | string): number | undefined => {\n if (typeof value === 'number') {\n return normalizeStatusValue(value)\n }\n if (statuses && value in statuses) {\n return statuses[value as keyof TStatuses]\n }\n return undefined\n }\n\n return Error0.plugin().prop('status', {\n init: (status: number | Extract<keyof TStatuses, string>) => convertStatusValue(status),\n resolve: ({ flow }) => flow.find(Boolean),\n serialize: ({ resolved }) => resolved,\n deserialize: ({ value }) => (typeof value === 'number' ? value : undefined),\n })\n}\n"],"mappings":"AAAA,SAAS,cAAc;AAEhB,MAAM,eAAe,CAAmE;AAAA,EAC7F;AAAA,EACA,SAAS;AACX,
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/status.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const statusPlugin = <TStatuses extends Record<string, number> = Record<never, number>>({\n isPublic = false,\n statuses,\n strict = false,\n}: { isPublic?: boolean; statuses?: TStatuses; strict?: boolean } = {}) => {\n const statusValues = statuses ? Object.values(statuses) : undefined\n const isStatusValue = (value: unknown): value is number =>\n typeof value === 'number' && (!statusValues || !strict || statusValues.includes(value))\n const normalizeStatusValue = (value: unknown): number | undefined => {\n return isStatusValue(value) ? value : undefined\n }\n const convertStatusValue = (value: number | string): number | undefined => {\n if (typeof value === 'number') {\n return normalizeStatusValue(value)\n }\n if (statuses && value in statuses) {\n return statuses[value as keyof TStatuses]\n }\n return undefined\n }\n\n return Error0.plugin().prop('status', {\n init: (status: number | Extract<keyof TStatuses, string>) => convertStatusValue(status),\n resolve: ({ flow }) => flow.find(Boolean),\n serialize: ({ resolved, isPublic: _isPublic }) => {\n if (!isPublic && _isPublic) {\n return undefined\n }\n return resolved\n },\n deserialize: ({ value }) => (typeof value === 'number' ? value : undefined),\n })\n}\n"],"mappings":"AAAA,SAAS,cAAc;AAEhB,MAAM,eAAe,CAAmE;AAAA,EAC7F,WAAW;AAAA,EACX;AAAA,EACA,SAAS;AACX,IAAoE,CAAC,MAAM;AACzE,QAAM,eAAe,WAAW,OAAO,OAAO,QAAQ,IAAI;AAC1D,QAAM,gBAAgB,CAAC,UACrB,OAAO,UAAU,aAAa,CAAC,gBAAgB,CAAC,UAAU,aAAa,SAAS,KAAK;AACvF,QAAM,uBAAuB,CAAC,UAAuC;AACnE,WAAO,cAAc,KAAK,IAAI,QAAQ;AAAA,EACxC;AACA,QAAM,qBAAqB,CAAC,UAA+C;AACzE,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,qBAAqB,KAAK;AAAA,IACnC;AACA,QAAI,YAAY,SAAS,UAAU;AACjC,aAAO,SAAS,KAAwB;AAAA,IAC1C;AACA,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,OAAO,EAAE,KAAK,UAAU;AAAA,IACpC,MAAM,CAAC,WAAsD,mBAAmB,MAAM;AAAA,IACtF,SAAS,CAAC,EAAE,KAAK,MAAM,KAAK,KAAK,OAAO;AAAA,IACxC,WAAW,CAAC,EAAE,UAAU,UAAU,UAAU,MAAM;AAChD,UAAI,CAAC,YAAY,WAAW;AAC1B,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,IACA,aAAa,CAAC,EAAE,MAAM,MAAO,OAAO,UAAU,WAAW,QAAQ;AAAA,EACnE,CAAC;AACH;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.js';
|
|
2
2
|
|
|
3
|
-
declare const tagsPlugin: <TTag extends string>({
|
|
4
|
-
|
|
3
|
+
declare const tagsPlugin: <TTag extends string>({ isPublic, tags, strict, }?: {
|
|
4
|
+
isPublic?: boolean;
|
|
5
5
|
tags?: TTag[] | readonly TTag[];
|
|
6
6
|
strict?: boolean;
|
|
7
7
|
}) => PluginError0<Record<never, never> & Record<"tags", ErrorPluginPropOptions<string[], string[], Error0, string[] | undefined>>, Record<never, never> & Record<"hasTag", {
|
package/dist/esm/plugins/tags.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Error0 } from "../index.js";
|
|
2
2
|
const tagsPlugin = ({
|
|
3
|
-
|
|
3
|
+
isPublic = false,
|
|
4
4
|
tags,
|
|
5
5
|
strict = true
|
|
6
6
|
} = {}) => {
|
|
@@ -29,8 +29,8 @@ const tagsPlugin = ({
|
|
|
29
29
|
}
|
|
30
30
|
return merged.length > 0 ? Array.from(new Set(merged)) : void 0;
|
|
31
31
|
},
|
|
32
|
-
serialize: ({ resolved, isPublic }) => {
|
|
33
|
-
if (
|
|
32
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
33
|
+
if (!isPublic && _isPublic) {
|
|
34
34
|
return void 0;
|
|
35
35
|
}
|
|
36
36
|
return resolved;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/tags.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const tagsPlugin = <TTag extends string>({\n
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/tags.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const tagsPlugin = <TTag extends string>({\n isPublic = false,\n tags,\n strict = true,\n}: { isPublic?: boolean; tags?: TTag[] | readonly TTag[]; strict?: boolean } = {}) => {\n function hasTag(error: Error0, tag: TTag): boolean\n function hasTag(error: Error0, tag: TTag[], policy: 'every' | 'some'): boolean\n function hasTag(error: Error0, tag: TTag | TTag[], policy?: 'every' | 'some'): boolean {\n const tags = (error as any).tags as string[] | undefined\n if (!tags) {\n return false\n }\n if (Array.isArray(tag)) {\n if (policy === 'every') {\n return tag.every((item) => tags.includes(item))\n }\n return tag.some((item) => tags.includes(item))\n }\n return tags.includes(tag)\n }\n const isTag = (value: unknown): value is TTag =>\n typeof value === 'string' && (!tags || !strict || tags.includes(value as TTag))\n return Error0.plugin()\n .prop('tags', {\n init: (input: string[]) => input,\n resolve: ({ flow }) => {\n const merged: string[] = []\n for (const value of flow) {\n if (Array.isArray(value)) {\n merged.push(...value)\n }\n }\n return merged.length > 0 ? Array.from(new Set(merged)) : undefined\n },\n serialize: ({ resolved, isPublic: _isPublic }) => {\n if (!isPublic && _isPublic) {\n return undefined\n }\n return resolved\n },\n deserialize: ({ value }) => {\n if (!Array.isArray(value)) {\n return undefined\n }\n return value.filter((item) => isTag(item))\n },\n })\n .method('hasTag', hasTag)\n}\n"],"mappings":"AAAA,SAAS,cAAc;AAEhB,MAAM,aAAa,CAAsB;AAAA,EAC9C,WAAW;AAAA,EACX;AAAA,EACA,SAAS;AACX,IAA+E,CAAC,MAAM;AAGpF,WAAS,OAAO,OAAe,KAAoB,QAAoC;AACrF,UAAMA,QAAQ,MAAc;AAC5B,QAAI,CAACA,OAAM;AACT,aAAO;AAAA,IACT;AACA,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,UAAI,WAAW,SAAS;AACtB,eAAO,IAAI,MAAM,CAAC,SAASA,MAAK,SAAS,IAAI,CAAC;AAAA,MAChD;AACA,aAAO,IAAI,KAAK,CAAC,SAASA,MAAK,SAAS,IAAI,CAAC;AAAA,IAC/C;AACA,WAAOA,MAAK,SAAS,GAAG;AAAA,EAC1B;AACA,QAAM,QAAQ,CAAC,UACb,OAAO,UAAU,aAAa,CAAC,QAAQ,CAAC,UAAU,KAAK,SAAS,KAAa;AAC/E,SAAO,OAAO,OAAO,EAClB,KAAK,QAAQ;AAAA,IACZ,MAAM,CAAC,UAAoB;AAAA,IAC3B,SAAS,CAAC,EAAE,KAAK,MAAM;AACrB,YAAM,SAAmB,CAAC;AAC1B,iBAAW,SAAS,MAAM;AACxB,YAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,iBAAO,KAAK,GAAG,KAAK;AAAA,QACtB;AAAA,MACF;AACA,aAAO,OAAO,SAAS,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI;AAAA,IAC3D;AAAA,IACA,WAAW,CAAC,EAAE,UAAU,UAAU,UAAU,MAAM;AAChD,UAAI,CAAC,YAAY,WAAW;AAC1B,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,IACA,aAAa,CAAC,EAAE,MAAM,MAAM;AAC1B,UAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,eAAO;AAAA,MACT;AACA,aAAO,MAAM,OAAO,CAAC,SAAS,MAAM,IAAI,CAAC;AAAA,IAC3C;AAAA,EACF,CAAC,EACA,OAAO,UAAU,MAAM;AAC5B;","names":["tags"]}
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -203,13 +203,20 @@ describe('Error0', () => {
|
|
|
203
203
|
expect('code' in json).toBe(false)
|
|
204
204
|
})
|
|
205
205
|
|
|
206
|
-
it('serialize keeps stack by default without stack plugin', () => {
|
|
206
|
+
it('serialize keeps stack by default without stack plugin when not public', () => {
|
|
207
207
|
const AppError = Error0.use(statusPlugin)
|
|
208
208
|
const error = new AppError('test', { status: 500 })
|
|
209
|
-
const json = AppError.serialize(error)
|
|
209
|
+
const json = AppError.serialize(error, false)
|
|
210
210
|
expect(json.stack).toBe(error.stack)
|
|
211
211
|
})
|
|
212
212
|
|
|
213
|
+
it('serialize does not keep stack when public', () => {
|
|
214
|
+
const AppError = Error0.use(statusPlugin)
|
|
215
|
+
const error = new AppError('test', { status: 500 })
|
|
216
|
+
const json = AppError.serialize(error, true)
|
|
217
|
+
expect('stack' in json).toBe(false)
|
|
218
|
+
})
|
|
219
|
+
|
|
213
220
|
it('stack plugin can customize stack serialization without defining prop plugin', () => {
|
|
214
221
|
const AppError = Error0.use('stack', { serialize: ({ value }) => (value ? `custom:${value}` : undefined) })
|
|
215
222
|
const error = new AppError('test')
|
package/src/index.ts
CHANGED
|
@@ -79,11 +79,22 @@ export type ErrorPluginStackSerialize<TError extends Error0> = (options: {
|
|
|
79
79
|
}) => unknown
|
|
80
80
|
export type ErrorPluginStack<TError extends Error0 = Error0> = { serialize: ErrorPluginStackSerialize<TError> }
|
|
81
81
|
export type ErrorPluginCauseSerialize<TError extends Error0> = (options: {
|
|
82
|
-
|
|
82
|
+
cause: unknown
|
|
83
83
|
error: TError
|
|
84
84
|
isPublic: boolean
|
|
85
|
+
is: (cause: unknown) => boolean
|
|
86
|
+
serialize: (cause: unknown) => Record<string, unknown>
|
|
85
87
|
}) => unknown
|
|
86
|
-
export type
|
|
88
|
+
export type ErrorPluginCauseDeserialize = (options: {
|
|
89
|
+
cause: unknown
|
|
90
|
+
error: Record<string, unknown>
|
|
91
|
+
isSerialized: (serializedCause: unknown) => boolean
|
|
92
|
+
fromSerialized: (serializedCause: unknown) => Error0
|
|
93
|
+
}) => unknown
|
|
94
|
+
export type ErrorPluginCause<TError extends Error0 = Error0> = {
|
|
95
|
+
serialize: ErrorPluginCauseSerialize<TError>
|
|
96
|
+
deserialize: ErrorPluginCauseDeserialize
|
|
97
|
+
}
|
|
87
98
|
export type ErrorPluginMessageSerialize<TError extends Error0> = (options: {
|
|
88
99
|
value: string
|
|
89
100
|
error: TError
|
|
@@ -897,26 +908,18 @@ export class Error0 extends Error {
|
|
|
897
908
|
console.error(`Error0: failed to deserialize property ${key}`, errorRecord)
|
|
898
909
|
}
|
|
899
910
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if ('stack' in errorRecord) {
|
|
903
|
-
try {
|
|
904
|
-
if (typeof errorRecord.stack === 'string') {
|
|
905
|
-
recreated.stack = errorRecord.stack
|
|
906
|
-
}
|
|
907
|
-
} catch {
|
|
908
|
-
// eslint-disable-next-line no-console
|
|
909
|
-
console.error('Error0: failed to deserialize stack', errorRecord)
|
|
910
|
-
}
|
|
911
|
+
if ('stack' in errorRecord && typeof errorRecord.stack === 'string') {
|
|
912
|
+
recreated.stack = errorRecord.stack
|
|
911
913
|
}
|
|
912
914
|
const causePlugin = plugin.cause
|
|
913
|
-
if (causePlugin
|
|
915
|
+
if (causePlugin && 'cause' in errorRecord) {
|
|
914
916
|
try {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
917
|
+
;(recreated as { cause?: unknown }).cause = causePlugin.deserialize({
|
|
918
|
+
cause: errorRecord.cause,
|
|
919
|
+
error: errorRecord,
|
|
920
|
+
isSerialized: (serializedCause) => this.isSerialized(serializedCause),
|
|
921
|
+
fromSerialized: (serializedCause) => this._fromSerialized(serializedCause),
|
|
922
|
+
})
|
|
920
923
|
} catch {
|
|
921
924
|
// eslint-disable-next-line no-console
|
|
922
925
|
console.error('Error0: failed to deserialize cause', errorRecord)
|
|
@@ -1098,8 +1101,13 @@ export class Error0 extends Error {
|
|
|
1098
1101
|
if (typeof key === 'undefined') {
|
|
1099
1102
|
throw new Error('Error0.use("cause", value) requires cause plugin value')
|
|
1100
1103
|
}
|
|
1101
|
-
if (
|
|
1102
|
-
|
|
1104
|
+
if (
|
|
1105
|
+
typeof key !== 'object' ||
|
|
1106
|
+
key === null ||
|
|
1107
|
+
typeof (key as { serialize?: unknown }).serialize !== 'function' ||
|
|
1108
|
+
typeof (key as { deserialize?: unknown }).deserialize !== 'function'
|
|
1109
|
+
) {
|
|
1110
|
+
throw new Error('Error0.use("cause", value) expects { serialize: function, deserialize: function }')
|
|
1103
1111
|
}
|
|
1104
1112
|
return this._useWithPlugin({
|
|
1105
1113
|
cause: key as ErrorPluginCause,
|
|
@@ -1166,8 +1174,6 @@ export class Error0 extends Error {
|
|
|
1166
1174
|
}
|
|
1167
1175
|
const json: Record<string, unknown> = {
|
|
1168
1176
|
name: error0.name,
|
|
1169
|
-
// we do not serialize causes, it is enough that we have floated props and adapt helper
|
|
1170
|
-
// cause: error0.cause,
|
|
1171
1177
|
}
|
|
1172
1178
|
if (serializedMessage !== undefined) {
|
|
1173
1179
|
json.message = serializedMessage
|
|
@@ -1206,7 +1212,7 @@ export class Error0 extends Error {
|
|
|
1206
1212
|
if (stackPlugin) {
|
|
1207
1213
|
serializedStack = stackPlugin.serialize({ value: error0.stack, error: error0, isPublic })
|
|
1208
1214
|
} else {
|
|
1209
|
-
serializedStack = error0.stack
|
|
1215
|
+
serializedStack = isPublic ? undefined : error0.stack
|
|
1210
1216
|
}
|
|
1211
1217
|
if (serializedStack !== undefined) {
|
|
1212
1218
|
json.stack = serializedStack
|
|
@@ -1219,9 +1225,11 @@ export class Error0 extends Error {
|
|
|
1219
1225
|
if (causePlugin?.serialize) {
|
|
1220
1226
|
try {
|
|
1221
1227
|
const serializedCause = causePlugin.serialize({
|
|
1222
|
-
|
|
1228
|
+
cause: (error0 as { cause?: unknown }).cause,
|
|
1223
1229
|
error: error0,
|
|
1224
1230
|
isPublic,
|
|
1231
|
+
is: (cause) => this.is(cause),
|
|
1232
|
+
serialize: (cause) => this.serialize(cause, isPublic),
|
|
1225
1233
|
})
|
|
1226
1234
|
if (serializedCause !== undefined) {
|
|
1227
1235
|
json.cause = serializedCause
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test'
|
|
2
2
|
import { Error0 } from '../index.js'
|
|
3
|
-
import {
|
|
3
|
+
import { causePlugin } from './cause.js'
|
|
4
4
|
|
|
5
|
-
describe('
|
|
5
|
+
describe('causePlugin', () => {
|
|
6
6
|
const statusPlugin = Error0.plugin().use('prop', 'status', {
|
|
7
7
|
init: (input: number) => input,
|
|
8
8
|
resolve: ({ flow }) => flow.find((value) => typeof value === 'number'),
|
|
@@ -23,7 +23,7 @@ describe('causeSerializePlugin', () => {
|
|
|
23
23
|
it('serializes and deserializes nested Error0 causes', () => {
|
|
24
24
|
const AppError = Error0.use(statusPlugin)
|
|
25
25
|
.use(codePlugin)
|
|
26
|
-
.use(
|
|
26
|
+
.use(causePlugin({ isPublic: true }))
|
|
27
27
|
const deepCauseError = new AppError('deep cause')
|
|
28
28
|
const causeError = new AppError('cause', { status: 409, code: 'NOT_FOUND', cause: deepCauseError })
|
|
29
29
|
const error = new AppError('root', { status: 500, cause: causeError })
|
|
@@ -50,4 +50,57 @@ describe('causeSerializePlugin', () => {
|
|
|
50
50
|
expect((recreated.cause as any).cause.code).toBe(undefined)
|
|
51
51
|
expect((recreated.cause as any).cause.cause).toBeUndefined()
|
|
52
52
|
})
|
|
53
|
+
|
|
54
|
+
it('supports variants', () => {
|
|
55
|
+
class DbError extends Error {
|
|
56
|
+
query: string
|
|
57
|
+
constructor(message: string, options: { cause?: unknown; query: string }) {
|
|
58
|
+
super(message, { cause: options.cause })
|
|
59
|
+
this.query = options.query
|
|
60
|
+
this.name = 'DbError'
|
|
61
|
+
}
|
|
62
|
+
static serialize(error: DbError): Record<string, unknown> {
|
|
63
|
+
return {
|
|
64
|
+
message: error.message,
|
|
65
|
+
query: error.query,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
static from(error: unknown): DbError {
|
|
69
|
+
if (error instanceof DbError) {
|
|
70
|
+
return error
|
|
71
|
+
}
|
|
72
|
+
const object = typeof error === 'object' && error !== null ? (error as Record<string, unknown>) : {}
|
|
73
|
+
const message =
|
|
74
|
+
typeof object.message === 'string' ? object.message : typeof error === 'string' ? error : 'Unknown error'
|
|
75
|
+
const query = typeof object.query === 'string' ? object.query : 'NOT_FOUND'
|
|
76
|
+
return new DbError(message, { cause: error, query })
|
|
77
|
+
}
|
|
78
|
+
static isSerialized(serializedCause: unknown): boolean {
|
|
79
|
+
return (
|
|
80
|
+
typeof serializedCause === 'object' &&
|
|
81
|
+
serializedCause !== null &&
|
|
82
|
+
'query' in serializedCause &&
|
|
83
|
+
typeof serializedCause.query === 'string'
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const AppError = Error0.use(statusPlugin)
|
|
88
|
+
.use(codePlugin)
|
|
89
|
+
.use(
|
|
90
|
+
causePlugin({
|
|
91
|
+
variants: {
|
|
92
|
+
DbError,
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
)
|
|
96
|
+
const dbError = new DbError('test', { query: 'SELECT * FROM users' })
|
|
97
|
+
const error = new AppError('root', { status: 500, cause: dbError })
|
|
98
|
+
const json = AppError.serialize(error, false)
|
|
99
|
+
expect(json.cause).toBeDefined()
|
|
100
|
+
expect((json.cause as any).query).toBe('SELECT * FROM users')
|
|
101
|
+
const recreated = AppError.from(json)
|
|
102
|
+
expect(recreated).toBeInstanceOf(AppError)
|
|
103
|
+
expect(recreated.cause).toBeInstanceOf(DbError)
|
|
104
|
+
expect((recreated.cause as any).query).toBe('SELECT * FROM users')
|
|
105
|
+
})
|
|
53
106
|
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Error0 } from '../index.js'
|
|
2
|
+
|
|
3
|
+
type Variant = {
|
|
4
|
+
new (...args: any[]): unknown
|
|
5
|
+
[Symbol.hasInstance]: (value: any) => boolean
|
|
6
|
+
isSerialized: (serializedCause: any) => boolean
|
|
7
|
+
serialize: (error: any) => unknown
|
|
8
|
+
from: (error: any) => unknown
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const causePlugin = <TVariants extends Record<string, Variant> = Record<never, Variant>>({
|
|
12
|
+
isPublic = false,
|
|
13
|
+
variants = undefined,
|
|
14
|
+
}: { isPublic?: boolean; variants?: TVariants } = {}) =>
|
|
15
|
+
Error0.plugin().cause({
|
|
16
|
+
serialize: ({ cause, isPublic: _isPublic, is, serialize }) => {
|
|
17
|
+
if (!isPublic && _isPublic) {
|
|
18
|
+
return undefined
|
|
19
|
+
}
|
|
20
|
+
if (variants) {
|
|
21
|
+
for (const variant of Object.values(variants)) {
|
|
22
|
+
if (cause instanceof variant) {
|
|
23
|
+
return variant.serialize(cause)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (is(cause)) {
|
|
28
|
+
return serialize(cause)
|
|
29
|
+
}
|
|
30
|
+
return undefined
|
|
31
|
+
},
|
|
32
|
+
deserialize: ({ cause, fromSerialized, isSerialized }) => {
|
|
33
|
+
if (variants) {
|
|
34
|
+
for (const variant of Object.values(variants)) {
|
|
35
|
+
if (variant.isSerialized(cause)) {
|
|
36
|
+
return variant.from(cause)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (isSerialized(cause)) {
|
|
41
|
+
return fromSerialized(cause)
|
|
42
|
+
}
|
|
43
|
+
return cause
|
|
44
|
+
},
|
|
45
|
+
})
|
package/src/plugins/code.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { Error0 } from '../index.js'
|
|
2
2
|
|
|
3
|
-
export const codePlugin = <TCode extends string>({
|
|
3
|
+
export const codePlugin = <TCode extends string>({
|
|
4
|
+
codes,
|
|
5
|
+
isPublic = false,
|
|
6
|
+
}: { codes?: TCode[]; isPublic?: boolean } = {}) => {
|
|
4
7
|
const isCode = (value: unknown): value is TCode =>
|
|
5
8
|
typeof value === 'string' && (!codes || codes.includes(value as TCode))
|
|
6
9
|
return Error0.plugin().prop('code', {
|
|
7
10
|
init: (code: TCode) => code,
|
|
8
11
|
resolve: ({ flow }) => flow.find(Boolean),
|
|
9
|
-
serialize: ({ resolved, isPublic }) =>
|
|
12
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
13
|
+
if (!isPublic && _isPublic) {
|
|
14
|
+
return undefined
|
|
15
|
+
}
|
|
16
|
+
return resolved
|
|
17
|
+
},
|
|
10
18
|
deserialize: ({ value, record }) => (isCode(value) ? value : undefined),
|
|
11
19
|
})
|
|
12
20
|
}
|
|
@@ -11,7 +11,7 @@ describe('expectedPlugin', () => {
|
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
it('can be used to control error tracker behavior', () => {
|
|
14
|
-
const AppError = Error0.use(statusPlugin).use(expectedPlugin({
|
|
14
|
+
const AppError = Error0.use(statusPlugin).use(expectedPlugin({ isPublic: true }))
|
|
15
15
|
const errorExpected = new AppError('test', { status: 400, expected: true })
|
|
16
16
|
const errorUnexpected = new AppError('test', { status: 400, expected: false })
|
|
17
17
|
const usualError = new Error('test')
|
|
@@ -30,7 +30,7 @@ describe('expectedPlugin', () => {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
it('resolves to false when any cause has false', () => {
|
|
33
|
-
const AppError = Error0.use(expectedPlugin({
|
|
33
|
+
const AppError = Error0.use(expectedPlugin({ isPublic: true }))
|
|
34
34
|
const root = new AppError('root', { expected: true })
|
|
35
35
|
const middle = new AppError('middle', { expected: false, cause: root })
|
|
36
36
|
const leaf = new AppError('leaf', { expected: false, cause: middle })
|
|
@@ -39,9 +39,28 @@ describe('expectedPlugin', () => {
|
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
it('treats undefined expected as unexpected', () => {
|
|
42
|
-
const AppError = Error0.use(expectedPlugin({
|
|
42
|
+
const AppError = Error0.use(expectedPlugin({ isPublic: true }))
|
|
43
43
|
const error = new AppError('without expected')
|
|
44
44
|
expect(error.expected).toBe(false)
|
|
45
45
|
expect(error.isExpected()).toBe(false)
|
|
46
46
|
})
|
|
47
|
+
|
|
48
|
+
it('supports override', () => {
|
|
49
|
+
const AppError = Error0.use(statusPlugin).use(
|
|
50
|
+
expectedPlugin({
|
|
51
|
+
isPublic: true,
|
|
52
|
+
override: (error) => {
|
|
53
|
+
return error.message.includes('CRITICAL') ? false : undefined
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
57
|
+
const errorNonCritical = new AppError('USUAL: test', { status: 400 })
|
|
58
|
+
const errorNonCriticalExpected = new AppError('USUAL: test', { status: 400, expected: true })
|
|
59
|
+
const errorCritical = new AppError('CRITICAL: test', { status: 400 })
|
|
60
|
+
const errorCriticalExpected = new AppError('CRITICAL: test', { status: 400, expected: true })
|
|
61
|
+
expect(errorNonCritical.expected).toBe(false) // becouse expected was not provided at all
|
|
62
|
+
expect(errorNonCriticalExpected.expected).toBe(true)
|
|
63
|
+
expect(errorCritical.expected).toBe(false)
|
|
64
|
+
expect(errorCriticalExpected.expected).toBe(false)
|
|
65
|
+
})
|
|
47
66
|
})
|
package/src/plugins/expected.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { Error0 } from '../index.js'
|
|
2
2
|
|
|
3
|
-
const isExpected = (
|
|
3
|
+
const isExpected = ({
|
|
4
|
+
flow,
|
|
5
|
+
error,
|
|
6
|
+
override,
|
|
7
|
+
}: {
|
|
8
|
+
flow: unknown[]
|
|
9
|
+
error: Error0
|
|
10
|
+
override?: (error: any) => boolean | undefined
|
|
11
|
+
}) => {
|
|
12
|
+
if (override) {
|
|
13
|
+
const overridden = override(error)
|
|
14
|
+
if (overridden !== undefined) {
|
|
15
|
+
return overridden
|
|
16
|
+
}
|
|
17
|
+
}
|
|
4
18
|
let expected = false
|
|
5
19
|
for (const value of flow) {
|
|
6
20
|
if (value === false) {
|
|
@@ -13,13 +27,16 @@ const isExpected = (flow: unknown[]) => {
|
|
|
13
27
|
return expected
|
|
14
28
|
}
|
|
15
29
|
|
|
16
|
-
export const expectedPlugin =
|
|
30
|
+
export const expectedPlugin = <TError extends Error0>({
|
|
31
|
+
isPublic = false,
|
|
32
|
+
override,
|
|
33
|
+
}: { isPublic?: boolean; override?: (error: TError) => boolean | undefined } = {}) =>
|
|
17
34
|
Error0.plugin()
|
|
18
35
|
.prop('expected', {
|
|
19
36
|
init: (input: boolean) => input,
|
|
20
|
-
resolve: ({ flow }) => isExpected(flow),
|
|
21
|
-
serialize: ({ resolved, isPublic }) => {
|
|
22
|
-
if (
|
|
37
|
+
resolve: ({ flow, error }) => isExpected({ flow, error, override }),
|
|
38
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
39
|
+
if (isPublic && _isPublic) {
|
|
23
40
|
return undefined
|
|
24
41
|
}
|
|
25
42
|
return resolved
|
|
@@ -27,5 +44,5 @@ export const expectedPlugin = ({ hideWhenPublic = true }: { hideWhenPublic?: boo
|
|
|
27
44
|
deserialize: ({ value }) => (typeof value === 'boolean' ? value : undefined),
|
|
28
45
|
})
|
|
29
46
|
.method('isExpected', (error) => {
|
|
30
|
-
return isExpected(error.flow('expected'))
|
|
47
|
+
return isExpected({ flow: error.flow('expected'), error, override })
|
|
31
48
|
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { Error0 } from '../index.js'
|
|
3
|
+
import { flatOriginalPlugin } from './flat-original.js'
|
|
4
|
+
|
|
5
|
+
describe('flatOriginalPlugin', () => {
|
|
6
|
+
it('without plugin original error comes to cause', () => {
|
|
7
|
+
const usualError = new Error('another error')
|
|
8
|
+
const error = Error0.from(usualError)
|
|
9
|
+
expect(error).toBeInstanceOf(Error0)
|
|
10
|
+
expect(error).toBeInstanceOf(Error)
|
|
11
|
+
expect(error.name).toBe('Error0')
|
|
12
|
+
expect(error.cause).not.toBeInstanceOf(Error0)
|
|
13
|
+
expect(error.cause).toBeInstanceOf(Error)
|
|
14
|
+
expect(error.cause).toBe(usualError)
|
|
15
|
+
expect((error.cause as any).name).toBe('Error')
|
|
16
|
+
expect(error.causes()).toEqual([error, usualError])
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('with plugin original error becomes error0 itself', () => {
|
|
20
|
+
const usualError = new Error('another error')
|
|
21
|
+
const AppError = Error0.use(flatOriginalPlugin())
|
|
22
|
+
const error = AppError.from(usualError)
|
|
23
|
+
expect(error).toBeInstanceOf(AppError)
|
|
24
|
+
expect(error).toBeInstanceOf(Error0)
|
|
25
|
+
expect(error).toBeInstanceOf(Error)
|
|
26
|
+
expect(error.message).toBe(usualError.message)
|
|
27
|
+
expect(error.stack).toBe(usualError.stack)
|
|
28
|
+
expect(error.name).toBe('Error0')
|
|
29
|
+
expect(error.cause).toBeUndefined()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('with plugin original error becomes error0 itself but keep it own causes', () => {
|
|
33
|
+
const causeError = new Error('cause error')
|
|
34
|
+
const usualError = new Error('another error', { cause: causeError })
|
|
35
|
+
const AppError = Error0.use(flatOriginalPlugin())
|
|
36
|
+
const error = AppError.from(usualError)
|
|
37
|
+
expect(error).toBeInstanceOf(AppError)
|
|
38
|
+
expect(error).toBeInstanceOf(Error0)
|
|
39
|
+
expect(error).toBeInstanceOf(Error)
|
|
40
|
+
expect(error.message).toBe(usualError.message)
|
|
41
|
+
expect(error.stack).toBe(usualError.stack)
|
|
42
|
+
expect(error.name).toBe('Error0')
|
|
43
|
+
expect(error.causes()).toEqual([error, causeError])
|
|
44
|
+
})
|
|
45
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Error0 } from '../index.js'
|
|
2
|
+
|
|
3
|
+
export const flatOriginalPlugin = ({ prefix }: { prefix?: string } = {}) => {
|
|
4
|
+
return Error0.plugin().adapt((error) => {
|
|
5
|
+
const cause = error.cause
|
|
6
|
+
if (cause instanceof Error && cause.constructor === Error) {
|
|
7
|
+
error.cause = cause.cause
|
|
8
|
+
error.message = `${prefix ?? ''}${cause.message}`
|
|
9
|
+
error.stack = cause.stack
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
}
|
package/src/plugins/meta.ts
CHANGED
|
@@ -28,7 +28,7 @@ const toJsonSafe = (input: unknown): Json | undefined => {
|
|
|
28
28
|
const isMetaRecord = (value: unknown): value is Record<string, unknown> =>
|
|
29
29
|
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
30
30
|
|
|
31
|
-
export const metaPlugin = ({
|
|
31
|
+
export const metaPlugin = ({ isPublic = false }: { isPublic?: boolean } = {}) =>
|
|
32
32
|
Error0.plugin().prop('meta', {
|
|
33
33
|
init: (input: Record<string, unknown>) => input,
|
|
34
34
|
resolve: ({ flow }) => {
|
|
@@ -44,8 +44,8 @@ export const metaPlugin = ({ hideWhenPublic = true }: { hideWhenPublic?: boolean
|
|
|
44
44
|
}
|
|
45
45
|
return merged
|
|
46
46
|
},
|
|
47
|
-
serialize: ({ resolved, isPublic }) => {
|
|
48
|
-
if (
|
|
47
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
48
|
+
if (!isPublic && _isPublic) {
|
|
49
49
|
return undefined
|
|
50
50
|
}
|
|
51
51
|
return toJsonSafe(resolved)
|
|
@@ -54,11 +54,4 @@ describe('stackMergePlugin', () => {
|
|
|
54
54
|
`)
|
|
55
55
|
expect(mergedStack2Public).toBeUndefined()
|
|
56
56
|
})
|
|
57
|
-
|
|
58
|
-
it('by default serializes stack of this error only', () => {
|
|
59
|
-
const AppError = Error0.use(statusPlugin).use(codePlugin).use(stackMergePlugin())
|
|
60
|
-
const error = new AppError('test', { status: 400, code: 'NOT_FOUND' })
|
|
61
|
-
const json = AppError.serialize(error, false)
|
|
62
|
-
expect(json.stack).toBe(error.stack)
|
|
63
|
-
})
|
|
64
57
|
})
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Error0 } from '../index.js'
|
|
2
2
|
|
|
3
3
|
export const stackMergePlugin = ({
|
|
4
|
-
|
|
4
|
+
isPublic = false,
|
|
5
5
|
delimiter = '\n',
|
|
6
|
-
}: {
|
|
6
|
+
}: { isPublic?: boolean; delimiter?: string } = {}) =>
|
|
7
7
|
Error0.plugin().stack({
|
|
8
|
-
serialize: ({ error, isPublic }) => {
|
|
9
|
-
if (
|
|
8
|
+
serialize: ({ error, isPublic: _isPublic }) => {
|
|
9
|
+
if (!isPublic && _isPublic) {
|
|
10
10
|
return undefined
|
|
11
11
|
}
|
|
12
12
|
return error
|
package/src/plugins/status.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Error0 } from '../index.js'
|
|
2
2
|
|
|
3
3
|
export const statusPlugin = <TStatuses extends Record<string, number> = Record<never, number>>({
|
|
4
|
+
isPublic = false,
|
|
4
5
|
statuses,
|
|
5
6
|
strict = false,
|
|
6
|
-
}: { statuses?: TStatuses; strict?: boolean } = {}) => {
|
|
7
|
+
}: { isPublic?: boolean; statuses?: TStatuses; strict?: boolean } = {}) => {
|
|
7
8
|
const statusValues = statuses ? Object.values(statuses) : undefined
|
|
8
9
|
const isStatusValue = (value: unknown): value is number =>
|
|
9
10
|
typeof value === 'number' && (!statusValues || !strict || statusValues.includes(value))
|
|
@@ -23,7 +24,12 @@ export const statusPlugin = <TStatuses extends Record<string, number> = Record<n
|
|
|
23
24
|
return Error0.plugin().prop('status', {
|
|
24
25
|
init: (status: number | Extract<keyof TStatuses, string>) => convertStatusValue(status),
|
|
25
26
|
resolve: ({ flow }) => flow.find(Boolean),
|
|
26
|
-
serialize: ({ resolved }) =>
|
|
27
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
28
|
+
if (!isPublic && _isPublic) {
|
|
29
|
+
return undefined
|
|
30
|
+
}
|
|
31
|
+
return resolved
|
|
32
|
+
},
|
|
27
33
|
deserialize: ({ value }) => (typeof value === 'number' ? value : undefined),
|
|
28
34
|
})
|
|
29
35
|
}
|
package/src/plugins/tags.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Error0 } from '../index.js'
|
|
2
2
|
|
|
3
3
|
export const tagsPlugin = <TTag extends string>({
|
|
4
|
-
|
|
4
|
+
isPublic = false,
|
|
5
5
|
tags,
|
|
6
6
|
strict = true,
|
|
7
|
-
}: {
|
|
7
|
+
}: { isPublic?: boolean; tags?: TTag[] | readonly TTag[]; strict?: boolean } = {}) => {
|
|
8
8
|
function hasTag(error: Error0, tag: TTag): boolean
|
|
9
9
|
function hasTag(error: Error0, tag: TTag[], policy: 'every' | 'some'): boolean
|
|
10
10
|
function hasTag(error: Error0, tag: TTag | TTag[], policy?: 'every' | 'some'): boolean {
|
|
@@ -34,8 +34,8 @@ export const tagsPlugin = <TTag extends string>({
|
|
|
34
34
|
}
|
|
35
35
|
return merged.length > 0 ? Array.from(new Set(merged)) : undefined
|
|
36
36
|
},
|
|
37
|
-
serialize: ({ resolved, isPublic }) => {
|
|
38
|
-
if (
|
|
37
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
38
|
+
if (!isPublic && _isPublic) {
|
|
39
39
|
return undefined
|
|
40
40
|
}
|
|
41
41
|
return resolved
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/cause-serialize.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const causeSerializePlugin = ({ hideWhenPublic = true }: { hideWhenPublic?: boolean } = {}) =>\n Error0.plugin().cause({\n serialize: ({ value, error, isPublic }) => {\n if (hideWhenPublic && isPublic) {\n return undefined\n }\n const ctor = error.constructor as typeof Error0\n if (ctor.is(value)) {\n return ctor.serialize(value, isPublic)\n }\n return undefined\n },\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAEhB,MAAM,uBAAuB,CAAC,EAAE,iBAAiB,KAAK,IAAkC,CAAC,MAC9F,gBAAO,OAAO,EAAE,MAAM;AAAA,EACpB,WAAW,CAAC,EAAE,OAAO,OAAO,SAAS,MAAM;AACzC,QAAI,kBAAkB,UAAU;AAC9B,aAAO;AAAA,IACT;AACA,UAAM,OAAO,MAAM;AACnB,QAAI,KAAK,GAAG,KAAK,GAAG;AAClB,aAAO,KAAK,UAAU,OAAO,QAAQ;AAAA,IACvC;AACA,WAAO;AAAA,EACT;AACF,CAAC;","names":[]}
|