Skip to content

Improve tasks and batches types, refactor related tests #1943

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

Closed
wants to merge 79 commits into from

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented May 8, 2025

Pull Request

What does this PR do?

Summary by CodeRabbit

  • Documentation

    • Updated usage examples and documentation to reflect new method access patterns for task and batch operations, now accessed via tasks and batches namespaces on the client.
  • New Features

    • Added new TypeScript utility types for improved type safety and flexibility.
    • Expanded and refined task and batch type definitions, including new fields and improved pagination handling.
    • Added customizable default wait options to client configuration.
  • Bug Fixes

    • Improved test utilities and assertions for validating task and batch data structures.
  • Tests

    • Consolidated and enhanced task and batch tests, providing comprehensive coverage for all filter and pagination options.
    • Introduced new test utilities for more robust assertions and promise resolution checks.
    • Removed outdated or redundant test files.

@flevi29
Copy link
Collaborator Author

flevi29 commented May 19, 2025

@Strift I'm having trouble finding names in the documentation for these types https://www.meilisearch.com/docs/reference/api/tasks.
The only reliable place I can get names for these types is the source code.
One thing that is obviously differently named in the documentation is kind -> type, but other than that.. I'm not sure what to rely on.
Can you be more specific?

Copy link

coderabbitai bot commented May 19, 2025

Walkthrough

This update refactors all task and batch management API calls in documentation, code samples, and tests to use the new client.tasks and client.batches namespaces, replacing direct method calls on the client object. Type definitions are modernized for greater flexibility. Tests are consolidated and enhanced, with new utility assertions added.

Changes

