Skip to content

Commit

Permalink
feat(core): introduce Requester API (#540)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Dayan <[email protected]>
  • Loading branch information
francoischalifour and sarahdayan authored Apr 22, 2021
1 parent f5254e9 commit be1cee7
Show file tree
Hide file tree
Showing 106 changed files with 2,373 additions and 1,603 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
coverage
dist
node_modules
.parcel-cache
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ You can find more on the [documentation](https://autocomplete.algolia.com).
| [`autocomplete-plugin-recent-searches`](packages/autocomplete-plugin-recent-searches) | A plugin to add recent searches to Algolia Autocomplete | [Documentation](https://autocomplete.algolia.com/docs/createLocalStorageRecentSearchesPlugin) |
| [`autocomplete-plugin-query-suggestions`](packages/autocomplete-plugin-query-suggestions) | A plugin to add query suggestions to Algolia Autocomplete | [Documentation](https://autocomplete.algolia.com/docs/createQuerySuggestionsPlugin) |
| [`autocomplete-plugin-algolia-insights`](packages/autocomplete-plugin-algolia-insights) | A plugin to add Algolia Insights to Algolia Autocomplete | [Documentation](https://autocomplete.algolia.com/docs/createAlgoliaInsightsPlugin) |
| [`autocomplete-preset-algolia`](packages/autocomplete-preset-algolia) | Presets to use Algolia features with Autocomplete | [Documentation](https://autocomplete.algolia.com/docs/getAlgoliaHits) |
| [`autocomplete-preset-algolia`](packages/autocomplete-preset-algolia) | Presets to use Algolia features with Autocomplete | [Documentation](https://autocomplete.algolia.com/docs/getAlgoliaResults) |
| [`autocomplete-theme-classic`](packages/autocomplete-theme-classic) | Classic theme for Autocomplete | [Documentation](https://autocomplete.algolia.com/docs/autocomplete-theme-classic) |

## Showcase
Expand Down
6 changes: 3 additions & 3 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"files": [
{
"path": "packages/autocomplete-core/dist/umd/index.production.js",
"maxSize": "4.75 kB"
"maxSize": "5 kB"
},
{
"path": "packages/autocomplete-js/dist/umd/index.production.js",
"maxSize": "14.75 kB"
"maxSize": "15.25 kB"
},
{
"path": "packages/autocomplete-preset-algolia/dist/umd/index.production.js",
"maxSize": "2 kB"
"maxSize": "2.25 kB"
},
{
"path": "packages/autocomplete-plugin-algolia-insights/dist/umd/index.production.js",
Expand Down
4 changes: 2 additions & 2 deletions cypress/test-apps/js/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
autocomplete,
AutocompleteComponents,
getAlgoliaHits,
getAlgoliaResults,
} from '@algolia/autocomplete-js';
import {
AutocompleteInsightsApi,
Expand Down Expand Up @@ -78,7 +78,7 @@ autocomplete({
{
sourceId: 'products',
getItems() {
return getAlgoliaHits<Product>({
return getAlgoliaResults<Product>({
searchClient,
queries: [
{
Expand Down
9 changes: 3 additions & 6 deletions cypress/test-apps/js/categoriesPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/** @jsx h */
import {
AutocompletePlugin,
getAlgoliaFacetHits,
} from '@algolia/autocomplete-js';
import { AutocompletePlugin, getAlgoliaFacets } from '@algolia/autocomplete-js';
import { SearchClient } from 'algoliasearch/lite';
import { h, Fragment } from 'preact';

Expand All @@ -24,13 +21,13 @@ export function createCategoriesPlugin({
{
sourceId: 'categoriesPlugin',
getItems() {
return getAlgoliaFacetHits({
return getAlgoliaFacets({
searchClient,
queries: [
{
indexName: 'instant_search',
facet: 'categories',
params: {
facetName: 'categories',
facetQuery: query,
maxFacetHits: query ? 3 : 10,
},
Expand Down
4 changes: 2 additions & 2 deletions cypress/test-apps/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@algolia/autocomplete-plugin-recent-searches": "1.0.0-alpha.44",
"@algolia/autocomplete-preset-algolia": "1.0.0-alpha.44",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.44",
"@algolia/client-search": "4.8.6",
"algoliasearch": "4.8.6",
"@algolia/client-search": "4.9.0",
"algoliasearch": "4.9.0",
"preact": "10.5.13",
"search-insights": "1.7.1"
},
Expand Down
7 changes: 2 additions & 5 deletions examples/multiple-datasets-with-headers/categoriesPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/** @jsx h */
import {
AutocompletePlugin,
getAlgoliaFacetHits,
} from '@algolia/autocomplete-js';
import { AutocompletePlugin, getAlgoliaFacets } from '@algolia/autocomplete-js';
import { SearchClient } from 'algoliasearch/lite';
import { h, Fragment } from 'preact';

Expand All @@ -24,7 +21,7 @@ export function createCategoriesPlugin({
{
sourceId: 'categoriesPlugin',
getItems() {
return getAlgoliaFacetHits({
return getAlgoliaFacets({
searchClient,
queries: [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple-datasets-with-headers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.45",
"@algolia/autocomplete-plugin-recent-searches": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"algoliasearch": "4.8.6",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
Expand Down
29 changes: 16 additions & 13 deletions examples/playground/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
autocomplete,
AutocompleteComponents,
getAlgoliaHits,
getAlgoliaResults,
} from '@algolia/autocomplete-js';
import {
AutocompleteInsightsApi,
Expand All @@ -18,7 +18,7 @@ import '@algolia/autocomplete-theme-classic';

import { createCategoriesPlugin } from './categoriesPlugin';
import { shortcutsPlugin } from './shortcutsPlugin';
import { ProductHit } from './types';
import { ProductRecord, ProductHit } from './types';

const appId = 'latency';
const apiKey = '6be0576ff61c053d5f9a3225e2a90f76';
Expand Down Expand Up @@ -72,7 +72,7 @@ autocomplete<ProductHit>({
{
sourceId: 'products',
getItems() {
return getAlgoliaHits<ProductHit>({
return getAlgoliaResults<ProductRecord>({
searchClient,
queries: [
{
Expand All @@ -85,16 +85,19 @@ autocomplete<ProductHit>({
},
},
],
}).then(([hits]) => {
return hits.map((hit) => ({
...hit,
comments: hit.popularity % 100,
sale: hit.free_shipping,
// eslint-disable-next-line @typescript-eslint/camelcase
sale_price: hit.free_shipping
? (hit.price - hit.price / 10).toFixed(2)
: hit.price.toString(),
}));
transformResponse({ hits }) {
const [bestBuyHits] = hits;

return bestBuyHits.map((hit) => ({
...hit,
comments: hit.popularity % 100,
sale: hit.free_shipping,
// eslint-disable-next-line @typescript-eslint/camelcase
sale_price: hit.free_shipping
? (hit.price - hit.price / 10).toFixed(2)
: hit.price.toString(),
}));
},
});
},
templates: {
Expand Down
9 changes: 3 additions & 6 deletions examples/playground/categoriesPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/** @jsx h */
import {
AutocompletePlugin,
getAlgoliaFacetHits,
} from '@algolia/autocomplete-js';
import { AutocompletePlugin, getAlgoliaFacets } from '@algolia/autocomplete-js';
import { SearchClient } from 'algoliasearch/lite';
import { h, Fragment } from 'preact';

Expand All @@ -24,13 +21,13 @@ export function createCategoriesPlugin({
{
sourceId: 'categoriesPlugin',
getItems() {
return getAlgoliaFacetHits({
return getAlgoliaFacets({
searchClient,
queries: [
{
indexName: 'instant_search',
facet: 'categories',
params: {
facetName: 'categories',
facetQuery: query,
maxFacetHits: query ? 3 : 5,
},
Expand Down
4 changes: 2 additions & 2 deletions examples/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@algolia/autocomplete-plugin-recent-searches": "1.0.0-alpha.45",
"@algolia/autocomplete-preset-algolia": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"@algolia/client-search": "4.8.6",
"algoliasearch": "4.8.6",
"@algolia/client-search": "4.9.0",
"algoliasearch": "4.9.0",
"preact": "10.5.13",
"search-insights": "1.7.1"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/playground/types/ProductHit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Hit } from '@algolia/client-search';

type ProductRecord = {
export type ProductRecord = {
brand: string;
categories: string[];
comments: number;
Expand Down
2 changes: 1 addition & 1 deletion examples/query-suggestions-with-categories/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@algolia/autocomplete-js": "1.0.0-alpha.45",
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"algoliasearch": "4.8.6",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/query-suggestions-with-hits/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
autocomplete,
AutocompleteComponents,
getAlgoliaHits,
getAlgoliaResults,
} from '@algolia/autocomplete-js';
import {
AutocompleteInsightsApi,
Expand Down Expand Up @@ -50,7 +50,7 @@ autocomplete<ProductHit>({
{
sourceId: 'products',
getItems() {
return getAlgoliaHits<ProductHit>({
return getAlgoliaResults<ProductHit>({
searchClient,
queries: [
{
Expand Down
4 changes: 2 additions & 2 deletions examples/query-suggestions-with-hits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@algolia/autocomplete-plugin-recent-searches": "1.0.0-alpha.45",
"@algolia/autocomplete-preset-algolia": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"@algolia/client-search": "4.8.6",
"algoliasearch": "4.8.6",
"@algolia/client-search": "4.9.0",
"algoliasearch": "4.9.0",
"preact": "10.5.13",
"search-insights": "1.7.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@algolia/autocomplete-js": "1.0.0-alpha.45",
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"algoliasearch": "4.8.6",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.45",
"@algolia/autocomplete-plugin-recent-searches": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"@algolia/client-search": "4.8.6",
"algoliasearch": "4.8.6",
"@algolia/client-search": "4.9.0",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.45",
"@algolia/autocomplete-plugin-recent-searches": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"algoliasearch": "4.8.6",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/query-suggestions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@algolia/autocomplete-js": "1.0.0-alpha.45",
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"algoliasearch": "4.8.6",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/react-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"@algolia/autocomplete-core": "1.0.0-alpha.45",
"@algolia/autocomplete-preset-algolia": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"@algolia/client-search": "4.8.4",
"algoliasearch": "4.8.4",
"@algolia/client-search": "4.9.0",
"algoliasearch": "4.9.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-scripts": "4.0.1"
Expand Down
4 changes: 2 additions & 2 deletions examples/react-renderer/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
AutocompleteState,
createAutocomplete,
} from '@algolia/autocomplete-core';
import { getAlgoliaHits } from '@algolia/autocomplete-preset-algolia';
import { getAlgoliaResults } from '@algolia/autocomplete-preset-algolia';
import { Hit } from '@algolia/client-search';
import algoliasearch from 'algoliasearch/lite';
import React from 'react';
Expand Down Expand Up @@ -54,7 +54,7 @@ export function Autocomplete(
{
sourceId: 'products',
getItems({ query }) {
return getAlgoliaHits({
return getAlgoliaResults({
searchClient,
queries: [
{
Expand Down
4 changes: 2 additions & 2 deletions examples/recently-viewed-items/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
autocomplete,
AutocompleteComponents,
getAlgoliaHits,
getAlgoliaResults,
} from '@algolia/autocomplete-js';
import algoliasearch from 'algoliasearch';
import { h, Fragment } from 'preact';
Expand Down Expand Up @@ -35,7 +35,7 @@ autocomplete<ProductHit>({
{
sourceId: 'products',
getItems() {
return getAlgoliaHits<ProductHit>({
return getAlgoliaResults<ProductHit>({
searchClient,
queries: [
{
Expand Down
4 changes: 2 additions & 2 deletions examples/recently-viewed-items/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@algolia/autocomplete-js": "1.0.0-alpha.45",
"@algolia/autocomplete-plugin-recent-searches": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"@algolia/client-search": "4.8.6",
"algoliasearch": "4.8.6",
"@algolia/client-search": "4.9.0",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/starter-algolia/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsx h */
import { autocomplete, getAlgoliaHits } from '@algolia/autocomplete-js';
import { autocomplete, getAlgoliaResults } from '@algolia/autocomplete-js';
import { Hit } from '@algolia/client-search';
import algoliasearch from 'algoliasearch';
import { h } from 'preact';
Expand Down Expand Up @@ -30,7 +30,7 @@ autocomplete<AutocompleteItem>({
{
sourceId: 'products',
getItems() {
return getAlgoliaHits<AutocompleteItem>({
return getAlgoliaResults<AutocompleteItem>({
searchClient,
queries: [
{
Expand Down
4 changes: 2 additions & 2 deletions examples/starter-algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"dependencies": {
"@algolia/autocomplete-js": "1.0.0-alpha.45",
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.45",
"algoliasearch": "4.8.6",
"algoliasearch": "4.9.0",
"preact": "10.5.13"
},
"devDependencies": {
"@algolia/client-search": "4.8.6",
"@algolia/client-search": "4.9.0",
"parcel": "2.0.0-beta.2"
},
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions examples/voice-search/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsx h */
import { autocomplete, getAlgoliaHits } from '@algolia/autocomplete-js';
import { autocomplete, getAlgoliaResults } from '@algolia/autocomplete-js';
import { Hit } from '@algolia/client-search';
import algoliasearch from 'algoliasearch';
import { h } from 'preact';
Expand Down Expand Up @@ -35,7 +35,7 @@ autocomplete<AutocompleteItem>({
{
sourceId: 'products',
getItems() {
return getAlgoliaHits<AutocompleteItem>({
return getAlgoliaResults<AutocompleteItem>({
searchClient,
queries: [
{
Expand Down
Loading

0 comments on commit be1cee7

Please sign in to comment.