Skip to content
Open
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
2 changes: 2 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ create_an_index_1: |-
client.createIndex('movies', { primaryKey: 'id' })
update_an_index_1: |-
client.updateIndex('movies', { primaryKey: 'id' })
rename_an_index_1: |-
client.updateIndex('INDEX_A', { indexUid: 'INDEX_B' })
delete_an_index_1: |-
client.deleteIndex('movies')
swap_indexes_1: |-
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"build:docs": "typedoc",
"build": "vite build && tsc -p tsconfig.build.json && vite --mode production-umd build",
"postbuild": "node scripts/build.js",
"test": "vitest run --coverage",
"test": "vitest run --coverage --hook-timeout=120000 --test-timeout=120000",
"types": "tsc -p tsconfig.json --noEmit",
"types:watch": "yarn types --watch",
"test:env:browser": "yarn build && node scripts/copy-umd-file.js --to ./tests/env/express/public && yarn --cwd tests/env/express && yarn --cwd tests/env/express test",
Expand Down
2 changes: 2 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export type ResultsWrapper<T> = {

export type IndexOptions = {
primaryKey?: string;
uid?: string;
};

export type IndexObject = {
Expand Down Expand Up @@ -408,6 +409,7 @@ export type SearchResponse<
facetDistribution?: FacetDistribution;
facetStats?: FacetStats;
facetsByIndex?: FacetsByIndex;
queryVector?: number[];
} & (undefined extends S
? Partial<FinitePagination & InfinitePagination>
: true extends IsFinitePagination<NonNullable<S>>
Expand Down
25 changes: 25 additions & 0 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,31 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
ErrorStatusCode.INVALID_SWAP_DUPLICATE_INDEX_FOUND,
);
});

test(`${permission} key: Swap two indexes with rename`, async () => {
const client = await getClient(permission);
const originalUid1 = index.uid;
const originalUid2 = index2.uid;

await client
.index(originalUid1)
.addDocuments([{ id: 1, title: "index_1" }])
.waitTask();
await client
.index(originalUid2)
.addDocuments([{ id: 1, title: "index_2" }])
.waitTask();

const swaps: IndexSwap[] = [
{ indexes: [originalUid1, originalUid2], rename: true },
];

const resolvedTask = await client.swapIndexes(swaps).waitTask();

// Verify the swap task completed with expected details
expect(resolvedTask.type).toEqual("indexSwap");
expect(resolvedTask.details?.swaps).toEqual(swaps);
});
});

describe("Test on base routes", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/get_search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ describe.each([
});
});

// This test deletes the index, so following tests may fail if they need an existing index
test(`${permission} key: Try to search on deleted index and fail`, async () => {
const client = await getClient(permission);
const masterClient = await getClient("Master");
Expand Down
21 changes: 21 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,27 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
expect(index).toHaveProperty("primaryKey", "newPrimaryKey");
});

test(`${permission} key: rename index using update method`, async () => {
const client = await getClient(permission);
const originalUid = indexNoPk.uid;
const newUid = "renamed_index";

await client.createIndex(originalUid).waitTask();
await client
.updateIndex(originalUid, {
uid: newUid,
})
.waitTask();

await expect(client.getIndex(originalUid)).rejects.toHaveProperty(
"cause.code",
ErrorStatusCode.INDEX_NOT_FOUND,
);

const renamed = await client.getIndex(newUid);
expect(renamed).toHaveProperty("uid", newUid);
});

test(`${permission} key: delete index`, async () => {
const client = await getClient(permission);
await client.createIndex(indexNoPk.uid).waitTask();
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/meilisearch-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const BAD_HOST = "http://127.0.0.1:7701";
const config: Config = {
host: HOST,
apiKey: MASTER_KEY,
defaultWaitOptions: { interval: 10 },
defaultWaitOptions: { interval: 10, timeout: 60_000 },
};
const badHostClient = new MeiliSearch({
host: BAD_HOST,
Expand All @@ -25,12 +25,12 @@ const badHostClient = new MeiliSearch({
const masterClient = new MeiliSearch({
host: HOST,
apiKey: MASTER_KEY,
defaultWaitOptions: { interval: 10 },
defaultWaitOptions: { interval: 10, timeout: 60_000 },
});

const anonymousClient = new MeiliSearch({
host: HOST,
defaultWaitOptions: { interval: 10 },
defaultWaitOptions: { interval: 10, timeout: 60_000 },
});

async function getKey(permission: string): Promise<string> {
Expand Down Expand Up @@ -70,7 +70,7 @@ async function getClient(permission: string): Promise<MeiliSearch> {
const searchClient = new MeiliSearch({
host: HOST,
apiKey: searchKey,
defaultWaitOptions: { interval: 10 },
defaultWaitOptions: { interval: 10, timeout: 60_000 },
});
return searchClient;
}
Expand All @@ -80,7 +80,7 @@ async function getClient(permission: string): Promise<MeiliSearch> {
const adminClient = new MeiliSearch({
host: HOST,
apiKey: adminKey,
defaultWaitOptions: { interval: 10 },
defaultWaitOptions: { interval: 10, timeout: 60_000 },
});
return adminClient;
}
Expand Down