Skip to content

Commit f65d660

Browse files
Merge #708
708: Remove meilisearch client from public access r=bidoubiwa a=bidoubiwa Fixes: #578 Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 5446e6e + fd137f2 commit f65d660

13 files changed

+118
-121
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test:build": "yarn build && jest --runInBand --selectProjects build",
1212
"test:e2e": "yarn local:env:setup && concurrently --kill-others -s first \"yarn local:env:react\" \"cypress run --env playground=local \"",
1313
"test:e2e:watch": "yarn local:env:setup && concurrently --kill-others -s first \"yarn local:env:react\" \"cypress open --env playground=local\"",
14-
"test:all": "yarn test:e2e:all && yarn test && test:build",
14+
"test:all": "yarn test:e2e && yarn test && yarn test:build",
1515
"cy:open": "cypress open",
1616
"playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue serve",
1717
"playground:react": "yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react start",

src/client/instant-meilisearch-client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ export function instantMeiliSearch(
3131
const searchResolver = SearchResolver(SearchCache())
3232
// paginationTotalHits can be 0 as it is a valid number
3333
let defaultFacetDistribution: any = {}
34+
const meilisearchClient = new MeiliSearch({ host: hostUrl, apiKey: apiKey })
3435

3536
return {
36-
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
37-
3837
/**
3938
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
4039
* @returns {Array}
@@ -57,7 +56,7 @@ export function instantMeiliSearch(
5756
const searchResponse = await searchResolver.searchResponse(
5857
searchContext,
5958
adaptedSearchRequest,
60-
this.MeiliSearchClient
59+
meilisearchClient
6160
)
6261

6362
// Cache first facets distribution of the instantMeilisearch instance

src/types/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,4 @@ export type SearchContext = Omit<
8585
pagination: PaginationContext
8686
}
8787

88-
export type InstantMeiliSearchInstance = SearchClient & {
89-
MeiliSearchClient: MeiliSearch
90-
}
88+
export type InstantMeiliSearchInstance = SearchClient

tests/assets/utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { instantMeiliSearch } from '../../src'
2+
import { MeiliSearch } from 'meilisearch'
23

34
const dataset = [
45
{
@@ -223,5 +224,15 @@ const wrongSearchClient = instantMeiliSearch(
223224
'http://localhost:7777',
224225
'masterKey'
225226
)
227+
const meilisearchClient = new MeiliSearch({
228+
host: 'http://localhost:7700',
229+
apiKey: 'masterKey',
230+
})
226231

227-
export { searchClient, dataset, wrongSearchClient, geoDataset }
232+
export {
233+
searchClient,
234+
dataset,
235+
wrongSearchClient,
236+
geoDataset,
237+
meilisearchClient,
238+
}

tests/base.tests.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/build.tests.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const CJSclient = CJSinstantMeiliSearch('http://localhost:7700', 'masterKey')
1010
const instantsearch = require('instantsearch.js')
1111

1212
test('UMD client should correctly created', () => {
13-
expect(UMDclient.MeiliSearchClient.config.apiKey).toBe('masterKey')
13+
expect(UMDclient.search).not.toBeUndefined()
1414
})
1515

1616
test('CJS client should correctly created', () => {
17-
expect(CJSclient.MeiliSearchClient.config.apiKey).toBe('masterKey')
17+
expect(CJSclient.search).not.toBeUndefined()
1818
})
1919

2020
test('CJS instantsearch client should correctly created', () => {
@@ -23,9 +23,7 @@ test('CJS instantsearch client should correctly created', () => {
2323
searchClient: CJSclient,
2424
})
2525
expect(CJSInstantSearch.indexName).toBe('cjs_index')
26-
expect(CJSInstantSearch.client.MeiliSearchClient.config.apiKey).toBe(
27-
'masterKey'
28-
)
26+
expect(CJSInstantSearch.client.search).not.toBeUndefined()
2927
})
3028

3129
test('UMD instantsearch client should correctly created', () => {
@@ -34,7 +32,5 @@ test('UMD instantsearch client should correctly created', () => {
3432
searchClient: UMDclient,
3533
})
3634
expect(UMDInstantSearch.indexName).toBe('umd_index')
37-
expect(UMDInstantSearch.client.MeiliSearchClient.config.apiKey).toBe(
38-
'masterKey'
39-
)
35+
expect(UMDInstantSearch.client.search).not.toBeUndefined()
4036
})

tests/configure.attributes-to-retrieve.tests.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { searchClient, dataset, Movies } from './assets/utils'
1+
import {
2+
searchClient,
3+
dataset,
4+
Movies,
5+
meilisearchClient,
6+
} from './assets/utils'
27

38
describe('Instant Meilisearch Browser test', () => {
49
beforeAll(async () => {
5-
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6-
'movies'
7-
)
8-
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
10+
const deleteTask = await meilisearchClient.deleteIndex('movies')
11+
await meilisearchClient.waitForTask(deleteTask.uid)
912

10-
const documentsTask = await searchClient.MeiliSearchClient.index(
11-
'movies'
12-
).addDocuments(dataset)
13-
await searchClient.MeiliSearchClient.index('movies').waitForTask(
14-
documentsTask.uid
15-
)
13+
const documentsTask = await meilisearchClient
14+
.index('movies')
15+
.addDocuments(dataset)
16+
await meilisearchClient.index('movies').waitForTask(documentsTask.uid)
1617
})
1718

1819
test('Test attributesToRetrieve on no attributes', async () => {

tests/facets-distribution.tests.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import { searchClient, dataset } from './assets/utils'
1+
import { searchClient, dataset, meilisearchClient } from './assets/utils'
22

33
describe('Instant Meilisearch Browser test', () => {
44
beforeAll(async () => {
5-
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6-
'movies'
7-
)
8-
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
9-
await searchClient.MeiliSearchClient.index(
10-
'movies'
11-
).updateFilterableAttributes(['genres'])
12-
const documentsTask = await searchClient.MeiliSearchClient.index(
13-
'movies'
14-
).addDocuments(dataset)
15-
await searchClient.MeiliSearchClient.index('movies').waitForTask(
16-
documentsTask.uid
17-
)
5+
const deleteTask = await meilisearchClient.deleteIndex('movies')
6+
await meilisearchClient.waitForTask(deleteTask.uid)
7+
await meilisearchClient
8+
.index('movies')
9+
.updateFilterableAttributes(['genres'])
10+
const documentsTask = await meilisearchClient
11+
.index('movies')
12+
.addDocuments(dataset)
13+
await meilisearchClient.index('movies').waitForTask(documentsTask.uid)
1814
})
1915

2016
test('Test empty array on facetsDistribution', async () => {

tests/filter.tests.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { searchClient, dataset, Movies } from './assets/utils'
1+
import {
2+
searchClient,
3+
dataset,
4+
Movies,
5+
meilisearchClient,
6+
} from './assets/utils'
27

38
describe('Instant Meilisearch Browser test', () => {
49
beforeAll(async () => {
5-
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6-
'movies'
7-
)
8-
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
9-
await searchClient.MeiliSearchClient.index(
10-
'movies'
11-
).updateFilterableAttributes(['genres', 'title'])
12-
const documentsTask = await searchClient.MeiliSearchClient.index(
13-
'movies'
14-
).addDocuments(dataset)
15-
await searchClient.MeiliSearchClient.index('movies').waitForTask(
16-
documentsTask.uid
17-
)
10+
const deleteTask = await meilisearchClient.deleteIndex('movies')
11+
await meilisearchClient.waitForTask(deleteTask.uid)
12+
await meilisearchClient
13+
.index('movies')
14+
.updateFilterableAttributes(['genres', 'title'])
15+
const documentsTask = await meilisearchClient
16+
.index('movies')
17+
.addDocuments(dataset)
18+
await meilisearchClient.index('movies').waitForTask(documentsTask.uid)
1819
})
1920

2021
test('Test one string facet on filter without a query', async () => {

tests/geosearch.tests.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import { searchClient, geoDataset, City } from './assets/utils'
1+
import {
2+
searchClient,
3+
geoDataset,
4+
City,
5+
meilisearchClient,
6+
} from './assets/utils'
27

38
describe('Instant Meilisearch Browser test', () => {
49
beforeAll(async () => {
5-
const deleteTask = await searchClient.MeiliSearchClient.deleteIndex(
6-
'geotest'
7-
)
8-
await searchClient.MeiliSearchClient.waitForTask(deleteTask.uid)
9-
await searchClient.MeiliSearchClient.index(
10-
'geotest'
11-
).updateFilterableAttributes(['_geo'])
12-
await searchClient.MeiliSearchClient.index(
13-
'geotest'
14-
).updateSortableAttributes(['_geo'])
15-
const documentsTask = await searchClient.MeiliSearchClient.index(
16-
'geotest'
17-
).addDocuments(geoDataset)
18-
await searchClient.MeiliSearchClient.index('movies').waitForTask(
19-
documentsTask.uid
20-
)
10+
const deleteTask = await meilisearchClient.deleteIndex('geotest')
11+
await meilisearchClient.waitForTask(deleteTask.uid)
12+
await meilisearchClient
13+
.index('geotest')
14+
.updateFilterableAttributes(['_geo'])
15+
await meilisearchClient.index('geotest').updateSortableAttributes(['_geo'])
16+
const documentsTask = await meilisearchClient
17+
.index('geotest')
18+
.addDocuments(geoDataset)
19+
await meilisearchClient.index('movies').waitForTask(documentsTask.uid)
2120
})
2221

2322
test('Test aroundRadius and aroundLatLng in geo search', async () => {

0 commit comments

Comments
 (0)