diff --git a/.changeset/remove-all-task-batch-list.md b/.changeset/remove-all-task-batch-list.md new file mode 100644 index 00000000..054bc57f --- /dev/null +++ b/.changeset/remove-all-task-batch-list.md @@ -0,0 +1,5 @@ +--- +"@meilisearch/cli": minor +--- + +**Breaking:** Remove `--all` from `meili task list` and `meili batch list`: an instance can hold millions of tasks. Page with `--limit` and `--from` instead: pass the `next` of each response as the `--from` of the next call, and stop when `next` is `null`. ([#87](https://github.com/meilisearch/cli/pull/87)) diff --git a/docs/contract/commands.md b/docs/contract/commands.md index cadd3d44..f0ec63f9 100644 --- a/docs/contract/commands.md +++ b/docs/contract/commands.md @@ -173,7 +173,7 @@ Commands reuse these groups. A command that matches a group uses the whole group |---|---| | `--limit ` | Passed to the API. | | `--offset ` or `--from ` | Passed to the API. The name is the API parameter name for that route. | -| `--all` | Fetch every page, and print them as one list. `document list` has no `--all`: an index can hold millions of documents. On `document delete`, select the route that deletes every document. | +| `--all` | Fetch every page, and print them as one list. `document list`, `task list` and `batch list` have no `--all`: an index can hold millions of documents, and an instance millions of tasks and batches. On `document delete`, select the route that deletes every document. | **Body input** (commands that send a JSON body): diff --git a/docs/contract/output.md b/docs/contract/output.md index 99ab5319..16655519 100644 --- a/docs/contract/output.md +++ b/docs/contract/output.md @@ -151,7 +151,7 @@ Destructive commands are the commands of the verb `delete`, as `commands.md` der ## Pagination - `--limit` and `--offset` (or `--from` for tasks and batches) are passed to the API unchanged. -- `--all` follows the API pagination until the end. The CLI returns the envelope of the last page, with `results` replaced by the full list and without the fields that describe one page: `limit` and `offset`, or `limit` and `from` on the routes that page with a cursor. +- `--all` follows the API pagination until the end. The CLI returns the envelope of the last page, with `results` replaced by the full list and without the fields that describe one page: `limit` and `offset`. Tasks and batches have no `--all`: an instance can hold millions of them. - The list commands of the Management API do not offer these flags yet. The Management API numbers its pages instead of counting an offset, and the flags wait until the two APIs page the same way. Each command prints the first page as the API sends it, envelope included. ## Help diff --git a/oclif.manifest.json b/oclif.manifest.json index d2fa9fb7..d23d5622 100644 --- a/oclif.manifest.json +++ b/oclif.manifest.json @@ -141,11 +141,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -317,11 +312,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -493,11 +483,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -669,11 +654,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -893,12 +873,6 @@ "helpValue": "", "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "name": "all", - "allowNo": false, - "type": "boolean" } }, "hasDynamicHelp": false, @@ -1010,11 +984,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -1224,11 +1193,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -1401,11 +1365,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -1612,11 +1571,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -1821,11 +1775,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -2007,11 +1956,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -2226,11 +2170,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -2502,11 +2441,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -2810,11 +2744,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -3100,11 +3029,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -3376,11 +3300,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -3615,11 +3534,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -3907,11 +3821,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -4232,11 +4141,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -4435,11 +4339,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -4697,11 +4596,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -4936,11 +4830,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -5164,11 +5053,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -5435,11 +5319,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -5649,11 +5528,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -5854,11 +5728,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -6131,11 +6000,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -6352,11 +6216,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -6580,11 +6439,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -6831,11 +6685,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -7045,11 +6894,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -7288,11 +7132,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -7481,11 +7320,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -7659,11 +7493,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -7874,11 +7703,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -8061,11 +7885,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -8318,11 +8137,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -8528,11 +8342,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -8715,11 +8524,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -8946,11 +8750,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -9142,11 +8941,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -9320,11 +9114,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -9507,11 +9296,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -9693,11 +9477,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -10139,11 +9918,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -10378,11 +10152,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -10809,11 +10578,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -11024,11 +10788,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -11340,11 +11099,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -11573,11 +11327,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -11902,11 +11651,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -12239,11 +11983,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -12463,12 +12202,6 @@ "helpValue": "", "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "name": "all", - "allowNo": false, - "type": "boolean" } }, "hasDynamicHelp": false, @@ -12580,11 +12313,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -12794,11 +12522,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -13008,11 +12731,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -13202,11 +12920,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -13380,11 +13093,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -13604,11 +13312,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -13791,11 +13494,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -13977,11 +13675,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { @@ -14152,11 +13845,6 @@ "input": [], "multiple": false, "type": "option" - }, - "all": { - "description": "Fetch every page, and print them as one list.", - "allowNo": false, - "type": "boolean" } }, "bodyInputFlags": { diff --git a/src/commands/batch/list.ts b/src/commands/batch/list.ts index f75485ae..a530c629 100644 --- a/src/commands/batch/list.ts +++ b/src/commands/batch/list.ts @@ -1,6 +1,5 @@ import { Flags } from "@oclif/core"; import { type Api, BaseCommand } from "../../lib/base-command.js"; -import { nextFromQuery } from "../../lib/pagination.js"; import { batchFilterFlags, batchFilterQuery } from "../../lib/task-filters.js"; export default class BatchList extends BaseCommand { @@ -36,11 +35,12 @@ export default class BatchList extends BaseCommand { ...batchFilterQuery(flags), reverse: flags.reverse ? true : undefined, }; - await this.outputList( - (page) => this.meilisearch.batches.getBatches({ ...filters, ...page }), - { limit: flags.limit, from: flags.from }, - flags.all, - nextFromQuery, + await this.output( + await this.meilisearch.batches.getBatches({ + ...filters, + limit: flags.limit, + from: flags.from, + }), ); } } diff --git a/src/commands/index/list.ts b/src/commands/index/list.ts index 7d4c3836..4c7ba256 100644 --- a/src/commands/index/list.ts +++ b/src/commands/index/list.ts @@ -1,5 +1,4 @@ import { type Api, BaseCommand } from "../../lib/base-command.js"; -import { nextOffsetQuery } from "../../lib/pagination.js"; export default class IndexList extends BaseCommand { static api: Api = "meilisearch"; @@ -26,7 +25,6 @@ export default class IndexList extends BaseCommand { (query) => this.meilisearch.getRawIndexes(query), { limit: flags.limit, offset: flags.offset }, flags.all, - nextOffsetQuery, ); } } diff --git a/src/commands/key/list.ts b/src/commands/key/list.ts index c853dc90..7189cc06 100644 --- a/src/commands/key/list.ts +++ b/src/commands/key/list.ts @@ -2,7 +2,7 @@ import { type Api, BaseCommand } from "../../lib/base-command.js"; import { fetchKeys } from "../../lib/clients/meilisearch.js"; import { defaultView } from "../../lib/human.js"; import { type HumanView, paint } from "../../lib/output.js"; -import { type ListPage, nextOffsetQuery } from "../../lib/pagination.js"; +import type { ListPage } from "../../lib/pagination.js"; /** The length a description keeps in the table, ellipsis included. */ const DESCRIPTION_LENGTH = 30; @@ -34,7 +34,6 @@ The answer is the API body as it is, so it carries the \`key\` field of every ke (query) => fetchKeys(this.meilisearch, query), { limit: flags.limit, offset: flags.offset }, flags.all, - nextOffsetQuery, view, ); } diff --git a/src/commands/task/list.ts b/src/commands/task/list.ts index 52f9dcee..35fa0f35 100644 --- a/src/commands/task/list.ts +++ b/src/commands/task/list.ts @@ -1,6 +1,5 @@ import { Flags } from "@oclif/core"; import { type Api, BaseCommand } from "../../lib/base-command.js"; -import { nextFromQuery } from "../../lib/pagination.js"; import { taskFilterFlags, taskFilterQuery } from "../../lib/task-filters.js"; export default class TaskList extends BaseCommand { @@ -36,11 +35,8 @@ export default class TaskList extends BaseCommand { ...taskFilterQuery(flags), reverse: flags.reverse ? true : undefined, }; - await this.outputList( - (page) => this.meilisearch.tasks.getTasks({ ...filters, ...page }), - { limit: flags.limit, from: flags.from }, - flags.all, - nextFromQuery, + await this.output( + await this.meilisearch.tasks.getTasks({ ...filters, limit: flags.limit, from: flags.from }), ); } } diff --git a/src/lib/base-command.ts b/src/lib/base-command.ts index 10aa85fa..525c11e7 100644 --- a/src/lib/base-command.ts +++ b/src/lib/base-command.ts @@ -39,7 +39,13 @@ import { writeData, writeView, } from "./output.js"; -import { iteratePages, type ListPage, mergePages } from "./pagination.js"; +import { + iteratePages, + type ListPage, + mergePages, + nextOffsetQuery, + type OffsetQuery, +} from "./pagination.js"; import { credentialsFilePath, readCredentialsFile, @@ -66,11 +72,8 @@ export type GlobalFlags = Interfaces.InferredFlags< typeof BaseCommand.syncWithCloudFlags >; -/** The two flags a list route declares whichever way it pages, shared by both groups below. */ +/** `--limit`, which a list route declares whichever way it pages, shared by both groups below. */ const LIMIT_FLAG = Flags.integer({ description: "Passed to the API.", helpValue: "" }); -const ALL_FLAG = Flags.boolean({ - description: "Fetch every page, and print them as one list.", -}); export interface WaitFlagValues { wait?: boolean | undefined; @@ -200,13 +203,14 @@ export abstract class BaseCommand extends Command { static paginationFlags = { limit: LIMIT_FLAG, offset: Flags.integer({ description: "Passed to the API.", helpValue: "" }), - all: ALL_FLAG, + all: Flags.boolean({ description: "Fetch every page, and print them as one list." }), }; /** * The same group for a route that pages with a cursor rather than an offset: * tasks and batches take `from` and answer `next`. One group per cursor name, * because the contract names the flag after the parameter of its route. + * No `--all`: an instance can hold millions of tasks and batches. */ static fromPaginationFlags = { limit: LIMIT_FLAG, @@ -214,7 +218,6 @@ export abstract class BaseCommand extends Command { description: "Passed to the API: the uid the page starts at, going down.", helpValue: "", }), - all: ALL_FLAG, }; /** Shared group for commands that send a JSON body. */ @@ -403,11 +406,10 @@ export abstract class BaseCommand extends Command { * one envelope. List routes end with this call. `fetchPage` is one API call, * returning the API body as it is. `view` is the text for a human, as in `output`. */ - protected async outputList( - fetchPage: (query: Q) => Promise, - query: Q, + protected async outputList( + fetchPage: (query: OffsetQuery) => Promise, + query: OffsetQuery, all: boolean, - nextQuery: (query: Q, page: ListPage) => Q | undefined, view?: (page: ListPage) => HumanView, ): Promise { if (!all) { @@ -415,7 +417,7 @@ export abstract class BaseCommand extends Command { return; } const pages: ListPage[] = []; - for await (const page of iteratePages(fetchPage, query, nextQuery)) pages.push(page); + for await (const page of iteratePages(fetchPage, query, nextOffsetQuery)) pages.push(page); await this.output(mergePages(pages), view); } diff --git a/src/lib/pagination.ts b/src/lib/pagination.ts index 3a1274c8..62a1acdb 100644 --- a/src/lib/pagination.ts +++ b/src/lib/pagination.ts @@ -1,5 +1,5 @@ /** - * Pagination for list routes: `--limit`, `--offset` or `--from`, and `--all`. + * Pagination for list routes: `--limit`, `--offset` and `--all`. * See docs/contract/output.md, section Pagination. */ @@ -11,14 +11,8 @@ export interface OffsetQuery { offset?: number | undefined; } -/** The query of a route that pages with a cursor: tasks and batches. */ -export interface FromQuery { - limit?: number | undefined; - from?: number | undefined; -} - /** The envelope fields that describe one page rather than the whole list. */ -const PAGE_FIELDS = ["limit", "offset", "from"]; +const PAGE_FIELDS = ["limit", "offset"]; function numberField(page: ListPage, name: string): number { const value = page[name]; @@ -32,16 +26,6 @@ export function nextOffsetQuery(query: OffsetQuery, page: ListPage): OffsetQuery return done ? undefined : { ...query, offset }; } -/** - * The query of the page after `page` on a cursor route: the API answers the - * `from` of the next page in `next`, and a `next` that is not a number, null - * on the last page, ends the walk. - */ -export function nextFromQuery(query: FromQuery, page: ListPage): FromQuery | undefined { - const next = page.next; - return typeof next === "number" ? { ...query, from: next } : undefined; -} - /** The query of a route that pages by number: the Management API's. */ export interface PageQuery { page?: number | undefined; @@ -70,8 +54,7 @@ export async function* iteratePages( /** * The envelope of the last page with `results` replaced by every item and the - * fields that describe one page removed. The others, like `total`, stay. A - * route carries one pair or the other, so dropping all three is dropping its. + * fields that describe one page removed. The others, like `total`, stay. */ export function mergePages(pages: readonly ListPage[]): ListPage { const last = { ...(pages.at(-1) ?? { results: [] }) }; diff --git a/test/commands/batch/__snapshots__/list.test.ts.snap b/test/commands/batch/__snapshots__/list.test.ts.snap index 6e89c52d..52727235 100644 --- a/test/commands/batch/__snapshots__/list.test.ts.snap +++ b/test/commands/batch/__snapshots__/list.test.ts.snap @@ -19,7 +19,7 @@ USAGE [--statuses ] [--after-enqueued-at ] [--before-enqueued-at ] [--after-started-at ] [--before-started-at ] [--after-finished-at ] [--before-finished-at ] [--reverse] - [--limit ] [--from ] [--all] + [--limit ] [--from ] OUTPUT FLAGS --json Print compact JSON. The default when stdout is not a terminal. @@ -35,7 +35,6 @@ FLAGS RFC 3339 format. --after-started-at= Match the tasks started after this date, in RFC 3339 format. - --all Fetch every page, and print them as one list. --before-enqueued-at= Match the tasks enqueued before this date, in RFC 3339 format. --before-finished-at= Match the tasks finished before this date, in diff --git a/test/commands/batch/list.test.ts b/test/commands/batch/list.test.ts index c646d7ab..1b2a76a1 100644 --- a/test/commands/batch/list.test.ts +++ b/test/commands/batch/list.test.ts @@ -6,7 +6,7 @@ import { makeBatch, meilisearchHandlers, } from "../../helpers/meilisearch-handlers.js"; -import { countRequests, recordRequests, server, useMockServer } from "../../helpers/msw.js"; +import { recordRequests, server, useMockServer } from "../../helpers/msw.js"; import { runCli, runCommand } from "../../helpers/run-command.js"; useMockServer(); @@ -80,17 +80,6 @@ describe("meili batch list", () => { }); }); - it("follows the next cursor with --all and merges every page into one envelope", async () => { - server.use(meilisearchHandlers.batches(five)); - let result: Awaited> | undefined; - const requests = await countRequests(async () => { - result = await runCommand(BatchList, ["--all", "--limit", "2", ...project]); - }); - expect(requests).toBe(3); - expect(result?.exitCode).toBe(0); - expect(JSON.parse(result?.stdout ?? "")).toEqual({ results: five, total: 5, next: null }); - }); - it("passes an authentication error through with a hint and exits 3", async () => { server.use(meilisearchHandlers.apiError("/batches", 403, invalidApiKeyError)); const result = await runCommand(BatchList, [...project]); diff --git a/test/commands/task/__snapshots__/list.test.ts.snap b/test/commands/task/__snapshots__/list.test.ts.snap index 29fdd97b..f61eacf0 100644 --- a/test/commands/task/__snapshots__/list.test.ts.snap +++ b/test/commands/task/__snapshots__/list.test.ts.snap @@ -19,7 +19,7 @@ USAGE [--statuses ] [--after-enqueued-at ] [--before-enqueued-at ] [--after-started-at ] [--before-started-at ] [--after-finished-at ] [--before-finished-at ] [--reverse] - [--limit ] [--from ] [--all] + [--limit ] [--from ] OUTPUT FLAGS --json Print compact JSON. The default when stdout is not a terminal. @@ -35,7 +35,6 @@ FLAGS RFC 3339 format. --after-started-at= Match the tasks started after this date, in RFC 3339 format. - --all Fetch every page, and print them as one list. --batch-ids= Match the tasks of these batch uids, comma-separated. \`*\` matches every one. --before-enqueued-at= Match the tasks enqueued before this date, in diff --git a/test/commands/task/list.test.ts b/test/commands/task/list.test.ts index 930b4871..a48fafdb 100644 --- a/test/commands/task/list.test.ts +++ b/test/commands/task/list.test.ts @@ -6,7 +6,7 @@ import { makeTask, meilisearchHandlers, } from "../../helpers/meilisearch-handlers.js"; -import { countRequests, recordRequests, server, useMockServer } from "../../helpers/msw.js"; +import { recordRequests, server, useMockServer } from "../../helpers/msw.js"; import { runCli, runCommand } from "../../helpers/run-command.js"; useMockServer(); @@ -82,17 +82,6 @@ describe("meili task list", () => { }); }); - it("follows the next cursor with --all and merges every page into one envelope", async () => { - server.use(meilisearchHandlers.tasks(five)); - let result: Awaited> | undefined; - const requests = await countRequests(async () => { - result = await runCommand(TaskList, ["--all", "--limit", "2", ...project]); - }); - expect(requests).toBe(3); - expect(result?.exitCode).toBe(0); - expect(JSON.parse(result?.stdout ?? "")).toEqual({ results: five, total: 5, next: null }); - }); - it("passes an authentication error through with a hint and exits 3", async () => { server.use(meilisearchHandlers.apiError("/tasks", 403, invalidApiKeyError)); const result = await runCommand(TaskList, [...project]); diff --git a/test/contract/__snapshots__/commands.test.ts.snap b/test/contract/__snapshots__/commands.test.ts.snap index 6b8886e2..25d9e783 100644 --- a/test/contract/__snapshots__/commands.test.ts.snap +++ b/test/contract/__snapshots__/commands.test.ts.snap @@ -174,11 +174,6 @@ Says whether a session of \`auth login\` exists, whether the authorization serve "name": "from", "type": "option", }, - { - "description": "Fetch every page, and print them as one list.", - "name": "all", - "type": "boolean", - }, ], "id": "batch list", "keyActions": [ @@ -3381,11 +3376,6 @@ Deletes the finished tasks matched by --ids, --statuses, --types and the other f "name": "from", "type": "option", }, - { - "description": "Fetch every page, and print them as one list.", - "name": "all", - "type": "boolean", - }, ], "id": "task list", "keyActions": [ diff --git a/test/integration/meilisearch/batch-list.test.ts b/test/integration/meilisearch/batch-list.test.ts index 4b65651a..e0e9a84f 100644 --- a/test/integration/meilisearch/batch-list.test.ts +++ b/test/integration/meilisearch/batch-list.test.ts @@ -25,7 +25,7 @@ describe.skipIf(!meilisearchUp)("meili batch list against a real Meilisearch", ( }); it("returns the list envelope filtered by --index-ids", async () => { - const result = await runBinary(["batch", "list", "--index-ids", uid, "--all", ...project]); + const result = await runBinary(["batch", "list", "--index-ids", uid, ...project]); expect(result.exitCode).toBe(0); expect(result.stderr).toBe(""); const page = JSON.parse(result.stdout) as { results: Array<{ uid: number }> }; diff --git a/test/integration/meilisearch/task-list.test.ts b/test/integration/meilisearch/task-list.test.ts index 670cdbcb..8b46f39b 100644 --- a/test/integration/meilisearch/task-list.test.ts +++ b/test/integration/meilisearch/task-list.test.ts @@ -23,7 +23,7 @@ describe.skipIf(!meilisearchUp)("meili task list against a real Meilisearch", () }); it("returns the list envelope filtered by --index-ids", async () => { - const result = await runBinary(["task", "list", "--index-ids", uid, "--all", ...project]); + const result = await runBinary(["task", "list", "--index-ids", uid, ...project]); expect(result.exitCode).toBe(0); expect(result.stderr).toBe(""); const page = JSON.parse(result.stdout) as { results: Array<{ uid: number; type: string }> }; diff --git a/test/lib/pagination.test.ts b/test/lib/pagination.test.ts index 8b0ec7fd..661346a1 100644 --- a/test/lib/pagination.test.ts +++ b/test/lib/pagination.test.ts @@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest"; import { iteratePages, mergePages, - nextFromQuery, nextOffsetQuery, type OffsetQuery, } from "../../src/lib/pagination.js"; @@ -25,21 +24,6 @@ describe("nextOffsetQuery", () => { }); }); -describe("nextFromQuery", () => { - it("follows the next cursor the API answers", () => { - expect(nextFromQuery({ limit: 2 }, { results: [5, 4], from: 5, limit: 2, next: 3 })).toEqual({ - limit: 2, - from: 3, - }); - }); - - it("stops on the last page, which answers a null next", () => { - expect( - nextFromQuery({ limit: 2, from: 3 }, { results: [3], from: 3, limit: 2, next: null }), - ).toBeUndefined(); - }); -}); - describe("iteratePages", () => { it("fetches page after page and yields each one", async () => { const calls: number[] = []; @@ -58,26 +42,6 @@ describe("iteratePages", () => { expect(calls).toEqual([0, 2, 4]); expect(pages).toEqual([[1, 2], [3, 4], [5]]); }); - - it("walks a cursor route down from one uid to the next", async () => { - const uids = [5, 4, 3, 2, 1]; - const calls: Array = []; - const pages: unknown[][] = []; - for await (const page of iteratePages( - async (query: { from?: number | undefined }) => { - calls.push(query.from); - const start = uids.indexOf(query.from ?? 5); - const results = uids.slice(start, start + 2); - return { results, from: results[0], limit: 2, next: uids[start + 2] ?? null }; - }, - {}, - nextFromQuery, - )) { - pages.push([...page.results]); - } - expect(calls).toEqual([undefined, 3, 1]); - expect(pages).toEqual([[5, 4], [3, 2], [1]]); - }); }); describe("mergePages", () => { @@ -88,12 +52,5 @@ describe("mergePages", () => { { results: [3], offset: 2, limit: 2, total: 3 }, ]), ).toEqual({ results: [1, 2, 3], total: 3 }); - - expect( - mergePages([ - { results: [5, 4], from: 5, limit: 2, next: 3 }, - { results: [3], from: 3, limit: 2, next: null }, - ]), - ).toEqual({ results: [5, 4, 3], next: null }); }); });