Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ jobs:
MEILI_NO_ANALYTICS: 'true'
ports:
- '7700:7700'
export-meilisearch:
image: getmeili/meilisearch:latest
env:
MEILI_MASTER_KEY: 'masterKey'
MEILI_NO_ANALYTICS: 'true'
ports:
- '7702:7700'
strategy:
fail-fast: false
matrix:
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ services:
environment:
- MEILI_MASTER_KEY=masterKey
- MEILI_NO_ANALYTICS=true

export-meilisearch:
image: getmeili/meilisearch
ports:
- "7702:7700"
environment:
- MEILI_MASTER_KEY=masterKey
- MEILI_NO_ANALYTICS=true
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
38 changes: 38 additions & 0 deletions tests/export.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 task2 = await ms
.index(INDEX_UID)
.addDocuments([{ id: 0, beep: "boop" }])
.waitTask();
assert.isTaskSuccessful(task2);
});

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://127.0.0.1:7702",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this work in Docker? Shouldn't we use the service's internal name, e.g., http://export-meilisearch:7700?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah, you're right. Nevertheless it should err and not hang, so it still counts as a bug.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, now I get:

{
  "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",
}

Not sure what the problem is here.

apiKey: "masterKey",
payloadSize: "50MiB",
indexes: {
[INDEX_UID]: { filter: "beep = boop", overrideSettings: true },
},
})
.waitTask({ timeout: 60_000 });

assert.isTaskSuccessful(task);
assert.strictEqual(task.type, "export");
});
1 change: 1 addition & 0 deletions tests/utils/meilisearch-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const source = {
taskDeletion: null,
dumpCreation: null,
snapshotCreation: null,
export: null,
upgradeDatabase: null,
}),
);
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