using zCustomMutation with convex-ents
How can I create a zMutation I can use from a mutation with a customCtx? I'm using this from the saas-starter:
I don't know if it's correct but I'm trying to export this:
but I'm getting a gigantic TS error and I'm pretty sure it's because it expects the db property on the context
5 Replies
If I try to go with this:
wherever I try to use zMutation the context is of type 'never'
Chatted offline - the issue was likely around having z.record as the validator.
z.record
is not supported. v.record
is not officially supported. The suggested approach is something like recordToListOfObjects
something like Object.entries(myRecord).map(([key, valu]) => { key, value })
and on the other end like Object.fromEntries(listOfObjects.map(({key, value}) => [key, value]))
Thanks Ian 👍
Besides changing the mutation argument to:
will I also have to change my schema from
to an array of objects?
Is it possible to have the name be an object I can push anything to? since records are not supported
I guess having name be name: v.any() ?
You can make one validator object and share it:
And use it both in arguments and in the table def:
Make sense @hyperzone ? You can also use
v.any()
and cast, but the type hints are nice
Aside: the zCustomMutation shouldn't be returning never
when using a z.record
. It'll fail at runtime but the types right now don't help you catch unsupported zod validators. Michal is looking into why Ents and zCustomMutation don't play well together.Yes it makes sense thank you!