forked from algolia/instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types): allow typed access to properties added to entry (algolia…
…#4814) also removes the file for "main" as it's inconsistent with index.es.ts
- Loading branch information
Showing
12 changed files
with
219 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import instantsearch from '../index.es'; | ||
|
||
describe('instantsearch()', () => { | ||
it('includes a version', () => { | ||
expect(instantsearch.version).toMatch( | ||
/^(\d+\.)?(\d+\.)?(\*|\d+)(-beta.\d+)?$/ | ||
); | ||
}); | ||
|
||
it('does not include the widget functions', () => { | ||
// @ts-expect-error | ||
expect(() => instantsearch.widgets).toThrowErrorMatchingInlineSnapshot(` | ||
"\\"instantsearch.widgets\\" are not available from the ES build. | ||
To import the widgets: | ||
import { searchBox } from 'instantsearch.js/es/widgets'" | ||
`); | ||
}); | ||
|
||
it('does not include the connectors functions', () => { | ||
// @ts-expect-error | ||
expect(() => instantsearch.connectors).toThrowErrorMatchingInlineSnapshot(` | ||
"\\"instantsearch.connectors\\" are not available from the ES build. | ||
To import the connectors: | ||
import { connectSearchBox } from 'instantsearch.js/es/connectors'" | ||
`); | ||
}); | ||
|
||
it('includes the helper functions', () => { | ||
expect(Object.keys(instantsearch)).toMatchInlineSnapshot(` | ||
Array [ | ||
"version", | ||
"createInfiniteHitsSessionStorageCache", | ||
"highlight", | ||
"reverseHighlight", | ||
"snippet", | ||
"reverseSnippet", | ||
"insights", | ||
"getInsightsAnonymousUserToken", | ||
] | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/connectors/configure-related-items/__tests__/connectConfigureRelatedItems-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,70 @@ | ||
import instantsearch from './lib/main'; | ||
import InstantSearch, { InstantSearchOptions } from './lib/InstantSearch'; | ||
import { Expand, UiState } from './types'; | ||
|
||
import version from './lib/version'; | ||
|
||
import * as connectors from './connectors/index'; | ||
import * as widgets from './widgets/index'; | ||
import * as helpers from './helpers/index'; | ||
import * as middlewares from './middlewares/index'; | ||
|
||
import * as routers from './lib/routers/index'; | ||
import * as stateMappings from './lib/stateMappings/index'; | ||
import { createInfiniteHitsSessionStorageCache } from './lib/infiniteHitsCache/index'; | ||
|
||
type InstantSearchModule = { | ||
<TUiState = Record<string, unknown>, TRouteState = TUiState>( | ||
options: InstantSearchOptions<Expand<UiState & TUiState>, TRouteState> | ||
): InstantSearch<Expand<UiState & TUiState>, TRouteState>; | ||
version: string; | ||
|
||
connectors: typeof connectors; | ||
widgets: typeof widgets; | ||
middlewares: typeof middlewares; | ||
|
||
routers: typeof routers; | ||
stateMappings: typeof stateMappings; | ||
|
||
createInfiniteHitsSessionStorageCache: typeof createInfiniteHitsSessionStorageCache; | ||
highlight: typeof helpers.highlight; | ||
reverseHighlight: typeof helpers.reverseHighlight; | ||
snippet: typeof helpers.snippet; | ||
reverseSnippet: typeof helpers.reverseSnippet; | ||
insights: typeof helpers.insights; | ||
}; | ||
|
||
/** | ||
* InstantSearch is the main component of InstantSearch.js. This object | ||
* manages the widget and lets you add new ones. | ||
* | ||
* Two parameters are required to get you started with InstantSearch.js: | ||
* - `indexName`: the main index that you will use for your new search UI | ||
* - `searchClient`: the search client to plug to InstantSearch.js | ||
* | ||
* The [search client provided by Algolia](algolia.com/doc/api-client/getting-started/what-is-the-api-client/javascript/) | ||
* needs an `appId` and an `apiKey`. Those parameters can be found in your | ||
* [Algolia dashboard](https://www.algolia.com/api-keys). | ||
* | ||
* If you want to get up and running quickly with InstantSearch.js, have a | ||
* look at the [getting started](https://www.algolia.com/doc/guides/building-search-ui/getting-started/js/). | ||
*/ | ||
const instantsearch: InstantSearchModule = options => | ||
new InstantSearch(options); | ||
|
||
instantsearch.version = version; | ||
|
||
instantsearch.connectors = connectors; | ||
instantsearch.widgets = widgets; | ||
instantsearch.middlewares = middlewares; | ||
|
||
instantsearch.routers = routers; | ||
instantsearch.stateMappings = stateMappings; | ||
|
||
instantsearch.createInfiniteHitsSessionStorageCache = createInfiniteHitsSessionStorageCache; | ||
instantsearch.highlight = helpers.highlight; | ||
instantsearch.reverseHighlight = helpers.reverseHighlight; | ||
instantsearch.snippet = helpers.snippet; | ||
instantsearch.reverseSnippet = helpers.reverseSnippet; | ||
instantsearch.insights = helpers.insights; | ||
|
||
export default instantsearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.