Skip to content

Commit 4d305ed

Browse files
authored
Merge branch 'main' into token-web-crypto
2 parents 3511588 + 47fcb09 commit 4d305ed

30 files changed

+1326
-143
lines changed

.code-samples.meilisearch.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,19 @@ update_localized_attribute_settings_1: |-
805805
];)
806806
reset_localized_attribute_settings_1: |-
807807
client.index('INDEX_NAME').resetLocalizedAttributes()
808+
get_facet_search_settings_1: |-
809+
client.index('INDEX_NAME').getFacetSearch();
810+
update_facet_search_settings_1: |-
811+
client.index('INDEX_NAME').updateFacetSearch(false);
812+
reset_facet_search_settings_1: |-
813+
client.index('INDEX_NAME').resetFacetSearch();
814+
get_prefix_search_settings_1: |-
815+
client.index('INDEX_NAME').getPrefixSearch();
816+
update_prefix_search_settings_1: |-
817+
client.index('INDEX_NAME').updatePrefixSearch('disabled');
818+
reset_prefix_search_settings_1: |-
819+
client.index('INDEX_NAME').resetPrefixSearch();
820+
get_all_batches_1: |-
821+
client.getBatches();
822+
get_batch_1: |-
823+
client.getBatch(BATCH_UID);

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume
3434

3535
To run this project, you will need:
3636

37-
- Node.js >= v16 and node <= 18
38-
- Yarn
39-
- vitest
37+
- Node >= v18 and Node <= 20
38+
- Yarn v1.x
4039

4140
### Setup
4241

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ We recommend installing `meilisearch-js` in your project with your package manag
6060
npm install meilisearch
6161
```
6262

63-
`meilisearch-js` officially supports `node` versions >= 14 and <= 18.
63+
`meilisearch-js` officially supports `node` versions 18 LTS and 20 LTS.
6464

6565
Instead of using a package manager, you may also import the library directly into your [HTML via a CDN](#include-script-tag).
6666

@@ -565,6 +565,20 @@ client.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number })
565565
client.index('myIndex').waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Task[]>
566566
```
567567

568+
### Batches <!-- omit in toc -->
569+
570+
#### [Get one batch](https://www.meilisearch.com/docs/reference/api/batches#get-one-batch)
571+
572+
```ts
573+
client.getBatch(uid: number): Promise<Batch>
574+
```
575+
576+
#### [Get all batches](https://www.meilisearch.com/docs/reference/api/batchess#get-batches)
577+
578+
```ts
579+
client.getBatches(parameters: BatchesQuery = {}): Promise<BatchesResults>
580+
```
581+
568582
### Indexes <!-- omit in toc -->
569583

