-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(preset-algolia): support algoliasearch v5 (#1002)
* fix(preset-algolia): support algoliasearch v5 * generic
- Loading branch information
Showing
8 changed files
with
86 additions
and
15 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
2 changes: 1 addition & 1 deletion
2
packages/autocomplete-preset-algolia/src/highlight/HighlightedHit.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
2 changes: 1 addition & 1 deletion
2
packages/autocomplete-preset-algolia/src/highlight/SnippetedHit.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
9 changes: 4 additions & 5 deletions
9
packages/autocomplete-preset-algolia/src/requester/createRequester.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
2 changes: 1 addition & 1 deletion
2
packages/autocomplete-preset-algolia/src/requester/getAlgoliaFacets.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
71 changes: 71 additions & 0 deletions
71
packages/autocomplete-preset-algolia/src/types/algoliasearch.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as ClientSearch from '@algolia/client-search'; | ||
import type * as AlgoliaSearch from 'algoliasearch/lite'; | ||
|
||
// turns any to unknown, so it can be used as a conditional | ||
type AnyToUnknown<TSubject> = (any extends TSubject ? true : false) extends true | ||
? unknown | ||
: TSubject; | ||
|
||
type SearchClientShape = { | ||
search: unknown; | ||
}; | ||
|
||
type ClientLiteV5 = AnyToUnknown< | ||
// @ts-ignore | ||
ReturnType<typeof AlgoliaSearch.liteClient> | ||
>; | ||
type ClientSearchV5 = AnyToUnknown< | ||
// @ts-ignore | ||
ReturnType<typeof ClientSearch.searchClient> | ||
>; | ||
type ClientV5 = ClientLiteV5 extends SearchClientShape | ||
? ClientLiteV5 | ||
: ClientSearchV5 extends SearchClientShape | ||
? ClientSearchV5 | ||
: unknown; | ||
|
||
type PickForClient< | ||
TMapping extends { v4: unknown; v5: unknown } | ||
> = ClientV5 extends SearchClientShape ? TMapping['v5'] : TMapping['v4']; | ||
|
||
export type SearchClient = PickForClient<{ | ||
// @ts-ignore | ||
v4: AlgoliaSearch.SearchClient; | ||
// @ts-ignore | ||
v5: ClientV5; | ||
}>; | ||
|
||
export type MultipleQueriesQuery = PickForClient<{ | ||
// @ts-ignore | ||
v4: ClientSearch.MultipleQueriesQuery; | ||
// @ts-ignore | ||
v5: AlgoliaSearch.LegacySearchMethodProps[number]; | ||
}>; | ||
|
||
export type SearchForFacetValuesResponse = PickForClient<{ | ||
// @ts-ignore | ||
v4: ClientSearch.SearchForFacetValuesResponse; | ||
// @ts-ignore | ||
v5: AlgoliaSearch.SearchForFacetValuesResponse; | ||
}>; | ||
|
||
export type SearchResponse<THit> = PickForClient<{ | ||
// @ts-ignore | ||
v4: ClientSearch.SearchResponse<THit>; | ||
// @ts-ignore | ||
v5: AlgoliaSearch.SearchResponse<THit>; | ||
}>; | ||
|
||
export type HighlightResult<THit> = PickForClient<{ | ||
// @ts-ignore | ||
v4: ClientSearch.HighlightResult<THit>; | ||
// @ts-ignore | ||
v5: AlgoliaSearch.HighlightResult; // should be generic, but isn't yet in the client | ||
}>; | ||
|
||
export type SnippetResult<THit> = PickForClient<{ | ||
// @ts-ignore | ||
v4: ClientSearch.SnippetResult<THit>; | ||
// @ts-ignore | ||
v5: AlgoliaSearch.SnippetResult; // should be generic, but isn't yet in the client | ||
}>; |
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 @@ | ||
export * from './algoliasearch'; |