cloudinary-community / cloudinary-community/next-cloudinary

Type Mismatch in onQueuesEnd Callback: returns a single file Instead of an array of files

Open
#569 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
300
Forks
137
Avg merge
3m
Merged PRs (30d)
2

Description

# **Bug Report**

## **Describe the bug**

The onQueuesEnd callback is expected to return a single file's information according to its assigned type, but instead, it returns an array of files. This results in a type mismatch when logging the results from onQueuesEnd, as the actual output is an array, not a single file.

## **Is this a regression?**

No, this is the first time using next-cloudinary, so it's unclear if this behavior existed in previous versions.

## **Steps To Reproduce the error**

1. Add a console.log statement to log the output of onQueuesEnd.
2. Observe the type declared for onQueuesEnd in the codebase.
3. Compare the console output to the expected type declaration.
4. Notice that onQueuesEnd returns an array of files, not a single file's information.

## **Expected behaviour**

The onQueuesEnd callback should return a result in the format of results.info.files, consistent with the declared type (an array of files) instead of a single file.

## **Screenshot or Video Recording**

Images of the declared type:
![image](https://github.com/user-attachments/assets/20eec063-6490-43a0-8181-ac2689846da0)
![image](https://github.com/user-attachments/assets/304b48dc-e707-4a8a-8dbc-d4a7af2ef7cb)

Image of the console output:
![image](https://github.com/user-attachments/assets/f5b0ca03-4bdb-452f-a7b1-c3ddc741c253)

## **Additional context**

I am currently using Zod to validate the results returned from onQueuesEnd.

```tsx
{
if (results.info === undefined || typeof results.info === 'string') {
return;
}
const fileSchema = z.object({
uploadInfo: z.object({
width: z.number(),
height: z.number(),
asset_id: z.string(),
format: z.string(),
secure_url: z.string(),
original_filename: z.string(),
public_id: z.string(),
// declare more fields here if needed
}),
});

const onQueuesEndResultsSchema = z.object({
info: z.object({
files: z.array(fileSchema),
}),
});

const validationResult =
onQueuesEndResultsSchema.safeParse(results);
if (!validationResult.success) {
console.error('Invalid results structure', validationResult.error);
} else {
console.log('Valid results structure', validationResult.data);
}
}}
>
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.