Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 15 additions & 8 deletions types/cloudinary_ts_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,48 +411,55 @@ cloudinary.v2.api.resources(
}
);

// $ExpectType Promise<any>
// $ExpectType Promise<ResourceApiResponse>
cloudinary.v2.api.resources_by_context("mycontextkey", "mycontextvalue",
{resource_type: 'video'}, function (error, result) {
console.log(result, error);
});

// $ExpectType Promise<any>
// $ExpectType Promise<ResourceApiResponse>
cloudinary.v2.api.resources_by_context("mycontextkey",
function (error, result) {
console.log(result, error);
});

// $ExpectType Promise<any>
// $ExpectType Promise<ResourceApiResponse>
cloudinary.v2.api.resources_by_ids(["user_photo_1", "user_photo_2"],
function (error, result) {
console.log(result, error);
});

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

// $ExpectType Promise<any>
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<ResourceApiResponse>
cloudinary.v2.api.resources_by_moderation('webpurify', 'approved',
function (error, result) {
console.log(result, error);
});

// $ExpectType Promise<any>
// $ExpectType Promise<ResourceApiResponse>
cloudinary.v2.api.resources_by_moderation('manual', 'pending',
function (error, result) {
console.log(result, error);
});

// $ExpectType Promise<any>
// $ExpectType Promise<ResourceApiResponse>
cloudinary.v2.api.resources_by_tag("mytag",
{resource_type: 'raw'},
function (error, result) {
console.log(result, error);
});

// $ExpectType Promise<any>
// $ExpectType Promise<ResourceApiResponse>
cloudinary.v2.api.resources_by_tag("mytag",
function (error, result) {
console.log(result, error);
Expand Down
60 changes: 50 additions & 10 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,46 @@ declare module 'cloudinary' {
class UploadStream extends Transform {
}

export interface ResourceApiResponse {
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<string>;
context: object;
next_cursor: string;
derived_next_cursor: string;
exif: object;
image_metadata: object;
faces: number[][];
quality_analysis: number;
colors: string[][];
derived: Array<string>;
moderation: object;
phash: string;
predominant: object;
coordinates: object;
access_control: Array<string>;
pages: number;

[futureKey: string]: any;
}
]
}


export namespace v2 {

/****************************** Global Utils *************************************/
Expand Down Expand Up @@ -685,25 +725,25 @@ declare module 'cloudinary' {

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

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

function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise<any>;
function resources_by_context(key: string, value?: string, options?: AdminAndResourceOptions): Promise<ResourceApiResponse>;

function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise<any>;
function resources_by_context(key: string, options?: AdminAndResourceOptions): Promise<ResourceApiResponse>;

function resources_by_context(key: string, callback?: ResponseCallback): Promise<any>;
function resources_by_context(key: string, callback?: ResponseCallback): Promise<ResourceApiResponse>;

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

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

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

function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise<any>;
function resources_by_moderation(moderation: ModerationKind, status: Status, callback?: ResponseCallback): Promise<ResourceApiResponse>;

function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;
function resources_by_tag(tag: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<ResourceApiResponse>;

function resources_by_tag(tag: string, callback?: ResponseCallback): Promise<any>;
function resources_by_tag(tag: string, callback?: ResponseCallback): Promise<ResourceApiResponse>;

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

Expand Down