Skip to content

Conversation

@sshader
Copy link
Owner

@sshader sshader commented Jun 10, 2024

Main change is that I cherry-picked the "exposing validator innards" PR onto Convex, and then used it to make betterV which has a doc("Messages") type on it.

It makes quite a few things nicer

@vercel
Copy link

vercel bot commented Jun 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
proset-g7r2 ❌ Failed (Inspect) Jun 14, 2024 9:04pm

},
doc: <T extends TableNames>(tableName: T): Validator<Doc<T>, false, any> => {
const validator = v.object(
(schema.tables[tableName] as any).documentSchema
Copy link
Owner Author

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') {
Copy link
Owner Author

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)

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') {
Copy link
Owner Author

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

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?

@sshader sshader force-pushed the sshader-return-value-validators-helpers branch from f6eb979 to 362f03a Compare June 14, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants