feat: standard schema for validation#543
Conversation
🦋 Changeset detectedLatest commit: 3f77e8a 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/
natemoo-re
left a comment
There was a problem hiding this comment.
Code looks great, changeset is perfect, just minor feedback on the example!
|
I also want to note that the PR does not support schema transforms (they will run but not be used). That would require more changes to represent input and output in types. Out of scope of this PR but if you're interested let me know! |
|
@ghostdevv docs PR is available at bombshell-dev/docs#42 |
|
Also, this would be breaking right? |
Co-authored-by: James Garbutt <43081j@users.noreply.github.com>
Co-authored-by: James Garbutt <43081j@users.noreply.github.com>
|
@43081j yeah I was also hesitating. I inlined it, the spec says it's absolutely fine |
@ghostdevv by "this", are you referring to input/output/transforms or this PR? |
Yea, as this PR changes the behavior of the |
|
I'm not sure it's fully breaking. No change as a user but it's true that if you are dealing with lower level APIs like in the date prompt, then it requires changes. So maybe it's a major for core and a minor for prompts |
Ah, I'm so sorry but I missed the fact that the old behavior is still available 🤦♀️ |
|
technically, we can strip the standard schema types down to only the parts we use too. but i'm happy either way. inlining it is better than pulling a dependency still |
|
I just checked and very little can be stripped, only |
| import { isCancel, note, text } from '@clack/prompts'; | ||
| import { type } from 'arktype'; | ||
|
|
||
| async function main() { |
There was a problem hiding this comment.
btw @florian-lefebvre what I meant by top level await was removing the main fn and just doing everything at the top - but it's not that deep 😄
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | ||
| * that validates user input. Return a `string` or `Error` to show as a validation error, | ||
| * or `undefined` to accept the result. |
There was a problem hiding this comment.
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | |
| * that validates user input. Return a `string` or `Error` to show as a validation error, | |
| * or `undefined` to accept the result. | |
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | |
| * that validates user input. If a custom function is given, you should return a `string` or `Error` | |
| * to show as a validation error, or `undefined` to accept the result. |
at the risk of bikeshedding, this is a bit more clear?
| * Runs the `validate()` option and normalizes the result | ||
| * @param validate - The validate option | ||
| * @param value - The user input | ||
| * @returns string | Error | undefined |
There was a problem hiding this comment.
| * @returns string | Error | undefined | |
| * @returns the validation result |
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