Skip to content

Commit ba15b50

Browse files
authored
updated promise types for resources methods (#358)
* updated types for resources promises
1 parent 2c9cc5b commit ba15b50

File tree

2 files changed

+65
-18
lines changed

2 files changed

+65
-18
lines changed

types/cloudinary_ts_spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,48 +411,55 @@ cloudinary.v2.api.resources(
411411
}
412412
);
413413

414-
// $ExpectType Promise<any>
414+
// $ExpectType Promise<ResourceApiResponse>
415415
cloudinary.v2.api.resources_by_context("mycontextkey", "mycontextvalue",
416416
{resource_type: 'video'}, function (error, result) {
417417
console.log(result, error);
418418
});
419419

420-
// $ExpectType Promise<any>
420+
// $ExpectType Promise<ResourceApiResponse>
421421
cloudinary.v2.api.resources_by_context("mycontextkey",
422422
function (error, result) {
423423
console.log(result, error);
424424
});
425425

426-
// $ExpectType Promise<any>
426+
// $ExpectType Promise<ResourceApiResponse>
427427
cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"],
428428
function (error, result) {
429429
console.log(result, error);
430430
});
431431

432-
// $ExpectType Promise<any>
432+
// $ExpectType Promise<ResourceApiResponse>
433433
cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"],
434434
{resource_type: 'video'},);
435435

436-
// $ExpectType Promise<any>
436+
cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"], {
437+
context: true,
438+
tags: true,
439+
}).then((result) => {
440+
console.log(result.resources[0].public_id);
441+
})
442+
443+
// $ExpectType Promise<ResourceApiResponse>
437444
cloudinary.v2.api.resources_by_moderation('webpurify', 'approved',
438445
function (error, result) {
439446
console.log(result, error);
440447
});
441448

442-
// $ExpectType Promise<any>
449+
// $ExpectType Promise<ResourceApiResponse>
443450
cloudinary.v2.api.resources_by_moderation('manual', 'pending',
444451
function (error, result) {
445452
console.log(result, error);
446453
});
447454

448-
// $ExpectType Promise<any>
455+
// $ExpectType Promise<ResourceApiResponse>
449456
cloudinary.v2.api.resources_by_tag("mytag",
450457
{resource_type: 'raw'},
451458
function (error, result) {
452459
console.log(result, error);
453460
});
454461

455-
// $ExpectType Promise<any>
462+
// $ExpectType Promise<ResourceApiResponse>
456463
cloudinary.v2.api.resources_by_tag("mytag",
457464
function (error, result) {
458465
console.log(result, error);

types/index.d.ts

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,46 @@ declare module 'cloudinary' {
555555
class UploadStream extends Transform {
556556
}
557557

558+
export interface ResourceApiResponse {
559+
resources: [
560+
{
561+
public_id: string;
562+
format: string;
563+
version: number;
564+
resource_type: string;
565+
type: string;
566+
placeholder: boolean;
567+
created_at: string;
568+
bytes: number;
569+
width: number;
570+
height: number;
571+
backup: boolean;
572+
access_mode: string;
573+
url: string;
574+
secure_url: string;
575+
tags: Array<string>;
576+
context: object;
577+
next_cursor: string;
578+
derived_next_cursor: string;
579+
exif: object;
580+
image_metadata: object;
581+
faces: number[][];
582+
quality_analysis: number;
583+
colors: string[][];
584+
derived: Array<string>;
585+
moderation: object;
586+
phash: string;
587+
predominant: object;
588+
coordinates: object;
589+
access_control: Array<string>;
590+
pages: number;
591+
592+
[futureKey: string]: any;
593+
}
594+
]
595+
}
596+
597+
558598
export namespace v2 {
559599

560600
/****************************** Global Utils *************************************/
@@ -685,25 +725,25 @@ declare module 'cloudinary' {
685725

686726
function resources(options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;
687727

688-
function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;
728+
function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<ResourceApiResponse>;
689729

690-
function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise<any>;
730+
function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise<ResourceApiResponse>;
691731

692-
function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise<any>;
732+
function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise<ResourceApiResponse>;
693733

694-
function resources_by_context(key: string, callback?: ResponseCallback): Promise<any>;
734+
function resources_by_context(key: string, callback?: ResponseCallback): Promise<ResourceApiResponse>;
695735

696-
function resources_by_ids(public_ids: string[], options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;
736+
function resources_by_ids(public_ids: string[] | string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<ResourceApiResponse>;
697737

698-
function resources_by_ids(public_ids: string[], callback?: ResponseCallback): Promise<any>;
738+
function resources_by_ids(public_ids: string[] | string, callback?: ResponseCallback): Promise<ResourceApiResponse>;
699739

700-
function resources_by_moderation(moderation: ModerationKind, status: Status, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;
740+
function resources_by_moderation(moderation: ModerationKind, status: Status, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<ResourceApiResponse>;
701741

702-
function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise<any>;
742+
function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise<ResourceApiResponse>;
703743

704-
function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;
744+
function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<ResourceApiResponse>;
705745

706-
function resources_by_tag(tag: string, callback?: ResponseCallback): Promise<any>;
746+
function resources_by_tag(tag: string, callback?: ResponseCallback): Promise<ResourceApiResponse>;
707747

708748
function restore(public_ids: string[], options?: AdminApiOptions | { resource_type: ResourceType, type: DeliveryType }, callback?: ResponseCallback): Promise<any>;
709749

0 commit comments

Comments
 (0)