Repository navigation
bun-types: declare S3File.name as string and remove S3File.readable
#46754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
1
commit into
main
Choose a base branch
from
robobun/15d0f7b0/s3file-name-string
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 (optional) Users who slice a zero-size S3 slice now get
nametypedstringwhile the runtime returnsundefined, so code TypeScript accepts throws or builds aFilenamed "undefined".slice()on a blob whose size is 0 returns a plain emptyBlobwith no store (src/runtime/webcore/Blob.rs:1755), and itsnamegetter yieldsundefined(Blob.rs:1845), yet the overloads at s3.d.ts:535-537 still returnS3Filewithreadonly name: string(s3.d.ts:634). Fix: make the declaration true on that path too, e.g. have the zero-size arm ofBlob::slicecarry the parent'sname(and S3 store) into the result, or type the overloads so the empty-slice result is notS3File; the JSDoc note alone leaves the type lying. The same hole opens afterresolve_size()zeroes a live S3 blob (Blob.rs:2067).Why this was flagged
A caller does
const hole = s3.file("k").slice(0, 0).slice()(or slices an S3 blob after something calledresolve_size()on it, Blob.rs:2067, which sets an S3 blob's size to 0).Blob::sliceat src/runtime/webcore/Blob.rs:1755 seesself.size.get() == 0and returnsBlob::init_empty, a plain Blob with no store. Itsget_name(Blob.rs:1842-1846) finds no name and nostore_path, so it returnsJSValue::UNDEFINED. The declarations sayslice(): S3File(s3.d.ts:535-537) and, after this diff,readonly name: string(s3.d.ts:634), sohole.name.lengthornew File([..], hole.name)compiles with no narrowing. On the base branchname?: stringforced a??/!guard, so the undefined was visible to the type checker; after merge the user gets a runtimeTypeErroror aFilenamed "undefined" that tsc said was impossible. The only safeguard is the new JSDoc sentence at s3.d.ts:510-512, which the compiler does not enforce and which also omits theresolve_size()trigger.Verification:
slice()on an S3 blob whose size is 0 (s3.file("k").slice(0, 0).slice()) yields noname.Blob::slice(src/runtime/webcore/Blob.rs:1755-1760) returns a plain Blob with no store, soget_name(Blob.rs:1842-1846) returnsundefined. s3.d.ts:535-537 still declaresslice(...): S3Fileand this PR changes s3.d.ts:634 toreadonly name: string, so TypeScript now acceptshole.name.length(runtime TypeError) where the base forced narrowing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true, and the PR states it (Downsides, second bullet, and "The
slice()exception" under Notes). On canary1.4.4-canary.1+a8fcd319b:I did not apply either fix here. The reasons:
Blob::slice. The result is then anS3Fileof size 0, asfile.slice(0, 0)is today. A read of that object goes to the network:await file.slice(0, 0).text()sendsRange: bytes=0-0and returns the first byte of the object (S3: a zero-length slice sendsRange: bytes=N-Nand reads one byte #43929). Todayawait hole.text()is""with no request. So this trades a wrongnamefor wrong bytes until the zero-length read changes too.namebecomes true andpresignstaysundefined, soslice(): S3Fileis still wrong for the value. That arm also drops the name of aFile, of aBun.file()and of aBlobwith a name set:new File(["abc"], "a.txt").slice(0, 1).nameis"a.txt", and.slice(0, 0).slice().nameisundefined. So the change is aboutBlob::slicefor every kind of blob. It needs a native build and run-time tests of its own.S3File | Blob. Thenfile.slice(0, 1024).presign(),.bucketand.namefail for every caller:TS2339: Property 'presign' does not exist on type 'Blob | S3File'.The JSDoc leaves out the
resolve_size()route on purpose. #46653 changes that arm (store::DataTag::S3 => {}), so the JSDoc describes only the part that stays: the slice of a zero-length slice.The decision for a maintainer: take
name: stringwith this one documented exception, or keepname?: stringuntil the run-time hole is closed. If the second is preferred, I will reduce this PR to the removal ofreadable.