diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index c31299426..5ee231733 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -711,7 +711,7 @@ tenant_token_guide_generate_sdk_1: |- const apiKeyUid = '85c3c2f9-bdd6-41f1-abd8-11fcf80e0f76' const expiresAt = new Date('2025-12-20') // optional - const token = await generateTenantToken(apiKeyUid, searchRules, { + const token = generateTenantToken(apiKeyUid, searchRules, { apiKey: apiKey, expiresAt: expiresAt, }) diff --git a/eslint.config.js b/eslint.config.js index 4f07c0942..77cd210b5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -5,35 +5,31 @@ import vitest from "@vitest/eslint-plugin"; import globals from "globals"; import prettier from "eslint-config-prettier"; -/** @type {import("eslint").Linter.Config[]} */ -export default [ +export default tseslint.config([ + { ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"] }, + eslint.configs.recommended, { - ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"], + files: ["**/*.js"], + languageOptions: { globals: globals.node }, }, - // Standard linting for js files + // TSDoc { - files: ["**/*.js"], - languageOptions: { sourceType: "module", globals: globals.node }, - plugins: { eslint }, - rules: eslint.configs.recommended.rules, + files: ["src/**/*.ts"], + plugins: { tsdoc }, + rules: { "tsdoc/syntax": "error" }, }, - // TypeScript linting for ts files - ...tseslint.configs.recommendedTypeChecked.map((config) => ({ - ...config, + // TypeScript + { files: ["**/*.ts"], + extends: [tseslint.configs.recommendedTypeChecked], languageOptions: { - ...config.languageOptions, - globals: { ...config.languageOptions?.globals, ...globals.node }, parserOptions: { - ...config.languageOptions?.parserOptions, - project: "tsconfig.json", + projectService: true, + tsconfigRootDir: __dirname, }, }, - plugins: { ...config.plugins, tsdoc }, rules: { - ...config.rules, - "tsdoc/syntax": "error", - // @TODO: Remove the ones between "~~", adapt code + // TODO: Remove the ones between "~~", adapt code // ~~ "@typescript-eslint/prefer-as-const": "off", "@typescript-eslint/ban-ts-comment": "off", @@ -45,7 +41,7 @@ export default [ "@typescript-eslint/no-floating-promises": "off", // ~~ "@typescript-eslint/array-type": ["warn", { default: "array-simple" }], - // @TODO: Should be careful with this rule, should leave it be and disable + // TODO: Should be careful with this rule, should leave it be and disable // it within files where necessary with explanations "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unused-vars": [ @@ -54,16 +50,16 @@ export default [ // varsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#varsignorepattern { args: "all", argsIgnorePattern: "^_", varsIgnorePattern: "^_" }, ], - // @TODO: Not recommended to disable rule, should instead disable locally + // TODO: Not recommended to disable rule, should instead disable locally // with explanation "@typescript-eslint/ban-ts-ignore": "off", }, - })), - // Vitest linting for test files + }, + // Vitest { - files: ["tests/*.ts"], - plugins: { vitest }, - rules: vitest.configs.recommended.rules, + files: ["tests/**/*.test.ts"], + extends: [vitest.configs.recommended], }, + // Disable any style linting, as prettier takes care of that separately prettier, -]; +]); diff --git a/package.json b/package.json index 63813fec5..92e0a7642 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "build": "vite build && tsc -p tsconfig.build.json && vite --mode production-umd build", "postbuild": "node scripts/build.js", "test": "vitest run --coverage", - "types": "tsc -p tsconfig.build.json --noEmit", + "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", "test:watch": "vitest watch", @@ -56,8 +56,8 @@ "test:env:nitro-app": "yarn build && yarn --cwd tests/env/nitro-app test", "fmt": "prettier -c ./**/*.{js,ts}", "fmt:fix": "prettier -w ./**/*.{js,ts}", - "lint": "eslint .", - "lint:fix": "eslint --fix .", + "lint": "eslint", + "lint:fix": "eslint --fix", "style": "yarn fmt && yarn lint", "style:fix": "yarn fmt:fix && yarn lint:fix" }, diff --git a/tests/env/typescript-browser/package.json b/tests/env/typescript-browser/package.json index 1d5f2c25e..ca42686f8 100644 --- a/tests/env/typescript-browser/package.json +++ b/tests/env/typescript-browser/package.json @@ -2,6 +2,7 @@ "name": "typescript-demo", "version": "0.1.0", "description": "Meilisearch Typescript Demo", + "type": "module", "main": "index.js", "scripts": { "build": "webpack", diff --git a/tests/env/typescript-browser/src/index.ts b/tests/env/typescript-browser/src/index.ts index 803be4c19..bcdaa9acc 100644 --- a/tests/env/typescript-browser/src/index.ts +++ b/tests/env/typescript-browser/src/index.ts @@ -1,6 +1,5 @@ -import { MeiliSearch } from '../../../../' -import { IndexObject } from '../../../../src' -import { generateTenantToken } from '../../../../src/token' +import { MeiliSearch, type IndexObject } from '../../../../src/index.js' +import { generateTenantToken } from '../../../../src/token.js' const config = { host: 'http://127.0.0.1:7700', @@ -22,5 +21,5 @@ function greeter(person: string) { user )} this is the list of all your indexes: \n ${uids.join(', ')}` - console.log(await generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [], { apiKey: config.apiKey })) // Resolved using the `browser` field + console.log(generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [], { apiKey: config.apiKey })) // Resolved using the `browser` field })() diff --git a/tests/env/typescript-browser/tsconfig.json b/tests/env/typescript-browser/tsconfig.json index 07062f202..618c6c3e9 100644 --- a/tests/env/typescript-browser/tsconfig.json +++ b/tests/env/typescript-browser/tsconfig.json @@ -1,6 +1,3 @@ { - "compilerOptions": { - "resolveJsonModule": true, - "esModuleInterop": true - } + "extends": "../../../tsconfig.json" } diff --git a/tests/env/typescript-node/package.json b/tests/env/typescript-node/package.json index f2a7f80c5..e2cf559cf 100644 --- a/tests/env/typescript-node/package.json +++ b/tests/env/typescript-node/package.json @@ -2,6 +2,7 @@ "name": "typescript-node", "version": "0.1.0", "description": "Demo typescrypt node", + "type": "module", "main": "src/index.js", "scripts": { "build": "tsc --project tsconfig.json", diff --git a/tests/env/typescript-node/src/index.ts b/tests/env/typescript-node/src/index.ts index 62c15b807..c2d600cec 100644 --- a/tests/env/typescript-node/src/index.ts +++ b/tests/env/typescript-node/src/index.ts @@ -1,12 +1,14 @@ import { MeiliSearch, +} from '../../../../src/index.js' +import type { IndexObject, SearchResponse, Hits, Hit, SearchParams, -} from '../../../../src/index' -import { generateTenantToken } from '../../../../src/token' +} from '../../../../src/index.js' +import { generateTenantToken } from '../../../../src/token.js' const config = { host: 'http://127.0.0.1:7700', @@ -60,7 +62,7 @@ const indexUid = "movies" console.log(hit?._formatted?.title) }) - console.log(await generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [], { apiKey: config.apiKey })) + console.log(generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [], { apiKey: config.apiKey })) await index.delete() })() diff --git a/tests/env/typescript-node/tsconfig.json b/tests/env/typescript-node/tsconfig.json index 811d2c482..623e4ad1c 100644 --- a/tests/env/typescript-node/tsconfig.json +++ b/tests/env/typescript-node/tsconfig.json @@ -2,11 +2,7 @@ "extends": "../../../tsconfig.json", "compilerOptions": { "noEmit": false, - "noEmitOnError": true, - "moduleResolution": "node", - "module": "commonjs", "outDir": "./dist", - "verbatimModuleSyntax": false }, "include": ["src/index.ts"] } diff --git a/tests/search.test.ts b/tests/search.test.ts index 939371fd2..b713e697e 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -7,6 +7,10 @@ import { beforeAll, } from "vitest"; import { ErrorStatusCode, MatchingStrategies } from "../src/types/types.js"; +import type { + FederatedMultiSearchParams, + MultiSearchParams, +} from "../src/types/types.js"; import { EnqueuedTask } from "../src/enqueued-task.js"; import { clearAllIndexes, @@ -19,11 +23,6 @@ import { getKey, } from "./utils/meilisearch-test-utils.js"; -if (typeof fetch === "undefined") { - // eslint-disable-next-line @typescript-eslint/no-require-imports - require("cross-fetch/polyfill"); -} - const index = { uid: "books", }; @@ -180,7 +179,10 @@ describe.each([ id: 1; }; - const response = await client.multiSearch({ + const response = await client.multiSearch< + MultiSearchParams, + MyIndex & Books + >({ queries: [{ indexUid: index.uid, q: "prince" }], }); @@ -193,6 +195,7 @@ describe.each([ const client = await getClient(permission); const response1 = await client.multiSearch< + FederatedMultiSearchParams, Books | { id: number; asd: string } >({ federation: {}, @@ -251,7 +254,10 @@ describe.each([ await masterClient.waitForTask(task2); // Make a multi search on both indexes with facetsByIndex - const response = await client.multiSearch({ + const response = await client.multiSearch< + FederatedMultiSearchParams, + Books | Movies + >({ federation: { limit: 20, offset: 0, @@ -329,7 +335,10 @@ describe.each([ await masterClient.waitForTask(task2); // Make a multi search on both indexes with mergeFacets - const response = await client.multiSearch({ + const response = await client.multiSearch< + FederatedMultiSearchParams, + Books | Movies + >({ federation: { limit: 20, offset: 0, diff --git a/tsconfig.json b/tsconfig.json index 25935128d..2e7cbfcbb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,3 @@ -// @TODO: This should be used to type check whole project with script `types` -// but for now because of tests/env this is not possible { "compilerOptions": { // We don't want to check node_modules