Skip to content
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
14 changes: 2 additions & 12 deletions packages/recommend/src/methods/getRecommendations.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { MethodEnum } from '@algolia/requester-common';

import {
BaseRecommendClient,
RecommendationsQuery,
TrendingFacetsQuery,
TrendingItemsQuery,
TrendingModel,
WithRecommendMethods,
} from '../types';
import { BaseRecommendClient, RecommendationsQuery, WithRecommendMethods } from '../types';
import { TrendingQuery } from '../types/TrendingQuery';

type GetRecommendations = (
base: BaseRecommendClient
) => WithRecommendMethods<BaseRecommendClient>['getRecommendations'];

type TrendingQuery =
| (TrendingItemsQuery & { readonly model: TrendingModel })
| (TrendingFacetsQuery & { readonly model: TrendingModel });

export const getRecommendations: GetRecommendations = base => {
return (queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>, requestOptions) => {
const requests: ReadonlyArray<RecommendationsQuery | TrendingQuery> = queries.map(query => ({
Expand Down
7 changes: 7 additions & 0 deletions packages/recommend/src/types/TrendingQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TrendingFacetsQuery } from '../types/TrendingFacetsQuery';
import { TrendingItemsQuery } from '../types/TrendingItemsQuery';
import { TrendingModel } from './RecommendModel';

export type TrendingQuery =
| (TrendingItemsQuery & { readonly model: TrendingModel })
| (TrendingFacetsQuery & { readonly model: TrendingModel });
3 changes: 2 additions & 1 deletion packages/recommend/src/types/WithRecommendMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { RecommendationsQuery } from './RecommendationsQuery';
import { RelatedProductsQuery } from './RelatedProductsQuery';
import { TrendingFacetsQuery } from './TrendingFacetsQuery';
import { TrendingItemsQuery } from './TrendingItemsQuery';
import { TrendingQuery } from './TrendingQuery';

export type WithRecommendMethods<TType> = TType & {
/**
* Returns recommendations.
*/
readonly getRecommendations: <TObject>(
queries: readonly RecommendationsQuery[],
queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>,
requestOptions?: RequestOptions & SearchOptions
) => Readonly<Promise<MultipleQueriesResponse<TObject>>>;

Expand Down
1 change: 1 addition & 0 deletions packages/recommend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export * from './RecommendationsQuery';
export * from './RelatedProductsQuery';
export * from './TrendingFacetsQuery';
export * from './TrendingItemsQuery';
export * from './TrendingQuery';
export * from './WithRecommendMethods';