Skip to content

Commit 1b2e22b

Browse files
authored
feat(types): add downloadStream and uploadStream types to TailorDBFileAPI (#178)
1 parent bcb684b commit 1b2e22b

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

.changeset/witty-lands-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tailor-platform/function-types": minor
3+
---
4+
5+
Add `downloadStream` and `uploadStream` types to `TailorDBFileAPI`. Mark `openDownloadStream` as deprecated.

packages/types/tailor.d.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ interface FileUploadOptions {
166166
contentType?: string;
167167
}
168168

169+
/**
170+
* Upload stream options interface
171+
*/
172+
interface FileUploadStreamOptions {
173+
contentType?: string;
174+
fileSize?: number;
175+
}
176+
169177
/**
170178
* Upload response interface
171179
*/
@@ -189,6 +197,14 @@ interface FileDownloadAsBase64Response {
189197
metadata: DownloadMetadata;
190198
}
191199

200+
/**
201+
* Download stream response interface
202+
*/
203+
interface FileDownloadStreamResponse {
204+
body: ReadableStream<Uint8Array>;
205+
metadata: DownloadMetadata;
206+
}
207+
192208
/**
193209
* Stream chunk types
194210
*/
@@ -223,7 +239,7 @@ interface TailorDBFileAPI {
223239

224240
/**
225241
* Download a file from TailorDB
226-
* @throws {TailorDBFileError} FILE_TOO_LARGE if file exceeds 10MB - use openDownloadStream() for large files
242+
* @throws {TailorDBFileError} FILE_TOO_LARGE if file exceeds 10MB - use downloadStream() for large files
227243
*/
228244
download(
229245
namespace: string,
@@ -237,7 +253,7 @@ interface TailorDBFileAPI {
237253
* Unlike download which returns decoded binary data (Uint8Array),
238254
* this returns the raw Base64-encoded string for use cases requiring
239255
* Base64 format (e.g., embedding in JSON responses, data URIs)
240-
* @throws {TailorDBFileError} FILE_TOO_LARGE if file exceeds 10MB - use openDownloadStream() for large files
256+
* @throws {TailorDBFileError} FILE_TOO_LARGE if file exceeds 10MB - use downloadStream() for large files
241257
*/
242258
downloadAsBase64(
243259
namespace: string,
@@ -268,13 +284,36 @@ interface TailorDBFileAPI {
268284

269285
/**
270286
* Open a download stream for large files
287+
* @deprecated Use downloadStream() instead
271288
*/
272289
openDownloadStream(
273290
namespace: string,
274291
typeName: string,
275292
fieldName: string,
276293
recordId: string
277294
): Promise<FileStreamIterator>;
295+
296+
/**
297+
* Download a file as a ReadableStream
298+
*/
299+
downloadStream(
300+
namespace: string,
301+
typeName: string,
302+
fieldName: string,
303+
recordId: string
304+
): Promise<FileDownloadStreamResponse>;
305+
306+
/**
307+
* Upload a file using a ReadableStream
308+
*/
309+
uploadStream(
310+
namespace: string,
311+
typeName: string,
312+
fieldName: string,
313+
recordId: string,
314+
readableStream: ReadableStream<Uint8Array | ArrayBuffer>,
315+
options?: FileUploadStreamOptions
316+
): Promise<FileUploadResponse>;
278317
}
279318

280319
declare namespace tailor.idp {

0 commit comments

Comments
 (0)