Skip to content

Changes related to the next Meilisearch release (v0.28.0) #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ Here is the [CSS customization](https://github.com/meilisearch/vuepress-plugin-m

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).

## ⚙️ Development Workflow and Contributing

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"dependencies": {
"autocomplete.js": "^0.38.1",
"meilisearch": "^0.26.0",
"meilisearch": "^0.27.0",
"to-factory": "^1.0.0",
"zepto": "^1.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/html/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ const { MeiliSearch } = require('meilisearch')

const response = await index.addDocuments(dataset)

const task = await client.waitForTask(response.uid)
const task = await client.waitForTask(response.taskUid)
console.log(task)
})()
30 changes: 26 additions & 4 deletions src/lib/DocsSearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import templates from './templates'
import utils from './utils'
import $ from './zepto'
import { MeiliSearch } from 'meilisearch'
import { constructClientAgents } from './agents'

/**
* Adds an autocomplete dropdown to an input field
Expand Down Expand Up @@ -56,6 +57,7 @@ class DocsSearchBar {
enhancedSearchInput = false,
layout = 'columns',
enableDarkMode = false,
clientAgents = [],
}) {
DocsSearchBar.checkArguments({
hostUrl,
Expand All @@ -72,6 +74,7 @@ class DocsSearchBar {
enhancedSearchInput,
layout,
enableDarkMode,
clientAgents,
})

this.apiKey = apiKey
Expand Down Expand Up @@ -115,6 +118,7 @@ class DocsSearchBar {
this.client = new MeiliSearch({
host: hostUrl,
apiKey: this.apiKey,
clientAgents: constructClientAgents(clientAgents),
})

DocsSearchBar.addThemeWrapper(inputSelector, this.enableDarkMode)
Expand Down Expand Up @@ -255,6 +259,8 @@ class DocsSearchBar {
false,
)

DocsSearchBar.typeCheck(args, ['clientAgents'], 'array', true)

DocsSearchBar.typeCheck(
args,
['queryDataCallback', 'transformData', 'queryHook', 'handleSelected'],
Expand All @@ -268,6 +274,20 @@ class DocsSearchBar {
)
}
}
/**
* Throw a type error.
*
* @param {string} argument - Name of the parameter
* @param {string} type - Type the parameter should have
* @param {string} value - Value the parameter has
*
* @returns {void}
*/
static throwTypeError(argument, type, value) {
throw new Error(
`Error: "${argument}" must be of type: ${type}. Found type: ${typeof value}`,
)
}

