Skip to content

Commit db83046

Browse files
committed
Merge with main
2 parents 4219bd3 + 77505c0 commit db83046

File tree

7 files changed

+95
-54
lines changed

7 files changed

+95
-54
lines changed

src/meilisearch.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type {
2727
IndexViewList,
2828
ListIndexes,
2929
IndexCreateRequest,
30+
RuntimeTogglableFeatures,
3031
} from "./types/index.js";
3132
import { HttpRequests } from "./http-requests.js";
3233
import {
@@ -352,4 +353,25 @@ export class MeiliSearch {
352353
path: "snapshots",
353354
});
354355
}
356+
357+
///
358+
/// EXPERIMENTAL-FEATURES
359+
///
360+
361+
/** {@link https://www.meilisearch.com/docs/reference/api/experimental_features#get-all-experimental-features} */
362+
async getExperimentalFeatures(): Promise<RuntimeTogglableFeatures> {
363+
return await this.httpRequest.get({
364+
path: "experimental-features",
365+
});
366+
}
367+
368+
/** {@link https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features} */
369+
async updateExperimentalFeatures(
370+
runtimeTogglableFeatures: RuntimeTogglableFeatures,
371+
): Promise<RuntimeTogglableFeatures> {
372+
return await this.httpRequest.patch({
373+
path: "experimental-features",
374+
body: runtimeTogglableFeatures,
375+
});
376+
}
355377
}

