-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types): support algoliasearch v5 (#5066)
* feat(types): support algoliasearch v5 simplifies the types on top of algolia/algoliasearch-helper-js#910 * update with trial * try with that other file * let's do it this way * cast as any, because the type is too narrow * udpate helper again * answers * tryalong * upd * update helper * update to released helper * fix ^ * fix unit test * move anys * Update src/connectors/geo-search/__tests__/connectGeoSearch-test.ts * remove T * allez, avoidable like this
- Loading branch information
Showing
13 changed files
with
52 additions
and
101 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
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
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,72 +1,3 @@ | ||
/* eslint-disable import/no-duplicates */ | ||
// Custom types to support both algoliasearch | ||
// `v3` and algoliasearch `v4` clients. | ||
export * from 'algoliasearch-helper/types/algoliasearch.js'; | ||
|
||
import type algoliasearch from 'algoliasearch/lite'; | ||
import type * as AlgoliaSearch from 'algoliasearch/lite'; | ||
/** @ts-ignore */ | ||
import type * as ClientSearch from '@algolia/client-search'; | ||
|
||
/** @ts-ignore */ | ||
type SearchResponseV3<TObject> = AlgoliaSearch.Response<TObject>; | ||
/** @ts-ignore */ | ||
type SearchResponseV4<TObject> = ClientSearch.SearchResponse<TObject>; | ||
|
||
type SearchForFacetValuesResponseV3 = | ||
/** @ts-ignore */ | ||
AlgoliaSearch.SearchForFacetValues.Response; | ||
/** @ts-ignore */ | ||
type SearchForFacetValuesResponseV4 = ClientSearch.SearchForFacetValuesResponse; | ||
|
||
type RelevantSortResponse = { | ||
appliedRelevancyStrictness?: number; | ||
nbSortedHits?: number; | ||
}; | ||
|
||
type DummySearchClientV4 = { | ||
readonly transporter: any; | ||
}; | ||
|
||
type DefaultSearchClient = ReturnType<typeof algoliasearch>; | ||
|
||
type SearchIndex = ReturnType<DefaultSearchClient['initIndex']>; | ||
|
||
export type SearchClient = { | ||
search: DefaultSearchClient['search']; | ||
searchForFacetValues: DefaultSearchClient['searchForFacetValues']; | ||
addAlgoliaAgent?: DefaultSearchClient['addAlgoliaAgent']; | ||
initIndex?: ( | ||
indexName: string | ||
) => SearchIndex extends { findAnswers: any } | ||
? Partial<Pick<SearchIndex, 'findAnswers'>> | ||
: SearchIndex; | ||
}; | ||
|
||
export type MultiResponse<THit = any> = { | ||
results: Array<SearchResponse<THit>>; | ||
}; | ||
|
||
export type SearchResponse<THit> = | ||
DefaultSearchClient extends DummySearchClientV4 | ||
? SearchResponseV4<THit> | ||
: SearchResponseV3<THit> & RelevantSortResponse; | ||
|
||
export type SearchForFacetValuesResponse = | ||
DefaultSearchClient extends DummySearchClientV4 | ||
? SearchForFacetValuesResponseV4 | ||
: SearchForFacetValuesResponseV3; | ||
|
||
export type FindAnswersParameters = SearchIndex extends { | ||
findAnswers: (...params: infer Params) => any; | ||
} | ||
? Params | ||
: any; | ||
|
||
export type FindAnswersOptions = DefaultSearchClient extends DummySearchClientV4 | ||
? ClientSearch.FindAnswersOptions | ||
: any; | ||
|
||
export type FindAnswersResponse<TObject> = | ||
DefaultSearchClient extends DummySearchClientV4 | ||
? ClientSearch.FindAnswersResponse<TObject> | ||
: any; | ||
export {}; |
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
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