Repository navigation
fix: type each temporal format to admit what its regex accepts - #36
Open
maxholman[bot] wants to merge 4 commits into
Open
maxholman[bot] wants to merge 4 commits into
maxholman[bot] wants to merge 4 commits into
Conversation
A hint that names a generated type, such as `EmbedUrl`, reached valibot.ts as `v.custom<EmbedUrl>` with no import, so the module did not compile. The validators module now imports every type it references that the types module exports, which also covers the annotations on lazy refs. Co-Authored-By: LLM <noreply@block65.dev>
The regex that checks a format and the template-literal type it produces were written out in both generators, so a change to one could miss the other. Co-Authored-By: LLM <noreply@block65.dev>
The date-time regex accepts `T`, `t` or a space between the date and the time, as RFC 3339 allows, but the generated type admitted only `T`. A value such as `2024-01-01t00:00:00Z` passed validation and still did not assign to the type. Co-Authored-By: LLM <noreply@block65.dev>
The generated validator ran the format's regex in `v.regex` and then narrowed the output with `v.custom<…>(() => true)`, a step that accepts anything. One `v.custom` now runs the regex and types the output, and a component schema names its alias from the types module, so the template literal is written out once. A failed check reports a `custom` issue where it reported `regex`. Co-Authored-By: LLM <noreply@block65.dev>
| function temporalHintSchema(format: string | undefined) { | ||
| const type = temporalTypeHint(format); | ||
| return type ? `v.custom<${type}>(() => true)` : undefined; | ||
| return `v.custom<${typeName ?? temporal.type}>((input) => typeof input === "string" && ${temporal.regex}.test(input), ${message})`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every temporal format's generated type admits each value its regex accepts, so a
date-timesuch as2024-01-01t00:00:00Zor2024-01-01 00:00:00Z, which RFC 3339 allows, assigns to the type the schema outputs. Each format's regex and type sit in one table, andvalibot.tsimports the alias fromtypes.tsand runs the regex in the samev.customthat types the output, so the literal is written out once and the typing step checks the value.An
x-typescript-hintthat names a generated type, such asEmbedUrl, compiles invalibot.ts, which imports each type it references thattypes.tsexports.A consumer that inspects issue types sees
customwhere a failed temporal check reportedregex; the message is still the format name.This conflicts with the open
fix/ts-import-specifierswork near theimportLazyTypescall inlib/process-document.ts, renamed here toimportNamedTypes. Whichever lands second rebases.