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

feat(clients): add recommend to algoliasearch #2860

Merged
merged 8 commits into from
Jun 24, 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
91 changes: 63 additions & 28 deletions clients/algoliasearch-client-javascript/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3067,7 +3067,16 @@ __metadata:
languageName: node
linkType: hard

"acorn@npm:^8.1.0, acorn@npm:^8.11.0, acorn@npm:^8.8.1, acorn@npm:^8.8.2":
"acorn@npm:^8.1.0, acorn@npm:^8.8.1, acorn@npm:^8.8.2":
version: 8.11.3
resolution: "acorn@npm:8.11.3"
bin:
acorn: bin/acorn
checksum: 10/b688e7e3c64d9bfb17b596e1b35e4da9d50553713b3b3630cf5690f2b023a84eac90c56851e6912b483fe60e8b4ea28b254c07e92f17ef83d72d78745a8352dd
languageName: node
linkType: hard

"acorn@npm:^8.11.0":
version: 8.12.0
resolution: "acorn@npm:8.12.0"
bin:
Expand Down Expand Up @@ -4460,9 +4469,9 @@ __metadata:
linkType: hard

"electron-to-chromium@npm:^1.4.796":
version: 1.4.810
resolution: "electron-to-chromium@npm:1.4.810"
checksum: 10/425de710336094330fd026cc2cfa0b383bfc9a49a2f575ceec2ac76198663ff95d0109bb45b243a43f0bf0f91a2e9c2768693a136d0968ae59728d5e8eea22ef
version: 1.4.805
resolution: "electron-to-chromium@npm:1.4.805"
checksum: 10/69ff2b7098ec80666c7cfed3ae045894b1bf8ae72a77233c37b4496698a1c20a24e9b97822df7fe5dad226d32ca52defa10dee4b36438da35af6d51810d652d3
languageName: node
linkType: hard

Expand Down Expand Up @@ -5153,18 +5162,17 @@ __metadata:
linkType: hard

"glob@npm:^10.2.2, glob@npm:^10.3.10":
version: 10.4.2
resolution: "glob@npm:10.4.2"
version: 10.4.1
resolution: "glob@npm:10.4.1"
dependencies:
foreground-child: "npm:^3.1.0"
jackspeak: "npm:^3.1.2"
minimatch: "npm:^9.0.4"
minipass: "npm:^7.1.2"
package-json-from-dist: "npm:^1.0.0"
path-scurry: "npm:^1.11.1"
bin:
glob: dist/esm/bin.mjs
checksum: 10/e412776b5952a818eba790c830bea161c9a56813fd767d8c4c49f855603b1fb962b3e73f1f627a47298a57d2992b9f0f2fe15cf93e74ecaaa63fb45d63fdd090
checksum: 10/d7bb49d2b413f77bdd59fea4ca86dcc12450deee221af0ca93e09534b81b9ef68fe341345751d8ff0c5b54bad422307e0e44266ff8ad7fbbd0c200e8ec258b16
languageName: node
linkType: hard

Expand Down Expand Up @@ -5333,7 +5341,7 @@ __metadata:
languageName: node
linkType: hard

"hasown@npm:^2.0.0, hasown@npm:^2.0.2":
"hasown@npm:^2.0.0":
version: 2.0.2
resolution: "hasown@npm:2.0.2"
dependencies:
Expand Down Expand Up @@ -5675,11 +5683,11 @@ __metadata:
linkType: hard

"is-core-module@npm:^2.13.0, is-core-module@npm:^2.5.0, is-core-module@npm:^2.8.1":
version: 2.14.0
resolution: "is-core-module@npm:2.14.0"
version: 2.13.1
resolution: "is-core-module@npm:2.13.1"
dependencies:
hasown: "npm:^2.0.2"
checksum: 10/1e0d1a16cb3a94746f6a28db09ccab4562860c94c74bacedb3a6729736d61cfb97001d2052f9622637aa7ea8e0643a3f0f4f16965c70ba6ce30a8ccfe8074af8
hasown: "npm:^2.0.0"
checksum: 10/d53bd0cc24b0a0351fb4b206ee3908f71b9bbf1c47e9c9e14e5f06d292af1663704d2abd7e67700d6487b2b7864e0d0f6f10a1edf1892864bdffcb197d1845a2
languageName: node
linkType: hard

Expand Down Expand Up @@ -7350,7 +7358,7 @@ __metadata:
languageName: node
linkType: hard

"node-gyp@npm:^10.0.0, node-gyp@npm:latest":
"node-gyp@npm:^10.0.0":
version: 10.1.0
resolution: "node-gyp@npm:10.1.0"
dependencies:
Expand All @@ -7370,6 +7378,26 @@ __metadata:
languageName: node
linkType: hard

"node-gyp@npm:latest":
version: 10.0.1
resolution: "node-gyp@npm:10.0.1"
dependencies:
env-paths: "npm:^2.2.0"
exponential-backoff: "npm:^3.1.1"
glob: "npm:^10.3.10"
graceful-fs: "npm:^4.2.6"
make-fetch-happen: "npm:^13.0.0"
nopt: "npm:^7.0.0"
proc-log: "npm:^3.0.0"
semver: "npm:^7.3.5"
tar: "npm:^6.1.2"
which: "npm:^4.0.0"
bin:
node-gyp: bin/node-gyp.js
checksum: 10/578cf0c821f258ce4b6ebce4461eca4c991a4df2dee163c0624f2fe09c7d6d37240be4942285a0048d307230248ee0b18382d6623b9a0136ce9533486deddfa8
languageName: node
linkType: hard

