Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
export type JSONValue =
| string
Expand Down Expand Up @@ -70,7 +69,7 @@ export interface HTTPResponse {
/**
* Http Body
*/
body: string | Buffer | NodeJS.ReadableStream;
body: string | Buffer | ReadableStream;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Non-blocking-

I'm not sure if it matters, but I think the instances of ReadableStream in this file could instead be Readable. And WritableStream could be Writeable. For example:

import {
  Readable, Writable,
} from "stream";
// ...
body: string | Buffer | Readable;
// ...
export interface IFile {
  delete(): Promise<void>;
  createReadStream(): Promise<Readable>;
  createWriteStream(contentType?: string, contentLength?: number): Promise<Writable>;
  toEncodedString(encoding?: string, start?: number, end?: number): Promise<string>;
  toUrl(): Promise<string>;
  toFile(localFilePath: string): Promise<void>;
  toBuffer(): Promise<Buffer>;
  fromReadableStream(readableStream: Readable, contentType?: string, contentSize?: number): Promise<IFile>;

If you call File.fromReadableStream(readStream) with a stream derived from fs.createReadStream(), for example, then the readStream would have the type fs.ReadStream, which extends stream.Readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - I'll follow up on this. Shipping the current change for now to unblock building components

/**
* If true, issue the response when the promise returned is resolved, otherwise issue
* the response at the end of the workflow execution
Expand Down Expand Up @@ -115,13 +114,13 @@ export interface IApi {

export interface IFile {
delete(): Promise<void>;
createReadStream(): Promise<NodeJS.ReadableStream>;
createWriteStream(contentType?: string, contentLength?: number): Promise<NodeJS.WritableStream>;
createReadStream(): Promise<ReadableStream>;
createWriteStream(contentType?: string, contentLength?: number): Promise<WritableStream>;
toEncodedString(encoding?: string, start?: number, end?: number): Promise<string>;
toUrl(): Promise<string>;
toFile(localFilePath: string): Promise<void>;
toBuffer(): Promise<Buffer>;
fromReadableStream(readableStream: NodeJS.ReadableStream, contentType?: string, contentSize?: number): Promise<IFile>;
fromReadableStream(readableStream: ReadableStream, contentType?: string, contentSize?: number): Promise<IFile>;
fromFile(localFilePath: string, contentType?: string): Promise<IFile>;
fromUrl(url: string, options?: any): Promise<IFile>;
toJSON(): any;
Expand Down
1 change: 1 addition & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"lib": ["es6"],
"strictFunctionTypes": true,
"strictNullChecks": true,
"skipLibCheck": true, /* Skip type checking of declaration files in node_modules. */
"baseUrl": ".",
"paths": { "@pipedream/types": ["."] }
},
Expand Down
Loading