UNPKG

@tanstack/router-core

Version:

Modern and scalable routing for React applications

1 lines 1.63 kB
{"version":3,"file":"ShallowErrorPlugin.cjs","names":[],"sources":["../../../../src/ssr/serializer/ShallowErrorPlugin.ts"],"sourcesContent":["import { createPlugin } from 'seroval'\nimport type { SerovalNode } from 'seroval'\n\nexport interface ErrorNode {\n message: SerovalNode\n}\n\n/**\n * this plugin serializes only the `message` part of an Error\n * this helps with serializing e.g. a ZodError which has functions attached that cannot be serialized\n */\nexport const ShallowErrorPlugin = /* @__PURE__ */ createPlugin<\n Error,\n ErrorNode\n>({\n tag: '$TSR/Error',\n test(value) {\n return value instanceof Error\n },\n parse: {\n sync(value, ctx) {\n return {\n message: ctx.parse(value.message),\n }\n },\n async async(value, ctx) {\n return {\n message: await ctx.parse(value.message),\n }\n },\n stream(value, ctx) {\n return {\n message: ctx.parse(value.message),\n }\n },\n },\n serialize(node, ctx) {\n return 'new Error(' + ctx.serialize(node.message) + ')'\n },\n deserialize(node, ctx) {\n return new Error(ctx.deserialize(node.message))\n },\n})\n"],"mappings":";;;;;;AAWA,IAAa,qBAAqC,iBAAA,sBAAA,cAGhD;CACA,KAAK;CACL,KAAK,OAAO;AACV,SAAO,iBAAiB;;CAE1B,OAAO;EACL,KAAK,OAAO,KAAK;AACf,UAAO,EACL,SAAS,IAAI,MAAM,MAAM,QAAQ,EAClC;;EAEH,MAAM,MAAM,OAAO,KAAK;AACtB,UAAO,EACL,SAAS,MAAM,IAAI,MAAM,MAAM,QAAQ,EACxC;;EAEH,OAAO,OAAO,KAAK;AACjB,UAAO,EACL,SAAS,IAAI,MAAM,MAAM,QAAQ,EAClC;;EAEJ;CACD,UAAU,MAAM,KAAK;AACnB,SAAO,eAAe,IAAI,UAAU,KAAK,QAAQ,GAAG;;CAEtD,YAAY,MAAM,KAAK;AACrB,SAAO,IAAI,MAAM,IAAI,YAAY,KAAK,QAAQ,CAAC;;CAElD,CAAC"}