Files
SnowLuma/.pnpm-store/v11/files/b5/2dfd7e18d8e9a7f21322d6e59dfec0ae28e118f0e961a5b9d793290a294700592d4acc89924d046affe929430e7dbb42b29f5cf5b802779547607a88162f5c
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

33 lines
905 B
Plaintext

import { createPlugin } from "seroval";
//#region src/ssr/serializer/ShallowErrorPlugin.ts
/**
* this plugin serializes only the `message` part of an Error
* this helps with serializing e.g. a ZodError which has functions attached that cannot be serialized
*/
const ShallowErrorPlugin = /* @__PURE__ */ createPlugin({
tag: "$TSR/Error",
test(value) {
return value instanceof Error;
},
parse: {
sync(value, ctx) {
return { message: ctx.parse(value.message) };
},
async async(value, ctx) {
return { message: await ctx.parse(value.message) };
},
stream(value, ctx) {
return { message: ctx.parse(value.message) };
}
},
serialize(node, ctx) {
return "new Error(" + ctx.serialize(node.message) + ")";
},
deserialize(node, ctx) {
return new Error(ctx.deserialize(node.message));
}
});
//#endregion
export { ShallowErrorPlugin };
//# sourceMappingURL=ShallowErrorPlugin.js.map