Skip to content

Commit 9eb183d

Browse files
authored
Change update API to task API (#1113)
* Change updates to tasks * Complete implementation of asynchronous index CRUD * Add client tests * Add index tests * Add documents test * Improve js doc * Add distinct attributes tests * Add distrinct attributes tests * Remove unused variable from tests * Add dump tests * Add filterable attributes tests * Add ranking rules tests * Add settings tests * Add sortable attr tests * Add stop words * Fix types for Tasks * Add search tests * Finish tests compatibility * Fix tasks issues * Fix tests * Fix task type * Add await in return statement * Fix tests * Fix node12 jest tests * Fix tests environments * Remove obsolete test * Fix tests * Fix document tests * Update update information in readme * Add type check test * Fix types of env * Put back express tests to check for CORS issues * Remove env from typescript type test * Rename test file * Fix typing
1 parent 525e7da commit 9eb183d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3451
-2264
lines changed

.github/workflows/pre-release-tests.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ jobs:
4343
run: yarn test:env:esm
4444
- name: Run Node.js env
4545
run: yarn test:env:nodejs
46-
- name: Run Browser env
47-
run: yarn test:env:browser
4846
- name: Run node typescript env
4947
run: yarn test:env:node-ts
48+
types_test:
49+
runs-on: ubuntu-latest
50+
name: types-test
51+
steps:
52+
- uses: actions/checkout@v2
53+
- name: Cache dependencies
54+
uses: actions/cache@v2
55+
with:
56+
path: |
57+
./node_modules
58+
key: ${{ hashFiles('yarn.lock') }}
59+
- name: Setup node
60+
uses: actions/setup-node@v2
61+
- name: Install dependencies
62+
run: yarn --dev
63+
- name: Run style check
64+
run: yarn types

.github/workflows/tests.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ jobs:
4646
run: yarn test:env:esm
4747
- name: Run Node.js env
4848
run: yarn test:env:nodejs
49-
- name: Run Browser env
50-
run: yarn test:env:browser
5149
- name: Run node typescript env
5250
run: yarn test:env:node-ts
5351

@@ -72,3 +70,21 @@ jobs:
7270
uses: ibiqlik/action-yamllint@v3
7371
with:
7472
config_file: .yamllint.yml
73+
74+
types_test:
75+
runs-on: ubuntu-latest
76+
name: types-test
77+
steps:
78+
- uses: actions/checkout@v2
79+
- name: Cache dependencies
80+
uses: actions/cache@v2
81+
with:
82+
path: |
83+
./node_modules
84+
key: ${{ hashFiles('yarn.lock') }}
85+
- name: Setup node
86+
uses: actions/setup-node@v2
87+
- name: Install dependencies
88+
run: yarn --dev
89+
- name: Run style check
90+
run: yarn types

README.md

Lines changed: 91 additions & 75 deletions
Large diffs are not rendered by default.

bors.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ status = [
22
'linter-check',
33
'integration-tests (Node.js 12)',
44
'integration-tests (Node.js 14)',
5-
'integration-tests (Node.js 16)'
5+
'integration-tests (Node.js 16)',
6+
'types-test'
67
]
78
# 1 hour timeout
89
timeout-sec = 3600

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const config = {
22
rootDir: '.',
33
testMatch: ['<rootDir>/tests/**/*.ts?(x)'],
4+
verbose: true,
45
testPathIgnorePatterns: ['meilisearch-test-utils', 'env'],
56
coverageThreshold: {
67
global: {

nodemon.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extension": "ts",
3+
"verbose": true,
4+
"ignore": ["tests/*", "*.tests.js", "fixtures/*"],
5+
"exec": "yarn tsc"
6+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
"watch": "yarn cleanup && rollup -c --watch",
3535
"postbuild": "yarn size && yarn typingsheader",
3636
"test": "yarn clear_jest && jest --runInBand",
37+
"types:watch": "nodemon --config nodemon.json",
38+
"types": "yarn tsc",
39+
"test:env:browser": "yarn --cwd tests/env/express && yarn --cwd tests/env/express test",
3740
"test:watch": "yarn clear_jest && yarn test --watch",
3841
"test:coverage": "yarn test --coverage",
3942
"test:ci": "yarn test --ci",
40-
"test:env": "yarn build && yarn test:env:browser && yarn test:env:nodejs && yarn test:env:esm && yarn test:env:node-ts",
41-
"test:env:browser": "yarn --cwd tests/env/express && yarn --cwd tests/env/express test",
43+
"test:env": "yarn build && yarn test:env:nodejs && yarn test:env:esm && yarn test:env:node-ts",
4244
"test:env:node-ts": "yarn --cwd tests/env/typescript-node start",
4345
"test:env:nodejs": "node tests/env/node/index.js",
4446
"test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start",
@@ -94,6 +96,7 @@
9496
"jest-watch-typeahead": "^0.6.3",
9597
"kleur": "^4.1.4",
9698
"lint-staged": "11.1.2",
99+
"nodemon": "^2.0.15",
97100
"prettier": "^2.2.1",
98101
"pretty-bytes": "^5.6.0",
99102
"rollup": "^2.60.0",

playgrounds/javascript/src/app.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ const config = {
66
}
77

88
const client = new MeiliSearch(config)
9-
const uid = 'movies'
9+
const indexUid = 'movies'
1010

1111
const addDataset = async () => {
12-
const index = await client.getOrCreateIndex(uid)
12+
const index = await client.deleteIndex(indexUid)
13+
const { uid } = await client.createIndex(indexUid)
14+
await index.waitForTask(uid)
15+
1316
const documents = await index.getDocuments()
1417

1518
const dataset = [
@@ -25,8 +28,8 @@ const addDataset = async () => {
2528
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
2629
]
2730
if (documents.length === 0) {
28-
const { updateId } = await index.addDocuments(dataset)
29-
await index.waitForPendingUpdate(updateId)
31+
const task = await index.addDocuments(dataset)
32+
await index.waitForPendingUpdate(task.uid)
3033
}
3134
}
3235

@@ -39,7 +42,7 @@ const addDataset = async () => {
3942
null,
4043
2
4144
)
42-
const resp = await client.index(uid).search(
45+
const resp = await client.index(indexUid).search(
4346
'',
4447
{
4548
attributesToHighlight: ['title'],

src/lib/http-requests.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import 'cross-fetch/polyfill'
22

3-
import {
4-
Config,
5-
IndexRequest,
6-
EnqueuedUpdate,
7-
IndexResponse,
8-
IndexOptions,
9-
} from '../types'
3+
import { Config, EnqueuedTask } from '../types'
104

115
import { httpResponseErrorHandler, httpErrorHandler } from '../errors'
126

@@ -15,7 +9,7 @@ class HttpRequests {
159
url: URL
1610

1711
constructor(config: Config) {
18-
this.headers = config.headers || {}
12+
this.headers = Object.assign({}, config.headers || {}) // assign to avoid referencing
1913
this.headers['Content-Type'] = 'application/json'
2014
if (config.apiKey) {
2115
this.headers['Authorization'] = `Bearer ${config.apiKey}`
@@ -53,7 +47,7 @@ class HttpRequests {
5347
}
5448

5549
try {
56-
const response: Response = await fetch(constructURL.toString(), {
50+
const response: any = await fetch(constructURL.toString(), {
5751
...config,
5852
method,
5953
body: JSON.stringify(body),
@@ -98,14 +92,7 @@ class HttpRequests {
9892
})
9993
}
10094

101-
async post(
102-
url: string,
103-
data: IndexRequest,
104-
params?: { [key: string]: any },
105-
config?: Record<string, any>
106-
): Promise<IndexResponse>
107-
108-
async post<T = any, R = EnqueuedUpdate>(
95+
async post<T = any, R = EnqueuedTask>(
10996
url: string,
11097
data?: T,
11198
params?: { [key: string]: any },
@@ -127,14 +114,7 @@ class HttpRequests {
127114
})
128115
}
129116

130-
async put(
131-
url: string,
132-
data: IndexOptions | IndexRequest,
133-
params?: { [key: string]: any },
134-
config?: Record<string, any>
135-
): Promise<IndexResponse>
136-
137-
async put<T = any, R = EnqueuedUpdate>(
117+
async put<T = any, R = EnqueuedTask>(
138118
url: string,
139119
data?: T,
140120
params?: { [key: string]: any },
@@ -161,7 +141,7 @@ class HttpRequests {
161141
data?: any,
162142
params?: { [key: string]: any },
163143
config?: Record<string, any>
164-
): Promise<void>
144+
): Promise<EnqueuedTask>
165145
async delete<T>(
166146
url: string,
167147
data?: any,

0 commit comments

Comments
 (0)