Skip to content

Commit

Permalink
Merge with main and adapt code
Browse files Browse the repository at this point in the history
  • Loading branch information
flevi29 committed Dec 27, 2024
2 parents 974477f + 47fcb09 commit 3d564fa
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
50 changes: 23 additions & 27 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand All @@ -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,
];
]);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions tests/env/typescript-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "typescript-demo",
"version": "0.1.0",
"description": "Meilisearch Typescript Demo",
"type": "module",
"main": "index.js",
"scripts": {
"build": "webpack",
Expand Down
7 changes: 3 additions & 4 deletions tests/env/typescript-browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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
})()
5 changes: 1 addition & 4 deletions tests/env/typescript-browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true
}
"extends": "../../../tsconfig.json"
}
1 change: 1 addition & 0 deletions tests/env/typescript-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions tests/env/typescript-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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()
})()
4 changes: 0 additions & 4 deletions tests/env/typescript-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"noEmitOnError": true,
"moduleResolution": "node",
"module": "commonjs",
"outDir": "./dist",
"verbatimModuleSyntax": false
},
"include": ["src/index.ts"]
}
25 changes: 17 additions & 8 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
};
Expand Down Expand Up @@ -180,7 +179,10 @@ describe.each([
id: 1;
};

const response = await client.multiSearch<MyIndex & Books>({
const response = await client.multiSearch<
MultiSearchParams,
MyIndex & Books
>({
queries: [{ indexUid: index.uid, q: "prince" }],
});

Expand All @@ -193,6 +195,7 @@ describe.each([
const client = await getClient(permission);

const response1 = await client.multiSearch<
FederatedMultiSearchParams,
Books | { id: number; asd: string }
>({
federation: {},
Expand Down Expand Up @@ -251,7 +254,10 @@ describe.each([
await masterClient.waitForTask(task2);

// Make a multi search on both indexes with facetsByIndex
const response = await client.multiSearch<Books | Movies>({
const response = await client.multiSearch<
FederatedMultiSearchParams,
Books | Movies
>({
federation: {
limit: 20,
offset: 0,
Expand Down Expand Up @@ -329,7 +335,10 @@ describe.each([
await masterClient.waitForTask(task2);

// Make a multi search on both indexes with mergeFacets
const response = await client.multiSearch<Books | Movies>({
const response = await client.multiSearch<
FederatedMultiSearchParams,
Books | Movies
>({
federation: {
limit: 20,
offset: 0,
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3d564fa

Please sign in to comment.