Skip to content
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

fix(algolia): fix getAlgoliaResults typings #336

Merged
merged 1 commit into from
Oct 12, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Hit } from '@algolia/client-search';

import { search, SearchParams } from './search';

export function getAlgoliaHits<THit>({
export function getAlgoliaHits<TRecord>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened to the idea of making this an indexName indexed object of records? The client doesn't have the feature, but I think we could assert the type here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to implement this type mapping in the client first, and then to leverage that in Autocomplete. It'll avoid shipping any inconsistencies.

(The more I work on multi-index UIs with the search client, the more I need this type support btw 🙂)

searchClient,
queries,
}: SearchParams): Promise<Array<Array<Hit<THit>>>> {
return search<THit>({ searchClient, queries }).then((response) => {
}: SearchParams): Promise<Array<Array<Hit<TRecord>>>> {
return search<TRecord>({ searchClient, queries }).then((response) => {
const results = response.results;

return results.map((result) => result.hits);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MultipleQueriesResponse } from '@algolia/client-search';
import { SearchResponse } from '@algolia/client-search';

import { search, SearchParams } from './search';

export function getAlgoliaResults<THit>({
export function getAlgoliaResults<TRecord>({
searchClient,
queries,
}: SearchParams): Promise<MultipleQueriesResponse<THit>['results']> {
return search<THit>({ searchClient, queries }).then((response) => {
}: SearchParams): Promise<Array<SearchResponse<TRecord>>> {
return search<TRecord>({ searchClient, queries }).then((response) => {
return response.results;
});
}
4 changes: 2 additions & 2 deletions packages/autocomplete-preset-algolia/src/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export interface SearchParams {
queries: MultipleQueriesQuery[];
}

export function search<THit>({ searchClient, queries }: SearchParams) {
export function search<TRecord>({ searchClient, queries }: SearchParams) {
if (typeof searchClient.addAlgoliaAgent === 'function') {
searchClient.addAlgoliaAgent('autocomplete-core', version);
}

return searchClient.search<THit>(
return searchClient.search<TRecord>(
queries.map((searchParameters) => {
const { indexName, query, params } = searchParameters;

Expand Down