Closed IdoPesok closed 2 weeks ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
zsa | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 21, 2024 1:01am |
Latest commit: 09c5ada8d8f3c1f9b592cae8be087e1ba7ca6f8a
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Added ability to dynamically generate the input/output schemas from the openapi metadata. @blechatellier I think you may find this interesting. Prob not the safest idea to change validation based on just headers, but maybe a use case can be to parse an API key in the input function then have different schemas for different roles.
export const dynamicSchemasAction = publicAction
.input(({ request }) =>
z.object({
min: z
.number()
.min(parseInt(request?.headers.get("x-min-number") || "0")),
max: z
.number()
.max(parseInt(request?.headers.get("x-max-number") || "100")),
})
)
.output(({ request, responseMeta }) =>
z.object({
randomNumber: z.number().transform((n) => {
const min = parseInt(request?.headers.get("x-min-number") || "0")
const max = parseInt(request?.headers.get("x-max-number") || "100")
const mid = (min + max) / 2
if (n > mid) {
responseMeta?.headers.set("x-test", ">")
} else {
responseMeta?.headers.set("x-test", "<")
}
return n
}),
})
)
.handler(({ input }) => {
const { min, max } = input
return {
randomNumber: Math.random() * (max - min) + min,
}
})
Changed input chains from zod intersections to zod merges
Requested by @andresgutgon in #107
Added ability to pass functions that return the input schema
Also for outputs