diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 74c22cfbd..86a3bdeec 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,9 +1,9 @@ --- name: Bug Report 🐞 about: Create a report to help us improve. -title: '' -labels: '' -assignees: '' +title: "" +labels: "" +assignees: "" --- @@ -21,6 +21,7 @@ What happened. If applicable, add screenshots or logs to help explain your problem. **Environment (please complete the following information):** + - OS: [e.g. Debian GNU/Linux] - Meilisearch version: [e.g. v.0.20.0] - meilisearch-js version: [e.g v0.18.2] diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 8a9165189..0923f0e0d 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,9 +1,9 @@ --- name: Feature Request & Enhancement 💡 about: Suggest a new idea for the project. -title: '' -labels: '' -assignees: '' +title: "" +labels: "" +assignees: "" --- diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c21c2afbb..42bfe1b25 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,20 +1,20 @@ version: 2 updates: - - package-ecosystem: 'github-actions' - directory: '/' + - package-ecosystem: "github-actions" + directory: "/" schedule: - interval: 'monthly' + interval: "monthly" labels: - - 'skip-changelog' - - 'dependencies' + - "skip-changelog" + - "dependencies" rebase-strategy: disabled - package-ecosystem: npm - directory: '/' + directory: "/" schedule: - interval: 'monthly' - time: '04:00' + interval: "monthly" + time: "04:00" open-pull-requests-limit: 10 labels: - skip-changelog diff --git a/.github/release-draft-template.yml b/.github/release-draft-template.yml index 2fc0243e5..d1e8ad880 100644 --- a/.github/release-draft-template.yml +++ b/.github/release-draft-template.yml @@ -1,37 +1,37 @@ -name-template: 'v$RESOLVED_VERSION 🌻' -tag-template: 'v$RESOLVED_VERSION' +name-template: "v$RESOLVED_VERSION 🌻" +tag-template: "v$RESOLVED_VERSION" exclude-labels: - - 'skip-changelog' + - "skip-changelog" version-resolver: minor: labels: - - 'breaking-change' + - "breaking-change" default: patch categories: - - title: '⚠️ Breaking changes' - label: 'breaking-change' - - title: '🚀 Enhancements' - label: 'enhancement' - - title: '🐛 Bug Fixes' - label: 'bug' - - title: '🔒 Security' - label: 'security' - - title: '⚙️ Maintenance/misc' + - title: "⚠️ Breaking changes" + label: "breaking-change" + - title: "🚀 Enhancements" + label: "enhancement" + - title: "🐛 Bug Fixes" + label: "bug" + - title: "🔒 Security" + label: "security" + - title: "⚙️ Maintenance/misc" label: - - 'maintenance' - - 'documentation' + - "maintenance" + - "documentation" template: | $CHANGES Thanks again to $CONTRIBUTORS! 🎉 -no-changes-template: 'Changes are coming soon 😎' -sort-direction: 'ascending' +no-changes-template: "Changes are coming soon 😎" +sort-direction: "ascending" replacers: - search: '/(?:and )?@dependabot-preview(?:\[bot\])?,?/g' - replace: '' + replace: "" - search: '/(?:and )?@dependabot(?:\[bot\])?,?/g' - replace: '' + replace: "" - search: '/(?:and )?@bors(?:\[bot\])?,?/g' - replace: '' - - search: '/(?:and )?@meili-bot,?/g' - replace: '' + replace: "" + - search: "/(?:and )?@meili-bot,?/g" + replace: "" diff --git a/.github/workflows/meilisearch-prototype-tests.yml b/.github/workflows/meilisearch-prototype-tests.yml index 14f44e4a8..6354a520d 100644 --- a/.github/workflows/meilisearch-prototype-tests.yml +++ b/.github/workflows/meilisearch-prototype-tests.yml @@ -5,10 +5,10 @@ name: Meilisearch prototype tests on: pull_request: branches: - - 'prototype-beta/**' + - "prototype-beta/**" push: branches: - - 'prototype-beta/**' + - "prototype-beta/**" jobs: meilisearch-version: @@ -31,18 +31,18 @@ jobs: echo "meilisearch_version=$MEILISEARCH_VERSION" >> $GITHUB_OUTPUT integration_tests: runs-on: ubuntu-latest - needs: ['meilisearch-version'] + needs: ["meilisearch-version"] services: meilisearch: image: getmeili/meilisearch:${{ needs.meilisearch-version.outputs.version }} env: - MEILI_MASTER_KEY: 'masterKey' - MEILI_NO_ANALYTICS: 'true' + MEILI_MASTER_KEY: "masterKey" + MEILI_NO_ANALYTICS: "true" ports: - - '7700:7700' + - "7700:7700" strategy: matrix: - node: ['18', '20', '22'] + node: ["18", "20", "22"] name: integration-tests (Node.js ${{ matrix.node }}) steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/pre-release-tests.yml b/.github/workflows/pre-release-tests.yml index 84a9925b0..7faf7532c 100644 --- a/.github/workflows/pre-release-tests.yml +++ b/.github/workflows/pre-release-tests.yml @@ -5,12 +5,12 @@ name: Pre-Release Tests on: pull_request: branches: - - 'bump-meilisearch-v**' - - 'pre-release-beta/**' + - "bump-meilisearch-v**" + - "pre-release-beta/**" push: branches: - - 'bump-meilisearch-v**' - - 'pre-release-beta/**' + - "bump-meilisearch-v**" + - "pre-release-beta/**" jobs: meilisearch-version: @@ -28,18 +28,18 @@ jobs: integration_tests: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || startsWith(github.base_ref, 'bump-meilisearch-v') || startsWith(github.base_ref, 'pre-release-beta') - needs: ['meilisearch-version'] + needs: ["meilisearch-version"] services: meilisearch: image: getmeili/meilisearch:${{ needs.meilisearch-version.outputs.version }} env: - MEILI_MASTER_KEY: 'masterKey' - MEILI_NO_ANALYTICS: 'true' + MEILI_MASTER_KEY: "masterKey" + MEILI_NO_ANALYTICS: "true" ports: - - '7700:7700' + - "7700:7700" strategy: matrix: - node: ['18', '20', '22'] + node: ["18", "20", "22"] name: integration-tests (Node.js ${{ matrix.node }}) steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 92ad3b889..913de5b3d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,7 +12,7 @@ jobs: with: node-version: 22 registry-url: https://registry.npmjs.org/ - cache: 'yarn' + cache: "yarn" - name: Check release validity run: sh .github/scripts/check-release.sh - name: Check tag format @@ -22,12 +22,12 @@ jobs: - name: Build meilisearch-js run: yarn build - name: Publish with latest tag - if: '!github.event.release.prerelease' + if: !github.event.release.prerelease run: npm publish . env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - name: Publish with beta tag - if: 'github.event.release.prerelease' + if: github.event.release.prerelease run: npm publish . --tag beta env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7324eaf1d..38080c937 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,14 +27,14 @@ jobs: meilisearch: image: getmeili/meilisearch:latest env: - MEILI_MASTER_KEY: 'masterKey' - MEILI_NO_ANALYTICS: 'true' + MEILI_MASTER_KEY: "masterKey" + MEILI_NO_ANALYTICS: "true" ports: - - '7700:7700' + - "7700:7700" strategy: fail-fast: false matrix: - node: ['18', '20', '22'] + node: ["18", "20", "22"] name: integration-tests (Node.js ${{ matrix.node }}) steps: - uses: actions/checkout@v4 @@ -42,7 +42,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - cache: 'yarn' + cache: "yarn" - name: Install dependencies run: yarn --dev - name: Run tests @@ -70,7 +70,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: 22 - cache: 'yarn' + cache: "yarn" - name: Install dependencies run: yarn --dev - name: Run code style check @@ -88,7 +88,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: 22 - cache: 'yarn' + cache: "yarn" - name: Install dependencies run: yarn --dev - name: Build project diff --git a/.prettierignore b/.prettierignore index 602d307f0..71d97fc6a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1 @@ -node_modules -dist -/tests/env -/coverage -*.md +tests/env/browser/meilisearch.umd.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8952a91b6..c6eea16d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,7 +26,7 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume 4. Review the [Development Workflow](#development-workflow) section that describes the steps to maintain the repository. 5. Make the changes on your branch. 6. [Submit the branch as a PR](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) pointing to the `main` branch of the main meilisearch-js repository. A maintainer should comment and/or review your Pull Request within a few days. Although depending on the circumstances, it may take longer.
- We do not enforce a naming convention for the PRs, but **please use something descriptive of your changes**, having in mind that the title of your PR will be automatically added to the next [release changelog](https://github.com/meilisearch/meilisearch-js/releases/). + We do not enforce a naming convention for the PRs, but **please use something descriptive of your changes**, having in mind that the title of your PR will be automatically added to the next [release changelog](https://github.com/meilisearch/meilisearch-js/releases/). ## Development Workflow @@ -42,6 +42,7 @@ To run this project, you will need: You can set up your local environment natively or using `docker`, check out the [`docker-compose.yml`](/docker-compose.yml). Example of running all the checks with docker: + ```bash docker-compose run --rm package bash -c "yarn install && yarn test && yarn lint" ``` @@ -79,6 +80,7 @@ We do not enforce any branch naming style, but please use something descriptive ### Git Commits As minimal requirements, your commit message should: + - be capitalized - not finish by a dot or any other punctuation character (!,?) - start with a verb so that we can read your commit message this way: "This commit will ...", where "..." is the commit message. @@ -119,13 +121,15 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m Make a PR modifying the following files with the right version: [`package.json`](/package.json): + ```javascript "version": "X.X.X", ``` [`src/package-version`](/src/package-version.ts) + ```javascript -export const PACKAGE_VERSION = 'X.X.X' +export const PACKAGE_VERSION = "X.X.X"; ``` #### Github publish @@ -137,6 +141,7 @@ GitHub Actions will be triggered and push the package to [npm](https://www.npmjs #### Release a `beta` Version This package is able to create multiple types of betas: + - A standard package beta, working on the latest version of Meilisearch. - A beta implementing the changes of a rc version of Meilisearch. - A beta implementing a specific feature `prototype` of Meilisearch. @@ -144,31 +149,33 @@ This package is able to create multiple types of betas: Here are the steps to release a beta version of this package depending on its type: 1. Create a new branch containing the changes with the correct name format following these rules: - - `package beta`: create a branch `beta/xx-xx` with the context of your beta. - Example: `beta/refactor`. - - Meilisearch `pre-release beta`: create a branch originating from `bump-meilisearch-v*.*.*` named `pre-release-beta/v*.*.*`.
- Example: `pre-release-beta/v0.30.0` - - Meilisearch `prototype beta`: create a branch `prototype-beta/xx-xx`. Where `xxx` has the same name as the docker image containing the prototype. - Example: If the [docker image](https://hub.docker.com/r/getmeili/meilisearch/tags) is named: `prototype-multi-search-0`, the branch should be named: `prototype-beta/prototype-multi-search` + + - `package beta`: create a branch `beta/xx-xx` with the context of your beta. + Example: `beta/refactor`. + - Meilisearch `pre-release beta`: create a branch originating from `bump-meilisearch-v*.*.*` named `pre-release-beta/v*.*.*`.
+ Example: `pre-release-beta/v0.30.0` + - Meilisearch `prototype beta`: create a branch `prototype-beta/xx-xx`. Where `xxx` has the same name as the docker image containing the prototype. + Example: If the [docker image](https://hub.docker.com/r/getmeili/meilisearch/tags) is named: `prototype-multi-search-0`, the branch should be named: `prototype-beta/prototype-multi-search` 2. [Update the version](#version-update) following the correct format (X are numbers): - - package and prototype beta: `X.X.X-***.X` - example: `0.2.0-new-feature.0` - - pre-release beta: `X.X.X-vX.X.X-pre-release.X` - example: `0.2.0-v0.30.0-pre-release.0` -3. Commit and push your code to the newly created branch (step 1). + - package and prototype beta: `X.X.X-***.X` + example: `0.2.0-new-feature.0` + - pre-release beta: `X.X.X-vX.X.X-pre-release.X` + example: `0.2.0-v0.30.0-pre-release.0` +3. Commit and push your code to the newly created branch (step 1). 4. Go to the [GitHub interface for releasing](https://github.com/meilisearch/meilisearch-js/releases): on this page, click on `Draft a new release`. 5. Create a GitHub pre-release: - - Fill the description with the detailed changelogs - - Fill the title with `vX.X.X-beta.0` - - Fill the tag with `vX.X.X-beta.0` - - ⚠️ Select the `vX.X.X-beta.0` branch and NOT `main` - - ⚠️ Click on the "This is a pre-release" checkbox - - Click on "Publish release" + +- Fill the description with the detailed changelogs +- Fill the title with `vX.X.X-beta.0` +- Fill the tag with `vX.X.X-beta.0` +- ⚠️ Select the `vX.X.X-beta.0` branch and NOT `main` +- ⚠️ Click on the "This is a pre-release" checkbox +- Click on "Publish release"
diff --git a/README.md b/README.md index 3b786b94f..2006db89c 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ this package, please open an issue. ⚡️ **Launch, scale, and streamline in minutes with Meilisearch Cloud**—no maintenance, no commitment, cancel anytime. [Try it free now](https://cloud.meilisearch.com/login?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-js). -🪨 Prefer to self-host? [Download and deploy](https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-js) our fast, open-source search engine on your own infrastructure. +🪨 Prefer to self-host? [Download and deploy](https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-js) our fast, open-source search engine on your own infrastructure. ### Import @@ -118,8 +118,8 @@ tag: ```html ``` @@ -164,33 +164,36 @@ Take a look at the [playground](./playgrounds/javascript/src/meilisearch.ts) for ### Add documents ```js -const { MeiliSearch } = require('meilisearch') +const { MeiliSearch } = require("meilisearch"); // Or if you are in a ES environment -import { MeiliSearch } from 'meilisearch' - -;(async () => { +import { MeiliSearch } from "meilisearch"; +(async () => { const client = new MeiliSearch({ - host: 'http://127.0.0.1:7700', - apiKey: 'masterKey', - }) + host: "http://127.0.0.1:7700", + apiKey: "masterKey", + }); // An index is where the documents are stored. - const index = client.index('movies') + const index = client.index("movies"); const documents = [ - { id: 1, title: 'Carol', genres: ['Romance', 'Drama'] }, - { id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] }, - { id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] }, - { id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] }, - { id: 5, title: 'Moana', genres: ['Fantasy', 'Action']}, - { id: 6, title: 'Philadelphia', genres: ['Drama'] }, - ] + { id: 1, title: "Carol", genres: ["Romance", "Drama"] }, + { id: 2, title: "Wonder Woman", genres: ["Action", "Adventure"] }, + { id: 3, title: "Life of Pi", genres: ["Adventure", "Drama"] }, + { + id: 4, + title: "Mad Max: Fury Road", + genres: ["Adventure", "Science Fiction"], + }, + { id: 5, title: "Moana", genres: ["Fantasy", "Action"] }, + { id: 6, title: "Philadelphia", genres: ["Drama"] }, + ]; // If the index 'movies' does not exist, Meilisearch creates it when you first add the documents. - let response = await index.addDocuments(documents) + let response = await index.addDocuments(documents); - console.log(response) // => { "uid": 0 } -})() + console.log(response); // => { "uid": 0 } +})(); ``` Tasks such as document addition always return a unique identifier. You can use this identifier `taskUid` to check the status (`enqueued`, `canceled`, `processing`, `succeeded` or `failed`) of a [task](https://www.meilisearch.com/docs/reference/api/tasks). @@ -199,8 +202,8 @@ Tasks such as document addition always return a unique identifier. You can use t ```javascript // Meilisearch is typo-tolerant: -const search = await index.search('philoudelphia') -console.log(search) +const search = await index.search("philoudelphia"); +console.log(search); ``` Output: @@ -227,12 +230,9 @@ Output: `meilisearch-js` supports all [search parameters](https://www.meilisearch.com/docs/reference/api/search#search-parameters) described in our main documentation website. ```javascript -await index.search( - 'wonder', - { - attributesToHighlight: ['*'] - } -) +await index.search("wonder", { + attributesToHighlight: ["*"], +}); ``` ```json @@ -262,10 +262,7 @@ await index.search( To enable filtering, you must first add your attributes to the [`filterableAttributes` index setting](https://www.meilisearch.com/docs/reference/api/settings#filterable-attributes). ```js -await index.updateFilterableAttributes([ - 'id', - 'genres' - ]) +await index.updateFilterableAttributes(["id", "genres"]); ``` You only need to perform this operation once per index. @@ -275,12 +272,9 @@ Note that Meilisearch rebuilds your index whenever you update `filterableAttribu After you configured `filterableAttributes`, you can use the [`filter` search parameter](https://www.meilisearch.com/docs/reference/api/search#filter) to refine your search: ```js -await index.search( - 'wonder', - { - filter: ['id > 1 AND genres = Action'] - } -) +await index.search("wonder", { + filter: ["id > 1 AND genres = Action"], +}); ``` ```json @@ -289,7 +283,7 @@ await index.search( { "id": 2, "title": "Wonder Woman", - "genres": ["Action","Adventure"] + "genres": ["Action", "Adventure"] } ], "offset": 0, @@ -305,13 +299,10 @@ await index.search( Placeholder search makes it possible to receive hits based on your parameters without having any query (`q`). For example, in a movies database you can run an empty query to receive all results filtered by `genre`. ```javascript -await index.search( - '', - { - filter: ['genres = fantasy'], - facets: ['genres'] - } -) +await index.search("", { + filter: ["genres = fantasy"], + facets: ["genres"], +}); ``` ```json @@ -320,12 +311,12 @@ await index.search( { "id": 2, "title": "Wonder Woman", - "genres": ["Action","Adventure"] + "genres": ["Action", "Adventure"] }, { "id": 5, "title": "Moana", - "genres": ["Fantasy","Action"] + "genres": ["Fantasy", "Action"] } ], "offset": 0, @@ -350,20 +341,24 @@ Note that to enable faceted search on your dataset you need to add `genres` to t You can abort a pending search request by providing an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to the request. ```js -const controller = new AbortController() +const controller = new AbortController(); index - .search('wonder', {}, { - signal: controller.signal, - }) + .search( + "wonder", + {}, + { + signal: controller.signal, + }, + ) .then((response) => { /** ... */ }) .catch((e) => { /** Catch AbortError here. */ - }) + }); -controller.abort() +controller.abort(); ``` ### Using Meilisearch behind a proxy @@ -374,15 +369,15 @@ You can provide a custom request configuration. for example, with custom headers ```ts const client: MeiliSearch = new MeiliSearch({ - host: 'http://localhost:3000/api/meilisearch/proxy', + host: "http://localhost:3000/api/meilisearch/proxy", requestConfig: { headers: { - Authorization: AUTH_TOKEN + Authorization: AUTH_TOKEN, }, // OR - credentials: 'include' - } -}) + credentials: "include", + }, +}); ``` #### Custom http client @@ -391,18 +386,18 @@ You can use your own HTTP client, for example, with [`axios`](https://github.com ```ts const client: MeiliSearch = new MeiliSearch({ - host: 'http://localhost:3000/api/meilisearch/proxy', + host: "http://localhost:3000/api/meilisearch/proxy", httpClient: async (url, opts) => { const response = await $axios.request({ url, data: opts?.body, headers: opts?.headers, - method: (opts?.method?.toLocaleUpperCase() as Method) ?? 'GET' - }) + method: (opts?.method?.toLocaleUpperCase() as Method) ?? "GET", + }); - return response.data - } -}) + return response.data; + }, +}); ``` ## 🤖 Compatibility with Meilisearch @@ -564,10 +559,8 @@ client.index('myIndex').getTasks(parameters: TasksQuery): Promise client.index('myIndex').getTask(uid: number): Promise ``` - #### Wait for one task - ##### Using the client ```ts @@ -622,7 +615,6 @@ client.getIndexes(parameters: IndexesQuery): Promise> client.getRawIndexes(parameters: IndexesQuery): Promise> ``` - #### [Create a new index](https://www.meilisearch.com/docs/reference/api/indexes#create-an-index) ```ts @@ -670,11 +662,13 @@ client.index('myIndex').update(data: IndexOptions): Promise #### [Delete index](https://www.meilisearch.com/docs/reference/api/indexes#delete-an-index) ##### Using the client + ```ts client.deleteIndex(uid): Promise ``` ##### Using the index object + ```ts client.index('myIndex').delete(): Promise ``` @@ -943,7 +937,6 @@ client.index('myIndex').updateTypoTolerance(typoTolerance: TypoTolerance | null) client.index('myIndex').resetTypoTolerance(): Promise ``` - ### Separator tokens #### [Get separator tokens](https://www.meilisearch.com/docs/reference/api/settings#get-separator-tokens) diff --git a/package.json b/package.json index fb85c4491..fb6cd71db 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,8 @@ "test:env:nodejs": "yarn build && node tests/env/node/index.cjs && node tests/env/node/getting_started.cjs", "test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start", "test:env:nitro-app": "yarn build && yarn --cwd tests/env/nitro-app test", - "fmt": "prettier -c ./**/*.{js,ts}", - "fmt:fix": "prettier -w ./**/*.{js,ts}", + "fmt": "prettier -c .", + "fmt:fix": "prettier -w .", "lint": "eslint", "lint:fix": "eslint --fix", "style": "yarn fmt && yarn lint", diff --git a/tests/env/browser/index.html b/tests/env/browser/index.html index 0117acbc3..5224cd139 100644 --- a/tests/env/browser/index.html +++ b/tests/env/browser/index.html @@ -1,52 +1,50 @@ - + - - - - - Page Title - - - - - - + + + + Page Title + + + + diff --git a/tests/env/esm/src/index.js b/tests/env/esm/src/index.js index 4907ea75b..d86eb6e60 100644 --- a/tests/env/esm/src/index.js +++ b/tests/env/esm/src/index.js @@ -1,11 +1,23 @@ -import { MeiliSearch, default as DefaultMeiliSearch } from '../../../../dist/esm/index.js' -import { generateTenantToken } from '../../../../dist/esm/token.js' +import { + MeiliSearch, + default as DefaultMeiliSearch, +} from "../../../../dist/esm/index.js"; +import { generateTenantToken } from "../../../../dist/esm/token.js"; -const client = new MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) -const defaultClient = new DefaultMeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) -generateTenantToken({ apiKey: 'masterKey', apiKeyUid:'e489fe16-3381-431b-bee3-00430192915d' }) +const client = new MeiliSearch({ + host: "http://localhost:7700", + apiKey: "masterKey", +}); +const defaultClient = new DefaultMeiliSearch({ + host: "http://localhost:7700", + apiKey: "masterKey", +}); +generateTenantToken({ + apiKey: "masterKey", + apiKeyUid: "e489fe16-3381-431b-bee3-00430192915d", +}) .then((token) => console.log({ client, token, defaultClient })) .catch((error) => { - console.error(error) - process.exitCode = 1 - }) + console.error(error); + process.exitCode = 1; + }); diff --git a/tests/env/esm/webpack.config.js b/tests/env/esm/webpack.config.js index 61259d571..ccc942125 100644 --- a/tests/env/esm/webpack.config.js +++ b/tests/env/esm/webpack.config.js @@ -1,14 +1,14 @@ -const path = require('node:path') +const path = require("node:path"); module.exports = { - entry: './src/index.js', - mode: 'production', + entry: "./src/index.js", + mode: "production", output: { - path: path.resolve(__dirname, 'dist'), - filename: 'esm-meilisearch-js-test.js', + path: path.resolve(__dirname, "dist"), + filename: "esm-meilisearch-js-test.js", }, - target: 'node', + target: "node", resolve: { - extensions: ['.js'], // resolve all the modules other than index.ts + extensions: [".js"], // resolve all the modules other than index.ts }, -} +}; diff --git a/tests/env/express/jest-puppeteer.config.js b/tests/env/express/jest-puppeteer.config.js index ab07dd52a..b265c0d6f 100644 --- a/tests/env/express/jest-puppeteer.config.js +++ b/tests/env/express/jest-puppeteer.config.js @@ -1,10 +1,10 @@ // jest-puppeteer.config.js module.exports = { server: { - command: 'node src/server.js', - protocol: 'http', + command: "node src/server.js", + protocol: "http", port: 3000, debug: true, launchTimeout: 240000, }, -} +}; diff --git a/tests/env/express/jest.config.js b/tests/env/express/jest.config.js index 2919810d1..6c53d5468 100644 --- a/tests/env/express/jest.config.js +++ b/tests/env/express/jest.config.js @@ -1,5 +1,5 @@ // jest.config.js module.exports = { - preset: 'jest-puppeteer', - setupFilesAfterEnv: ['./jest.setup.js'] -} + preset: "jest-puppeteer", + setupFilesAfterEnv: ["./jest.setup.js"], +}; diff --git a/tests/env/express/jest.setup.js b/tests/env/express/jest.setup.js index daa161e9b..1399c9110 100644 --- a/tests/env/express/jest.setup.js +++ b/tests/env/express/jest.setup.js @@ -1 +1 @@ -jest.setTimeout(30000) +jest.setTimeout(30000); diff --git a/tests/env/express/public/headers.html b/tests/env/express/public/headers.html index 8ea4cb005..ad096c7e4 100644 --- a/tests/env/express/public/headers.html +++ b/tests/env/express/public/headers.html @@ -1,49 +1,48 @@ - + - - - - - Page Title - - - - -
- - + + + + Page Title + + + + +
+ diff --git a/tests/env/express/public/index.html b/tests/env/express/public/index.html index 7dda4eeb8..91b96a4fd 100644 --- a/tests/env/express/public/index.html +++ b/tests/env/express/public/index.html @@ -1,56 +1,56 @@ - + - - - - - Page Title - - - - - Index name: -
- - + + + + Page Title + + + + + Index name: +
+ diff --git a/tests/env/express/src/server.js b/tests/env/express/src/server.js index 770fe5f19..82b22c514 100644 --- a/tests/env/express/src/server.js +++ b/tests/env/express/src/server.js @@ -1,19 +1,19 @@ -const express = require('express') -const app = express() -const router = express.Router() +const express = require("express"); +const app = express(); +const router = express.Router(); -console.log(process.cwd()) -router.get('/meilisearch', function (req, res) { - res.sendFile(`${process.cwd()}/public/index.html`) -}) +console.log(process.cwd()); +router.get("/meilisearch", function (req, res) { + res.sendFile(`${process.cwd()}/public/index.html`); +}); -router.get('/headers', function (req, res) { - res.sendFile(`${process.cwd()}/public/headers.html`) -}) -app.use(express.static('public')) +router.get("/headers", function (req, res) { + res.sendFile(`${process.cwd()}/public/headers.html`); +}); +app.use(express.static("public")); // add the router -app.use('/', router) -app.listen(process.env.port || 3000) +app.use("/", router); +app.listen(process.env.port || 3000); -console.log('Running at Port 3000') +console.log("Running at Port 3000"); diff --git a/tests/env/express/tests/client.test.js b/tests/env/express/tests/client.test.js index f08b345ca..800881aa7 100644 --- a/tests/env/express/tests/client.test.js +++ b/tests/env/express/tests/client.test.js @@ -1,25 +1,24 @@ -describe('Meilisearch JS Browser test', () => { +describe("Meilisearch JS Browser test", () => { beforeAll(async () => { - await page.goto('http://localhost:3000/meilisearch') - }) + await page.goto("http://localhost:3000/meilisearch"); + }); - it('Should have created an index and displayed it', async () => { - await page.waitForSelector("#indexes") - let element = await page.$('#indexes') - let value = await page.evaluate(el => el.textContent, element) - await expect(value).toMatch('testIndex') - }) -}) + it("Should have created an index and displayed it", async () => { + await page.waitForSelector("#indexes"); + let element = await page.$("#indexes"); + let value = await page.evaluate((el) => el.textContent, element); + await expect(value).toMatch("testIndex"); + }); +}); -describe('Meilisearch JS CORS test', () => { +describe("Meilisearch JS CORS test", () => { beforeAll(async () => { - await page.goto('http://localhost:3000/headers') - }) - it('Should not throw cors error', async () => { - await page.waitForSelector("#error") - let element = await page.$('#error') - let value = await page.evaluate(el => el.textContent, element) - await expect(value).toMatch('NO ERRORS') - }) - -}) + await page.goto("http://localhost:3000/headers"); + }); + it("Should not throw cors error", async () => { + await page.waitForSelector("#error"); + let element = await page.$("#error"); + let value = await page.evaluate((el) => el.textContent, element); + await expect(value).toMatch("NO ERRORS"); + }); +}); diff --git a/tests/env/nitro-app/routes/index.js b/tests/env/nitro-app/routes/index.js index a517d4596..2b5edf747 100644 --- a/tests/env/nitro-app/routes/index.js +++ b/tests/env/nitro-app/routes/index.js @@ -1,19 +1,19 @@ -import { MeiliSearch } from 'meilisearch' +import { MeiliSearch } from "meilisearch"; const meilisearch = new MeiliSearch({ - host: 'http://localhost:7700', - apiKey: 'masterKey', -}) + host: "http://localhost:7700", + apiKey: "masterKey", +}); export default defineEventHandler(async () => { try { - const health = await meilisearch.isHealthy() + const health = await meilisearch.isHealthy(); - return { health } + return { health }; } catch (error) { throw createError({ statusCode: 500, - statusMessage: 'Unexpected Error', - }) + statusMessage: "Unexpected Error", + }); } -}) +}); diff --git a/tests/env/nitro-app/tests/client.test.js b/tests/env/nitro-app/tests/client.test.js index 2d25d84d1..9fe547507 100644 --- a/tests/env/nitro-app/tests/client.test.js +++ b/tests/env/nitro-app/tests/client.test.js @@ -1,26 +1,26 @@ -const { spawn } = require('node:child_process') +const { spawn } = require("node:child_process"); -let server +let server; beforeAll(() => { - server = spawn('node', ['.output/server/index.mjs']) -}) + server = spawn("node", [".output/server/index.mjs"]); +}); afterAll(() => { - server.kill() -}) + server.kill(); +}); -describe('Meilisearch JS w/ Nitro App Server Browser test', () => { - it('Should have created an index and displayed it', async () => { +describe("Meilisearch JS w/ Nitro App Server Browser test", () => { + it("Should have created an index and displayed it", async () => { await new Promise((next) => { - server.stdout.on('data', () => { - next() - server.stdout.removeAllListeners('data') - }) - }) - const response = await fetch('http://[::]:3000') - const data = await response.json() + server.stdout.on("data", () => { + next(); + server.stdout.removeAllListeners("data"); + }); + }); + const response = await fetch("http://[::]:3000"); + const data = await response.json(); - expect(data.health).toBe(true) - }) -}) + expect(data.health).toBe(true); + }); +}); diff --git a/tests/env/node/README.md b/tests/env/node/README.md index 46fe2d9c9..452921e84 100644 --- a/tests/env/node/README.md +++ b/tests/env/node/README.md @@ -20,6 +20,7 @@ The credentials are written in each script. To try it out you just need to execute the script that you want to try out. For example: + ``` node search_example.cjs ``` diff --git a/tests/env/node/getting_started.cjs b/tests/env/node/getting_started.cjs index 651101b27..f6144e065 100644 --- a/tests/env/node/getting_started.cjs +++ b/tests/env/node/getting_started.cjs @@ -1,49 +1,46 @@ -const { MeiliSearch } = require('../../../dist/cjs/index.cjs') +const { MeiliSearch } = require("../../../dist/cjs/index.cjs"); -;(async () => { +(async () => { const client = new MeiliSearch({ - host: 'http://127.0.0.1:7700', - apiKey: 'masterKey', - }) + host: "http://127.0.0.1:7700", + apiKey: "masterKey", + }); // An index is where the documents are stored. - const index = client.index('movies') + const index = client.index("movies"); const dataset = [ - { id: 1, title: 'Carol', genres: ['Romance', 'Drama'] }, - { id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] }, - { id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] }, - { id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] }, - { id: 5, title: 'Moana', genres: ['Fantasy', 'Action']}, - { id: 6, title: 'Philadelphia', genres: ['Drama'] }, - ] + { id: 1, title: "Carol", genres: ["Romance", "Drama"] }, + { id: 2, title: "Wonder Woman", genres: ["Action", "Adventure"] }, + { id: 3, title: "Life of Pi", genres: ["Adventure", "Drama"] }, + { + id: 4, + title: "Mad Max: Fury Road", + genres: ["Adventure", "Science Fiction"], + }, + { id: 5, title: "Moana", genres: ["Fantasy", "Action"] }, + { id: 6, title: "Philadelphia", genres: ["Drama"] }, + ]; // If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents. - await index.updateFilterableAttributes([ - 'director', - 'genres', - 'id' - ]) - - let response = await index.addDocuments(dataset) - - console.log(response) // => { "updateId": 0 } - - await client.waitForTask(response.taskUid) - - const search = await index.search('philoudelphia') - console.log({ search, hit: search.hits }) - const filteredSearch = await index.search('Wonder', { - attributesToHighlight: ['*'], - filter: 'id >= 1' - }) - console.log({ filteredSearch, hit: filteredSearch.hits[0] }) - const facetedSearch = await index.search( - '', - { - filter: ['genres = action'], - facets: ['genres'] - } - ) - console.log(JSON.stringify(facetedSearch)) -})() + await index.updateFilterableAttributes(["director", "genres", "id"]); + + let response = await index.addDocuments(dataset); + + console.log(response); // => { "updateId": 0 } + + await client.waitForTask(response.taskUid); + + const search = await index.search("philoudelphia"); + console.log({ search, hit: search.hits }); + const filteredSearch = await index.search("Wonder", { + attributesToHighlight: ["*"], + filter: "id >= 1", + }); + console.log({ filteredSearch, hit: filteredSearch.hits[0] }); + const facetedSearch = await index.search("", { + filter: ["genres = action"], + facets: ["genres"], + }); + console.log(JSON.stringify(facetedSearch)); +})(); diff --git a/tests/env/node/index.cjs b/tests/env/node/index.cjs index 24c1df064..78cb2c523 100644 --- a/tests/env/node/index.cjs +++ b/tests/env/node/index.cjs @@ -1,12 +1,24 @@ -const { MeiliSearch, default: DefaultMeiliSearch } = require('../../../dist/cjs/index.cjs') -const { generateTenantToken } = require('../../../dist/cjs/token.cjs') +const { + MeiliSearch, + default: DefaultMeiliSearch, +} = require("../../../dist/cjs/index.cjs"); +const { generateTenantToken } = require("../../../dist/cjs/token.cjs"); -const CJStest = new MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) -const DefaultCJSTest = new DefaultMeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) +const CJStest = new MeiliSearch({ + host: "http://localhost:7700", + apiKey: "masterKey", +}); +const DefaultCJSTest = new DefaultMeiliSearch({ + host: "http://localhost:7700", + apiKey: "masterKey", +}); -generateTenantToken({ apiKey: 'masterKey', apiKeyUid:'e489fe16-3381-431b-bee3-00430192915d' }) +generateTenantToken({ + apiKey: "masterKey", + apiKeyUid: "e489fe16-3381-431b-bee3-00430192915d", +}) .then((token) => console.log({ CJStest, DefaultCJSTest, token })) .catch((error) => { - console.error(error) - process.exitCode = 1 - }) + console.error(error); + process.exitCode = 1; + }); diff --git a/tests/env/node/search_example.cjs b/tests/env/node/search_example.cjs index 51fbf8d83..6ad7e488c 100644 --- a/tests/env/node/search_example.cjs +++ b/tests/env/node/search_example.cjs @@ -1,35 +1,35 @@ -const { MeiliSearch } = require('../../../dist/bundles/meilisearch.umd.js') -const dataset = require('../../../assets/small_movies.json') +const { MeiliSearch } = require("../../../dist/bundles/meilisearch.umd.js"); +const dataset = require("../../../assets/small_movies.json"); const config = { - host: 'http://127.0.0.1:7700', - apiKey: 'masterKey', -} + host: "http://127.0.0.1:7700", + apiKey: "masterKey", +}; -const client = new MeiliSearch(config) -const indexUid = 'movies' +const client = new MeiliSearch(config); +const indexUid = "movies"; const addDataset = async () => { - await client.deleteIndex(indexUid) - const { taskUid } = await client.createIndex(indexUid) - await client.waitForTask(taskUid) + await client.deleteIndex(indexUid); + const { taskUid } = await client.createIndex(indexUid); + await client.waitForTask(taskUid); - const index = client.index(indexUid) + const index = client.index(indexUid); - const documents = await index.getDocuments() + const documents = await index.getDocuments(); if (documents.results.length === 0) { - const { taskUid } = await index.addDocuments(dataset) - await index.waitForTask(taskUid) + const { taskUid } = await index.addDocuments(dataset); + await index.waitForTask(taskUid); } -} +}; -;(async () => { - await addDataset() - const index = await client.index('movies') - const resp = await index.search('Avengers', { +(async () => { + await addDataset(); + const index = await client.index("movies"); + const resp = await index.search("Avengers", { limit: 1, - attributesToHighlight: ['title'], - }) - console.log({ resp }) - console.log({ hit: resp.hits[0] }) -})() + attributesToHighlight: ["title"], + }); + console.log({ resp }); + console.log({ hit: resp.hits[0] }); +})(); diff --git a/tests/env/typescript-browser/public/index.html b/tests/env/typescript-browser/public/index.html index a8ace3c8f..a548a240a 100644 --- a/tests/env/typescript-browser/public/index.html +++ b/tests/env/typescript-browser/public/index.html @@ -1,13 +1,13 @@ - + - - - - Page Title - - - + + + + Page Title + + + hello - + diff --git a/tests/env/typescript-browser/src/index.ts b/tests/env/typescript-browser/src/index.ts index 67ec1d0a2..051a9eb8c 100644 --- a/tests/env/typescript-browser/src/index.ts +++ b/tests/env/typescript-browser/src/index.ts @@ -1,25 +1,30 @@ -import { MeiliSearch, type IndexObject } from '../../../../src/index.js' -import { generateTenantToken } from '../../../../src/token.js' +import { MeiliSearch, type IndexObject } from "../../../../src/index.js"; +import { generateTenantToken } from "../../../../src/token.js"; const config = { - host: 'http://127.0.0.1:7700', - apiKey: 'masterKey', -} + host: "http://127.0.0.1:7700", + apiKey: "masterKey", +}; -const client = new MeiliSearch(config) -const user = 'MeiliSearch User' +const client = new MeiliSearch(config); +const user = "MeiliSearch User"; function greeter(person: string) { - return 'Hello, ' + person + return "Hello, " + person; } -;(async () => { - const indexes = await client.getRawIndexes() - console.log({ indexes }, 'hello') - const uids = indexes.results.map((index: IndexObject) => index.uid) +(async () => { + const indexes = await client.getRawIndexes(); + console.log({ indexes }, "hello"); + const uids = indexes.results.map((index: IndexObject) => index.uid); document.body.innerHTML = `${greeter( - user - )} this is the list of all your indexes: \n ${uids.join(', ')}` + user, + )} this is the list of all your indexes: \n ${uids.join(", ")}`; - console.log(await generateTenantToken({ apiKey: config.apiKey, apiKeyUid: 'e489fe16-3381-431b-bee3-00430192915d' })) // Resolved using the `browser` field -})() + console.log( + await generateTenantToken({ + apiKey: config.apiKey, + apiKeyUid: "e489fe16-3381-431b-bee3-00430192915d", + }), + ); // Resolved using the `browser` field +})(); diff --git a/tests/env/typescript-browser/webpack.config.js b/tests/env/typescript-browser/webpack.config.js index 45f9dc8e2..59323572b 100644 --- a/tests/env/typescript-browser/webpack.config.js +++ b/tests/env/typescript-browser/webpack.config.js @@ -1,29 +1,28 @@ -const webpack = require('webpack') -const path = require('node:path') +const webpack = require("webpack"); +const path = require("node:path"); let config = { - entry: './src/index.ts', + entry: "./src/index.ts", output: { - path: path.resolve(__dirname, './public'), - filename: './bundle.js', + path: path.resolve(__dirname, "./public"), + filename: "./bundle.js", }, - mode: 'development', + mode: "development", module: { rules: [ { test: /\.tsx?$/, - use: 'ts-loader', + use: "ts-loader", exclude: /node_modules/, }, ], }, devServer: { - static: './public', + static: "./public", }, resolve: { - extensions: ['.tsx', '.ts', '.js'], - + extensions: [".tsx", ".ts", ".js"], }, -} +}; -module.exports = config +module.exports = config; diff --git a/tests/env/typescript-node/src/index.ts b/tests/env/typescript-node/src/index.ts index 0ca8ecba5..a57aaca56 100644 --- a/tests/env/typescript-node/src/index.ts +++ b/tests/env/typescript-node/src/index.ts @@ -1,68 +1,71 @@ -import { - MeiliSearch, -} from '../../../../src/index.js' +import { MeiliSearch } from "../../../../src/index.js"; import type { IndexObject, SearchResponse, Hits, Hit, SearchParams, -} from '../../../../src/index.js' -import { generateTenantToken } from '../../../../src/token.js' +} from "../../../../src/index.js"; +import { generateTenantToken } from "../../../../src/token.js"; const config = { - host: 'http://127.0.0.1:7700', - apiKey: 'masterKey', -} + host: "http://127.0.0.1:7700", + apiKey: "masterKey", +}; interface Movie { - id: number - title: string - genre?: string - comment?: string - isNull?: null - isTrue?: true + id: number; + title: string; + genre?: string; + comment?: string; + isNull?: null; + isTrue?: true; } -const client = new MeiliSearch(config) -const indexUid = "movies" +const client = new MeiliSearch(config); +const indexUid = "movies"; -;(async () => { - await client.deleteIndex(indexUid) - const { taskUid } = await client.createIndex(indexUid) - await client.waitForTask(taskUid) +(async () => { + await client.deleteIndex(indexUid); + const { taskUid } = await client.createIndex(indexUid); + await client.waitForTask(taskUid); - const index = client.index(indexUid) - const indexes = await client.getRawIndexes() + const index = client.index(indexUid); + const indexes = await client.getRawIndexes(); indexes.results.map((index: IndexObject) => { - console.log(index.uid) + console.log(index.uid); // console.log(index.something) -> ERROR - }) + }); const searchParams: SearchParams = { limit: 5, - attributesToRetrieve: ['title', 'genre'], - attributesToHighlight: ['title'], + attributesToRetrieve: ["title", "genre"], + attributesToHighlight: ["title"], // test: true -> ERROR Test does not exist on type SearchParams - } - indexes.results.map((index: IndexObject) => index.uid) + }; + indexes.results.map((index: IndexObject) => index.uid); const res: SearchResponse = await index.search( - 'avenger', - searchParams - ) + "avenger", + searchParams, + ); // both work - const { hits }: { hits: Hits } = res + const { hits }: { hits: Hits } = res; hits.map((hit: Hit) => { - console.log(hit?.genre) - console.log(hit.title) + console.log(hit?.genre); + console.log(hit.title); // console.log(hit._formatted.title) -> ERROR, _formatted could be undefined // console.log(hit?._formatted.title) -> ERROR, title could be undefined - console.log(hit?._formatted?.title) - }) + console.log(hit?._formatted?.title); + }); - console.log(await generateTenantToken({ apiKey: config.apiKey, apiKeyUid: 'e489fe16-3381-431b-bee3-00430192915d' })) + console.log( + await generateTenantToken({ + apiKey: config.apiKey, + apiKeyUid: "e489fe16-3381-431b-bee3-00430192915d", + }), + ); - await index.delete() -})() + await index.delete(); +})(); diff --git a/tests/env/typescript-node/tsconfig.json b/tests/env/typescript-node/tsconfig.json index 623e4ad1c..2a0935e1b 100644 --- a/tests/env/typescript-node/tsconfig.json +++ b/tests/env/typescript-node/tsconfig.json @@ -2,7 +2,7 @@ "extends": "../../../tsconfig.json", "compilerOptions": { "noEmit": false, - "outDir": "./dist", + "outDir": "./dist" }, "include": ["src/index.ts"] } diff --git a/typedoc/style.css b/typedoc/style.css index 2b190e6de..1eb5032ca 100644 --- a/typedoc/style.css +++ b/typedoc/style.css @@ -1,6 +1,6 @@ :root { - --font-family-code: "JetBrains Mono", Menlo, Consolas, Monaco, Liberation Mono, - Lucida Console, monospace; + --font-family-code: "JetBrains Mono", Menlo, Consolas, Monaco, + Liberation Mono, Lucida Console, monospace; --font-family-system: Inter, Roboto, "Helvetica Neue", "Arial Nova", "Nimbus Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",