feat(sdk): add downloadStream and uploadStream to file api#1275
Conversation
🦋 Changeset detectedLatest commit: ae02530 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 |
⚡ pkg.pr.new@tailor-platform/sdk@tailor-platform/create-sdk
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR extends the SDK’s TailorDB file (BLOB) runtime wrapper and Vitest mock to support streaming uploads/downloads via uploadStream and downloadStream, and deprecates the older openDownloadStream iterator-based API. It also updates runtime/testing documentation and adds unit tests for the new wrapper methods.
Changes:
- Add
downloadStream/uploadStreamto the runtimetailordb.filewrapper API and export helpers. - Extend the Vitest
tailordb.filemock to support the new methods and update defaults. - Add runtime unit tests and update docs to document
downloadStreamand deprecateopenDownloadStream.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/sdk/src/vitest/mock.ts | Adds downloadStream/uploadStream mock methods and defaults for tailordb.file. |
| packages/sdk/src/runtime/file.ts | Adds new stream types/options, adds methods to TailorDBFileAPI, and exports downloadStream/uploadStream; deprecates openDownloadStream. |
| packages/sdk/src/runtime/file.test.ts | Adds wrapper forwarding tests for downloadStream and uploadStream. |
| packages/sdk/docs/testing.md | Documents mocking downloadStream and clarifies openDownloadStream as deprecated. |
| packages/sdk/docs/runtime.md | Updates exported runtime API list to include new stream methods and mark openDownloadStream deprecated. |
| .changeset/tangy-views-tie.md | Adds a minor changeset entry for the new stream methods and deprecation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fa454ff to
cc0cf29
Compare
This comment has been minimized.
This comment has been minimized.
📖 Docs Consistency Check
|
| File | Issue | Suggested Fix |
|---|---|---|
packages/sdk/src/plugin/builtin/file-utils/generate-file-utils.ts |
Generator does not create helpers for new downloadStream and uploadStream methods |
Update generator to produce downloadFileStream and uploadFileStream helpers alongside the existing openFileDownloadStream |
Details
File Utils Generator (packages/sdk/src/plugin/builtin/file-utils/generate-file-utils.ts:40-141)
The file utils plugin generates typed helper functions for file operations, but currently only includes the deprecated openDownloadStream method:
- Missing imports (lines 40-48): Should import
FileDownloadStreamResponseandFileUploadStreamOptionstypes - Missing
downloadStreamhelper: Should generate adownloadFileStreamfunction similar toopenFileDownloadStreambut calling the newfile.downloadStreamAPI - Missing
uploadStreamhelper: Should generate anuploadFileStreamfunction that callsfile.uploadStream
Current generated output (example/generated/files.ts):
- Lines 1-7: Only imports
FileStreamIterator(for deprecated API) - Lines 61-67: Only generates
openFileDownloadStreamhelper - Missing:
downloadFileStreamanduploadFileStreamhelpers
Impact:
Users relying on the generated file utilities will not have typed helpers for the new stream APIs and will continue using the deprecated openDownloadStream method without awareness of the newer alternatives.
Recommended Actions
-
Update
packages/sdk/src/plugin/builtin/file-utils/generate-file-utils.ts:- Add
FileDownloadStreamResponseandFileUploadStreamOptionsto the import statement (line 42-47) - Generate
downloadFileStreamhelper that callsfile.downloadStream - Generate
uploadFileStreamhelper that callsfile.uploadStream - Consider marking
openFileDownloadStreamas@deprecatedin generated JSDoc
- Add
-
Run code generation to update
example/generated/files.ts -
Update
example/tests/fixtures/expected/files.tsto match the new generated output
Re-run this check by adding the
docs-checklabel to the PR.
| fieldName: string, | ||
| recordId: string, | ||
| readableStream: ReadableStream<Uint8Array | ArrayBuffer>, | ||
| options?: FileUploadStreamOptions, |
There was a problem hiding this comment.
[q] I do not quite understand the significance of this being optional.
What is the difference between when it is specified and when it is not?
There was a problem hiding this comment.
Both contentType and fileSize have default values, so callers don't need to specify them unless they want to override.
toiroakr
left a comment
There was a problem hiding this comment.
LGTM (with 1 question.)
|
@haru0017 It looks like the commits are not signed. |
cc0cf29 to
ae02530
Compare
Code Metrics Report (packages/sdk)
Details | | main (c4f5dd0) | #1275 (928d66f) | +/- |
|--------------------|----------------|-----------------|-------|
+ | Coverage | 64.3% | 64.3% | +0.0% |
| Files | 380 | 380 | 0 |
| Lines | 13132 | 13142 | +10 |
+ | Covered | 8447 | 8455 | +8 |
- | Code to Test Ratio | 1:0.4 | 1:0.4 | -0.1 |
| Code | 87381 | 87484 | +103 |
+ | Test | 37420 | 37461 | +41 |Code coverage of files in pull request scope (91.9% → 91.4%)
SDK Configure Bundle Size
Runtime Performance
Type Performance (instantiations)
Reported by octocov |
Summary
downloadStreamanduploadStreammethods to the file runtime wrapper and vitest mockopenDownloadStreamas deprecatedMirrors tailor-platform/function#178.