src/types/experimental-features.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* {@link https://www.meilisearch.com/docs/reference/api/experimental_features#experimental-features-object}
3+
*
4+
* @see `meilisearch::routes::features::RuntimeTogglableFeatures`
5+
*/
6+
export type RuntimeTogglableFeatures = {
7+
metrics?: boolean | null;
8+
logsRoute?: boolean | null;
9+
editDocumentsByFunction?: boolean | null;
10+
containsFilter?: boolean | null;
11+
network?: boolean | null;
12+
getTaskDocumentsRoute?: boolean | null;
13+
compositeEmbedders?: boolean | null;
14+
};

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./experimental-features.js";
12
export * from "./indexes.js";
23
export * from "./task-and-batch.js";
34
export * from "./token.js";

tests/documents.test.ts

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -681,17 +681,13 @@ describe("Documents tests", () => {
681681
test(`${permission} key: test updateDocumentsByFunction`, async () => {
682682
const client = await getClient(permission);
683683
const index = client.index<(typeof dataset)[number]>(indexPk.uid);
684-
const adminKey = await getKey("Admin");
685684

686685
await index.updateFilterableAttributes(["id"]).waitTask();
687686

688-
await fetch(`${HOST}/experimental-features`, {
689-
body: JSON.stringify({ editDocumentsByFunction: true }),
690-
headers: {
691-
Authorization: `Bearer ${adminKey}`,
692-
"Content-Type": "application/json",
693-
},
694-
method: "PATCH",
687+
await (
688+
await getClient("Master")
689+
).updateExperimentalFeatures({
690+
editDocumentsByFunction: true,
695691
});
696692

697693
await index.addDocuments(dataset).waitTask();
@@ -762,15 +758,11 @@ describe("Documents tests", () => {
762758

763759
test(`${permission} key: Try updateDocumentsByFunction and be denied`, async () => {
764760
const client = await getClient(permission);
765-
const adminKey = await getKey("Admin");
766761

767-
await fetch(`${HOST}/experimental-features`, {
768-
body: JSON.stringify({ editDocumentsByFunction: true }),
769-
headers: {
770-
Authorization: `Bearer ${adminKey}`,
771-
"Content-Type": "application/json",
772-
},
773-
method: "PATCH",
762+
await (
763+
await getClient("Master")
764+
).updateExperimentalFeatures({
765+
editDocumentsByFunction: true,
774766
});
775767

776768
await expect(
@@ -849,15 +841,11 @@ describe("Documents tests", () => {
849841

850842
test(`${permission} key: Try updateDocumentsByFunction and be denied`, async () => {
851843
const client = await getClient(permission);
852-
const adminKey = await getKey("Admin");
853844

854-
await fetch(`${HOST}/experimental-features`, {
855-
body: JSON.stringify({ editDocumentsByFunction: true }),
856-
headers: {
857-
Authorization: `Bearer ${adminKey}`,
858-
"Content-Type": "application/json",
859-
},
860-
method: "PATCH",
845+
await (
846+
await getClient("Master")
847+
).updateExperimentalFeatures({
848+
editDocumentsByFunction: true,
861849
});
862850

863851
await expect(
@@ -963,15 +951,11 @@ describe("Documents tests", () => {
963951
const route = `indexes/${indexPk.uid}/documents/edit`;
964952
const client = new MeiliSearch({ host });
965953
const strippedHost = trailing ? host.slice(0, -1) : host;
966-
const adminKey = await getKey("Admin");
967-
968-
await fetch(`${HOST}/experimental-features`, {
969-
body: JSON.stringify({ editDocumentsByFunction: true }),
970-
headers: {
971-
Authorization: `Bearer ${adminKey}`,
972-
"Content-Type": "application/json",
973-
},
974-
method: "PATCH",
954+
955+
await (
956+
await getClient("Master")
957+
).updateExperimentalFeatures({
958+
editDocumentsByFunction: true,
975959
});
976960

977961
await expect(

tests/embedders.test.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import {
66
BAD_HOST,
77
MeiliSearch,
88
getClient,
9-
getKey,
10-
HOST,
9+
masterClient,
1110
} from "./utils/meilisearch-test-utils.js";
1211

1312
const index = {
@@ -239,16 +238,9 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
239238
});
240239

241240
test(`${permission} key: Update embedders with composite embedder`, async () => {
242-
const adminKey = await getKey("Admin");
243-
244241
// first enable the network endpoint.
245-
await fetch(`${HOST}/experimental-features`, {
246-
body: JSON.stringify({ compositeEmbedders: true }),
247-
headers: {
248-
Authorization: `Bearer ${adminKey}`,
249-
"Content-Type": "application/json",
250-
},
251-
method: "PATCH",
242+
await masterClient.updateExperimentalFeatures({
243+
compositeEmbedders: true,
252244
});
253245

254246
const client = await getClient(permission);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { afterAll, test } from "vitest";
2+
import { assert, getClient } from "./utils/meilisearch-test-utils.js";
3+
import type { RuntimeTogglableFeatures } from "../src/index.js";
4+
5+
const ms = await getClient("Master");
6+
7+
afterAll(async () => {
8+
await ms.updateExperimentalFeatures({
9+
metrics: false,
10+
logsRoute: false,
11+
editDocumentsByFunction: false,
12+
containsFilter: false,
13+
network: false,
14+
getTaskDocumentsRoute: false,
15+
compositeEmbedders: false,
16+
} satisfies { [TKey in keyof RuntimeTogglableFeatures]-?: false });
17+
});
18+
19+
test(`${ms.updateExperimentalFeatures.name} and ${ms.getExperimentalFeatures.name} methods`, async () => {
20+
const features: { [TKey in keyof RuntimeTogglableFeatures]-?: true } = {
21+
metrics: true,
22+
logsRoute: true,
23+
editDocumentsByFunction: true,
24+
containsFilter: true,
25+
network: true,
26+
getTaskDocumentsRoute: true,
27+
compositeEmbedders: true,
28+
};
29+
30+
const updateFeatures = await ms.updateExperimentalFeatures(features);
31+
assert.deepEqual(updateFeatures, features);
32+
33+
const getFeatures = await ms.getExperimentalFeatures();
34+
assert.deepEqual(getFeatures, features);
35+
});

tests/search.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,13 @@ describe.each([
234234
});
235235

236236
test(`${permission} key: Multi index search with federation and remote`, async () => {
237-
const adminKey = await getKey("Admin");
237+
const masterClient = await getClient("Master");
238238

239239
// first enable the network endpoint.
240-
await fetch(`${HOST}/experimental-features`, {
241-
body: JSON.stringify({ network: true }),
242-
headers: {
243-
Authorization: `Bearer ${adminKey}`,
244-
"Content-Type": "application/json",
245-
},
246-
method: "PATCH",
240+
await masterClient.updateExperimentalFeatures({
241+
network: true,
247242
});
248243

249-
const masterClient = await getClient("Master");
250-
251244
const searchKey = await getKey("Search");
252245

253246
// set the remote name and instances

0 commit comments

Comments
 (0)