feat: standard schema for validation#543
Conversation
🦋 Changeset detectedLatest commit: d071d6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
ghostdevv
left a comment
There was a problem hiding this comment.
the jsdoc comments above the validate options would need updating, as well as the docs https://github.com/bombshell-dev/docs/
| await setTimeout(1000); | ||
| } | ||
|
|
||
| main().catch(console.error); |
There was a problem hiding this comment.
Probably fine since it’s just an example
There was a problem hiding this comment.
something about being the change you want to see in the world 😇
| @@ -0,0 +1,22 @@ | |||
| import type { StandardSchemaV1 } from '@standard-schema/spec'; | |||
|
|
|||
| export type Validate<TValue> = | |||
There was a problem hiding this comment.
Could use a jsdoc comment
natemoo-re
left a comment
There was a problem hiding this comment.
Code looks great, changeset is perfect, just minor feedback on the example!
| const name = await text({ | ||
| message: 'Enter your name (letters only)', | ||
| initialValue: 'John123', // Invalid initial value with numbers | ||
| validate: type('string.alpha').describe('Name can only contain letters'), |
There was a problem hiding this comment.
To @ghostdevv s "be the change" comment, can we use a contrived number example or something neutral like a url? Names categorically cannot be validated.
| // https://standardschema.dev/schema#how-to-only-allow-synchronous-validation | ||
| if (result instanceof Promise) { | ||
| throw new TypeError( | ||
| 'Schema validation must be synchronous. Update `validate()` and get rid of any asynchronous logic.' |
There was a problem hiding this comment.
Bummer that we're stuck with this! Maybe a follow-up for v2.
What does this PR do?
Allows using Standard Schema compatible libraries for
validate(). Discussed on Discord.Docs PR: bombshell-dev/docs#42
Type of change
Checklist
pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure