From acd8a7f3cd2cf6e9aac6eb9878b540fe412b0aef Mon Sep 17 00:00:00 2001 From: Raed Date: Mon, 15 May 2023 10:16:21 +0200 Subject: [PATCH 1/2] fix(recommend): Align getRecommendations type with implementation --- .../recommend/src/methods/getRecommendations.ts | 14 ++------------ packages/recommend/src/types/TrendingQuery.ts | 7 +++++++ .../recommend/src/types/WithRecommendMethods.ts | 3 ++- 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 packages/recommend/src/types/TrendingQuery.ts diff --git a/packages/recommend/src/methods/getRecommendations.ts b/packages/recommend/src/methods/getRecommendations.ts index c2b8c51a9..5f57595f4 100644 --- a/packages/recommend/src/methods/getRecommendations.ts +++ b/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['getRecommendations']; -type TrendingQuery = - | (TrendingItemsQuery & { readonly model: TrendingModel }) - | (TrendingFacetsQuery & { readonly model: TrendingModel }); - export const getRecommendations: GetRecommendations = base => { return (queries: ReadonlyArray, requestOptions) => { const requests: ReadonlyArray = queries.map(query => ({ diff --git a/packages/recommend/src/types/TrendingQuery.ts b/packages/recommend/src/types/TrendingQuery.ts new file mode 100644 index 000000000..88a2ef217 --- /dev/null +++ b/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 }); diff --git a/packages/recommend/src/types/WithRecommendMethods.ts b/packages/recommend/src/types/WithRecommendMethods.ts index 25320a195..780fdfb1f 100644 --- a/packages/recommend/src/types/WithRecommendMethods.ts +++ b/packages/recommend/src/types/WithRecommendMethods.ts @@ -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 & { /** * Returns recommendations. */ readonly getRecommendations: ( - queries: readonly RecommendationsQuery[], + queries: ReadonlyArray, requestOptions?: RequestOptions & SearchOptions ) => Readonly>>; From a58f790a9671fe260c6183a76274a9d12102686a Mon Sep 17 00:00:00 2001 From: Raed Date: Mon, 15 May 2023 10:24:02 +0200 Subject: [PATCH 2/2] export TrendingQuery type --- packages/recommend/src/types/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/recommend/src/types/index.ts b/packages/recommend/src/types/index.ts index c5a779f30..13cd2aa34 100644 --- a/packages/recommend/src/types/index.ts +++ b/packages/recommend/src/types/index.ts @@ -12,4 +12,5 @@ export * from './RecommendationsQuery'; export * from './RelatedProductsQuery'; export * from './TrendingFacetsQuery'; export * from './TrendingItemsQuery'; +export * from './TrendingQuery'; export * from './WithRecommendMethods';