570584
#### [Get all indexes in Index instances](https://www.meilisearch.com/docs/reference/api/indexes#list-all-indexes)
@@ -981,6 +995,46 @@ client.index('myIndex').updateProximityPrecision(proximityPrecision: ProximityPr
981995
client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>
982996
```
983997

998+
### Facet search settings <!-- omit in toc -->
999+
1000+
#### [Get facet search settings](https://www.meilisearch.com/docs/reference/api/settings#get-facet-search-settings)
1001+
1002+
```ts
1003+
client.index('myIndex').getFacetSearch(): Promise<boolean>
1004+
```
1005+
1006+
#### [Update facet search settings](https://www.meilisearch.com/docs/reference/api/settings#update-facet-search-settings)
1007+
1008+
```ts
1009+
client.index('myIndex').updateFacetSearch(enabled: boolean): Promise<EnqueuedTask>
1010+
```
1011+
1012+
#### [Reset facet search settings](https://www.meilisearch.com/docs/reference/api/settings#reset-facet-search-settings)
1013+
1014+
```ts
1015+
client.index('myIndex').resetFacetSearch(): Promise<EnqueuedTask>
1016+
```
1017+
1018+
### Prefix search settings <!-- omit in toc -->
1019+
1020+
#### [Get prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#get-prefix-search-settings)
1021+
1022+
```ts
1023+
client.index('myIndex').getPrefixSearch(): Promise<PrefixSearch>
1024+
```
1025+
1026+
#### [Update prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#update-prefix-search-settings)
1027+
1028+
```ts
1029+
client.index('myIndex').updatePrefixSearch(prefixSearch: PrefixSearch): Promise<EnqueuedTask>
1030+
```
1031+
1032+
#### [Reset prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#reset-prefix-search-settings)
1033+
1034+
```ts
1035+
client.index('myIndex').resetPrefixSearch(): Promise<EnqueuedTask>
1036+
```
1037+
9841038
### Embedders <!-- omit in toc -->
9851039

9861040
⚠️ This feature is experimental. Activate the [`vectorStore` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features)

eslint.config.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,31 @@ const vitest = require("@vitest/eslint-plugin");
55
const globals = require("globals");
66
const prettier = require("eslint-config-prettier");
77

8-
/** @type {import("eslint").Linter.Config[]} */
9-
module.exports = [
8+
module.exports = tseslint.config([
9+
{ ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"] },
10+
eslint.configs.recommended,
1011
{
11-
ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"],
12+
files: ["**/*.js"],
13+
languageOptions: { sourceType: "commonjs", globals: globals.node },
1214
},
13-
// Standard linting for js files
15+
// TSDoc
1416
{
15-
files: ["**/*.js"],
16-
languageOptions: { sourceType: "script", globals: globals.node },
17-
plugins: { eslint },
18-
rules: eslint.configs.recommended.rules,
17+
files: ["src/**/*.ts"],
18+
plugins: { tsdoc },
19+
rules: { "tsdoc/syntax": "error" },
1920
},
20-
// TypeScript linting for ts files
21-
...tseslint.configs.recommendedTypeChecked.map((config) => ({
22-
...config,
21+
// TypeScript
22+
{
2323
files: ["**/*.ts"],
24+
extends: [tseslint.configs.recommendedTypeChecked],
2425
languageOptions: {
25-
...config.languageOptions,
26-
globals: { ...config.languageOptions?.globals, ...globals.node },
2726
parserOptions: {
28-
...config.languageOptions?.parserOptions,
29-
project: "tsconfig.eslint.json",
27+
projectService: true,
28+
tsconfigRootDir: __dirname,
3029
},
3130
},
32-
plugins: { ...config.plugins, tsdoc },
3331
rules: {
34-
...config.rules,
35-
"tsdoc/syntax": "error",
36-
// @TODO: Remove the ones between "~~", adapt code
32+
// TODO: Remove the ones between "~~", adapt code
3733
// ~~
3834
"@typescript-eslint/prefer-as-const": "off",
3935
"@typescript-eslint/ban-ts-comment": "off",
@@ -45,7 +41,7 @@ module.exports = [
4541
"@typescript-eslint/no-floating-promises": "off",
4642
// ~~
4743
"@typescript-eslint/array-type": ["warn", { default: "array-simple" }],
48-
// @TODO: Should be careful with this rule, should leave it be and disable
44+
// TODO: Should be careful with this rule, should leave it be and disable
4945
// it within files where necessary with explanations
5046
"@typescript-eslint/no-explicit-any": "off",
5147
"@typescript-eslint/no-unused-vars": [
@@ -54,16 +50,16 @@ module.exports = [
5450
// varsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#varsignorepattern
5551
{ args: "all", argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
5652
],
57-
// @TODO: Not recommended to disable rule, should instead disable locally
53+
// TODO: Not recommended to disable rule, should instead disable locally
5854
// with explanation
5955
"@typescript-eslint/ban-ts-ignore": "off",
6056
},
61-
})),
62-
// Vitest linting for test files
57+
},
58+
// Vitest
6359
{
64-
files: ["tests/*.ts"],
65-
plugins: { vitest },
66-
rules: vitest.configs.recommended.rules,
60+
files: ["tests/**/*.test.ts"],
61+
extends: [vitest.configs.recommended],
6762
},
63+
// Disable any style linting, as prettier takes care of that separately
6864
prettier,
69-
];
65+
]);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "meilisearch",
3-
"version": "0.46.0",
3+
"version": "0.47.0",
44
"description": "The Meilisearch JS client for Node.js and the browser.",
55
"keywords": [
66
"meilisearch",
@@ -66,8 +66,8 @@
6666
"style:fix": "yarn fmt:fix && yarn lint:fix",
6767
"fmt": "prettier -c ./**/*.{js,ts}",
6868
"fmt:fix": "prettier -w ./**/*.{js,ts}",
69-
"lint": "eslint .",
70-
"lint:fix": "eslint --fix .",
69+
"lint": "eslint",
70+
"lint:fix": "eslint --fix",
7171
"typingsheader": "node scripts/build.js"
7272
},
7373
"files": [

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const PLUGINS = [
1818
typescript({
1919
useTsconfigDeclarationDir: true,
2020
tsconfigOverride: {
21-
compilerOptions: { allowJs: false },
21+
tsconfig: "tsconfig.build.json",
2222
include: ["src"],
2323
exclude: ["tests", "examples", "*.js", "scripts"],
2424
},

src/batch.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import {
2+
Config,
3+
BatchObject,
4+
BatchesQuery,
5+
BatchesResults,
6+
BatchesResultsObject,
7+
} from "./types";
8+
import { HttpRequests, toQueryParams } from "./http-requests";
9+
10+
class Batch {
11+
uid: BatchObject["uid"];
12+
details: BatchObject["details"];
13+
stats: BatchObject["stats"];
14+
startedAt: BatchObject["startedAt"];
15+
finishedAt: BatchObject["finishedAt"];
16+
duration: BatchObject["duration"];
17+
progress: BatchObject["progress"];
18+
19+
constructor(batch: BatchObject) {
20+
this.uid = batch.uid;
21+
this.details = batch.details;
22+
this.stats = batch.stats;
23+
this.startedAt = batch.startedAt;
24+
this.finishedAt = batch.finishedAt;
25+
this.duration = batch.duration;
26+
this.progress = batch.progress;
27+
}
28+
}
29+
30+
class BatchClient {
31+
httpRequest: HttpRequests;
32+
33+
constructor(config: Config) {
34+
this.httpRequest = new HttpRequests(config);
35+
}
36+
37+
/**
38+
* Get one batch
39+
*
40+
* @param uid - Unique identifier of the batch
41+
* @returns
42+
*/
43+
async getBatch(uid: number): Promise<Batch> {
44+
const url = `batches/${uid}`;
45+
const batch = await this.httpRequest.get<BatchObject>(url);
46+
return new Batch(batch);
47+
}
48+
49+
/**
50+
* Get batches
51+
*
52+
* @param parameters - Parameters to browse the batches
53+
* @returns Promise containing all batches
54+
*/
55+
async getBatches(parameters: BatchesQuery = {}): Promise<BatchesResults> {
56+
const url = `batches`;
57+
58+
const batches = await this.httpRequest.get<Promise<BatchesResultsObject>>(
59+
url,
60+
toQueryParams<BatchesQuery>(parameters),
61+
);
62+
63+
return {
64+
...batches,
65+
results: batches.results.map((batch) => new Batch(batch)),
66+
};
67+
}
68+
}
69+
70+
export { BatchClient, Batch };

src/indexes.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
SearchSimilarDocumentsParams,
5757
LocalizedAttributes,
5858
UpdateDocumentsByFunctionOptions,
59+
PrefixSearch,
5960
} from "./types";
6061
import { removeUndefinedFromObject } from "./utils";
6162
import { HttpRequests } from "./http-requests";
@@ -1457,6 +1458,80 @@ class Index<T extends Record<string, any> = Record<string, any>> {
14571458

14581459
return new EnqueuedTask(task);
14591460
}
1461+
1462+
///
1463+
/// FACET SEARCH SETTINGS
1464+
///
1465+
1466+
/**
1467+
* Get the facet search settings.
1468+
*
1469+
* @returns Promise containing object of facet search settings
1470+
*/
1471+
async getFacetSearch(): Promise<boolean> {
1472+
const url = `indexes/${this.uid}/settings/facet-search`;
1473+
return await this.httpRequest.get<boolean>(url);
1474+
}
1475+
1476+
/**
1477+
* Update the facet search settings.
1478+
*
1479+
* @param facetSearch - Boolean value
1480+
* @returns Promise containing an EnqueuedTask
1481+
*/
1482+
async updateFacetSearch(facetSearch: boolean): Promise<EnqueuedTask> {
1483+
const url = `indexes/${this.uid}/settings/facet-search`;
1484+
const task = await this.httpRequest.put(url, facetSearch);
1485+
return new EnqueuedTask(task);
1486+
}
1487+
1488+
/**
1489+
* Reset the facet search settings.
1490+
*
1491+
* @returns Promise containing an EnqueuedTask
1492+
*/
1493+
async resetFacetSearch(): Promise<EnqueuedTask> {
1494+
const url = `indexes/${this.uid}/settings/facet-search`;
1495+
const task = await this.httpRequest.delete(url);
1496+
return new EnqueuedTask(task);
1497+
}
1498+
1499+
///
1500+
/// PREFIX SEARCH SETTINGS
1501+
///
1502+
1503+
/**
1504+
* Get the prefix search settings.
1505+
*
1506+
* @returns Promise containing object of prefix search settings
1507+
*/
1508+
async getPrefixSearch(): Promise<PrefixSearch> {
1509+
const url = `indexes/${this.uid}/settings/prefix-search`;
1510+
return await this.httpRequest.get<PrefixSearch>(url);
1511+
}
1512+
1513+
/**
1514+
* Update the prefix search settings.
1515+
*
1516+
* @param prefixSearch - PrefixSearch value
1517+
* @returns Promise containing an EnqueuedTask
1518+
*/
1519+
async updatePrefixSearch(prefixSearch: PrefixSearch): Promise<EnqueuedTask> {
1520+
const url = `indexes/${this.uid}/settings/prefix-search`;
1521+
const task = await this.httpRequest.put(url, prefixSearch);
1522+
return new EnqueuedTask(task);
1523+
}
1524+
1525+
/**
1526+
* Reset the prefix search settings.
1527+
*
1528+
* @returns Promise containing an EnqueuedTask
1529+
*/
1530+
async resetPrefixSearch(): Promise<EnqueuedTask> {
1531+
const url = `indexes/${this.uid}/settings/prefix-search`;
1532+
const task = await this.httpRequest.delete(url);
1533+
return new EnqueuedTask(task);
1534+
}
14601535
}
14611536

14621537
export { Index };

0 commit comments

Comments
 (0)