Skip to content
Draft
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
9 changes: 9 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,12 @@ search_parameter_reference_media_1: |-
}
}
})
export_post_1: |-
client.export({
url: 'TARGET_INSTANCE_URL',
indexes: {
'*': {
overrideSettings: true
}
}
})
7 changes: 7 additions & 0 deletions .github/workflows/meilisearch-prototype-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
MEILI_NO_ANALYTICS: 'true'
ports:
- '7700:7700'
export-meilisearch:
image: getmeili/meilisearch:${{ needs.meilisearch-version.outputs.version }}
env:
MEILI_MASTER_KEY: 'masterKey'
MEILI_NO_ANALYTICS: 'true'
ports:
- '7702:7700'
strategy:
matrix:
node: ['20', '22']
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
MEILI_NO_ANALYTICS: 'true'
ports:
- '7700:7700'
export-meilisearch:
image: getmeili/meilisearch:${{ needs.meilisearch-version.outputs.version }}
env:
MEILI_MASTER_KEY: 'masterKey'
MEILI_NO_ANALYTICS: 'true'
ports:
- '7702:7700'
strategy:
matrix:
node: ['20', '22']
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
MEILI_NO_ANALYTICS: 'true'
ports:
- '7700:7700'
export-meilisearch:
image: getmeili/meilisearch:latest
env:
MEILI_MASTER_KEY: 'masterKey'
MEILI_NO_ANALYTICS: 'true'
strategy:
fail-fast: false
matrix:
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ services:
environment:
- MEILI_MASTER_KEY=masterKey
- MEILI_NO_ANALYTICS=true
networks:
- ms-network

export-meilisearch:
image: getmeili/meilisearch
environment:
- MEILI_MASTER_KEY=masterKey
- MEILI_NO_ANALYTICS=true
networks:
- ms-network

networks:
ms-network:
driver: bridge
10 changes: 10 additions & 0 deletions src/meilisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
ResultsWrapper,
WebhookCreatePayload,
WebhookUpdatePayload,
ExportOptions,
} from "./types/index.js";
import { ErrorStatusCode } from "./types/index.js";
import { HttpRequests } from "./http-requests.js";
Expand Down Expand Up @@ -547,6 +548,15 @@ export class MeiliSearch {
});
}

///
/// EXPORT
///

/** {@link https://www.meilisearch.com/docs/reference/api/export} */
export(options: ExportOptions): EnqueuedTaskPromise {
return this.#httpRequestsWithTask.post({ path: "export", body: options });
}

///
/// EXPERIMENTAL-FEATURES
///
Expand Down
30 changes: 30 additions & 0 deletions src/types/export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Filter } from "./types.js";

/**
* {@link https://www.meilisearch.com/docs/reference/api/export#indexes}
*
* @see `meilisearch::routes::export::ExportIndexSettings`
*/
export type ExportIndexSettings = {
filter?: Filter;
overrideSettings?: boolean;
};

/** {@link https://www.meilisearch.com/docs/reference/api/export#indexes} */
export type ExportIndexSettingsRecord = Record<string, ExportIndexSettings>;

/**
* {@link https://www.meilisearch.com/docs/reference/api/export#body}
*
* @see `meilisearch::routes::export::Export`
*/
export type ExportOptions = {
/** {@link https://www.meilisearch.com/docs/reference/api/export#url} */
url: string;
/** {@link https://www.meilisearch.com/docs/reference/api/export#apikey} */
apiKey?: string;
/** {@link https://www.meilisearch.com/docs/reference/api/export#payloadsize} */
payloadSize?: string;
/** {@link https://www.meilisearch.com/docs/reference/api/export#indexes} */
indexes?: ExportIndexSettingsRecord;
};
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./experimental-features.js";
export * from "./export.js";
export * from "./task_and_batch.js";
export * from "./token.js";
export * from "./types.js";
Expand Down
1 change: 1 addition & 0 deletions src/types/task_and_batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type TaskType = PascalToCamelCase<
| "TaskDeletion"
| "DumpCreation"
| "SnapshotCreation"
| "Export"
| "UpgradeDatabase"
>;

