Add validation to server$ #18
Replies: 4 comments 2 replies
-
|
I forgot about this one when I wrote #24 😅 The |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @tzdesign for this proposal! 🙏 We've just reviewed this as a team and here are our thoughts: We agreed that having a solution for versions skew is important to add and also making sure that server functions are kept safe. This led us to re-evaluate the problem + solution to make sure we'll end up with an holistic, well thought of solution that will be easier to maintain. So our suggestion is to split this proposal into 3 potential RFC proposals (as part of an overall solution to the big "server function" problem):
So what I suggest: I'll open 2 other proposals (1 and 2), and this one could be edited to reflect the third one. WDYT? |
Beta Was this translation helpful? Give feedback.
-
|
OK so we went over this proposal again last night in the RFC meeting. I went ahead and renamed this to just about the validation and as mentioned above, there are two other proposals for the other steps required for a full solution - We discussed potential way to implement the type safety for closures, this was @mhevery proposal (pseudo code): let x = 123
let y = "abc"
let server_fn = server$((foo: string, bar: string) => {
// const [x,y] = useLexicalScope();
console.log(x, y);
}), {
$validator: {
x: Valibot.number(),
foo: Valibot.string(),
// [LINT]: warning missing [y]
}
})
export server_fn_$_HASH = (a1: string, a2: string) => {
const [a3,a4] = useLexicalScope();
console.log(a3, a4);
}
server_fn_$_HASH.$ = "foo,bar|x,y"The idea is to have the optimizer generate a string containing the names of the params and closed over variables so they could be matched against the Zod / Valibot validation. |
Beta Was this translation helpful? Give feedback.
-
|
Discussed some more with Fabian. To keep type inference but also have actual validation, we should make a plugin that maintains a validator on server$. The validator would be a function that receives the parameters in one array and the scope variables in the second array. It is very important that the scope order matches what the optimizer produces for a qrl. Then, it should use e.g. Then it should change the original code to have this validator. Furthermore, for complex types, like a brand such as That way, in the server code, the types will be correct but broad enough to validate, and the dev will automatically see where to test further constraints. E.g. if you pass |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What is it about?
server$ can be easily attacked if you don't validate inside or just pretend the data is what typescript tells you
What's the motivation for this proposal?
Problems you are trying to solve:
Goals you are trying to achieve:
Any other context or information you want to share:
My idea is to add validation in the same way as in actions.
Proposed Solution / Feature
What do you propose? (GPT generated 😉 )
The purpose of this initiative is to enhance the safety and consistency of the Qwik framework by addressing potential security risks and improving the reliability of server functions during rolling updates in Kubernetes clusters. This will be achieved by:
The ultimate goal is to make Qwik more robust, safe, and reliable in production environments, especially in distributed systems like Kubernetes.
Code examples
Links / References
No response
Beta Was this translation helpful? Give feedback.
All reactions