/**
* Checks if the arguments defined in the check variable are of the supplied
Expand All @@ -283,10 +303,12 @@ class DocsSearchBar {
.filter((argument) => !optional || args[argument])
.forEach((argument) => {
const value = args[argument]
if (typeof args[argument] !== type) {
throw new Error(
`Error: "${argument}" must be of type: ${type}. Found type: ${typeof value}`,
)
if (type === 'array') {
if (!Array.isArray(args[argument])) {
DocsSearchBar.throwTypeError(argument, type, value)
}
} else if (typeof args[argument] !== type) {
DocsSearchBar.throwTypeError(argument, type, value)
}
})
}
Expand Down
32 changes: 32 additions & 0 deletions src/lib/__tests__/DocsSearchBar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sinon from 'sinon'
import $ from '../zepto'
import DocsSearchBar from '../DocsSearchBar'
import PACKAGE_VERSION from '../version'
/**
* Pitfalls:
* Whenever you call new DocsSearchBar(), it will add the a new dropdown markup to
Expand Down Expand Up @@ -183,6 +184,7 @@ describe('DocsSearchBar', () => {
MeiliSearch.calledWith({
host: 'https://test.getmeili.com',
apiKey: 'apiKey',
clientAgents: [`Meilisearch docs-searchbar.js (v${PACKAGE_VERSION})`],
}),
).toBe(true)
})
Expand Down Expand Up @@ -226,6 +228,27 @@ describe('DocsSearchBar', () => {
expect(autocomplete.on.calledTwice).toBe(true)
expect(autocomplete.on.calledWith('autocomplete:selected')).toBe(true)
})

it('should have spread the user agents', () => {
// Given
const options = { ...defaultOptions, clientAgents: ['test'] }

// When
new DocsSearchBar(options)

// Then
expect(MeiliSearch.calledOnce).toBe(true)
expect(
MeiliSearch.calledWith({
host: 'https://test.getmeili.com',
apiKey: 'apiKey',
clientAgents: [
'test',
`Meilisearch docs-searchbar.js (v${PACKAGE_VERSION})`,
],
}),
).toBe(true)
})
})

describe('checkArguments', () => {
Expand Down Expand Up @@ -377,6 +400,15 @@ describe('DocsSearchBar', () => {
// Given
const options = { ...defaultOptions, handleSelected: 'not-a-function' }

// When
expect(() => {
checkArguments(options)
}).toThrow(/^Error:/)
})
it('should throw an error if clientAgents is not an array', () => {
// Given
const options = { ...defaultOptions, clientAgents: 'test' }

// When
expect(() => {
checkArguments(options)
Expand Down
7 changes: 7 additions & 0 deletions src/lib/agents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import version from './version'

export const constructClientAgents = (clientAgents = []) => {
const instantMeilisearchAgent = `Meilisearch docs-searchbar.js (v${version})`

return clientAgents.concat(instantMeilisearchAgent)
}
2 changes: 1 addition & 1 deletion tests/env/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"parcel-bundler": "^1.12.5"
},
"dependencies": {
"meilisearch": "^0.24.0"
"meilisearch": "^0.27.0"
}
}
2 changes: 1 addition & 1 deletion tests/env/browser/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,6 @@ const { MeiliSearch } = require('meilisearch')

const response = await index.addDocuments(dataset)

const task = await client.waitForTask(response.uid)
const task = await client.waitForTask(response.taskUid)
console.log(task)
})()
12 changes: 6 additions & 6 deletions tests/env/browser/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

cross-fetch@^3.1.4:
cross-fetch@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
Expand Down Expand Up @@ -3270,12 +3270,12 @@ [email protected]:
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b"
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==

meilisearch@^0.24.0:
version "0.24.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.24.0.tgz#a71454baac058f502b931af17069ab676fbaced6"
integrity sha512-qME1dsHZePBQi8qFdhbilcFzaL+oZJgUuls+FZ23hHpdhJI+iMFSmjjcfsxq5hdg2qczbCXv7yAo3Sh8xgfkgA==
meilisearch@^0.27.0:
version "0.27.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0.tgz#8bd57ddb77b975f93e054cb977b951c488ece297"
integrity sha512-kZOZFIuSO7c6xRf+Y2/9/h6A9pl0sCl/G44X4KuaSwxGbruOZPhmxbeVEgLHBv4pUFvQ56rNVTA/2d/5GCU1YA==
dependencies:
cross-fetch "^3.1.4"
cross-fetch "^3.1.5"

[email protected]:
version "1.0.4"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5442,10 +5442,10 @@ [email protected]:
resolved "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz"
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==

meilisearch@^0.26.0:
version "0.26.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.26.0.tgz#6bd19118c9841a5ece938da11372d227a75bdbb3"
integrity sha512-2JAxwqahhv5ToIDLdQAmQJcb3YuoH41m1L4WTtX+zeKeClnkowSxA1CHff+n4K6iEYxF5GiMxpqPsWTt4nQKFA==
meilisearch@^0.27.0:
version "0.27.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0.tgz#8bd57ddb77b975f93e054cb977b951c488ece297"
integrity sha512-kZOZFIuSO7c6xRf+Y2/9/h6A9pl0sCl/G44X4KuaSwxGbruOZPhmxbeVEgLHBv4pUFvQ56rNVTA/2d/5GCU1YA==
dependencies:
cross-fetch "^3.1.5"

Expand Down