feat(type): support File size bounds#1637
Open
ooospooky wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — Added byte-size bounds (minSize/maxSize) for the File intrinsic using SI unit literals, with parser support, schema nodes, JSON Schema fallback, and comprehensive tests.
- Added
minSize/maxSizeconstraint nodes inark/schema/refinements/minSize.tsandmaxSize.ts, mirroring the existingminLength/maxLengthpattern, withminSize: 0reducing to unconstrained and size-0 descriptions special-cased. - Added size-literal parsing in
ark/util/sizes.tsforB/KB/MB/GB/TB, resolving to canonical byte counts and rounding away IEEE-754 artifacts from fractional units like1.005KB. - Wired File bounds through the type parser in
ark/type/parser/ast/bounds.tsandark/type/parser/shift/operator/bounds.ts, allowing numeric or size-literal limits while rejecting date literals for File and vice versa at the type level. - Registered
Filein the intrinsic scope inark/schema/intrinsic.tsso bound detection can anchor on$ark.intrinsic.File. - Added
sizeJSON Schema fallback inark/schema/shared/toJsonSchema.tsso size constraints fail loudly rather than being silently dropped. - Expanded test coverage across
bounds.test.ts,range.test.ts, andkeywords/file.test.tsfor comparators, ranges, units, fractional rounding, empty-file rejection, and invalid-limit errors.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
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
Issue #1166 (Discord thread).
Adds size bounds for
File, using the same comparator syntax as numeric, length, and date bounds:Units are decimal SI (
B/KB/MB/GB/TB, 1000-based) and a bare number is bytes, per the questions raised on the issue — happy to switch to IEC/1024 units if you'd prefer.Implementation notes
minSize/maxSizejoin the existing bound kinds (min/max,minLength/maxLength,after/before), keyed off$ark.intrinsic.Fileand checkingdata.size.File >= 5MB,>= 5000KB, and>= 5000000are the same node ({ minSize: 5000000 }), with the description derived back to the most compact unit — the same approachDatebounds use withdescribeCollapsibleDate.Fileintrinsic uses the existingFileConstructor(globalThis.File ?? Blob) so importing the library doesn't throw on Node 18/19 whereFileisn't a global.1.005KBround to exact bytes (avoiding the1004.999…IEEE-754 boundary). AFilebound rejects date literals (and vice versa) at both the type and runtime level, andtoJsonSchemagains asizefallback so the constraint isn't silently dropped.Test plan
mainbranchpnpm prCheckslocallyrange.test.ts,bounds.test.ts,keywords/file.test.ts); DTS snapshots regenerated