@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
|
@@ -16,26 +16,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var flat_original_exports = {};
|
|
20
|
+
__export(flat_original_exports, {
|
|
21
|
+
flatOriginalPlugin: () => flatOriginalPlugin
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(flat_original_exports);
|
|
24
24
|
var import__ = require('../index.cjs');
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const flatOriginalPlugin = ({ prefix } = {}) => {
|
|
26
|
+
return import__.Error0.plugin().adapt((error) => {
|
|
27
|
+
const cause = error.cause;
|
|
28
|
+
if (cause instanceof Error && cause.constructor === Error) {
|
|
29
|
+
error.cause = cause.cause;
|
|
30
|
+
error.message = `${prefix ?? ""}${cause.message}`;
|
|
31
|
+
error.stack = cause.stack;
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return ctor.serialize(value, isPublic);
|
|
33
|
-
}
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
37
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
36
|
0 && (module.exports = {
|
|
39
|
-
|
|
37
|
+
flatOriginalPlugin
|
|
40
38
|
});
|
|
41
|
-
//# sourceMappingURL=
|
|
39
|
+
//# sourceMappingURL=flat-original.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/flat-original.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const flatOriginalPlugin = ({ prefix }: { prefix?: string } = {}) => {\n return Error0.plugin().adapt((error) => {\n const cause = error.cause\n if (cause instanceof Error && cause.constructor === Error) {\n error.cause = cause.cause\n error.message = `${prefix ?? ''}${cause.message}`\n error.stack = cause.stack\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAEhB,MAAM,qBAAqB,CAAC,EAAE,OAAO,IAAyB,CAAC,MAAM;AAC1E,SAAO,gBAAO,OAAO,EAAE,MAAM,CAAC,UAAU;AACtC,UAAM,QAAQ,MAAM;AACpB,QAAI,iBAAiB,SAAS,MAAM,gBAAgB,OAAO;AACzD,YAAM,QAAQ,MAAM;AACpB,YAAM,UAAU,GAAG,UAAU,EAAE,GAAG,MAAM,OAAO;AAC/C,YAAM,QAAQ,MAAM;AAAA,IACtB;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -45,7 +45,7 @@ const toJsonSafe = (input) => {
|
|
|
45
45
|
return void 0;
|
|
46
46
|
};
|
|
47
47
|
const isMetaRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
48
|
-
const metaPlugin = ({
|
|
48
|
+
const metaPlugin = ({ isPublic = false } = {}) => import__.Error0.plugin().prop("meta", {
|
|
49
49
|
init: (input) => input,
|
|
50
50
|
resolve: ({ flow }) => {
|
|
51
51
|
const values = flow.filter(isMetaRecord);
|
|
@@ -58,8 +58,8 @@ const metaPlugin = ({ hideWhenPublic = true } = {}) => import__.Error0.plugin().
|
|
|
58
58
|
}
|
|
59
59
|
return merged;
|
|
60
60
|
},
|
|
61
|
-
serialize: ({ resolved, isPublic }) => {
|
|
62
|
-
if (
|
|
61
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
62
|
+
if (!isPublic && _isPublic) {
|
|
63
63
|
return void 0;
|
|
64
64
|
}
|
|
65
65
|
return toJsonSafe(resolved);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/meta.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\nconst toJsonSafe = (input: unknown): Json | undefined => {\n if (input === null) {\n return null\n }\n if (typeof input === 'string' || typeof input === 'number' || typeof input === 'boolean') {\n return input\n }\n if (Array.isArray(input)) {\n return input.map((value) => toJsonSafe(value)) as Json[]\n }\n if (typeof input === 'object') {\n const output: Record<string, Json> = {}\n for (const [key, value] of Object.entries(input as Record<string, unknown>)) {\n const jsonValue = toJsonSafe(value)\n if (jsonValue !== undefined) {\n output[key] = jsonValue\n }\n }\n return output\n }\n return undefined\n}\n\nconst isMetaRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nexport const metaPlugin = ({
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/meta.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\nconst toJsonSafe = (input: unknown): Json | undefined => {\n if (input === null) {\n return null\n }\n if (typeof input === 'string' || typeof input === 'number' || typeof input === 'boolean') {\n return input\n }\n if (Array.isArray(input)) {\n return input.map((value) => toJsonSafe(value)) as Json[]\n }\n if (typeof input === 'object') {\n const output: Record<string, Json> = {}\n for (const [key, value] of Object.entries(input as Record<string, unknown>)) {\n const jsonValue = toJsonSafe(value)\n if (jsonValue !== undefined) {\n output[key] = jsonValue\n }\n }\n return output\n }\n return undefined\n}\n\nconst isMetaRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nexport const metaPlugin = ({ isPublic = false }: { isPublic?: boolean } = {}) =>\n Error0.plugin().prop('meta', {\n init: (input: Record<string, unknown>) => input,\n resolve: ({ flow }) => {\n const values = flow.filter(isMetaRecord)\n if (values.length === 0) {\n return undefined\n }\n\n // Merge cause meta into the current error; nearer errors win on conflicts.\n const merged: Record<string, unknown> = {}\n for (const value of [...values].reverse()) {\n Object.assign(merged, value)\n }\n return merged\n },\n serialize: ({ resolved, isPublic: _isPublic }) => {\n if (!isPublic && _isPublic) {\n return undefined\n }\n return toJsonSafe(resolved)\n },\n deserialize: ({ value }) => {\n if (!isMetaRecord(value)) {\n return undefined\n }\n return value\n },\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAIvB,MAAM,aAAa,CAAC,UAAqC;AACvD,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AACA,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW;AACxF,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,CAAC,UAAU,WAAW,KAAK,CAAC;AAAA,EAC/C;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,SAA+B,CAAC;AACtC,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAgC,GAAG;AAC3E,YAAM,YAAY,WAAW,KAAK;AAClC,UAAI,cAAc,QAAW;AAC3B,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,MAAM,eAAe,CAAC,UACpB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAE9D,MAAM,aAAa,CAAC,EAAE,WAAW,MAAM,IAA4B,CAAC,MACzE,gBAAO,OAAO,EAAE,KAAK,QAAQ;AAAA,EAC3B,MAAM,CAAC,UAAmC;AAAA,EAC1C,SAAS,CAAC,EAAE,KAAK,MAAM;AACrB,UAAM,SAAS,KAAK,OAAO,YAAY;AACvC,QAAI,OAAO,WAAW,GAAG;AACvB,aAAO;AAAA,IACT;AAGA,UAAM,SAAkC,CAAC;AACzC,eAAW,SAAS,CAAC,GAAG,MAAM,EAAE,QAAQ,GAAG;AACzC,aAAO,OAAO,QAAQ,KAAK;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EACA,WAAW,CAAC,EAAE,UAAU,UAAU,UAAU,MAAM;AAChD,QAAI,CAAC,YAAY,WAAW;AAC1B,aAAO;AAAA,IACT;AACA,WAAO,WAAW,QAAQ;AAAA,EAC5B;AAAA,EACA,aAAa,CAAC,EAAE,MAAM,MAAM;AAC1B,QAAI,CAAC,aAAa,KAAK,GAAG;AACxB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AACF,CAAC;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.cjs';
|
|
2
2
|
|
|
3
|
-
declare const metaPlugin: ({
|
|
4
|
-
|
|
3
|
+
declare const metaPlugin: ({ isPublic }?: {
|
|
4
|
+
isPublic?: boolean;
|
|
5
5
|
}) => PluginError0<Record<never, never> & Record<"meta", ErrorPluginPropOptions<Record<string, unknown>, Record<string, unknown>, Error0, Record<string, unknown> | undefined>>, Record<never, never>>;
|
|
6
6
|
|
|
7
7
|
export { metaPlugin };
|
|
@@ -23,11 +23,11 @@ __export(stack_merge_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(stack_merge_exports);
|
|
24
24
|
var import__ = require('../index.cjs');
|
|
25
25
|
const stackMergePlugin = ({
|
|
26
|
-
|
|
26
|
+
isPublic = false,
|
|
27
27
|
delimiter = "\n"
|
|
28
28
|
} = {}) => import__.Error0.plugin().stack({
|
|
29
|
-
serialize: ({ error, isPublic }) => {
|
|
30
|
-
if (
|
|
29
|
+
serialize: ({ error, isPublic: _isPublic }) => {
|
|
30
|
+
if (!isPublic && _isPublic) {
|
|
31
31
|
return void 0;
|
|
32
32
|
}
|
|
33
33
|
return error.causes().map((cause) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/stack-merge.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const stackMergePlugin = ({\n
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/stack-merge.ts"],"sourcesContent":["import { Error0 } from '../index.js'\n\nexport const stackMergePlugin = ({\n isPublic = false,\n delimiter = '\\n',\n}: { isPublic?: boolean; delimiter?: string } = {}) =>\n Error0.plugin().stack({\n serialize: ({ error, isPublic: _isPublic }) => {\n if (!isPublic && _isPublic) {\n return undefined\n }\n return error\n .causes()\n .map((cause) => {\n return cause instanceof Error ? cause.stack : undefined\n })\n .filter((value): value is string => typeof value === 'string')\n .join(delimiter)\n },\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;AAEhB,MAAM,mBAAmB,CAAC;AAAA,EAC/B,WAAW;AAAA,EACX,YAAY;AACd,IAAgD,CAAC,MAC/C,gBAAO,OAAO,EAAE,MAAM;AAAA,EACpB,WAAW,CAAC,EAAE,OAAO,UAAU,UAAU,MAAM;AAC7C,QAAI,CAAC,YAAY,WAAW;AAC1B,aAAO;AAAA,IACT;AACA,WAAO,MACJ,OAAO,EACP,IAAI,CAAC,UAAU;AACd,aAAO,iBAAiB,QAAQ,MAAM,QAAQ;AAAA,IAChD,CAAC,EACA,OAAO,CAAC,UAA2B,OAAO,UAAU,QAAQ,EAC5D,KAAK,SAAS;AAAA,EACnB;AACF,CAAC;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginError0 } from '../index.cjs';
|
|
2
2
|
|
|
3
|
-
declare const stackMergePlugin: ({
|
|
4
|
-
|
|
3
|
+
declare const stackMergePlugin: ({ isPublic, delimiter, }?: {
|
|
4
|
+
isPublic?: boolean;
|
|
5
5
|
delimiter?: string;
|
|
6
6
|
}) => PluginError0<Record<never, never>, Record<never, never>>;
|
|
7
7
|
|
|
@@ -23,6 +23,7 @@ __export(status_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(status_exports);
|
|
24
24
|
var import__ = require('../index.cjs');
|
|
25
25
|
const statusPlugin = ({
|
|
26
|
+
isPublic = false,
|
|
26
27
|
statuses,
|
|
27
28
|
strict = false
|
|
28
29
|
} = {}) => {
|
|
@@ -43,7 +44,12 @@ const statusPlugin = ({
|
|
|
43
44
|
return import__.Error0.plugin().prop("status", {
|
|
44
45
|
init: (status) => convertStatusValue(status),
|
|
45
46
|
resolve: ({ flow }) => flow.find(Boolean),
|
|
46
|
-
serialize: ({ resolved }) =>
|
|
47
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
48
|
+
if (!isPublic && _isPublic) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
return resolved;
|
|
52
|
+
},
|
|
47
53
|
deserialize: ({ value }) => typeof value === "number" ? value : void 0
|
|
48
54
|
});
|
|
49
55
|
};
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;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;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;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,gBAAO,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,6 +1,7 @@
|
|
|
1
1
|
import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.cjs';
|
|
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>>;
|
|
@@ -23,7 +23,7 @@ __export(tags_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(tags_exports);
|
|
24
24
|
var import__ = require('../index.cjs');
|
|
25
25
|
const tagsPlugin = ({
|
|
26
|
-
|
|
26
|
+
isPublic = false,
|
|
27
27
|
tags,
|
|
28
28
|
strict = true
|
|
29
29
|
} = {}) => {
|
|
@@ -52,8 +52,8 @@ const tagsPlugin = ({
|
|
|
52
52
|
}
|
|
53
53
|
return merged.length > 0 ? Array.from(new Set(merged)) : void 0;
|
|
54
54
|
},
|
|
55
|
-
serialize: ({ resolved, isPublic }) => {
|
|
56
|
-
if (
|
|
55
|
+
serialize: ({ resolved, isPublic: _isPublic }) => {
|
|
56
|
+
if (!isPublic && _isPublic) {
|
|
57
57
|
return void 0;
|
|
58
58
|
}
|
|
59
59
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,eAAuB;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,gBAAO,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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginError0, ErrorPluginPropOptions, Error0 } from '../index.cjs';
|
|
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/index.d.ts
CHANGED
|
@@ -48,12 +48,21 @@ type ErrorPluginStack<TError extends Error0 = Error0> = {
|
|
|
48
48
|
serialize: ErrorPluginStackSerialize<TError>;
|
|
49
49
|
};
|
|
50
50
|
type ErrorPluginCauseSerialize<TError extends Error0> = (options: {
|
|
51
|
-
|
|
51
|
+
cause: unknown;
|
|
52
52
|
error: TError;
|
|
53
53
|
isPublic: boolean;
|
|
54
|
+
is: (cause: unknown) => boolean;
|
|
55
|
+
serialize: (cause: unknown) => Record<string, unknown>;
|
|
56
|
+
}) => unknown;
|
|
57
|
+
type ErrorPluginCauseDeserialize = (options: {
|
|
58
|
+
cause: unknown;
|
|
59
|
+
error: Record<string, unknown>;
|
|
60
|
+
isSerialized: (serializedCause: unknown) => boolean;
|
|
61
|
+
fromSerialized: (serializedCause: unknown) => Error0;
|
|
54
62
|
}) => unknown;
|
|
55
63
|
type ErrorPluginCause<TError extends Error0 = Error0> = {
|
|
56
64
|
serialize: ErrorPluginCauseSerialize<TError>;
|
|
65
|
+
deserialize: ErrorPluginCauseDeserialize;
|
|
57
66
|
};
|
|
58
67
|
type ErrorPluginMessageSerialize<TError extends Error0> = (options: {
|
|
59
68
|
value: string;
|
|
@@ -340,4 +349,4 @@ declare class Error0 extends Error {
|
|
|
340
349
|
round<TThis extends Error0>(this: TThis, isPublic?: boolean): TThis;
|
|
341
350
|
}
|
|
342
351
|
|
|
343
|
-
export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseSerialize, type ErrorPluginMessage, type ErrorPluginMessageSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
|
|
352
|
+
export { type ClassError0, Error0, type ErrorInput, type ErrorInputBase, type ErrorPlugin, type ErrorPluginAdaptFn, type ErrorPluginAdaptResult, type ErrorPluginCause, type ErrorPluginCauseDeserialize, type ErrorPluginCauseSerialize, type ErrorPluginMessage, type ErrorPluginMessageSerialize, type ErrorPluginMethodFn, type ErrorPluginMethods, type ErrorPluginPropOptions, type ErrorPluginProps, type ErrorPluginStack, type ErrorPluginStackSerialize, type ErrorPluginsMap, type ErrorResolved, type IsEmptyObject, PluginError0 };
|
package/dist/esm/index.js
CHANGED
|
@@ -358,25 +358,19 @@ class Error0 extends Error {
|
|
|
358
358
|
console.error(`Error0: failed to deserialize property ${key}`, errorRecord);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
if ("stack" in errorRecord) {
|
|
362
|
-
|
|
363
|
-
if (typeof errorRecord.stack === "string") {
|
|
364
|
-
recreated.stack = errorRecord.stack;
|
|
365
|
-
}
|
|
366
|
-
} catch {
|
|
367
|
-
console.error("Error0: failed to deserialize stack", errorRecord);
|
|
368
|
-
}
|
|
361
|
+
if ("stack" in errorRecord && typeof errorRecord.stack === "string") {
|
|
362
|
+
recreated.stack = errorRecord.stack;
|
|
369
363
|
}
|
|
370
364
|
const causePlugin = plugin.cause;
|
|
371
|
-
if (causePlugin
|
|
365
|
+
if (causePlugin && "cause" in errorRecord) {
|
|
372
366
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
367
|
+
;
|
|
368
|
+
recreated.cause = causePlugin.deserialize({
|
|
369
|
+
cause: errorRecord.cause,
|
|
370
|
+
error: errorRecord,
|
|
371
|
+
isSerialized: (serializedCause) => this.isSerialized(serializedCause),
|
|
372
|
+
fromSerialized: (serializedCause) => this._fromSerialized(serializedCause)
|
|
373
|
+
});
|
|
380
374
|
} catch {
|
|
381
375
|
console.error("Error0: failed to deserialize cause", errorRecord);
|
|
382
376
|
}
|
|
@@ -447,8 +441,8 @@ class Error0 extends Error {
|
|
|
447
441
|
if (typeof key === "undefined") {
|
|
448
442
|
throw new Error('Error0.use("cause", value) requires cause plugin value');
|
|
449
443
|
}
|
|
450
|
-
if (typeof key !== "object" || key === null || typeof key.serialize !== "function") {
|
|
451
|
-
throw new Error('Error0.use("cause", value) expects { serialize: function }');
|
|
444
|
+
if (typeof key !== "object" || key === null || typeof key.serialize !== "function" || typeof key.deserialize !== "function") {
|
|
445
|
+
throw new Error('Error0.use("cause", value) expects { serialize: function, deserialize: function }');
|
|
452
446
|
}
|
|
453
447
|
return this._useWithPlugin({
|
|
454
448
|
cause: key
|
|
@@ -510,8 +504,6 @@ class Error0 extends Error {
|
|
|
510
504
|
}
|
|
511
505
|
const json = {
|
|
512
506
|
name: error0.name
|
|
513
|
-
// we do not serialize causes, it is enough that we have floated props and adapt helper
|
|
514
|
-
// cause: error0.cause,
|
|
515
507
|
};
|
|
516
508
|
if (serializedMessage !== void 0) {
|
|
517
509
|
json.message = serializedMessage;
|
|
@@ -548,7 +540,7 @@ class Error0 extends Error {
|
|
|
548
540
|
if (stackPlugin) {
|
|
549
541
|
serializedStack = stackPlugin.serialize({ value: error0.stack, error: error0, isPublic });
|
|
550
542
|
} else {
|
|
551
|
-
serializedStack = error0.stack;
|
|
543
|
+
serializedStack = isPublic ? void 0 : error0.stack;
|
|
552
544
|
}
|
|
553
545
|
if (serializedStack !== void 0) {
|
|
554
546
|
json.stack = serializedStack;
|
|
@@ -560,9 +552,11 @@ class Error0 extends Error {
|
|
|
560
552
|
if (causePlugin?.serialize) {
|
|
561
553
|
try {
|
|
562
554
|
const serializedCause = causePlugin.serialize({
|
|
563
|
-
|
|
555
|
+
cause: error0.cause,
|
|
564
556
|
error: error0,
|
|
565
|
-
isPublic
|
|
557
|
+
isPublic,
|
|
558
|
+
is: (cause) => this.is(cause),
|
|
559
|
+
serialize: (cause) => this.serialize(cause, isPublic)
|
|
566
560
|
});
|
|
567
561
|
if (serializedCause !== void 0) {
|
|
568
562
|
json.cause = serializedCause;
|