From d9ac12f1c6c49dfc81d36858fea79d6719fadced Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 12 Mar 2024 19:38:15 +0100 Subject: [PATCH] feat(clients): add recommend to algoliasearch --- .../algoliasearch-client-javascript/yarn.lock | 3 +- config/clients.config.json | 1 - .../codegen/AlgoliaJavascriptGenerator.java | 2 +- .../cts/manager/JavascriptCTSManager.java | 5 +- .../codegen/cts/tests/TestsRequest.java | 31 +++- scripts/buildClients.ts | 5 +- scripts/buildSpecs.ts | 59 ++++--- scripts/ci/githubActions/createMatrix.ts | 10 +- scripts/formatter.ts | 2 +- scripts/types.ts | 11 +- .../algoliasearch/builds/browser.mustache | 5 +- .../algoliasearch/builds/definition.mustache | 66 ++++---- .../algoliasearch/builds/initClients.mustache | 8 + .../algoliasearch/builds/models.mustache | 148 ++++++++++++++++-- .../algoliasearch/builds/node.mustache | 5 +- .../clients/client/api/imports.mustache | 4 +- .../clients/client/builds/definition.mustache | 6 +- .../client/model/clientMethodProps.mustache | 4 +- templates/javascript/clients/package.mustache | 26 +-- templates/javascript/snippets/method.mustache | 2 +- .../javascript/tests/client/suite.mustache | 4 +- templates/javascript/tests/package.mustache | 4 +- .../tests/requests/requests.mustache | 6 +- tests/output/javascript/yarn.lock | 28 ++-- .../contributing/testing/common-test-suite.md | 1 - 25 files changed, 321 insertions(+), 125 deletions(-) diff --git a/clients/algoliasearch-client-javascript/yarn.lock b/clients/algoliasearch-client-javascript/yarn.lock index 03f41fb35f..9040572d74 100644 --- a/clients/algoliasearch-client-javascript/yarn.lock +++ b/clients/algoliasearch-client-javascript/yarn.lock @@ -124,7 +124,7 @@ __metadata: languageName: unknown linkType: soft -"@algolia/recommend@workspace:packages/recommend": +"@algolia/recommend@npm:5.0.0-alpha.106, @algolia/recommend@workspace:packages/recommend": version: 0.0.0-use.local resolution: "@algolia/recommend@workspace:packages/recommend" dependencies: @@ -3119,6 +3119,7 @@ __metadata: "@algolia/client-common": "npm:5.0.0-alpha.107" "@algolia/client-personalization": "npm:5.0.0-alpha.106" "@algolia/client-search": "npm:5.0.0-alpha.106" + "@algolia/recommend": "npm:5.0.0-alpha.106" "@algolia/requester-browser-xhr": "npm:5.0.0-alpha.107" "@algolia/requester-node-http": "npm:5.0.0-alpha.107" "@babel/preset-env": "npm:7.24.0" diff --git a/config/clients.config.json b/config/clients.config.json index 1958ab0303..41ccdb168c 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -158,7 +158,6 @@ } ], "folder": "clients/algoliasearch-client-javascript", - "npmNamespace": "@algolia", "gitRepoId": "algoliasearch-client-javascript", "packageVersion": "5.0.0-alpha.108", "modelFolder": "model", diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index b062e31d07..c5718756eb 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -155,6 +155,7 @@ private void setDefaultGeneratorOptions() { additionalProperties.put("abtestingVersion", Helpers.getPackageJsonVersion("client-abtesting")); additionalProperties.put("personalizationVersion", Helpers.getPackageJsonVersion("client-personalization")); additionalProperties.put("searchVersion", Helpers.getPackageJsonVersion("client-search")); + additionalProperties.put("recommendVersion", Helpers.getPackageJsonVersion("recommend")); // Files used to generate the `lite` client apiName = "lite" + Helpers.API_SUFFIX; @@ -185,7 +186,6 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List supportingFiles) { @Override public void addDataToBundle(Map bundle) throws GeneratorException { - String npmNamespace = Helpers.getClientConfigField("javascript", "npmNamespace"); - bundle.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common")); - bundle.put("npmNamespace", npmNamespace); List> clients = new ArrayList<>(); String importName = ""; @@ -35,7 +32,7 @@ public void addDataToBundle(Map bundle) throws GeneratorExceptio String output = c.get("output").asText(); String packageName = output.substring(output.lastIndexOf("/") + 1); if (!packageName.equals("algoliasearch")) { - packageName = npmNamespace + "/" + packageName; + packageName = "@algolia/" + packageName; } clients.add(Map.of("packageName", packageName, "packagePath", "link:../../../" + output.replace("#{cwd}/", ""))); diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index 66429c6a2b..48ec4ecee1 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -4,6 +4,7 @@ import com.algolia.codegen.utils.*; import java.io.File; import java.util.*; +import org.apache.commons.lang3.ArrayUtils; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenResponse; @@ -19,10 +20,32 @@ protected Map loadRequestCTS() throws Exception { String clientName = client; // This special case allow us to read the `search` CTS to generated the tests for the // `lite` client, which is only available in Javascript - if ((language.equals("javascript") || language.equals("dart")) && client.equals("algoliasearch")) { + if (client.equals("algoliasearch")) { clientName = "search"; } - return super.loadCTS("requests", clientName, Request[].class); + + Map baseCTS = super.loadCTS("requests", clientName, Request[].class); + + // The algoliasearch client bundles many client and therefore should provide tests for all the + // subsequent specs + if (client.equals("algoliasearch")) { + Map recommendCTS = super.loadCTS("requests", "recommend", Request[].class); + for (Map.Entry entry : recommendCTS.entrySet()) { + String operation = entry.getKey(); + // custom methods are common to every clients, we don't want duplicate tests + if (operation.startsWith("custom")) { + continue; + } + + if (baseCTS.containsKey(operation)) { + baseCTS.put(operation, ArrayUtils.addAll(baseCTS.get(operation), entry.getValue())); + } else { + baseCTS.put(operation, entry.getValue()); + } + } + } + + return baseCTS; } @Override @@ -70,7 +93,9 @@ public void run(Map models, Map throw new CTSException( "operationId '" + operationId + - "' does not exist in the tests suite, please create the file:" + + "' does not exist in the " + + client + + " tests suite, please create the file:" + " 'tests/CTS/requests/" + client + "/" + diff --git a/scripts/buildClients.ts b/scripts/buildClients.ts index c6f41ee18b..2ddfd29304 100644 --- a/scripts/buildClients.ts +++ b/scripts/buildClients.ts @@ -2,7 +2,7 @@ import * as fsp from 'fs/promises'; import { run, toAbsolutePath } from './common.js'; -import { getClientsConfigField, getLanguageFolder } from './config.js'; +import { getLanguageFolder } from './config.js'; import { createSpinner } from './spinners.js'; import type { Generator, Language } from './types.js'; @@ -17,9 +17,8 @@ async function buildClient(language: Language, gens: Generator[]): Promise await run('dotnet build --configuration Release', { cwd, language }); break; case 'javascript': - const npmNamespace = getClientsConfigField('javascript', 'npmNamespace'); const packageNames = gens.map(({ additionalProperties: { packageName } }) => - packageName === 'algoliasearch' ? packageName : `${npmNamespace}/${packageName}`, + packageName === 'algoliasearch' ? packageName : `@algolia/${packageName}`, ); await run('YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install', { cwd }); diff --git a/scripts/buildSpecs.ts b/scripts/buildSpecs.ts index f5ea8bdb22..120ec505aa 100644 --- a/scripts/buildSpecs.ts +++ b/scripts/buildSpecs.ts @@ -7,7 +7,7 @@ import { GENERATORS, capitalize, createClientName, exists, run, toAbsolutePath } import { createSpinner } from './spinners.js'; import type { CodeSamples, Language, SnippetSamples, Spec } from './types.js'; -const ALGOLIASEARCH_LITE_OPERATIONS = ['search', 'customPost']; +const ALGOLIASEARCH_LITE_OPERATIONS = ['search', 'customPost', 'getRecommendations']; function mapLanguageToCodeSampleSupporter(language: Language): CodeSamples['lang'] { switch (language) { @@ -192,27 +192,36 @@ async function lintCommon(useCache: boolean): Promise { async function buildLiteSpec({ spec, bundledPath, + docs, + useCache, }: { spec: string; bundledPath: string; + docs: boolean; + useCache: boolean; }): Promise { - const parsed = yaml.load(await fsp.readFile(toAbsolutePath(bundledPath), 'utf8')) as Spec; - - // Filter methods. - parsed.paths = Object.entries(parsed.paths).reduce( - (acc, [path, operations]) => { - for (const [, operation] of Object.entries(operations)) { - if (ALGOLIASEARCH_LITE_OPERATIONS.includes(operation.operationId)) { - return { ...acc, [path]: { post: operation } }; - } - } + await buildSpec({ spec: 'recommend', outputFormat: 'yml', docs, useCache }); - return acc; - }, - {} as Spec['paths'], - ); + const base = yaml.load(await fsp.readFile(toAbsolutePath(bundledPath), 'utf8')) as Spec; + const recommend = yaml.load( + await fsp.readFile(toAbsolutePath(bundledPath.replace('algoliasearch', 'recommend')), 'utf8'), + ) as Spec; + base.paths = { ...base.paths, ...recommend.paths }; + base.components.schemas = { ...base.components.schemas, ...recommend.components.schemas }; - await fsp.writeFile(bundledPath, yaml.dump(parsed)); + const lite = { ...base, paths: {} }; + + for (const [path, operations] of Object.entries(base.paths)) { + for (const [, operation] of Object.entries(operations)) { + if (ALGOLIASEARCH_LITE_OPERATIONS.includes(operation.operationId)) { + lite.paths[path] = { post: operation }; + + break; + } + } + } + + await fsp.writeFile(bundledPath, yaml.dump(lite)); await transformBundle({ bundledPath, @@ -239,25 +248,26 @@ async function buildSpec({ // In case of lite we use a the `search` spec as a base because only its bundled form exists. const specBase = isAlgoliasearch ? 'search' : spec; + const deps = isAlgoliasearch ? ['search', 'recommend'] : [spec]; const logSuffix = docs ? 'doc spec' : 'spec'; const cache = new Cache({ folder: toAbsolutePath('specs/'), generatedFiles: [docs ? `bundled/${spec}.doc.yml` : `bundled/${spec}.yml`], - filesToCache: [specBase, 'common'], + filesToCache: [...deps, 'common'], cacheFile: toAbsolutePath(`specs/dist/${spec}.${docs ? 'doc.' : ''}cache`), }); const spinner = createSpinner(`starting '${spec}' ${logSuffix}`); if (useCache) { - spinner.text = `checking cache for '${specBase}'`; + spinner.text = `checking cache for '${spec}'`; if (await cache.isValid()) { - spinner.succeed(`job skipped, cache found for '${specBase}'`); + spinner.succeed(`job skipped, cache found for '${spec}'`); return; } - spinner.text = `cache not found for '${specBase}'`; + spinner.text = `cache not found for '${spec}'`; } // First linting the base @@ -281,6 +291,8 @@ async function buildSpec({ await buildLiteSpec({ spec, bundledPath: toAbsolutePath(bundledPath), + docs, + useCache, }); } @@ -314,6 +326,13 @@ export async function buildSpecs({ await lintCommon(useCache); + // the `lite` spec will build the `recommend` spec, so we remove it from the list + // to prevent concurrent builds + if (clients.includes('algoliasearch')) { + // eslint-disable-next-line no-param-reassign + clients = clients.filter((client) => client !== 'recommend'); + } + await Promise.all( clients.map((client) => buildSpec({ spec: client, outputFormat, docs, useCache })), ); diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index d1eb0b3d20..bc524ad1ec 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -2,12 +2,7 @@ import * as core from '@actions/core'; import { CLIENTS, createClientName, GENERATORS, LANGUAGES } from '../../common.js'; -import { - getClientsConfigField, - getLanguageFolder, - getTestExtension, - getTestOutputFolder, -} from '../../config.js'; +import { getLanguageFolder, getTestExtension, getTestOutputFolder } from '../../config.js'; import { COMMON_DEPENDENCIES, DEPENDENCIES } from './setRunVariables.js'; import type { ClientMatrix, CreateMatrix, ToRunMatrix } from './types.js'; @@ -102,12 +97,11 @@ async function createClientMatrix(baseBranch: string): Promise { testsToStore = `${testsToStore} ${testsRootFolder}/build.gradle`; break; case 'javascript': - const npmNamespace = getClientsConfigField('javascript', 'npmNamespace'); const packageNames = matrix[language].toRun.map((client) => { const packageName = GENERATORS[`${language}-${client}`].additionalProperties.packageName; // `algoliasearch` is not preceded by `@algolia` - return client === 'algoliasearch' ? packageName : `${npmNamespace}/${packageName}`; + return client === 'algoliasearch' ? packageName : `@algolia/${packageName}`; }); buildCommand = `cd ${matrix[language].path} && yarn build:many '{${packageNames.join( diff --git a/scripts/formatter.ts b/scripts/formatter.ts index bb0c489e2f..16dca0d504 100644 --- a/scripts/formatter.ts +++ b/scripts/formatter.ts @@ -28,7 +28,7 @@ export async function formatter(language: string, cwd: string): Promise { await run('goimports -w . && golangci-lint run --fix', { cwd, language }); break; case 'javascript': - await run(`yarn eslint --ext=ts,json ${cwd} --fix --no-error-on-unmatched-pattern`); + await run(`yarn eslint --fix --no-error-on-unmatched-pattern --ext=ts,json ${cwd}`); break; case 'java': await run( diff --git a/scripts/types.ts b/scripts/types.ts index 3d87f18314..4876b4e44a 100644 --- a/scripts/types.ts +++ b/scripts/types.ts @@ -41,7 +41,10 @@ export type Language = keyof typeof config; export type Spec = { servers: Server[]; tags: Tag[]; - paths: Path[]; + paths: Path; + components: { + schemas: Record; + }; }; /** @@ -105,5 +108,9 @@ export type SnippetSamples = Record>; */ type Path = Record< Method, - Record & { operationId: string; 'x-codeSamples': CodeSamples[]; summary: string } + Record & { + operationId: string; + 'x-codeSamples': CodeSamples[]; + summary: string; + } >; diff --git a/templates/javascript/clients/algoliasearch/builds/browser.mustache b/templates/javascript/clients/algoliasearch/builds/browser.mustache index 97115d64dd..31118bf6e7 100644 --- a/templates/javascript/clients/algoliasearch/builds/browser.mustache +++ b/templates/javascript/clients/algoliasearch/builds/browser.mustache @@ -1,5 +1,7 @@ // {{{generationBanner}}} +import type { InitClientOptions, InitClientRegion } from "./models" + {{> algoliasearch/builds/definition}} const commonOptions: CreateClientOptions = { apiKey, @@ -33,8 +35,9 @@ get _ua(): string { return this.transporter.algoliaAgent.value; }, + initAbtesting, initAnalytics, initPersonalization, - initAbtesting, + initRecommend, }; } \ No newline at end of file diff --git a/templates/javascript/clients/algoliasearch/builds/definition.mustache b/templates/javascript/clients/algoliasearch/builds/definition.mustache index 6b04cfeb98..a1c584fdbf 100644 --- a/templates/javascript/clients/algoliasearch/builds/definition.mustache +++ b/templates/javascript/clients/algoliasearch/builds/definition.mustache @@ -1,28 +1,6 @@ -import type { PersonalizationClient } from '@algolia/client-personalization'; -import type { AnalyticsClient } from '@algolia/client-analytics'; -import type { AbtestingClient } from '@algolia/client-abtesting'; - -import type { Region as AnalyticsRegion } from '{{{npmNamespace}}}/client-analytics/src/analyticsClient'; -import { createAnalyticsClient, REGIONS as analyticsRegions } from '{{{npmNamespace}}}/client-analytics/src/analyticsClient'; - -import type { Region as AbtestingRegion } from '{{{npmNamespace}}}/client-abtesting/src/abtestingClient'; -import { createAbtestingClient, REGIONS as abtestingRegions } from '{{{npmNamespace}}}/client-abtesting/src/abtestingClient'; - -import type { Region as PersonalizationRegion } from '{{{npmNamespace}}}/client-personalization/src/personalizationClient'; -import { createPersonalizationClient, REGIONS as personalizationRegions } from '{{{npmNamespace}}}/client-personalization/src/personalizationClient'; -import { createSearchClient, apiClientVersion as searchClientVersion } from '{{{npmNamespace}}}/client-search/src/searchClient'; - -import type { serializeQueryParameters } from '{{{npmNamespace}}}/client-common'; -import type {} from '{{{npmNamespace}}}/client-common'; -import type { InitClientOptions, InitClientRegion, GenerateSecuredApiKeyOptions, GetSecuredApiKeyRemainingValidityOptions } from "./models" - -{{#nodeSearchHelpers}} -import {createHmac} from 'crypto'; -{{/nodeSearchHelpers}} +import { createHmac } from 'crypto'; import { - ClientOptions, - CreateClientOptions, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_BROWSER, @@ -33,11 +11,45 @@ import { createFallbackableCache, createMemoryCache, createNullCache, -} from '{{{npmNamespace}}}/client-common'; - -import { createHttpRequester } from '{{{npmNamespace}}}/requester-node-http'; + serializeQueryParameters, +} from '@algolia/client-common'; +import type { AbtestingClient } from '@algolia/client-abtesting'; +import type { Region as AbtestingRegion } from '@algolia/client-abtesting/src/abtestingClient'; +import { + createAbtestingClient, + REGIONS as abtestingRegions, +} from '@algolia/client-abtesting/src/abtestingClient'; +import type { AnalyticsClient } from '@algolia/client-analytics'; +import { + createAnalyticsClient, + REGIONS as analyticsRegions, +} from '@algolia/client-analytics/src/analyticsClient'; +import type { Region as AnalyticsRegion } from '@algolia/client-analytics/src/analyticsClient'; +import type { + ClientOptions, + CreateClientOptions, +} from '@algolia/client-common'; +import type { PersonalizationClient } from '@algolia/client-personalization'; +import type { Region as PersonalizationRegion } from '@algolia/client-personalization/src/personalizationClient'; +import { + createPersonalizationClient, + REGIONS as personalizationRegions, +} from '@algolia/client-personalization/src/personalizationClient'; +import { + createSearchClient, + apiClientVersion as searchClientVersion, +} from '@algolia/client-search/src/searchClient'; +import type { RecommendClient } from '@algolia/recommend'; +import { createRecommendClient } from '@algolia/recommend/src/recommendClient'; +import { createXhrRequester } from '@algolia/requester-browser-xhr'; +import { createHttpRequester } from '@algolia/requester-node-http'; -import { createXhrRequester } from '{{{npmNamespace}}}/requester-browser-xhr'; +import type { + InitClientOptions, + InitClientRegion, + GenerateSecuredApiKeyOptions, + GetSecuredApiKeyRemainingValidityOptions, +} from './models'; export * from './models'; diff --git a/templates/javascript/clients/algoliasearch/builds/initClients.mustache b/templates/javascript/clients/algoliasearch/builds/initClients.mustache index 73d36fe0e9..d2eb88176c 100644 --- a/templates/javascript/clients/algoliasearch/builds/initClients.mustache +++ b/templates/javascript/clients/algoliasearch/builds/initClients.mustache @@ -1,3 +1,11 @@ +function initRecommend(initOptions: InitClientOptions = {}): RecommendClient { + return createRecommendClient({ + ...commonOptions, + ...initOptions.options, + ...initOptions, + }); +} + function initAnalytics(initOptions: InitClientOptions & InitClientRegion = {}): AnalyticsClient { if ( initOptions.region && diff --git a/templates/javascript/clients/algoliasearch/builds/models.mustache b/templates/javascript/clients/algoliasearch/builds/models.mustache index a7cbf278d3..7a7d4c4799 100644 --- a/templates/javascript/clients/algoliasearch/builds/models.mustache +++ b/templates/javascript/clients/algoliasearch/builds/models.mustache @@ -4,24 +4,89 @@ import type { Host, Requester, ClientOptions, -} from '{{{npmNamespace}}}/client-common'; +} from '@algolia/client-common'; import { ErrorBase, CustomPutProps, CustomPostProps, CustomDeleteProps, CustomGetProps, -} from '{{{npmNamespace}}}/client-search/model'; + TypoToleranceEnum, + TypoTolerance, + TaskStatus, + TagFilters, + SortRemainingBy, + SnippetResultOption, + SnippetResult, + SemanticSearch, + SearchParamsQuery, + SearchParamsObject, + RenderingContent, + RemoveWordsIfNoResults, + RemoveStopWords, + RedirectRuleIndexMetadataData, + RedirectRuleIndexMetadata, + Redirect, + ReRankingApplyFilter, + RankingInfo, + QueryType, + PromoteObjectIDs, + PromoteObjectID, + Promote, + Personalization, + Params, + OptionalFilters, + NumericFilters, + Mode, + MixedSearchFilters, + MatchedGeoLocation, + MatchLevel, + IndexSettingsAsSearchParams, + IgnorePlurals, + HighlightResultOption, + HighlightResult, + FacetsStats, + Facets, + FacetOrdering, + FacetFilters, + Exhaustive, + ExactOnSingleWordQuery, + EditType, + Edit, + Distinct, + DeletedAtResponse, + ConsequenceQueryObject, + ConsequenceQuery, + ConsequenceParams, + ConsequenceHide, + Consequence, + Condition, + BaseSearchResponse, + BaseSearchParamsWithoutQuery, + BaseSearchParams, + AutomaticFacetFilters, + AutomaticFacetFilter, + AroundRadiusAll, + AroundRadius, + AroundPrecisionFromValueInner, + AroundPrecision, + Anchoring, + AlternativesAsExact, + AdvancedSyntaxFeatures, + Value, +} from '@algolia/client-search/model'; -export * from '{{{npmNamespace}}}/client-search/model'; -export * from '{{{npmNamespace}}}/client-personalization/model'; -export * from '{{{npmNamespace}}}/client-analytics/model'; -export * from '{{{npmNamespace}}}/client-abtesting/model'; +export * from '@algolia/client-search/model'; +export * from '@algolia/recommend/model'; +export * from '@algolia/client-personalization/model'; +export * from '@algolia/client-analytics/model'; +export * from '@algolia/client-abtesting/model'; -export { SearchClient } from '{{{npmNamespace}}}/client-search'; -export { PersonalizationClient } from '{{{npmNamespace}}}/client-personalization'; -export { AnalyticsClient } from '{{{npmNamespace}}}/client-analytics'; -export { AbtestingClient } from '{{{npmNamespace}}}/client-abtesting'; +export { SearchClient } from '@algolia/client-search'; +export { RecommendClient } from '@algolia/recommend'; +export { PersonalizationClient } from '@algolia/client-personalization'; +export { AnalyticsClient } from '@algolia/client-analytics'; +export { AbtestingClient } from '@algolia/client-abtesting'; export { ErrorBase, @@ -29,6 +94,69 @@ export { CustomPostProps, CustomDeleteProps, CustomGetProps, + TypoToleranceEnum, + TypoTolerance, + TaskStatus, + TagFilters, + SortRemainingBy, + SnippetResultOption, + SnippetResult, + SemanticSearch, + SearchParamsQuery, + SearchParamsObject, + RenderingContent, + RemoveWordsIfNoResults, + RemoveStopWords, + RedirectRuleIndexMetadataData, + RedirectRuleIndexMetadata, + Redirect, + ReRankingApplyFilter, + RankingInfo, + QueryType, + PromoteObjectIDs, + PromoteObjectID, + Promote, + Personalization, + Params, + OptionalFilters, + NumericFilters, + Mode, + MixedSearchFilters, + MatchedGeoLocation, + MatchLevel, + IndexSettingsAsSearchParams, + IgnorePlurals, + HighlightResultOption, + HighlightResult, + FacetsStats, + Facets, + FacetOrdering, + FacetFilters, + Exhaustive, + ExactOnSingleWordQuery, + EditType, + Edit, + Distinct, + DeletedAtResponse, + ConsequenceQueryObject, + ConsequenceQuery, + ConsequenceParams, + ConsequenceHide, + Consequence, + Condition, + BaseSearchResponse, + BaseSearchParamsWithoutQuery, + BaseSearchParams, + AutomaticFacetFilters, + AutomaticFacetFilter, + AroundRadiusAll, + AroundRadius, + AroundPrecisionFromValueInner, + AroundPrecision, + Anchoring, + AlternativesAsExact, + AdvancedSyntaxFeatures, + Value, }; /** diff --git a/templates/javascript/clients/algoliasearch/builds/node.mustache b/templates/javascript/clients/algoliasearch/builds/node.mustache index 070732ad37..67d4347c16 100644 --- a/templates/javascript/clients/algoliasearch/builds/node.mustache +++ b/templates/javascript/clients/algoliasearch/builds/node.mustache @@ -1,5 +1,7 @@ // {{{generationBanner}}} +import type { InitClientOptions, InitClientRegion {{#nodeSearchHelpers}}, GenerateSecuredApiKeyOptions, GetSecuredApiKeyRemainingValidityOptions {{/nodeSearchHelpers}} } from "./models" + {{> algoliasearch/builds/definition}} const commonOptions: CreateClientOptions = { apiKey, @@ -27,9 +29,10 @@ get _ua(): string { return this.transporter.algoliaAgent.value; }, + initAbtesting, initAnalytics, initPersonalization, - initAbtesting, + initRecommend, {{#nodeSearchHelpers}} {{> client/api/nodeHelpers}} {{/nodeSearchHelpers}} diff --git a/templates/javascript/clients/client/api/imports.mustache b/templates/javascript/clients/client/api/imports.mustache index a6cb7e8b76..b51b132eac 100644 --- a/templates/javascript/clients/client/api/imports.mustache +++ b/templates/javascript/clients/client/api/imports.mustache @@ -7,7 +7,7 @@ import { serializeQueryParameters, createIterablePromise, {{/isSearchClient}} -} from '{{{npmNamespace}}}/client-common'; +} from '@algolia/client-common'; import type { CreateClientOptions, Headers, @@ -19,7 +19,7 @@ import type { ApiError, IterableOptions, {{/isSearchClient}} -} from '{{{npmNamespace}}}/client-common'; +} from '@algolia/client-common'; {{#imports}} import { {{classname}} } from '{{filename}}'; diff --git a/templates/javascript/clients/client/builds/definition.mustache b/templates/javascript/clients/client/builds/definition.mustache index 628efea245..492d8c9d76 100644 --- a/templates/javascript/clients/client/builds/definition.mustache +++ b/templates/javascript/clients/client/builds/definition.mustache @@ -1,6 +1,6 @@ -import { createXhrRequester } from '{{{npmNamespace}}}/requester-browser-xhr'; -import { createHttpRequester } from '{{{npmNamespace}}}/requester-node-http'; -import { createMemoryCache, createFallbackableCache, createBrowserLocalStorageCache, createNullCache, ClientOptions, serializeQueryParameters, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_BROWSER } from '{{{npmNamespace}}}/client-common'; +import { createXhrRequester } from '@algolia/requester-browser-xhr'; +import { createHttpRequester } from '@algolia/requester-node-http'; +import { createMemoryCache, createFallbackableCache, createBrowserLocalStorageCache, createNullCache, ClientOptions, serializeQueryParameters, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_BROWSER } from '@algolia/client-common'; import { create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}, apiClientVersion } from '../src/{{apiName}}'; diff --git a/templates/javascript/clients/client/model/clientMethodProps.mustache b/templates/javascript/clients/client/model/clientMethodProps.mustache index 4d7961a5bd..a746674295 100644 --- a/templates/javascript/clients/client/model/clientMethodProps.mustache +++ b/templates/javascript/clients/client/model/clientMethodProps.mustache @@ -11,7 +11,7 @@ import { {{classname}} } from '{{filename}}'; {{! Imports for the helpers method of the search client }} {{#isSearchClient}} -import type { CreateIterablePromise } from '{{{npmNamespace}}}/client-common'; +import type { CreateIterablePromise } from '@algolia/client-common'; import type { Action } from './action'; import type { UpdatedAtResponse } from './updatedAtResponse'; {{/isSearchClient}} @@ -166,4 +166,4 @@ export type ReplaceAllObjectsResponse = { } {{/isSearchClient}} -{{/apiInfo.apis.0}} +{{/apiInfo.apis.0}} \ No newline at end of file diff --git a/templates/javascript/clients/package.mustache b/templates/javascript/clients/package.mustache index 63d959418c..aeb399d855 100644 --- a/templates/javascript/clients/package.mustache +++ b/templates/javascript/clients/package.mustache @@ -6,7 +6,7 @@ "author": "Algolia", "types": "./index.d.ts", {{^isAlgoliasearchClient}} - "name": "{{{npmNamespace}}}/{{packageName}}", + "name": "@algolia/{{packageName}}", "description": "JavaScript client for {{packageName}}", "jsdelivr": "./dist/{{packageName}}.umd.js", "unpkg": "./dist/{{packageName}}.umd.js", @@ -40,9 +40,9 @@ "clean": "rm -rf ./dist || true" }, "dependencies": { - "{{{npmNamespace}}}/client-common": "{{utilsPackageVersion}}", - "{{{npmNamespace}}}/requester-browser-xhr": "{{utilsPackageVersion}}", - "{{{npmNamespace}}}/requester-node-http": "{{utilsPackageVersion}}" + "@algolia/client-common": "{{utilsPackageVersion}}", + "@algolia/requester-browser-xhr": "{{utilsPackageVersion}}", + "@algolia/requester-node-http": "{{utilsPackageVersion}}" }, "devDependencies": { "@types/node": "20.11.25", @@ -106,13 +106,15 @@ "test": "jest" }, "dependencies": { - "{{{npmNamespace}}}/client-analytics": "{{analyticsVersion}}", - "{{{npmNamespace}}}/client-abtesting": "{{abtestingVersion}}", - "{{{npmNamespace}}}/client-personalization": "{{personalizationVersion}}", - "{{{npmNamespace}}}/client-search": "{{searchVersion}}", - "{{{npmNamespace}}}/client-common": "{{utilsPackageVersion}}", - "{{{npmNamespace}}}/requester-browser-xhr": "{{utilsPackageVersion}}", - "{{{npmNamespace}}}/requester-node-http": "{{utilsPackageVersion}}" + "@algolia/client-analytics": "{{analyticsVersion}}", + "@algolia/client-abtesting": "{{abtestingVersion}}", + "@algolia/client-personalization": "{{personalizationVersion}}", + "@algolia/recommend": "{{recommendVersion}}", + "@algolia/client-search": "{{searchVersion}}", + "@algolia/client-common": "{{utilsPackageVersion}}", + "@algolia/recommend": "{{recommendVersion}}", + "@algolia/requester-browser-xhr": "{{utilsPackageVersion}}", + "@algolia/requester-node-http": "{{utilsPackageVersion}}" }, "devDependencies": { "@babel/preset-env": "7.24.0", @@ -127,4 +129,4 @@ "engines": { "node": ">= 14.0.0" } -} +} \ No newline at end of file diff --git a/templates/javascript/snippets/method.mustache b/templates/javascript/snippets/method.mustache index 236996af19..48e51f7ee8 100644 --- a/templates/javascript/snippets/method.mustache +++ b/templates/javascript/snippets/method.mustache @@ -1,7 +1,7 @@ /* eslint no-console: ["error", { allow: ["log"] }] */ import { {{client}} } from '{{{import}}}'; -import type { RequestOptions } from '{{{npmNamespace}}}/client-common'; +import type { RequestOptions } from '@algolia/client-common'; {{#blocksRequests}} {{#snippet}} diff --git a/templates/javascript/tests/client/suite.mustache b/templates/javascript/tests/client/suite.mustache index b87287a7fb..54cd00b42d 100644 --- a/templates/javascript/tests/client/suite.mustache +++ b/templates/javascript/tests/client/suite.mustache @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-vars, require-await */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { {{client}}, {{#lambda.titlecase}}{{client}}{{/lambda.titlecase}} } from '{{{import}}}'; -import { echoRequester } from '{{{npmNamespace}}}/requester-node-http'; -import type { EchoResponse } from '{{{npmNamespace}}}/requester-node-http'; +import { echoRequester } from '@algolia/requester-node-http'; +import type { EchoResponse } from '@algolia/requester-node-http'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; diff --git a/templates/javascript/tests/package.mustache b/templates/javascript/tests/package.mustache index 624319ec99..eacf1804a7 100644 --- a/templates/javascript/tests/package.mustache +++ b/templates/javascript/tests/package.mustache @@ -8,8 +8,8 @@ {{#packageDependencies}} "{{{packageName}}}": "{{{packagePath}}}", {{/packageDependencies}} - "{{{npmNamespace}}}/client-common": "link:../../../clients/algoliasearch-client-javascript/packages/client-common", - "{{{npmNamespace}}}/requester-node-http": "link:../../../clients/algoliasearch-client-javascript/packages/requester-node-http" + "@algolia/client-common": "link:../../../clients/algoliasearch-client-javascript/packages/client-common", + "@algolia/requester-node-http": "link:../../../clients/algoliasearch-client-javascript/packages/requester-node-http" }, "devDependencies": { "@types/jest": "29.5.12", diff --git a/templates/javascript/tests/requests/requests.mustache b/templates/javascript/tests/requests/requests.mustache index 09ad0cb003..d16cb26f9f 100644 --- a/templates/javascript/tests/requests/requests.mustache +++ b/templates/javascript/tests/requests/requests.mustache @@ -6,9 +6,9 @@ import * as dotenv from 'dotenv'; dotenv.config({path:'../../.env'}); {{/hasE2E}} import { {{client}} } from '{{{import}}}'; -import { echoRequester } from '{{{npmNamespace}}}/requester-node-http'; -import type { EchoResponse } from '{{{npmNamespace}}}/client-common'; -import type { RequestOptions } from '{{{npmNamespace}}}/client-common'; +import { echoRequester } from '@algolia/requester-node-http'; +import type { EchoResponse } from '@algolia/client-common'; +import type { RequestOptions } from '@algolia/client-common'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; diff --git a/tests/output/javascript/yarn.lock b/tests/output/javascript/yarn.lock index 658e099b97..636c101af1 100644 --- a/tests/output/javascript/yarn.lock +++ b/tests/output/javascript/yarn.lock @@ -928,12 +928,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:20.11.20": - version: 20.11.20 - resolution: "@types/node@npm:20.11.20" +"@types/node@npm:20.11.25": + version: 20.11.25 + resolution: "@types/node@npm:20.11.25" dependencies: undici-types: "npm:~5.26.4" - checksum: ff449bdc94810dadb54e0f77dd587c6505ef79ffa5a208c16eb29b223365b188f4c935a3abaf0906a01d05257c3da1f72465594a841d35bcf7b6deac7a6938fb + checksum: 861265f1bbb151404bd8842b595f027a4ff067c61ecff9a37b9f7f53922c18dd532c8e795e8e7675dd8dba056645623fd2b9848d5ef72863ec3609096cd2923e languageName: node linkType: hard @@ -2056,11 +2056,11 @@ __metadata: "@algolia/recommend": "link:../../../clients/algoliasearch-client-javascript/packages/recommend" "@algolia/requester-node-http": "link:../../../clients/algoliasearch-client-javascript/packages/requester-node-http" "@types/jest": "npm:29.5.12" - "@types/node": "npm:20.11.20" + "@types/node": "npm:20.11.25" algoliasearch: "link:../../../clients/algoliasearch-client-javascript/packages/algoliasearch" dotenv: "npm:16.4.5" jest: "npm:29.7.0" - typescript: "npm:5.3.3" + typescript: "npm:5.4.2" languageName: unknown linkType: soft @@ -3434,23 +3434,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:5.3.3": - version: 5.3.3 - resolution: "typescript@npm:5.3.3" +"typescript@npm:5.4.2": + version: 5.4.2 + resolution: "typescript@npm:5.4.2" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 6e4e6a14a50c222b3d14d4ea2f729e79f972fa536ac1522b91202a9a65af3605c2928c4a790a4a50aa13694d461c479ba92cedaeb1e7b190aadaa4e4b96b8e18 + checksum: f8cfdc630ab1672f004e9561eb2916935b2d267792d07ce93e97fc601c7a65191af32033d5e9c0169b7dc37da7db9bf320f7432bc84527cb7697effaa4e4559d languageName: node linkType: hard -"typescript@patch:typescript@npm%3A5.3.3#optional!builtin": - version: 5.3.3 - resolution: "typescript@patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7" +"typescript@patch:typescript@npm%3A5.4.2#optional!builtin": + version: 5.4.2 + resolution: "typescript@patch:typescript@npm%3A5.4.2#optional!builtin::version=5.4.2&hash=e012d7" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: c93786fcc9a70718ba1e3819bab56064ead5817004d1b8186f8ca66165f3a2d0100fee91fa64c840dcd45f994ca5d615d8e1f566d39a7470fc1e014dbb4cf15d + checksum: ef4fc2994cc0219dc9ada94c92106ba8d44cbfd7a0328ed6f8d730311caf66e114cdfa07fbc6f369bfc0fc182d9493851b3bf1644c06fc5818690b19ee960d72 languageName: node linkType: hard diff --git a/website/docs/contributing/testing/common-test-suite.md b/website/docs/contributing/testing/common-test-suite.md index 1fced9d107..42e2eb8f54 100644 --- a/website/docs/contributing/testing/common-test-suite.md +++ b/website/docs/contributing/testing/common-test-suite.md @@ -248,7 +248,6 @@ As well as lambdas to transform strings: If specific values are needed for a specific languages, or custom generated files, they can be added using a custom CTS manager: - [javascript](https://github.com/algolia/api-clients-automation/blob/main/generators/src/main/java/com/algolia/codegen/cts/manager/JavaScriptCTSManager.java) - - `npmNamespace`: the npm namespace - `utilsPackageVersion`: the utils version to import - `import`: the name of the package or library to import - [java](https://github.com/algolia/api-clients-automation/blob/main/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java)