String-format long tail - #23
Merged
Merged
Conversation
ckPattern gains an optional JSON Schema format name, emitted alongside pattern by toJsonSchema; uuid/date/datetime now carry uuid/date/ date-time. Adds ckUrl backed by std/uri (a scheme and host required) since URL regexes are unreliable; it emits format: uri. Plumbing for the string-format refinements that follow.
Adds url (parser-based via std/uri: scheme and host required), ipv4, ipv6, hostname, e164, base64, base64url, hex(n), ulid, nanoid(len), jwt (structural), semver, and slug refinements on string schemas. All are pattern checks except url, all take the standard message override, and toJsonSchema emits format names where JSON Schema defines them (uri, ipv4, ipv6, hostname).
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.
Summary
Closes the string-format gap against zod with thirteen new refinements on
Schema[string], all chainable, all with the standardmessageoverride:urlstd/uri(URL regexes are unreliable)ipv4/ipv6::-compressed formhostnamee164+and 2-15 digitsbase64/base64urlhex(n = 0)nwhen givenulid/nanoid(len = 21)jwtsemverslugTwo commits:
ckPatterngains an optional JSON Schemaformatname emitted alongsidepattern, which retroactively givesuuid/date/datetimetheir properformat: uuid/date/date-time; plus a new parser-basedckUrlcheck emittingformat: uriwith no pattern.patternCheckone-liner excepturl.Deliberately omitted:
emoji(unicode property classes, low value),cuid/cuid2(ULID/nanoid cover the niche), and a combinedip()(already expressible asoneOfSchema(str().ipv4, str().ipv6)).ipv6accepts full and compressed forms but not zone indices or IPv4-embedded notation, documented in the doc comment.Tests
4 new tests (235 total, passing under orc and arc locally): a table-driven accept/reject matrix across all thirteen formats (~60 cases), message overrides,
formatemission intoJsonSchemaincluding the no-patternurlcase, and chaining witharray/optional.README (refinements table, string formats section) and DESIGN.md updated.