Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace array return types from api to object #703

Open
norkunas opened this issue Dec 9, 2024 · 2 comments
Open

Replace array return types from api to object #703

norkunas opened this issue Dec 9, 2024 · 2 comments
Labels
breaking-change The related changes are breaking for the users enhancement New feature or request

Comments

@norkunas
Copy link
Collaborator

norkunas commented Dec 9, 2024

Description
Currently all enqueued tasks are returned as an array without defined structure, so basically we cannot be sure that is safe to access any data from it.
As I've seen structure can differ per task status, but I could be mistaken.
This idea came up to my mind after I've seen https://github.com/meilisearch/meilisearch-js/blob/main/src/enqueued-task.ts

Basic example

class EnqueuedTask implements \ArrayAccess
{
  private int $taskUid;
  private string indexUid;
  private string $status; //  'succeeded'|'processing'|'failed'|'enqueued'|'canceled'; // this could be class constants and later migrated to enums after bumping up php requirement to 8+
  private string $type; // ...
  private DateTimeImmutable $enqueuedAt;
}

This could act as a base, and if response data is really different per task status, then we could extend this object into many ones with more additional information. another approach of course would be just add all data to EnqueuedTask and for consumers to check status before accessing it

Other
This is related to #573

To break things less the returned lets say EnqueuedTask object could implement the ArrayAccess interface so array access would still work, it would just break things if someone has extended any of Endpoint classes.

@norkunas norkunas added enhancement New feature or request breaking-change The related changes are breaking for the users labels Dec 9, 2024
@brunoocasali
Copy link
Member

We could make this change and also move on to the minimum supported PHP version to 8.0, WDYT?

@norkunas
Copy link
Collaborator Author

I'd even say 8.1 or 8.2 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants