Skip to content

Commit

Permalink
fix(recommend): Align getRecommendations type with actual implement…
Browse files Browse the repository at this point in the history
…ation (#1459)
  • Loading branch information
raed667 committed May 15, 2023
1 parent 9a0a94e commit d18391b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
14 changes: 2 additions & 12 deletions packages/recommend/src/methods/getRecommendations.ts
@@ -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
@@ -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
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
Expand Up @@ -12,4 +12,5 @@ export * from './RecommendationsQuery';
export * from './RelatedProductsQuery';
export * from './TrendingFacetsQuery';
export * from './TrendingItemsQuery';
export * from './TrendingQuery';
export * from './WithRecommendMethods';

0 comments on commit d18391b

Please sign in to comment.