Skip to content

feat(javascript): add search wrappers to lite client #3556

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

Merged
merged 6 commits into from
Aug 20, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ jobs:
run: cd clients/algoliasearch-client-javascript && yarn test ${{ !contains(fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun, 'algoliasearch') && '--ignore algoliasearch' || '' }}

- name: Test JavaScript bundle size
if: ${{ startsWith(env.head_ref, 'chore/prepare-release-') }}
run: cd clients/algoliasearch-client-javascript && yarn test:size

- name: Remove previous CTS output
Expand Down
10 changes: 5 additions & 5 deletions clients/algoliasearch-client-javascript/bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"files": [
{
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
"maxSize": "8.65KB"
"maxSize": "9.20KB"
},
{
"path": "packages/algoliasearch/dist/lite/lite.umd.js",
"maxSize": "3.90KB"
"maxSize": "3.95KB"
},
{
"path": "packages/client-abtesting/dist/client-abtesting.umd.js",
"maxSize": "4.05KB"
"maxSize": "4.10KB"
},
{
"path": "packages/client-analytics/dist/client-analytics.umd.js",
Expand All @@ -30,11 +30,11 @@
},
{
"path": "packages/client-search/dist/client-search.umd.js",
"maxSize": "7.05KB"
"maxSize": "7.15KB"
},
{
"path": "packages/ingestion/dist/ingestion.umd.js",
"maxSize": "5.20KB"
"maxSize": "5.90KB"
},
{
"path": "packages/monitoring/dist/monitoring.umd.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void setDefaultGeneratorOptions() {

additionalProperties.put("apiName", apiName);
additionalProperties.put("algoliaAgent", Helpers.capitalize(CLIENT));
additionalProperties.put("isSearchClient", CLIENT.equals("search"));
additionalProperties.put("isSearchClient", CLIENT.equals("search") || isAlgoliasearchClient);
additionalProperties.put("isIngestionClient", CLIENT.equals("ingestion"));
additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient);
additionalProperties.put("packageVersion", Helpers.getPackageJsonVersion(packageName));
Expand Down
62 changes: 32 additions & 30 deletions templates/javascript/clients/client/api/helpers.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{^isAlgoliasearchClient}}
/**
* Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
*
Expand Down Expand Up @@ -275,36 +276,6 @@ browseSynonyms(
});
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
* Disclaimer: We don't assert that the parameters you pass to this method only contains `hits` requests to prevent impacting search performances, this helper is purely for typing purposes.
*
* @summary Search multiple indices for `hits`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForHits<T>(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{results: Array<SearchResponse<T>>}> {
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchResponse<T>>}>;
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
* Disclaimer: We don't assert that the parameters you pass to this method only contains `facets` requests to prevent impacting search performances, this helper is purely for typing purposes.
*
* @summary Search multiple indices for `facets`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForFacets(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{results: Array<SearchForFacetValuesResponse>}> {
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchForFacetValuesResponse>}>;
},

/**
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
*
Expand Down Expand Up @@ -476,4 +447,35 @@ async replaceAllObjects(
});

return { copyOperationResponse, batchResponses, moveOperationResponse };
},
{{/isAlgoliasearchClient}}

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
* Disclaimer: We don't assert that the parameters you pass to this method only contains `hits` requests to prevent impacting search performances, this helper is purely for typing purposes.
*
* @summary Search multiple indices for `hits`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForHits<T>(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{results: Array<SearchResponse<T>>}> {
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchResponse<T>>}>;
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
* Disclaimer: We don't assert that the parameters you pass to this method only contains `facets` requests to prevent impacting search performances, this helper is purely for typing purposes.
*
* @summary Search multiple indices for `facets`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForFacets(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{results: Array<SearchForFacetValuesResponse>}> {
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchForFacetValuesResponse>}>;
},
5 changes: 5 additions & 0 deletions templates/javascript/clients/client/api/imports.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ import type {
import type { BatchRequest } from '../model/batchRequest';
{{/isSearchClient}}

{{#isAlgoliasearchClient}}
import type { SearchResponse } from '../model/searchResponse';
import type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse';
{{/isAlgoliasearchClient}}

{{#isIngestionClient}}
import type { OnDemandTrigger } from '../model/onDemandTrigger';
import type { ScheduleTrigger } from '../model/scheduleTrigger';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props = {
{{/operations}}

{{#isSearchClient}}
{{^isAlgoliasearchClient}}
/**
* The `browseObjects`, `browseRules`, `browseSynonyms` options.
*/
Expand Down Expand Up @@ -175,6 +176,7 @@ export type ReplaceAllObjectsOptions = {
*/
batchSize?: number;
}
{{/isAlgoliasearchClient}}
{{/isSearchClient}}

{{/apiInfo.apis.0}}
Loading