Return value validators with doc helpers#9
Return value validators with doc helpers#9sshader wants to merge 1 commit intosshader-return-value-validatorsfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| }, | ||
| doc: <T extends TableNames>(tableName: T): Validator<Doc<T>, false, any> => { | ||
| const validator = v.object( | ||
| (schema.tables[tableName] as any).documentSchema |
There was a problem hiding this comment.
I made normal Convex schema expose the validator as documentType. Ents have a private documentSchema, but I think we should ideally make it behave like documentType with vanilla Convex
| const validator = v.object( | ||
| (schema.tables[tableName] as any).documentSchema | ||
| ) as Validator<any, any, any> | ||
| if (validator?.kind !== 'object') { |
There was a problem hiding this comment.
I'm realizing now that this isn't right -- it should account for a union of objects as well as any (and probably record, once that exists)
There was a problem hiding this comment.
how does this pattern of being able to work directly with some validators if you know their .kind (curious why the ? is necessary here) but sometimes you just don't know? I guess that's not the pattern yet since ObjectValidator, StringValidator etc. is not exported yet
| validator1: Validator<O1, false, any>, | ||
| validator2: Validator<O2, false, any> | ||
| ): Validator<Omit<O1, keyof O2> & O2, false, any> => { | ||
| if (validator1.kind !== 'object' || validator2.kind !== 'object') { |
There was a problem hiding this comment.
I wanted something like a spread. Zod seems to call this .extend or .merge (https://zod.dev/?id=extend).
This also probably should allow for unions of objects, and maybe also any + record
There was a problem hiding this comment.
Should we expose all the validator types so you can use them here?
f6eb979 to
362f03a
Compare
Main change is that I cherry-picked the "exposing validator innards" PR onto Convex, and then used it to make
betterVwhich has adoc("Messages")type on it.It makes quite a few things nicer