"node-int64@npm:^0.4.0":
version: 0.4.0
resolution: "node-int64@npm:0.4.0"
Expand Down Expand Up @@ -7721,9 +7749,9 @@ __metadata:
linkType: hard

"object-inspect@npm:^1.13.1":
version: 1.13.2
resolution: "object-inspect@npm:1.13.2"
checksum: 10/7ef65583b6397570a17c56f0c1841e0920e83900f2c94638927abb7b81ac08a19c7aae135bd9dcca96208cac0c7332b4650fb927f027b0cf92d71df2990d0561
version: 1.13.1
resolution: "object-inspect@npm:1.13.1"
checksum: 10/92f4989ed83422d56431bc39656d4c780348eb15d397ce352ade6b7fec08f973b53744bd41b94af021901e61acaf78fcc19e65bf464ecc0df958586a672700f0
languageName: node
linkType: hard

Expand Down Expand Up @@ -7920,13 +7948,6 @@ __metadata:
languageName: node
linkType: hard

"package-json-from-dist@npm:^1.0.0":
version: 1.0.0
resolution: "package-json-from-dist@npm:1.0.0"
checksum: 10/ac706ec856a5a03f5261e4e48fa974f24feb044d51f84f8332e2af0af04fbdbdd5bbbfb9cbbe354190409bc8307c83a9e38c6672c3c8855f709afb0006a009ea
languageName: node
linkType: hard

"pacote@npm:^17.0.5":
version: 17.0.7
resolution: "pacote@npm:17.0.7"
Expand Down Expand Up @@ -9330,7 +9351,7 @@ __metadata:
languageName: node
linkType: hard

"tar@npm:6.2.1, tar@npm:^6.1.11, tar@npm:^6.1.2":
"tar@npm:6.2.1":
version: 6.2.1
resolution: "tar@npm:6.2.1"
dependencies:
Expand All @@ -9344,6 +9365,20 @@ __metadata:
languageName: node
linkType: hard

"tar@npm:^6.1.11, tar@npm:^6.1.2":
version: 6.2.0
resolution: "tar@npm:6.2.0"
dependencies:
chownr: "npm:^2.0.0"
fs-minipass: "npm:^2.0.0"
minipass: "npm:^5.0.0"
minizlib: "npm:^2.1.1"
mkdirp: "npm:^1.0.3"
yallist: "npm:^4.0.0"
checksum: 10/2042bbb14830b5cd0d584007db0eb0a7e933e66d1397e72a4293768d2332449bc3e312c266a0887ec20156dea388d8965e53b4fc5097f42d78593549016da089
languageName: node
linkType: hard

"temp-dir@npm:1.0.0":
version: 1.0.0
resolution: "temp-dir@npm:1.0.0"
Expand Down Expand Up @@ -9763,13 +9798,13 @@ __metadata:
linkType: hard

"v8-to-istanbul@npm:^9.0.1":
version: 9.3.0
resolution: "v8-to-istanbul@npm:9.3.0"
version: 9.2.0
resolution: "v8-to-istanbul@npm:9.2.0"
dependencies:
"@jridgewell/trace-mapping": "npm:^0.3.12"
"@types/istanbul-lib-coverage": "npm:^2.0.1"
convert-source-map: "npm:^2.0.0"
checksum: 10/fb1d70f1176cb9dc46cabbb3fd5c52c8f3e8738b61877b6e7266029aed0870b04140e3f9f4550ac32aebcfe1d0f38b0bac57e1e8fb97d68fec82f2b416148166
checksum: 10/18dd8cebfb6790f27f4e41e7cff77c7ab1c8904085f354dd7875e2eb65f4261c4cf40939132502875779d92304bfea46b8336346ecb40b6f33c3a3979e6f5729
languageName: node
linkType: hard

Expand Down
1 change: 0 additions & 1 deletion config/clients.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
}
],
"folder": "clients/algoliasearch-client-javascript",
"npmNamespace": "@algolia",
"gitRepoId": "algoliasearch-client-javascript",
"packageVersion": "5.0.0-beta.5",
"modelFolder": "model",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,7 +186,6 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
setDefaultGeneratorOptions();
try {
additionalProperties.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common"));
additionalProperties.put("npmNamespace", Helpers.getClientConfigField("javascript", "npmNamespace"));
} catch (GeneratorException e) {
e.printStackTrace();
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ public void addTestsSupportingFiles(List<SupportingFile> supportingFiles) {

@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
String npmNamespace = Helpers.getClientConfigField("javascript", "npmNamespace");

bundle.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common"));
bundle.put("npmNamespace", npmNamespace);

List<Map<String, String>> clients = new ArrayList<>();
String importName = "";
Expand All @@ -35,7 +32,7 @@ public void addDataToBundle(Map<String, Object> 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}/", "")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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;
Expand All @@ -24,10 +25,32 @@ protected Map<String, Request[]> 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<String, Request[]> 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<String, Request[]> recommendCTS = super.loadCTS("requests", "recommend", Request[].class);
for (Map.Entry<String, Request[]> 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
Expand Down Expand Up @@ -75,7 +98,9 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
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 +
"/" +
Expand Down
5 changes: 2 additions & 3 deletions scripts/buildClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -17,9 +17,8 @@ async function buildClient(language: Language, gens: Generator[]): Promise<void>
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 });
Expand Down
10 changes: 2 additions & 8 deletions scripts/ci/githubActions/createMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -102,12 +97,11 @@ async function createClientMatrix(baseBranch: string): Promise<void> {
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(
Expand Down
Loading
Loading