Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(recommend): only export default function #1514

Merged
merged 2 commits into from Mar 27, 2024

Conversation

dhayab
Copy link
Member

@dhayab dhayab commented Mar 26, 2024

In #1512 I exported Recommend methods in addition to the existing default function export, to allow algoliasearch to import them in CJS.

This causes an issue as now there are multiple exports, which means recommend() cannot be accessed directly and is instead available from require('@algolia/recommend').default.

To prevent this, the Recommend methods are now augmenting the default function export.

Note

The existing version of api-extractor does not correctly resolve type imports, resulting in import('../xyz').Type statements with relative paths that are incorrect. I updated to the fixed version and went through all 22 type declaration files. There are no meaningful changes (in some cases type imports are aliased with a suffix to prevent conflicts, ie: import { Type as Type_2 } from '...', but all exports have the appropriate name, and now imports are properly resolved.

declare namespace recommend {
     var version: string;
-    var getFrequentlyBoughtTogether: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<import("../types").RecommendationsQuery, "queryParameters" | "objectID" | "indexName" | "threshold" | "maxRecommendations">[], requestOptions?: (import("../../../transporter/src").RequestOptions & import("../../../client-search/src").SearchOptions) | undefined) => Readonly<Promise<import("../types").RecommendQueriesResponse<TObject>>>;
+    var getFrequentlyBoughtTogether: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<RecommendationsQuery, "queryParameters" | "objectID" | "indexName" | "threshold" | "maxRecommendations">[], requestOptions?: (RequestOptions_2 & SearchOptions_2) | undefined) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;

-    var getRecommendations: (base: BaseRecommendClient) => <TObject>(queries: readonly (import("../types").RecommendationsQuery | (import("../types").TrendingItemsQuery & {
-        readonly model: import("../types").TrendingModel;
-    }) | (import("../types").TrendingFacetsQuery & {
-        readonly model: import("../types").TrendingModel;
-    }) | import("../types").RecommendedForYouQuery)[], requestOptions?: (import("../../../transporter/src").RequestOptions & import("../../../client-search/src").SearchOptions) | undefined) => Readonly<Promise<import("../types").RecommendQueriesResponse<TObject>>>;
+    var getRecommendations: (base: BaseRecommendClient) => <TObject>(queries: readonly (RecommendationsQuery | (TrendingItemsQuery & {
+        readonly model: TrendingModel;
+    }) | (TrendingFacetsQuery & {
+        readonly model: TrendingModel;
+    }) | RecommendedForYouQuery)[], requestOptions?: (RequestOptions_2 & SearchOptions_2) | undefined) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;

-    var getRelatedProducts: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<import("../types").RecommendationsQuery, "queryParameters" | "objectID" | "indexName" | "threshold" | "maxRecommendations" | "fallbackParameters">[], requestOptions?: (import("../../../transporter/src").RequestOptions & import("../../../client-search/src").SearchOptions) | undefined) => Readonly<Promise<import("../types").RecommendQueriesResponse<TObject>>>;
+    var getRelatedProducts: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<RecommendationsQuery, "queryParameters" | "objectID" | "indexName" | "threshold" | "maxRecommendations" | "fallbackParameters">[], requestOptions?: (RequestOptions_2 & SearchOptions_2) | undefined) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;

-    var getTrendingFacets: (base: BaseRecommendClient) => <TObject>(queries: readonly import("../types").TrendingFacetsQuery[], requestOptions?: (import("../../../transporter/src").RequestOptions & import("../../../client-search/src").SearchOptions) | undefined) => Readonly<Promise<import("../types").RecommendTrendingFacetsQueriesResponse>>;
+    var getTrendingFacets: (base: BaseRecommendClient) => <TObject>(queries: readonly TrendingFacetsQuery[], requestOptions?: (RequestOptions_2 & SearchOptions_2) | undefined) => Readonly<Promise<RecommendTrendingFacetsQueriesResponse>>;

-    var getTrendingItems: (base: BaseRecommendClient) => <TObject>(queries: readonly import("../types").TrendingItemsQuery[], requestOptions?: (import("../../../transporter/src").RequestOptions & import("../../../client-search/src").SearchOptions) | undefined) => Readonly<Promise<import("../types").RecommendQueriesResponse<TObject>>>;
+    var getTrendingItems: (base: BaseRecommendClient) => <TObject>(queries: readonly TrendingItemsQuery[], requestOptions?: (RequestOptions_2 & SearchOptions_2) | undefined) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;

-    var getLookingSimilar: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<import("../types").RecommendationsQuery, "queryParameters" | "objectID" | "indexName" | "threshold" | "maxRecommendations" | "fallbackParameters">[], requestOptions?: (import("../../../transporter/src").RequestOptions & import("../../../client-search/src").SearchOptions) | undefined) => Readonly<Promise<import("../types").RecommendQueriesResponse<TObject>>>;
+    var getLookingSimilar: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<RecommendationsQuery, "queryParameters" | "objectID" | "indexName" | "threshold" | "maxRecommendations" | "fallbackParameters">[], requestOptions?: (RequestOptions_2 & SearchOptions_2) | undefined) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;

-    var getRecommendedForYou: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<import("../types").RecommendedForYouQuery, "queryParameters" | "indexName" | "threshold" | "maxRecommendations" | "fallbackParameters">[], requestOptions?: (import("../../../transporter/src").RequestOptions & import("../../../client-search/src").SearchOptions) | undefined) => Readonly<Promise<import("../types").RecommendQueriesResponse<TObject>>>;
+    var getRecommendedForYou: (base: BaseRecommendClient) => <TObject>(queries: readonly Pick<RecommendedForYouQuery, "queryParameters" | "indexName" | "threshold" | "maxRecommendations" | "fallbackParameters">[], requestOptions?: (RequestOptions_2 & SearchOptions_2) | undefined) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;
}

Tests on the built bundles are also added to catch this in CI.

Fixes #1515

@dhayab dhayab requested a review from a team March 26, 2024 17:29
@Haroenv
Copy link
Contributor

Haroenv commented Mar 27, 2024

This fixes #1515 right?

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes lgtm, and the test failing is probably unrelated (seems about api keys)

@dhayab dhayab merged commit 4a04d8e into master Mar 27, 2024
7 of 8 checks passed
@dhayab dhayab deleted the fix/recommend-default-export branch March 27, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default export is not a function since 4.23.1
2 participants