-
Notifications
You must be signed in to change notification settings - Fork 470
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
Add multi-file write support to the js and python sdks #451
base: main
Are you sure you want to change the base?
Add multi-file write support to the js and python sdks #451
Conversation
🦋 Changeset detectedLatest commit: 724fbc6 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 |
I pushed an edit that should sketch a type cleanup. There are two unfinished parts:
const { path, writeOpts, writeFiles } = typeof pathOrFiles === 'string'
? { path: pathOrFiles, writeFiles: [{ data: dataOrOpts }], writeOpts: opts }
: { path: undefined, writeFiles: pathOrFiles, writeOpts: dataOrOpts }
const blobs = await Promise.all(writeFiles.map(f => new Response(f.data).blob()))
return files.length === 1 ? files[0] : files Some edits I did:
Also, your previous code was mostly correct; this is more of an improvement. |
I also think the Let's keep it in the envd API though, because one of the uses was that you can use it to ensure that the path people upload files to is fixated. |
@ValentaTomas I addressed your comments and added extra tests for some edge cases. |
One important thing to note, and I've added it as a code comment, is that we can't expect specified directories in path of multipart filename to be taken into consideration; I've tested it with and sure enough only file name is used as path, the rest of the path is stripped by the std lib's
|
Ok, this is a very good find — how do you think we should handle this? We want to be able to upload files with any path, but the stripping of paths might make sense to preserve, because it allows people to upload by link easily. This might require some changes to the envd. |
If it's really important not to break the current API spec, we could add a custom field to the multipart dataform and look for it with some changes to |
@ValentaTomas I started by adding multi file write support for ConsiderationsI went the |
For the overload I think you can use the same system as we already have with https://github.com/e2b-dev/E2B/blob/beta/packages/python-sdk/e2b/sandbox_sync/process/main.py#L106 It should be the same thing, right? |
I also suggest naming and exporting all the types (from both SDKs). What do you say about having:
|
I'm thinking about what to do when you try to invoke write for multiple files and provide an empty array. Logically, you might want to notify the user that nothing was written, but throwing an error might not be optimal. If you are generating the field to write, you need to explicitly check if the array is empty; otherwise, you will get an error. In contrast to this, isn't writing 0 files a valid operation and you will also get an array with 0 results so everything is ok? |
Yeah, I'm thinking that we should probably do this, because people are already using the Beta SDK. |
From the perpective that there will likely be less control over which files, if any, are generated, your point makes sense. I will allow empty arrays |
Co-authored-by: Vasek Mlejnsky <[email protected]>
Co-authored-by: Vasek Mlejnsky <[email protected]>
Co-authored-by: Vasek Mlejnsky <[email protected]>
Co-authored-by: Vasek Mlejnsky <[email protected]>
Co-authored-by: Vasek Mlejnsky <[email protected]>
Co-authored-by: Vasek Mlejnsky <[email protected]>
Co-authored-by: Vasek Mlejnsky <[email protected]>
These client changes require changes in the envd which is in this PR. This will require us to rebuild our sandbox templates so they have the new envd.
|
Is this waiting for review and ready otherwise? |
It's ready for release and will be once the envd template is built — if I understood the order of things correctly cc @ValentaTomas |
Description
Filesystem.write
method to accept multiple filesenvd
supports multipart with multiple files out of the boxTest