You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{sql}from'@contra/slonik';import{resolverBuilders}from'#app/contra-api/__generated__/types.js';import{z}from'zod';exportconstresolve=resolverBuilders.UserAccount.lastPersonaInquiry().resolve(async(userAccount,_args,context)=>{constlastPersonaInquiryId=awaitcontext.pool.maybeOneFirst(sql.type(z.object({id: z.number()}).strict(),)` SELECT pi1.id FROM persona_inquiry pi1 WHERE pi1.user_account_id = ${userAccount.id} ORDER BY pi1.created_at DESC LIMIT 1 `);if(!lastPersonaInquiryId){returnnull;}returnawaitcontext.loaders.PersonaInquiry.load(lastPersonaInquiryId);},);
Is there an existing Babel plugin (or alternative technique) that would hoist zod object definitions to the top-most scope?, i.e. rewrite the code to:
import{sql}from'@contra/slonik';import{resolverBuilders}from'#app/contra-api/__generated__/types.js';import{z}from'zod';consttemp1=z.object({id: z.number()}).strict();exportconstresolve=resolverBuilders.UserAccount.lastPersonaInquiry().resolve(async(userAccount,_args,context)=>{constlastPersonaInquiryId=awaitcontext.pool.maybeOneFirst(sql.type(temp1,)` SELECT pi1.id FROM persona_inquiry pi1 WHERE pi1.user_account_id = ${userAccount.id} ORDER BY pi1.created_at DESC LIMIT 1 `);if(!lastPersonaInquiryId){returnnull;}returnawaitcontext.loaders.PersonaInquiry.load(lastPersonaInquiryId);},);
It would be pretty easy to write something like this.
However, I am not familiar enough with Zod internals to know if it is worth it, or if the initiailization logic of the object shapes is cheap enough to not matter?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Suppose I have a code like this:
Is there an existing Babel plugin (or alternative technique) that would hoist zod object definitions to the top-most scope?, i.e. rewrite the code to:
It would be pretty easy to write something like this.
However, I am not familiar enough with Zod internals to know if it is worth it, or if the initiailization logic of the object shapes is cheap enough to not matter?
Beta Was this translation helpful? Give feedback.
All reactions