-
Couldn't load subscription status.
- Fork 0
Return value validators with doc helpers #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sshader-return-value-validators
Are you sure you want to change the base?
Return value validators with doc helpers #9
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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