Skip to content

Add experimental features methods #1928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions src/meilisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
ExtraRequestInit,
Network,
RecordAny,
RuntimeTogglableFeatures,
} from "./types/index.js";
import { ErrorStatusCode } from "./types/index.js";
import { HttpRequests } from "./http-requests.js";
Expand Down Expand Up @@ -454,4 +455,25 @@ export class MeiliSearch {
path: "snapshots",
});
}

///
/// EXPERIMENTAL-FEATURES
///

/** {@link https://www.meilisearch.com/docs/reference/api/experimental_features#get-all-experimental-features} */
async getExperimentalFeatures(): Promise<RuntimeTogglableFeatures> {
return await this.httpRequest.get({
path: "experimental-features",
});
}

/** {@link https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features} */
async updateExperimentalFeatures(
runtimeTogglableFeatures: RuntimeTogglableFeatures,
): Promise<RuntimeTogglableFeatures> {
return await this.httpRequest.patch({
path: "experimental-features",
body: runtimeTogglableFeatures,
});
}
}
14 changes: 14 additions & 0 deletions src/types/experimental-features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* {@link https://www.meilisearch.com/docs/reference/api/experimental_features#experimental-features-object}
*
* @see `meilisearch::routes::features::RuntimeTogglableFeatures`
*/
export type RuntimeTogglableFeatures = {
metrics?: boolean | null;
logsRoute?: boolean | null;
editDocumentsByFunction?: boolean | null;
containsFilter?: boolean | null;
network?: boolean | null;
getTaskDocumentsRoute?: boolean | null;
compositeEmbedders?: boolean | null;
};
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./experimental-features.js";
export * from "./task_and_batch.js";
export * from "./token.js";
export * from "./types.js";
50 changes: 17 additions & 33 deletions tests/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,17 +680,13 @@ describe("Documents tests", () => {
test(`${permission} key: test updateDocumentsByFunction`, async () => {
const client = await getClient(permission);
const index = client.index<(typeof dataset)[number]>(indexPk.uid);
const adminKey = await getKey("Admin");

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

await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ editDocumentsByFunction: true }),
headers: {
Authorization: `Bearer ${adminKey}`,
"Content-Type": "application/json",
},
method: "PATCH",
await (
await getClient("Master")
).updateExperimentalFeatures({
editDocumentsByFunction: true,
});

await index.addDocuments(dataset).waitTask();
Expand Down Expand Up @@ -761,15 +757,11 @@ describe("Documents tests", () => {

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

await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ editDocumentsByFunction: true }),
headers: {
Authorization: `Bearer ${adminKey}`,
"Content-Type": "application/json",
},
method: "PATCH",
await (
await getClient("Master")
).updateExperimentalFeatures({
editDocumentsByFunction: true,
});

await expect(
Expand Down Expand Up @@ -848,15 +840,11 @@ describe("Documents tests", () => {

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

await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ editDocumentsByFunction: true }),
headers: {
Authorization: `Bearer ${adminKey}`,
"Content-Type": "application/json",
},
method: "PATCH",
await (
await getClient("Master")
).updateExperimentalFeatures({
editDocumentsByFunction: true,
});

await expect(
Expand Down Expand Up @@ -962,15 +950,11 @@ describe("Documents tests", () => {
const route = `indexes/${indexPk.uid}/documents/edit`;
const client = new MeiliSearch({ host });
const strippedHost = trailing ? host.slice(0, -1) : host;
const adminKey = await getKey("Admin");

await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ editDocumentsByFunction: true }),
headers: {
Authorization: `Bearer ${adminKey}`,
"Content-Type": "application/json",
},
method: "PATCH",

await (
await getClient("Master")
).updateExperimentalFeatures({
editDocumentsByFunction: true,
});

await expect(
Expand Down
14 changes: 3 additions & 11 deletions tests/embedders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
BAD_HOST,
MeiliSearch,
getClient,
getKey,
HOST,
masterClient,
} from "./utils/meilisearch-test-utils.js";

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

test(`${permission} key: Update embedders with composite embedder`, async () => {
const adminKey = await getKey("Admin");

// first enable the network endpoint.
await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ compositeEmbedders: true }),
headers: {
Authorization: `Bearer ${adminKey}`,
"Content-Type": "application/json",
},
method: "PATCH",
await masterClient.updateExperimentalFeatures({
compositeEmbedders: true,
});

const client = await getClient(permission);
Expand Down
35 changes: 35 additions & 0 deletions tests/experimental-features.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { afterAll, test } from "vitest";
import { assert, getClient } from "./utils/meilisearch-test-utils.js";
import type { RuntimeTogglableFeatures } from "../src/index.js";

const ms = await getClient("Master");

afterAll(async () => {
await ms.updateExperimentalFeatures({
metrics: false,
logsRoute: false,
editDocumentsByFunction: false,
containsFilter: false,
network: false,
getTaskDocumentsRoute: false,
compositeEmbedders: false,
} satisfies { [TKey in keyof RuntimeTogglableFeatures]-?: false });
});

test(`${ms.updateExperimentalFeatures.name} and ${ms.getExperimentalFeatures.name} methods`, async () => {
const features: { [TKey in keyof RuntimeTogglableFeatures]-?: true } = {
metrics: true,
logsRoute: true,
editDocumentsByFunction: true,
containsFilter: true,
network: true,
getTaskDocumentsRoute: true,
compositeEmbedders: true,
};

const updateFeatures = await ms.updateExperimentalFeatures(features);
assert.deepEqual(updateFeatures, features);

const getFeatures = await ms.getExperimentalFeatures();
assert.deepEqual(getFeatures, features);
});
13 changes: 3 additions & 10 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,13 @@ describe.each([
});

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

// first enable the network endpoint.
await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ network: true }),
headers: {
Authorization: `Bearer ${adminKey}`,
"Content-Type": "application/json",
},
method: "PATCH",
await masterClient.updateExperimentalFeatures({
network: true,
});

const masterClient = await getClient("Master");

const searchKey = await getKey("Search");

// set the remote name and instances
Expand Down