Expand Down
40 changes: 40 additions & 0 deletions tests/export.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { randomUUID } from "node:crypto";
import { afterAll, beforeAll, test } from "vitest";
import { assert, getClient } from "./utils/meilisearch-test-utils.js";

const INDEX_UID = randomUUID();
const ms = await getClient("Master");

beforeAll(async () => {
const task = await ms.createIndex(INDEX_UID).waitTask();
assert.isTaskSuccessful(task);

const idx = ms.index(INDEX_UID);

const task2 = await idx.updateFilterableAttributes(["beep"]).waitTask();
assert.isTaskSuccessful(task2);

const task3 = await idx.addDocuments([{ id: 0, beep: "boop" }]).waitTask();
assert.isTaskSuccessful(task3);
});

afterAll(async () => {
const task = await ms.deleteIndex(INDEX_UID).waitTask();
assert.isTaskSuccessful(task);
});

test(`${ms.export.name} method`, async () => {
const task = await ms
.export({
url: "http://export-meilisearch:7700",
apiKey: "masterKey",
payloadSize: "50MiB",
indexes: {
[INDEX_UID]: { filter: "beep = boop", overrideSettings: true },
},
})
.waitTask({ timeout: 60_000 });

assert.isTaskSuccessful(task);
assert.strictEqual(task.type, "export");
});
3 changes: 2 additions & 1 deletion tests/utils/meilisearch-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
},
isTask(task: Task) {
const { length } = Object.keys(task);
vitestAssert(length >= 11 && length <= 12);
vitestAssert(length >= 11 && length <= 13);
const {
indexUid,
status,
Expand Down Expand Up @@ -199,6 +199,7 @@
taskDeletion: null,
dumpCreation: null,
snapshotCreation: null,
export: null,
upgradeDatabase: null,
}),
);
Expand All @@ -224,7 +225,7 @@
},
isTaskSuccessful(task: Task) {
this.isTask(task);
vitestAssert.isNull(task.error);

Check failure on line 228 in tests/utils/meilisearch-test-utils.ts

View workflow job for this annotation

GitHub Actions / integration-tests (Node.js 20)

tests/export.test.ts > export method

AssertionError: expected { …(4) } to equal null - Expected: null + Received: { "code": "internal", "link": "https://docs.meilisearch.com/errors#internal", "message": "Failed to export documents to remote server missing_payload (invalid_request): A ndjson payload is missing. <https://docs.meilisearch.com/errors#missing_payload>", "type": "internal", } ❯ Function.isTaskSuccessful tests/utils/meilisearch-test-utils.ts:228:18 ❯ tests/export.test.ts:38:10

Check failure on line 228 in tests/utils/meilisearch-test-utils.ts

View workflow job for this annotation

GitHub Actions / integration-tests (Node.js 22)

tests/export.test.ts > export method

AssertionError: expected { …(4) } to equal null - Expected: null + Received: { "code": "internal", "link": "https://docs.meilisearch.com/errors#internal", "message": "Failed to export documents to remote server missing_payload (invalid_request): A ndjson payload is missing. <https://docs.meilisearch.com/errors#missing_payload>", "type": "internal", } ❯ Function.isTaskSuccessful tests/utils/meilisearch-test-utils.ts:228:18 ❯ tests/export.test.ts:38:10
vitestAssert.strictEqual(task.status, "succeeded");
},
};
Expand Down
1 change: 1 addition & 0 deletions tests/utils/tasks-and-batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const possibleTaskTypes = objectKeys<TaskType>({
taskDeletion: null,
dumpCreation: null,
snapshotCreation: null,
export: null,
upgradeDatabase: null,
});

Expand Down
Loading