File(s) Change Summary
.code-samples.meilisearch.yaml, README.md Updated all task and batch API usage examples to use client.tasks and client.batches namespaces.
src/batch.ts, src/task.ts Refactored method parameter names for clarity and simplified return statements; updated type usage.
src/types/shared.ts, src/types/task_and_batch.ts, src/types/types.ts Added utility types; modernized and unified task/batch type definitions; added new properties to types.
tests/batch.test.ts, tests/task.test.ts, tests/wait_for_task.test.ts Removed legacy test suites for batch, task, and wait-for-task functionalities.
tests/tasks-and-batches.test.ts Introduced a comprehensive new test suite for tasks and batches covering all methods and filter scenarios.
tests/utils/meilisearch-test-utils.ts Added new assertion methods for promises, error responses, and tasks; introduced type-safe object key/entry utilities.
tests/utils/tasks-and-batches.ts Added new utility module with custom assertions for task and batch structures and constants for valid statuses/types.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant Tasks
    participant Batches

    User->>Client: client.tasks.getTasks(query)
    Client->>Tasks: getTasks(query)
    Tasks-->>Client: TasksResults
    Client-->>User: TasksResults

    User->>Client: client.batches.getBatches(query)
    Client->>Batches: getBatches(query)
    Batches-->>Client: BatchesResults
    Client-->>User: BatchesResults
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Update documentation and code samples to use correct client.tasks and client.batches namespaces (#1944)
Ensure all task-related API references and examples are accurate for v0.50.0+ (#1944)
Remove outdated or incorrect test and usage patterns for task and batch APIs (#1944)

Poem

A hop, a skip, a namespace leap,
Tasks and batches now run deep!
From samples, docs, to types anew,
All paths are clear, all tests in view.
With every change, a tidy sweep—
🐇 The codebase fresh, the docs complete!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
src/task.ts (1)

109-134: ⚠️ Potential issue

Potential timeout handle leak – clear the timer in a finally block

clearTimeout(toId) is only invoked on the fast-path where the task leaves the
enqueued|processing states.
If the polling loop throws for a different reason (network error, 404, etc.),
or if a timeout error is re-thrown, the pending timer is left dangling until
Node’s event loop exits – a minor but avoidable resource leak.

-    try {
+    try {
       for (;;) {
         …
       }
-    } catch (error) {
+    } catch (error) {-    }
+    } finally {
+      if (toId !== undefined) clearTimeout(toId);
+    }
♻️ Duplicate comments (1)
README.md (1)

466-466: 🛠️ Refactor suggestion

Update the return type names in documentation to match implementation.

The documentation still references old type names like EnqueuedTask but according to the PR objectives and past review comments, these should be updated to match the new type names like SummarizedTaskView.

-client.index('myIndex').addDocuments(documents: Document<T>[]): Promise<EnqueuedTask>
+client.index('myIndex').addDocuments(documents: Document<T>[]): Promise<SummarizedTaskPromise>

-client.index('myIndex').deleteAllDocuments(): Promise<Types.EnqueuedTask>
+client.index('myIndex').deleteAllDocuments(): Promise<Types.SummarizedTaskPromise>

-client.tasks.deleteTasks(parameters: DeleteTasksQuery = {}): Promise<EnqueuedTask>
+client.tasks.deleteTasks(parameters: TaskDeletionOrCancelationQuery = {}): Promise<SummarizedTaskPromise>

Also applies to: 527-527, 546-546

🧹 Nitpick comments (8)
tests/tasks-and-batches.test.ts (2)

174-175: Improve comment clarity

The comment "this is the only way to get batch uids at the moment of writing this" lacks context. Consider expanding it to explain why batch UIDs are only available through this method and whether this is expected to change in the future.


211-248: Consider adding error case testing

While the happy path for cancel and delete tasks is well tested, the suite doesn't appear to test error conditions or edge cases with invalid parameters. Consider adding tests for scenarios like:

  • Invalid filter values
  • Non-existent tasks
  • Permissions issues
tests/utils/meilisearch-test-utils.ts (1)

152-153: Consider making the property count check more flexible

The task validation includes a hard-coded check for 11-12 properties. This approach might be brittle if the TaskView type is updated in the future. Consider using a more adaptable approach that won't break with minor property additions or removals.

-    vitestAssert(length >= 11 && length <= 12);
+    // Ensure task has at least all required properties
+    const requiredProperties = ['indexUid', 'status', 'type', 'enqueuedAt', 
+                              'uid', 'batchUid', 'canceledBy', 'error', 
+                              'duration', 'startedAt', 'finishedAt'];
+    for (const prop of requiredProperties) {
+      vitestAssert.property(task, prop);
+    }
src/types/task_and_batch.ts (1)

166-172: Results<T> is public but not exported – consider explicit export

Results<T> looks like a reusable helper for any cursor-style endpoint.
Declaring it as type Results<T> without the export keyword keeps it file-local, yet it is referenced by the exported aliases AllTasks and AllBatches.

While TypeScript allows re-export through those aliases, making Results itself exported improves discoverability and lets downstream users leverage the utility directly.

-type Results<T> = {
+export type Results<T> = {
src/task.ts (2)

143-152: waitForTasksIter processes tasks sequentially – consider parallel waits

The generator awaits each task one after another, which can be slow when many
tasks are in flight. A light refactor can run the polling concurrently and
yield results as soon as each completes, preserving back-pressure while cutting
total wait time.

If backwards-compatibility allows, Promise.allSettled or a simple pool of
waitForTask promises would achieve this.


50-56: Minor: inline arrow function reduces readability

getTaskUid is concise but its multi-line ternary coupled with an implicit
return hampers readability. A classic if statement or single-line arrow
would be clearer.

-const getTaskUid = (
-  taskUidOrSummarizedTask: TaskUidOrSummarizedTaskView,
-): number =>
-  typeof taskUidOrSummarizedTask === "number"
-    ? taskUidOrSummarizedTask
-    : taskUidOrSummarizedTask.taskUid;
+function getTaskUid(
+  task: TaskUidOrSummarizedTaskView,
+): number {
+  return typeof task === "number" ? task : task.taskUid;
+}
src/indexes.ts (2)

242-249: Parameter order of Index.create is error-prone

create(uid, options, config) places config last, while most factory
helpers in the code-base accept (config, …others). The current ordering
makes accidental omission of options easy and can lead to a runtime “config
undefined” bug.

If changing the signature is within scope, prefer

static create(config: Config, uid: string, options: IndexOptions = {})

to align with the other constructors.


390-404: addDocumentsInBatches returns an array but omits type safety on length

The method returns SummarizedTaskPromise[] but provides no hint about how
many promises correspond to the input array. Consider returning a tuple with a
batchSize field or exposing a helper that Promise.alls them to keep the UX
simple.

Not blocking, but worth brainstorming for a future DX enhancement.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 77505c0 and 05d87ec.

📒 Files selected for processing (15)
  • .code-samples.meilisearch.yaml (3 hunks)
  • README.md (2 hunks)
  • src/batch.ts (2 hunks)
  • src/indexes.ts (58 hunks)
  • src/meilisearch.ts (10 hunks)
  • src/task.ts (6 hunks)
  • src/types/shared.ts (1 hunks)
  • src/types/task_and_batch.ts (2 hunks)
  • src/types/types.ts (1 hunks)
  • tests/batch.test.ts (0 hunks)
  • tests/task.test.ts (0 hunks)
  • tests/tasks-and-batches.test.ts (1 hunks)
  • tests/utils/meilisearch-test-utils.ts (4 hunks)
  • tests/utils/tasks-and-batches.ts (1 hunks)
  • tests/wait_for_task.test.ts (0 hunks)
💤 Files with no reviewable changes (3)
  • tests/batch.test.ts
  • tests/wait_for_task.test.ts
  • tests/task.test.ts
🧰 Additional context used
🧬 Code Graph Analysis (5)
tests/tasks-and-batches.test.ts (3)
tests/utils/meilisearch-test-utils.ts (2)
  • getClient (364-364)
  • objectEntries (352-352)
src/types/task_and_batch.ts (1)
  • TasksFilterQuery (63-79)
tests/utils/tasks-and-batches.ts (3)
  • possibleKinds (19-33)
  • possibleStatuses (11-17)
  • assert (162-165)
src/batch.ts (1)
src/types/task_and_batch.ts (3)
  • BatchView (224-233)
  • TasksFilterQuery (63-79)
  • AllBatches (240-240)
tests/utils/meilisearch-test-utils.ts (3)
src/types/types.ts (1)
  • MeiliSearchErrorResponse (754-761)
src/types/task_and_batch.ts (3)
  • TaskView (143-152)
  • Status (33-35)
  • Kind (42-56)
src/http-requests.ts (1)
  • T (199-264)
src/types/task_and_batch.ts (3)
src/types/shared.ts (4)
  • PascalToCamelCase (21-21)
  • OptionStarOrList (27-27)
  • OptionStarOr (25-25)
  • SafeOmit (23-23)
src/types/types.ts (2)
  • Settings (638-668)
  • MeiliSearchErrorResponse (754-761)
src/http-requests.ts (1)
  • T (199-264)
src/task.ts (3)
src/types/task_and_batch.ts (8)
  • SummarizedTaskView (97-103)
  • SummarizedTaskPromise (158-164)
  • WaitOptions (11-26)
  • TaskView (143-152)
  • TaskUidOrSummarizedTaskView (106-108)
  • TasksFilterQuery (63-79)
  • AllTasks (179-179)
  • TaskDeletionOrCancelationQuery (87-90)
src/meilisearch.ts (1)
  • tasks (48-50)
src/http-requests.ts (1)
  • HttpRequests (140-290)
🔇 Additional comments (24)
src/types/types.ts (1)

79-80: LGTM: Good addition of the defaultWaitOptions config property.

The new optional property enhances the configuration options by allowing users to set default wait options globally, improving the task management experience.

.code-samples.meilisearch.yaml (1)

102-104: API restructuring provides better organization for task and batch methods.

All task-related methods (getTasks, getTask, deleteTasks, cancelTasks) have been moved under the tasks namespace, and batch-related methods (getBatches, getBatch) under the batches namespace. This creates a more intuitive API grouping that aligns with the internal restructuring.

Also applies to: 106-107, 108-112, 114-115, 116-117, 118-120, 122-123, 124-125, 126-127, 128-129, 130-131, 461-462, 809-811

src/types/shared.ts (1)

20-27: Great addition of utility types to enhance type safety.

These utility types improve the TypeScript system with:

  • PascalToCamelCase: Useful for type conversions between different naming conventions
  • SafeOmit: A well-named alias for the built-in Omit type
  • OptionStarOr and OptionStarOrList: Flexible type unions that support wildcard options

These types will help create more expressive and safer filtering queries for tasks and batches.

README.md (1)

534-535: Update the method access patterns for tasks and batches.

The documentation now correctly reflects the new API structure where task-related methods are accessed via client.tasks.* and batch-related methods via client.batches.*, matching the implementation changes.

Also applies to: 540-541, 546-547, 552-553, 558-559, 564-565, 584-585, 590-591

src/batch.ts (2)

1-1: Improved type imports to use the new type names.

The import statement now uses the renamed types (BatchView, AllBatches, TasksFilterQuery) that better align with the Meilisearch Rust source code and provide more consistent naming.


17-18: Method signatures updated with improved types and streamlined implementation.

The method signatures have been updated to use the new type names and the implementation has been simplified:

  • getBatch now returns Promise<BatchView> (previously Batch)
  • getBatches accepts TasksFilterQuery (previously TasksOrBatchesQuery) and returns Promise<AllBatches>
  • The implementation is more concise by directly returning the awaited HTTP request

These changes maintain the same functionality while improving type consistency.

Also applies to: 22-23

tests/tasks-and-batches.test.ts (3)

119-146: Test coverage for task operations looks good

The tests for waitForTask and getTask methods thoroughly verify the task structure and the timeout/interval parameters. Good use of spying on setTimeout to verify that the correct interval and timeout values are passed.


149-165: Comprehensive test for concurrent task waiting

The test implementation for waitForTasks correctly validates that multiple tasks can be waited on concurrently and that the returned tasks have the expected structure.


183-209: Well-designed dynamic test generation

The dynamic generation of test cases using describe.for() and test.for() with the filter parameters is an excellent approach. This ensures comprehensive testing of all filter options with minimal code duplication.

tests/utils/meilisearch-test-utils.ts (4)

137-143: Good addition of resolve assertion

The addition of a resolves assertion is a good complement to the existing rejects method and provides balanced testing capabilities for promise resolution in tests.


144-150: Well-structured error response validation

The isErrorResponse assertion properly validates the structure of MeiliSearch error responses with appropriate type checks.


171-199: Thorough status and type validation

The validation of task status and type using objectKeys<Status> and objectKeys<Kind> with oneOf assertions is a strong approach that ensures values match the defined enums. This aligns well with the type renaming objective of the PR.


342-344: Useful type-safe utility function

The objectKeys function provides a type-safe way to extract string literal keys from an object type, which is very useful for working with enum-like types in a type-safe manner.

src/meilisearch.ts (5)

27-27: Type renaming correctly implemented

The import change from EnqueuedTaskPromise to SummarizedTaskPromise aligns with the PR objective to standardize type names.


36-39: Function and type renaming correctly implemented

The updates to import getHttpRequestsWithSummarizedTaskPromise and use HttpRequestsWithSummarizedTaskPromise type are consistent with the PR's renaming strategy.


57-57: Property type correctly updated

The private property type has been updated to match the renamed type.


74-77: Function name correctly updated

The function call has been updated to use the renamed function.


152-452: Return types consistently updated

All method return types (createIndex, updateIndex, deleteIndex, swapIndexes, createDump, createSnapshot) have been consistently updated to use SummarizedTaskPromise, maintaining type consistency across the codebase.

tests/utils/tasks-and-batches.ts (5)

11-33: Well-defined constants for enum values

The definition of possibleStatuses and possibleKinds as constants derived from type definitions is excellent. This approach ensures that the test utilities stay in sync with the actual type definitions, and provides a source of truth for validating enum values in tests.


36-49: Thorough summarized task validation

The isSummarizedTask assertion provides a comprehensive validation of the SummarizedTaskView type structure, properly checking all required properties and their types.


51-145: Comprehensive batch validation

The isBatch assertion is thorough and validates the complex nested structure of batch objects, including proper handling of nullable fields and detailed validation of nested objects.


147-159: Clear result validation

The isResult assertion properly validates the structure of paginated results, including appropriate checks for nullable fields.


162-165: Smart composition of assertions

The approach of combining the external assertions with custom assertions creates a unified API that's easy to use in tests. This is a clean pattern that keeps the code organized.

src/types/task_and_batch.ts (1)

42-56: Double-check the literal for the new “UpgradeDatabase” kind

Great to see the new kind being exposed.
The public API currently documents a task type named databaseUpgrade (all lower-camel case). In Rust it is indeed written UpgradeDatabase, but the HTTP payload that the JS client receives must match the wire format. Please confirm that Meilisearch actually serialises this variant to the string upgradeDatabase (lower-camel) before shipping – otherwise the type‐level transformation will mis-match and Kind will accept a value the server never returns.

If the payload is upgradeDatabase, append it to the union and drop "UpgradeDatabase"; if both can appear, accept both at the type level.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 05d87ec and fddd1e3.

📒 Files selected for processing (1)
  • tests/tasks-and-batches.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/tasks-and-batches.test.ts (3)
tests/utils/meilisearch-test-utils.ts (2)
  • getClient (364-364)
  • objectEntries (352-352)
src/types/task_and_batch.ts (1)
  • TasksFilterQuery (63-79)
tests/utils/tasks-and-batches.ts (3)
  • possibleKinds (19-33)
  • possibleStatuses (11-17)
  • assert (162-165)

@flevi29
Copy link
Collaborator Author

flevi29 commented May 23, 2025

@Strift Should I revert all of the renames? And do the same for the other similar PRs?

@Strift
Copy link
Collaborator

Strift commented May 28, 2025

Hey @flevi29, I think the type vs kind change was the one that struck me the most.

I'm okay with renaming internal types, but anything that is exported should remain unchanged for now.

I'm mentioning this because I'm happy to merge the other changes in this PR as soon as possible, but we can't prioritize any breaking changes now.

@Strift Strift added the documentation Improvements or additions to documentation label May 28, 2025
@flevi29
Copy link
Collaborator Author

flevi29 commented May 28, 2025

Alright, then I think I'm switching the names back. We'll discuss renaming things later.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80095a0 and 9d1287c.

📒 Files selected for processing (3)
  • src/task.ts (2 hunks)
  • tests/tasks-and-batches.test.ts (1 hunks)
  • tests/utils/tasks-and-batches.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/task.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/utils/tasks-and-batches.ts (3)
tests/utils/meilisearch-test-utils.ts (2)
  • objectKeys (353-353)
  • assert (226-229)
src/types/task_and_batch.ts (5)
  • TaskStatus (33-35)
  • TaskType (42-56)
  • EnqueuedTask (97-103)
  • Batch (222-231)
  • TasksResults (177-177)
src/types/shared.ts (1)
  • SafeOmit (23-23)
tests/tasks-and-batches.test.ts (3)
tests/utils/meilisearch-test-utils.ts (3)
  • getClient (364-364)
  • assert (226-229)
  • objectEntries (352-352)
src/types/task_and_batch.ts (1)
  • TasksOrBatchesQuery (63-79)
tests/utils/tasks-and-batches.ts (3)
  • possibleTaskTypes (19-33)
  • possibleTaskStatuses (11-17)
  • assert (162-165)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: integration-tests (Node.js 22)
  • GitHub Check: integration-tests (Node.js 18)
  • GitHub Check: integration-tests (Node.js 20)
🔇 Additional comments (3)
tests/tasks-and-batches.test.ts (1)

1-253: Excellent comprehensive test suite implementation!

This is a well-structured consolidation of the previous separate test files. The implementation demonstrates several good practices:

  • Comprehensive test coverage using dynamic test generation with describe.for/test.for
  • Type-safe test value definitions using satisfies clause
  • Proper use of the new client.tasks and client.batches namespaces
  • Custom assertions for validating complex object structures
  • Good test isolation with beforeAll cleanup

The test value coverage is particularly thorough, testing all query parameters including edge cases with wildcard values.

tests/utils/tasks-and-batches.ts (2)

11-33: Well-implemented type-safe constants for test values.

The use of objectKeys<TaskStatus> and objectKeys<TaskType> provides excellent type safety, ensuring the test constants stay in sync with the actual type definitions. This approach prevents issues when task types or statuses are added or modified.


35-160: Comprehensive and detailed assertion implementations.

The custom assertions provide thorough validation of complex nested objects:

  • isEnqueuedTask: Validates exact object shape and property types
  • isBatch: Handles complex nested structures with optional fields
  • isResult: Validates pagination metadata structure

The assertions appropriately handle nullable fields and provide clear error messages. The validation of batch progress steps and statistics is particularly well-implemented.

@flevi29 flevi29 added maintenance Issue about maintenance (CI, tests, refacto...) and removed breaking-change The related changes are breaking for the users labels May 28, 2025
@flevi29
Copy link
Collaborator Author

flevi29 commented May 28, 2025

@Strift Done.

Co-authored-by: Laurent Cazanove <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/types/task_and_batch.ts (2)

206-211: Good addition of new BatchStats fields with proper documentation.

The new optional fields are well-documented with API links. Consider using more specific types instead of RecordAny if the structure is known, for better type safety.


227-227: Clarify the purpose of the commented field.

The commented batcherStoppedBecause field suggests uncertainty about its inclusion. Consider either removing it entirely or adding a comment explaining why it's commented out (e.g., "Reserved for future API version" or "Field exists but type TBD").

- // batcherStoppedBecause: unknown;
+ // batcherStoppedBecause: unknown; // Reserved for future API version
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7dd3fe and ff1e7e1.

📒 Files selected for processing (2)
  • src/types/task_and_batch.ts (6 hunks)
  • tests/utils/tasks-and-batches.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/utils/tasks-and-batches.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: integration-tests (Node.js 22)
  • GitHub Check: integration-tests (Node.js 20)
  • GitHub Check: integration-tests (Node.js 18)
🔇 Additional comments (7)
src/types/task_and_batch.ts (7)

1-7: LGTM! Good addition of utility types.

The new utility type imports from shared.js will improve type safety and flexibility while maintaining API compatibility.


28-35: Excellent solution for the naming convention issue.

Using PascalToCamelCase wrapper maintains API compatibility while aligning with Rust source naming internally. This addresses the discussion about avoiding breaking changes to exported types.


63-79: Excellent improvement in query type flexibility and accuracy.

The use of OptionStarOr and OptionStarOrList utility types better represents the API's wildcard support, and nullable types improve accuracy. This enhances both type safety and developer experience.


87-90: Good use of SafeOmit for improved type safety.

Replacing Omit with SafeOmit improves type safety while maintaining the same functionality.


111-134: Good expansion of TaskDetails with upgrade-related fields.

The new optional upgradeFrom and upgradeTo fields align with the new "UpgradeDatabase" task type. Non-breaking addition with improved documentation.


164-170: Excellent abstraction with generic Results type.

The generic Results<T> type provides good code reuse and consistency between TasksResults and BatchesResults. This unifies the pagination structure and improves maintainability.

Also applies to: 177-177, 235-235


37-56:

✅ Verification successful

Good consistency with TaskStatus pattern and new task type addition.

The PascalToCamelCase wrapper maintains consistency. The new "UpgradeDatabase" task type appears to be a valid addition.

Please verify that the new "UpgradeDatabase" task type is properly documented in the Meilisearch API:


🌐 Web query:

Does Meilisearch API support "UpgradeDatabase" task type? What version was it introduced?

💡 Result:

Yes, Meilisearch API supports the "UpgradeDatabase" task type. This task type was introduced in Meilisearch version 1.13 as part of the experimental "dumpless upgrade" feature.

The "UpgradeDatabase" task is specifically designed for upgrading Meilisearch databases without the need to create and import dumps, which was previously the only method for upgrading between versions. This task is automatically created when you upgrade from Meilisearch version 1.12 or later to version 1.13 or later using the dumpless upgrade method[1].

How the UpgradeDatabase Task Works

When you perform a dumpless upgrade, the following process occurs:

  1. You stop your current Meilisearch instance
  2. Install the new Meilisearch binary
  3. Relaunch Meilisearch with the same data directory
  4. Meilisearch automatically creates an "UpgradeDatabase" task[1]

The "UpgradeDatabase" task is processed immediately upon launch and cannot be canceled. You can monitor its progress using the tasks API endpoint:

GET /tasks?types=UpgradeDatabase

This will return the task UID, which you can then use to check the specific task status:

GET /tasks/TASK_UID

While the upgrade task is processing, you can still make search queries, and you can even enqueue new tasks. However, Meilisearch will only process these new tasks after the "UpgradeDatabase" task is completed[1].

Limitations and Considerations

The dumpless upgrade feature is experimental and only works when upgrading from Meilisearch version 1.12 or later to version 1.13 or later[1]. For earlier versions, you must still use the dump-based migration process.

Before performing a dumpless upgrade, it's recommended to create a snapshot of your instance as a backup in case the upgrade process fails or results in a corrupted database[1].

Kyethen 1.14, Meilisearch continued to develop its task system with additional features like more granular progress levels for measuring merging operations and displaying database sizes in the batch route[9].

Citations:


Approve TaskType update with “UpgradeDatabase”

Verified that the UpgradeDatabase task type was introduced in Meilisearch v1.13 as part of the dumpless upgrade feature and is supported by the API. The change in src/types/task_and_batch.ts (lines 37–56) aligns with the documented behavior.

  • src/types/task_and_batch.ts (37–56): TaskType now includes "UpgradeDatabase", matching Meilisearch API v1.13+

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love what you did here.

Only quirk is that I find the tests output a bit hard to read. We currently have:

 ✓ tests/tasks-and-batches.test.ts (105 tests) 1261ms
   ✓ waitForTask and getTask methods  648ms
   ✓ waitForTasks method 84ms
   ✓ getBatch method 20ms
   ✓ limit > getTasks method 2ms
   ✓ limit > getBatches method 2ms
   ✓ from > getTasks method 2ms
   ✓ from > getBatches method 2ms
   ✓ reverse > getTasks method 2ms
   ✓ reverse > getBatches method 3ms
   ✓ batchUids > getTasks method 1ms
   ✓ batchUids > getTasks method with * 2ms
   ✓ batchUids > getBatches method 1ms
   ✓ batchUids > getBatches method with * 2ms
   (...)

So, the pattern is currently: "specific field" > "method name (+ with special case)".
I think it would read better if it were: "method name" > "specific field (+ with special case)"

But I'm not sure there's a good way to do this without duplicating or complexifying the code, so we can leave it as is. I just mention it in case you have some magic fix in mind, but don't spend time on this otherwise

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about it, but right now it doesn't seem like a straight forward thing to do. But I'll try to make it more readable however I can in the future.

@flevi29 flevi29 added this pull request to the merge queue May 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch May 28, 2025
@flevi29
Copy link
Collaborator Author

flevi29 commented May 28, 2025

It says "This branch cannot be rebased due to conflicts". It would be nice if it would display those conflicts.
When I rebase manually by accepting my changes the code always gets garbled at some point. I'm really not sure what's going on.
I'm going to open another PR because this is too much of a mess to deal with, I don't really understand what happened that it got to this point.

flevi29 added a commit to flevi29/meilisearch-js that referenced this pull request May 28, 2025
@flevi29
Copy link
Collaborator Author

flevi29 commented May 28, 2025

Closing in favor of #1952

@flevi29 flevi29 closed this May 28, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation maintenance Issue about maintenance (CI, tests, refacto...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Outdated API reference and code samples
2 participants