From 5e0a6715cef96fbeacc3ed6e973bcb4129064c93 Mon Sep 17 00:00:00 2001 From: Raya Straus Date: Sun, 22 Mar 2020 14:15:43 +0200 Subject: [PATCH 1/3] updated types for resources promises --- types/cloudinary_ts_spec.ts | 24 +++++++++++++------- types/index.d.ts | 44 ++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/types/cloudinary_ts_spec.ts b/types/cloudinary_ts_spec.ts index 418cf839..78e29630 100644 --- a/types/cloudinary_ts_spec.ts +++ b/types/cloudinary_ts_spec.ts @@ -411,48 +411,56 @@ cloudinary.v2.api.resources( } ); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_context("mycontextkey", "mycontextvalue", {resource_type: 'video'}, function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_context("mycontextkey", function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], {resource_type: 'video'},); -// $ExpectType Promise +// $ExpectType Promise +cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], { + context: true, + tags: true, +}).then((result) => { + console.log(result.resources[0].public_id); +}) + +// $ExpectType Promise cloudinary.v2.api.resources_by_moderation('webpurify', 'approved', function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_moderation('manual', 'pending', function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_tag("mytag", {resource_type: 'raw'}, function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_tag("mytag", function (error, result) { console.log(result, error); diff --git a/types/index.d.ts b/types/index.d.ts index ace1e6d5..bad1efe6 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -555,6 +555,30 @@ declare module 'cloudinary' { class UploadStream extends Transform { } + export interface Resources { + resources: [ + { + public_id: string; + format: string; + version: number; + resource_type: string; + type: string; + placeholder: boolean; + created_at: string; + bytes: number; + width: number; + height: number; + backup: boolean; + access_mode: string; + url: string; + secure_url: string; + tags: Array; + context?: object; + } + ] + } + + export namespace v2 { /****************************** Global Utils *************************************/ @@ -685,25 +709,25 @@ declare module 'cloudinary' { function resources(options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise; + function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise; - function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise; + function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise; - function resources_by_context(key: string, callback?: ResponseCallback): Promise; + function resources_by_context(key: string, callback?: ResponseCallback): Promise; - function resources_by_ids(public_ids: string[], options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_ids(public_ids: string[] | string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_ids(public_ids: string[], callback?: ResponseCallback): Promise; + function resources_by_ids(public_ids: string[] | string, callback?: ResponseCallback): Promise; - function resources_by_moderation(moderation: ModerationKind, status: Status, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_moderation(moderation: ModerationKind, status: Status, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise; + function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise; - function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_tag(tag: string, callback?: ResponseCallback): Promise; + function resources_by_tag(tag: string, callback?: ResponseCallback): Promise; function restore(public_ids: string[], options?: AdminApiOptions | { resource_type: ResourceType, type: DeliveryType }, callback?: ResponseCallback): Promise; From 637d9aad249f42a8eaf513de23ed1ba5134d52dc Mon Sep 17 00:00:00 2001 From: Raya Straus Date: Sun, 22 Mar 2020 14:26:14 +0200 Subject: [PATCH 2/3] update test --- types/cloudinary_ts_spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/cloudinary_ts_spec.ts b/types/cloudinary_ts_spec.ts index 78e29630..f11cd558 100644 --- a/types/cloudinary_ts_spec.ts +++ b/types/cloudinary_ts_spec.ts @@ -433,7 +433,6 @@ cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], {resource_type: 'video'},); -// $ExpectType Promise cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], { context: true, tags: true, From 044e3279c6337379dffcc2e50d6a15c437bcce66 Mon Sep 17 00:00:00 2001 From: Raya Straus Date: Mon, 23 Mar 2020 16:40:26 +0200 Subject: [PATCH 3/3] Updated name and added resources result --- types/cloudinary_ts_spec.ts | 16 +++++++-------- types/index.d.ts | 40 ++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/types/cloudinary_ts_spec.ts b/types/cloudinary_ts_spec.ts index f11cd558..7f6c87a5 100644 --- a/types/cloudinary_ts_spec.ts +++ b/types/cloudinary_ts_spec.ts @@ -411,25 +411,25 @@ cloudinary.v2.api.resources( } ); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_context("mycontextkey", "mycontextvalue", {resource_type: 'video'}, function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_context("mycontextkey", function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], {resource_type: 'video'},); @@ -440,26 +440,26 @@ cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], { console.log(result.resources[0].public_id); }) -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_moderation('webpurify', 'approved', function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_moderation('manual', 'pending', function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_tag("mytag", {resource_type: 'raw'}, function (error, result) { console.log(result, error); }); -// $ExpectType Promise +// $ExpectType Promise cloudinary.v2.api.resources_by_tag("mytag", function (error, result) { console.log(result, error); diff --git a/types/index.d.ts b/types/index.d.ts index bad1efe6..2ac8051d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -555,7 +555,7 @@ declare module 'cloudinary' { class UploadStream extends Transform { } - export interface Resources { + export interface ResourceApiResponse { resources: [ { public_id: string; @@ -573,7 +573,23 @@ declare module 'cloudinary' { url: string; secure_url: string; tags: Array; - context?: object; + context: object; + next_cursor: string; + derived_next_cursor: string; + exif: object; + image_metadata: object; + faces: number[][]; + quality_analysis: number; + colors: string[][]; + derived: Array; + moderation: object; + phash: string; + predominant: object; + coordinates: object; + access_control: Array; + pages: number; + + [futureKey: string]: any; } ] } @@ -709,25 +725,25 @@ declare module 'cloudinary' { function resources(options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise; + function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise; - function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise; + function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise; - function resources_by_context(key: string, callback?: ResponseCallback): Promise; + function resources_by_context(key: string, callback?: ResponseCallback): Promise; - function resources_by_ids(public_ids: string[] | string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_ids(public_ids: string[] | string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_ids(public_ids: string[] | string, callback?: ResponseCallback): Promise; + function resources_by_ids(public_ids: string[] | string, callback?: ResponseCallback): Promise; - function resources_by_moderation(moderation: ModerationKind, status: Status, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_moderation(moderation: ModerationKind, status: Status, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise; + function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise; - function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; - function resources_by_tag(tag: string, callback?: ResponseCallback): Promise; + function resources_by_tag(tag: string, callback?: ResponseCallback): Promise; function restore(public_ids: string[], options?: AdminApiOptions | { resource_type: ResourceType, type: DeliveryType }, callback?: ResponseCallback): Promise;