From 9d5103fc8ca41f6efb6f60c6561f01e920877d24 Mon Sep 17 00:00:00 2001 From: Vlad Klimenkov Date: Tue, 21 Jan 2020 17:10:03 +0300 Subject: [PATCH 1/2] fix: type defs for stream upload methods --- types/index.d.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index a920c762..4a9c7347 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,3 +1,6 @@ +import { Transform } from 'stream'; + + declare module 'cloudinary' { /****************************** Constants *************************************/ @@ -531,6 +534,9 @@ declare module 'cloudinary' { type TargetArchiveFormat = string | "zip" | "tgz"; type ErrorCallBack = (error: any, result: any) => any; + class UploadStream extends Transform { + } + export namespace v2 { /****************************** Global Utils *************************************/ @@ -819,9 +825,9 @@ declare module 'cloudinary' { function unsigned_upload(file: string, upload_preset: string, callback?: ErrorCallBack): Promise; - function unsigned_upload_stream(upload_preset: string, options?: UploadApiOptions, callback?: ErrorCallBack): Promise; + function unsigned_upload_stream(upload_preset: string, options?: UploadApiOptions, callback?: ErrorCallBack): UploadStream; - function unsigned_upload_stream(upload_preset: string, callback?: ErrorCallBack): Promise; + function unsigned_upload_stream(upload_preset: string, callback?: ErrorCallBack): UploadStream; function upload(file: string, options?: UploadApiOptions, callback?: ErrorCallBack): Promise; @@ -831,15 +837,15 @@ declare module 'cloudinary' { function upload_chunked(path: string, callback?: ErrorCallBack): Promise; - function upload_chunked_stream(options?: UploadApiOptions, callback?: ErrorCallBack): Promise; + function upload_chunked_stream(options?: UploadApiOptions, callback?: ErrorCallBack): UploadStream; function upload_large(path: string, options?: UploadApiOptions, callback?: ErrorCallBack): Promise; function upload_large(path: string, callback?: ErrorCallBack): Promise; - function upload_stream(options?: UploadApiOptions, callback?: ErrorCallBack): Promise; + function upload_stream(options?: UploadApiOptions, callback?: ErrorCallBack): UploadStream; - function upload_stream(callback?: ErrorCallBack): Promise; + function upload_stream(callback?: ErrorCallBack): UploadStream; function upload_tag_params(options?: UploadApiOptions, callback?: ErrorCallBack): Promise; From 41bc0ef210d3ecc0e6fa54de420d5eac2a546115 Mon Sep 17 00:00:00 2001 From: Vlad Klimenkov Date: Fri, 24 Jan 2020 01:27:37 +0300 Subject: [PATCH 2/2] test: update upload_stream testcase to expect UploadStream type --- package.json | 1 + types/cloudinary_ts_spec.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index aca70bc1..91995823 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "typescript": "^2.9.2" }, "devDependencies": { + "@types/node": "^13.5.0", "babel-cli": "^6.26.0", "babel-core": "^6.26.3", "babel-plugin-transform-runtime": "^6.23.0", diff --git a/types/cloudinary_ts_spec.ts b/types/cloudinary_ts_spec.ts index c248fd87..c13f9989 100644 --- a/types/cloudinary_ts_spec.ts +++ b/types/cloudinary_ts_spec.ts @@ -764,7 +764,7 @@ cloudinary.v2.uploader.remove_tag('12', ['11'], function (err, res) { console.log(err, res); }); -// $ExpectType Promise +// $ExpectType UploadStream cloudinary.v2.uploader.upload_stream( {template: "http://www.example.com/images/"}, function (error, result) {