Skip to content

Commit

Permalink
fix(algolia): type Algolia presets
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Sep 17, 2020
1 parent 8da805f commit 7c34ada
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 150 deletions.
4 changes: 2 additions & 2 deletions examples/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ autocomplete<QuerySuggestionHit>({
debug: true,
// dropdownPlacement: 'start',
getSources({ query }) {
return getAlgoliaHits({
return getAlgoliaHits<QuerySuggestionHit>({
searchClient,
queries: [
{
Expand All @@ -28,7 +28,7 @@ autocomplete<QuerySuggestionHit>({
},
},
],
}).then((hits) => {
}).then(([hits]) => {
return [
{
getInputValue: ({ suggestion }) => suggestion.query,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "2.19.0",
"@typescript-eslint/parser": "2.19.0",
"algoliasearch": "4.4.0",
"algoliasearch": "4.5.1",
"babel-eslint": "10.1.0",
"babel-loader": "8.1.0",
"babel-plugin-inline-json": "1.2.2",
Expand Down
6 changes: 5 additions & 1 deletion packages/autocomplete-preset-algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
"sideEffects": false,
"files": [
"dist/"
]
],
"dependencies": {
"@algolia/client-search": "4.5.1",
"algoliasearch": "4.5.1"
}
}
43 changes: 21 additions & 22 deletions packages/autocomplete-preset-algolia/src/results.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import {
Hit,
MultipleQueriesQuery,
MultipleQueriesResponse,
} from '@algolia/client-search';
import { SearchClient } from 'algoliasearch/lite';

import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from './constants';
import { version } from './version';

type SearchClient = any;
export type Client = any;
type SearchResponse = any;
type QueryParameters = any;

interface SearchParameters {
indexName: string;
query: string;
params?: QueryParameters;
}

interface GetAlgoliaSourceParams {
searchClient: SearchClient;
queries: SearchParameters[];
queries: MultipleQueriesQuery[];
}

function getAlgoliaSource({ searchClient, queries }: GetAlgoliaSourceParams) {
if (typeof (searchClient as Client).addAlgoliaAgent === 'function') {
(searchClient as Client).addAlgoliaAgent('autocomplete-core', version);
function getAlgoliaSource<THit>({
searchClient,
queries,
}: GetAlgoliaSourceParams) {
if (typeof searchClient.addAlgoliaAgent === 'function') {
searchClient.addAlgoliaAgent('autocomplete-core', version);
}

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

Expand All @@ -40,20 +39,20 @@ function getAlgoliaSource({ searchClient, queries }: GetAlgoliaSourceParams) {
);
}

export function getAlgoliaResults({
export function getAlgoliaResults<THit>({
searchClient,
queries,
}: GetAlgoliaSourceParams): Promise<SearchResponse['results']> {
return getAlgoliaSource({ searchClient, queries }).then((response) => {
}: GetAlgoliaSourceParams): Promise<MultipleQueriesResponse<THit>['results']> {
return getAlgoliaSource<THit>({ searchClient, queries }).then((response) => {
return response.results;
});
}

export function getAlgoliaHits({
export function getAlgoliaHits<THit>({
searchClient,
queries,
}: GetAlgoliaSourceParams): Promise<SearchResponse['hits']> {
return getAlgoliaSource({ searchClient, queries }).then((response) => {
}: GetAlgoliaSourceParams): Promise<Array<Array<Hit<THit>>>> {
return getAlgoliaSource<THit>({ searchClient, queries }).then((response) => {
const results = response.results;

return results.map((result) => result.hits);
Expand Down
124 changes: 0 additions & 124 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,25 @@
# yarn lockfile v1


"@algolia/cache-browser-local-storage@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.4.0.tgz#f58055bdf798d7b31b6d5f86e465cb0fc7dd6694"
integrity sha512-2AiKgN7DpFypkRCRkpqH7waXXyFdcnsPWzmN8sLHrB/FfXqgmsQb3pGft+9YHZIDQ0vAnfgMxSGgMhMGW+0Qnw==
dependencies:
"@algolia/cache-common" "4.4.0"

"@algolia/cache-browser-local-storage@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.5.1.tgz#bdf58c30795683fd48310c552c3a10f10fb26e2b"
integrity sha512-TAQHRHaCUAR0bNhUHG0CnO6FTx3EMPwZQrjPuNS6kHvCQ/H8dVD0sLsHyM8C7U4j33xPQCWi9TBnSx8cYXNmNw==
dependencies:
"@algolia/cache-common" "4.5.1"

"@algolia/cache-common@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.4.0.tgz#bfe84790230f5d2de495238b29e9397c5ed2b26e"
integrity sha512-PrIgoMnXaDWUfwOekahro543pgcJfgRu/nd/ZQS5ffem3+Ow725eZY6HDpPaQ1k3cvLii9JH6V2sNJConjqUKA==

"@algolia/cache-common@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.5.1.tgz#3aefda3382dc30b67091b01a3d7461d937082821"
integrity sha512-Sux+pcedQi9sfScIiQdl6pEaTVl712qM9OblvDhnaeF1v6lf4jyTlRTiBLP7YBLuvO1Yo54W3maf03kmz9PVhA==

"@algolia/cache-in-memory@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.4.0.tgz#54a089094c2afa5b9cacab4b60a5f1ba29013a7c"
integrity sha512-9+XlUB0baDU/Dp9URRHPp6Q37YmTO0QmgPWt9+n+wqZrRL0jR3Jezr4jCT7RemqGMxBiR+YpnqaUv0orpb0ptw==
dependencies:
"@algolia/cache-common" "4.4.0"

"@algolia/cache-in-memory@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.5.1.tgz#127cd473474f62300a157f4ee3b3f6836003cf35"
integrity sha512-fzwAtBFwveuG+E5T/namChEIvdVl0DoV3djV1C078b/JpO5+DeAwuXIJGYbyl950u170n5NEYuIwYG+R6h4lJQ==
dependencies:
"@algolia/cache-common" "4.5.1"

"@algolia/client-account@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.4.0.tgz#7dbeff83e1c85d853b3ad224674a924e02b94d1b"
integrity sha512-Kynu3cMEs0clTLf674rtrCF+FWR/JwlQxKlIWsPzvLBRmNXdvYej9YBcNaOr4OTQFCCZn9JVE8ib91Z7J4IL1Q==
dependencies:
"@algolia/client-common" "4.4.0"
"@algolia/client-search" "4.4.0"
"@algolia/transporter" "4.4.0"

"@algolia/client-account@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.5.1.tgz#7d3ccda09d3c7849b171c915da0833e7649bab33"
Expand All @@ -58,16 +30,6 @@
"@algolia/client-search" "4.5.1"
"@algolia/transporter" "4.5.1"

"@algolia/client-analytics@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.4.0.tgz#50dde68b067c615fc91434c98db9b5ca429be33d"
integrity sha512-GQyjQimKAc9sZbafxln9Wk7j4pEYiORv28MZkZ+0Bjt7WNXIeO7OgOOECVpQHm9buyV6hCKpNtJcbb5/syRzdQ==
dependencies:
"@algolia/client-common" "4.4.0"
"@algolia/client-search" "4.4.0"
"@algolia/requester-common" "4.4.0"
"@algolia/transporter" "4.4.0"

"@algolia/client-analytics@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.5.1.tgz#bfc2a7292a9ea789ca3c99f79b1f96c08d378828"
Expand All @@ -78,14 +40,6 @@
"@algolia/requester-common" "4.5.1"
"@algolia/transporter" "4.5.1"

"@algolia/client-common@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.4.0.tgz#b9fa987bc7a148f9756da59ada51fe2494a4aa9a"
integrity sha512-a3yr6UhzjWPHDG/8iGp9UvrDOm1aeHVWJIf0Nj/cIvqX5tNCEIo4IMe59ovApkDgLOIpt/cLsyhn9/FiPXRhJA==
dependencies:
"@algolia/requester-common" "4.4.0"
"@algolia/transporter" "4.4.0"

"@algolia/client-common@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.5.1.tgz#91a401eba6eafd7cc74a0aeccb4c6e6cb1e72026"
Expand All @@ -94,15 +48,6 @@
"@algolia/requester-common" "4.5.1"
"@algolia/transporter" "4.5.1"

"@algolia/client-recommendation@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/client-recommendation/-/client-recommendation-4.4.0.tgz#82410f7a346ed8518b8dcd28bc47571e850ab74f"
integrity sha512-sBszbQH46rko6w2fdEG77ma8+fAg0SDkLZGxWhv4trgcnYGUBFl2dcpEPt/6koto9b4XYlf+eh+qi6iGvYqRPg==
dependencies:
"@algolia/client-common" "4.4.0"
"@algolia/requester-common" "4.4.0"
"@algolia/transporter" "4.4.0"

"@algolia/client-recommendation@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/client-recommendation/-/client-recommendation-4.5.1.tgz#57a1fe30987c90b10d5119b8e7d6cd91c423e54c"
Expand All @@ -112,15 +57,6 @@
"@algolia/requester-common" "4.5.1"
"@algolia/transporter" "4.5.1"

"@algolia/client-search@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.4.0.tgz#c1e107206f3ae719cd3a9877889eea5e5cbcdc62"
integrity sha512-jqWcxCUyPPHnHreoMb2PnN9iHTP+V/nL62R84XuTRDE3VgTnhm4ZnqyuRdzZQqaz+gNy5znav64TmQ9FN9WW5g==
dependencies:
"@algolia/client-common" "4.4.0"
"@algolia/requester-common" "4.4.0"
"@algolia/transporter" "4.4.0"

"@algolia/client-search@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.5.1.tgz#cb798c99d6621e29a36334b92205518a74ecdf3e"
Expand All @@ -130,77 +66,37 @@
"@algolia/requester-common" "4.5.1"
"@algolia/transporter" "4.5.1"

"@algolia/logger-common@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.4.0.tgz#8115d95d5f6227f0127d33130a9c4622cde64f6f"
integrity sha512-2vjmSENLaKNuF+ytRDysfWxxgFG95WXCHwHbueThdPMCK3hskkwqJ0Y/pugKfzl+54mZxegb4BYfgcCeuaHVUw==

"@algolia/logger-common@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.5.1.tgz#18d654516369a28e25ad7eee4fc2882fd47ed8ec"
integrity sha512-ZoVnGriinlLHlkvn5K7djOUn1/1IeTjU8rDzOJ3t06T+2hQytgJghaX7rSwKIeH4CjWMy61w8jLisuGJRBOEeg==

"@algolia/logger-console@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.4.0.tgz#1e0eaaf0879f152f9a1fa333c4cd8cb55e071552"
integrity sha512-st/GUWyKvr6YM72OOfF+RmpdVGda3BPXbQ+chpntUq1WyVkyZXGjSmH1IcBVlua27GzxabwOUYON39cF3x10/g==
dependencies:
"@algolia/logger-common" "4.4.0"

"@algolia/logger-console@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.5.1.tgz#c9def97c20bea5eecb4b07f8d3f733c0192d1761"
integrity sha512-1qa7K18+uAgxyWuguayaDS5ViiZFcOjI3J5ACBb0i/n7RsXUo149lP6mwmx6TIU7s135hT0f0TCqnvfMvN1ilA==
dependencies:
"@algolia/logger-common" "4.5.1"

"@algolia/requester-browser-xhr@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.4.0.tgz#f5877397ed92d2d64d08846ea969aeb559a5efb6"
integrity sha512-V3a4hXlNch355GnWaT1f5QfXhROpsjT6sd0Znq29gAhwLqfBExhLW6Khdkv5pENC0Qy7ClVhdXFrBL9QCQer1g==
dependencies:
"@algolia/requester-common" "4.4.0"

"@algolia/requester-browser-xhr@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.5.1.tgz#838b55209d2c83572df261338f7cd75be36de401"
integrity sha512-tsQz+9pZw9dwPm/wMvZDpsWFZgmghLjXi4c3O4rfwoP/Ikum5fhle5fiR14yb4Lw4WlOQ1AJIHJvrg1qLIG8hQ==
dependencies:
"@algolia/requester-common" "4.5.1"

"@algolia/requester-common@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.4.0.tgz#0e977939aae32ff81a6d27480a71771a65db6051"
integrity sha512-jPinHlFJEFokxQ5b3JWyjQKKn+FMy0hH99PApzOgQAYOSiFRXiPEZp6LeIexDeLLu7Y3eRt/3nHvjPKa6PmRRw==

"@algolia/requester-common@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.5.1.tgz#a34d02daa6093e112b528d3bcd5a5467c00ba823"
integrity sha512-bPCiLvhHKXaka7f5FLtheChToz0yHVhvza64naFJRRh/3kC0nvyrvQ0ogjiydiSrGIfdNDyyTVfKGdk4gS5gyA==

"@algolia/requester-node-http@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.4.0.tgz#6ffba93d54eeadf64cb1be67fae5c4e3f7c8f390"
integrity sha512-b7HC9C/GHxiV4+0GpCRTtjscvwarPr3dGm4CAhb6AkNjgjRcFUNr1NfsF75w3WVmzmt79/7QZihddztDdVMGjw==
dependencies:
"@algolia/requester-common" "4.4.0"

"@algolia/requester-node-http@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.5.1.tgz#29911c104c6714a5cb29d3991f2b50c52301e091"
integrity sha512-BfFc2h9eQOKu1gGs3DtQO7GrVZW/rxUgpJVLja4UVQyGplJyTCrFgkTyfl+8rb3MkNgA/S2LNo7cKNSPfpqeAQ==
dependencies:
"@algolia/requester-common" "4.5.1"

"@algolia/transporter@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.4.0.tgz#6ec79aac43bc515c8e4f6d6e27dc8d8cd7112f7e"
integrity sha512-Xxzq91DEEeKIzT3DU46n4LEyTGAKZNtSHc2H9wvIY5MYwhZwEribmXXZ6k8W1FvBvzggv3juu0SP+xwGoR7F0w==
dependencies:
"@algolia/cache-common" "4.4.0"
"@algolia/logger-common" "4.4.0"
"@algolia/requester-common" "4.4.0"

"@algolia/transporter@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.5.1.tgz#e0a5c64f358b6751f867001f51f384d6fc7ede14"
Expand Down Expand Up @@ -4092,26 +3988,6 @@ algoliasearch-helper@^3.1.1:
dependencies:
events "^1.1.1"

algoliasearch@4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.4.0.tgz#25c356d8bdcf7e3f941633f61e1ac111ddcba404"
integrity sha512-Ag3wxe/nSodNl/1KbHibtkh7TNLptKE300/wnGVtszRjXivaWD6333nUpCumrYObHym/fHMHyLcmQYezXbAIWQ==
dependencies:
"@algolia/cache-browser-local-storage" "4.4.0"
"@algolia/cache-common" "4.4.0"
"@algolia/cache-in-memory" "4.4.0"
"@algolia/client-account" "4.4.0"
"@algolia/client-analytics" "4.4.0"
"@algolia/client-common" "4.4.0"
"@algolia/client-recommendation" "4.4.0"
"@algolia/client-search" "4.4.0"
"@algolia/logger-common" "4.4.0"
"@algolia/logger-console" "4.4.0"
"@algolia/requester-browser-xhr" "4.4.0"
"@algolia/requester-common" "4.4.0"
"@algolia/requester-node-http" "4.4.0"
"@algolia/transporter" "4.4.0"

algoliasearch@4.5.1, algoliasearch@^4.0.0:
version "4.5.1"
resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.5.1.tgz#fd20cd76f6ba3fbecdd4e11bdaefefb44abc0b38"
Expand Down

0 comments on commit 7c34ada

Please sign in to comment.