-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support user provided custom serialization/deserialization #77
Comments
This should be trivial with @effect/schema but requires a big breaking change |
If I can, I'd like to mention my use-case for custom serialisation of I have a route that looks like this:
In Typescript it looks like so: type FooHandle =
| { id: string } // uuid
| { shortId: number } // without `id` prefix from URL Currently, I do the following when declaring export const Route = {
routeParams: z.object({
fooHandle: z.string().transform((h) => parseFooHandle(h)),
}),
} satisfies DynamicRoute; This work perfectly for deserialising raw string from URL into a valid However, when I need to create a path to this route, I have to serialise $path({
route: "/foos/[fooHandle]",
routeParams: {
fooHandle: serializeFooHandle(foo.handle),
},
}) since Ideally, |
the options as I see them:
pros: no breaking changes
export $path = buildPath({ transformer }) pros: idk
$path({ ... }, { transformer }) pros: non breaking change, still can be typesafe (I think)
Just thinking now though that even if we switch to schema, I think we would need to code gen a file with all of the schemas. Because right now $path at runtime doesnt actually depend on them at all- its pure. However I think we would need to create basically a runtime version of the anyways open to thoughts |
currently serialization/deserialization is hard coded in
there are many valid usecase for a user wanting a custom solution:
maybe look at how trpc handles custom transformers?
To discuss:
What should the signature of the swappable serializer be?
How to handle differences between search param and route param serialization / deserialization?
The text was updated successfully, but these errors were encountered: