Skip to content

Commit 5b8fa21

Browse files
committed
merge with main
2 parents 56ceb71 + 0875ec6 commit 5b8fa21

File tree

52 files changed

+2091
-2138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2091
-2138
lines changed

.github/actions/setup/action.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ outputs:
134134
RUN_JS_UTILS:
135135
description: Whether to build JS client common folders when RUN_JS is false
136136
value: ${{ steps.js-utils.outputs.RUN_JS_UTILS }}
137-
RUN_JS_TESTS:
138-
description: Determine if the `client_javascript_tests` job should run
139-
value: ${{ steps.diff.outputs.JS_COMMON_TESTS_CHANGED > 0 }}
140137

141138
RUN_CODEGEN:
142139
description: Determine if the `codegen` job should run

.github/workflows/check.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ jobs:
6767
RUN_GEN_PHP: ${{ steps.setup.outputs.RUN_GEN_PHP }}
6868

6969
RUN_JS_UTILS: ${{ steps.setup.outputs.RUN_JS_UTILS }}
70-
RUN_JS_TESTS: ${{ steps.setup.outputs.RUN_JS_TESTS }}
7170

7271
RUN_CODEGEN: ${{ steps.setup.outputs.RUN_CODEGEN }}
7372

@@ -162,10 +161,7 @@ jobs:
162161
run: yarn workspace algoliasearch-client-javascript build ${{ matrix.client }}
163162

164163
- name: Run tests for 'client-common'
165-
if: ${{
166-
steps.cache.outputs.cache-hit != 'true' &&
167-
needs.setup.outputs.RUN_JS_TESTS == 'true' &&
168-
matrix.client == 'client-common' }}
164+
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client == 'client-common' }}
169165
run: yarn workspace @experimental-api-clients-automation/client-common test
170166

171167
- name: Store '${{ matrix.client }}' JavaScript utils package
@@ -228,6 +224,10 @@ jobs:
228224
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
229225
run: yarn cli build clients javascript algoliasearch
230226

227+
- name: Run JavaScript 'algoliasearch' client tests
228+
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
229+
run: yarn workspace @experimental-api-clients-automation/algoliasearch test
230+
231231
- name: Clean CTS output before generate
232232
run: rm -rf ${{ matrix.client.testsToDelete }} || true
233233

.github/workflows/scheduled-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jobs:
1010
runs-on: ubuntu-20.04
1111
steps:
1212
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
ref: main
1316

1417
- name: Setup
1518
id: setup

clients/algoliasearch-client-java-2/algoliasearch-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java-library'
33
id 'com.vanniktech.maven.publish'
4-
id 'com.github.johnrengelman.shadow' version '7.0.0'
4+
id 'com.github.johnrengelman.shadow' version '7.1.2'
55
}
66

77
repositories {

clients/algoliasearch-client-javascript/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@
2424
"@babel/runtime": "7.18.3",
2525
"@rollup/plugin-babel": "5.3.1",
2626
"@rollup/plugin-node-resolve": "13.3.0",
27-
"@types/jest": "27.5.2",
27+
"@types/jest": "28.1.1",
2828
"@types/rollup-plugin-node-globals": "1.4.1",
2929
"@types/semver": "7.3.9",
3030
"bundlesize2": "0.0.31",
3131
"execa": "5.1.1",
32-
"lerna": "5.0.0",
33-
"rollup": "2.70.1",
32+
"lerna": "5.1.1",
33+
"rollup": "2.75.6",
3434
"rollup-plugin-filesize": "9.1.2",
3535
"rollup-plugin-node-globals": "1.4.0",
3636
"rollup-plugin-terser": "7.0.2",
37-
"rollup-plugin-typescript2": "0.31.2",
37+
"rollup-plugin-typescript2": "0.32.1",
3838
"semver": "7.3.7",
39-
"ts-node": "10.7.0",
40-
"typescript": "4.6.3"
39+
"ts-node": "10.8.1",
40+
"typescript": "4.7.3"
4141
},
4242
"engines": {
4343
"node": ">= 14.0.0",

clients/algoliasearch-client-javascript/packages/algoliasearch-lite/model/clientMethodProps.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import type { SearchForFacetsOptions } from './searchForFacetsOptions';
2+
import type { SearchForHitsOptions } from './searchForHitsOptions';
3+
import type { SearchParamsObject } from './searchParamsObject';
4+
15
/**
26
* Properties for the `post` method.
37
*/
@@ -15,3 +19,35 @@ export type PostProps = {
1519
*/
1620
body?: Record<string, any>;
1721
};
22+
23+
/**
24+
* In v4, the search parameters are wrapped in a `params` parameter.
25+
*
26+
* @deprecated The `search` method now accepts flat `searchParams` at the root of the method.
27+
*/
28+
type LegacySearchParams = {
29+
params?: SearchParamsObject;
30+
};
31+
32+
/**
33+
* In v4, the search parameters are wrapped in a `params` parameter.
34+
*
35+
* @deprecated The `search` method now accepts flat `searchParams` at the root of the method.
36+
*/
37+
type LegacySearchForFacets = LegacySearchParams & SearchForFacetsOptions;
38+
39+
/**
40+
* In v4, the search parameters are wrapped in a `params` parameter.
41+
*
42+
* @deprecated The `search` method now accepts flat `searchParams` at the root of the method.
43+
*/
44+
type LegacySearchForHits = LegacySearchParams & SearchForHitsOptions;
45+
46+
type LegacySearchQuery = LegacySearchForFacets | LegacySearchForHits;
47+
48+
/**
49+
* Search method signature compatible with the `algoliasearch` v4 package. When using this signature, extra computation will be required to make it match the new signature.
50+
*
51+
* @deprecated This signature will be removed from the next major version, we recommend using the `SearchMethodParams` type for performances and future proof reasons.
52+
*/
53+
export type LegacySearchMethodProps = LegacySearchQuery[];

clients/algoliasearch-client-javascript/packages/algoliasearch-lite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"@experimental-api-clients-automation/requester-node-http": "0.4.0"
2727
},
2828
"devDependencies": {
29-
"@types/node": "16.11.38",
30-
"typescript": "4.6.3"
29+
"@types/node": "16.11.39",
30+
"typescript": "4.7.3"
3131
},
3232
"engines": {
3333
"node": ">= 14.0.0"

clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/algoliasearchLiteClient.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import type {
1313
QueryParameters,
1414
} from '@experimental-api-clients-automation/client-common';
1515

16-
import type { PostProps } from '../model/clientMethodProps';
16+
import type {
17+
PostProps,
18+
LegacySearchMethodProps,
19+
} from '../model/clientMethodProps';
1720
import type { SearchMethodParams } from '../model/searchMethodParams';
1821
import type { SearchResponses } from '../model/searchResponses';
1922

@@ -129,9 +132,34 @@ export function createAlgoliasearchLiteClient({
129132
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
130133
*/
131134
search(
132-
searchMethodParams: SearchMethodParams,
135+
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
133136
requestOptions?: RequestOptions
134137
): Promise<SearchResponses> {
138+
if (searchMethodParams && Array.isArray(searchMethodParams)) {
139+
const newSignatureRequest: SearchMethodParams = {
140+
requests: searchMethodParams.map(({ params, ...legacyRequest }) => {
141+
if (legacyRequest.type === 'facet') {
142+
return {
143+
...legacyRequest,
144+
...params,
145+
type: 'facet',
146+
};
147+
}
148+
149+
return {
150+
...legacyRequest,
151+
...params,
152+
facet: undefined,
153+
maxFacetHits: undefined,
154+
facetQuery: undefined,
155+
};
156+
}),
157+
};
158+
159+
// eslint-disable-next-line no-param-reassign
160+
searchMethodParams = newSignatureRequest;
161+
}
162+
135163
if (!searchMethodParams) {
136164
throw new Error(
137165
'Parameter `searchMethodParams` is required when calling `search`.'
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import type { EchoResponse } from '@experimental-api-clients-automation/client-common';
2+
import { echoRequester } from '@experimental-api-clients-automation/requester-node-http';
3+
4+
import { algoliasearch, apiClientVersion } from '../builds/node';
5+
6+
const client = algoliasearch('APP_ID', 'API_KEY', {
7+
requester: echoRequester(),
8+
});
9+
10+
describe('api', () => {
11+
it('sets the user agent', async () => {
12+
const req = (await client.post({
13+
path: '/test',
14+
})) as unknown as EchoResponse;
15+
16+
expect(req.algoliaAgent).toMatchInlineSnapshot(
17+
`"Algolia%20for%20JavaScript%20(${apiClientVersion});%20Search%20(${apiClientVersion});%20Node.js%20(${process.versions.node})"`
18+
);
19+
});
20+
21+
it('throws with undefined API key', () => {
22+
try {
23+
algoliasearch('APP_ID', '');
24+
} catch (e) {
25+
expect((e as Error).message).toMatch('`apiKey` is missing.');
26+
}
27+
});
28+
29+
it('throws with undefined app ID', () => {
30+
try {
31+
algoliasearch('', 'API_KEY');
32+
} catch (e) {
33+
expect((e as Error).message).toMatch('`appId` is missing.');
34+
}
35+
});
36+
37+
it('provides the search client at the root of the API', () => {
38+
expect(client.search).not.toBeUndefined();
39+
});
40+
41+
it('provides an init method for the analytics client', () => {
42+
expect(client.initAnalytics).not.toBeUndefined();
43+
});
44+
45+
it('provides an init method for the personalization client', () => {
46+
expect(client.initPersonalization).not.toBeUndefined();
47+
});
48+
});
49+
50+
/**
51+
* We only test the legacy signature, as `algoliasearch` inherits methods from the `client-search`.
52+
* The new signatures are already tested in the CTS.
53+
*/
54+
describe('search with legacy signature', () => {
55+
it('allows searching for query', async () => {
56+
const req = (await client.search([
57+
{
58+
indexName: 'theIndexName',
59+
},
60+
])) as unknown as EchoResponse;
61+
62+
expect(req.path).toEqual('/1/indexes/*/queries');
63+
expect(req.method).toEqual('POST');
64+
expect(req.data).toEqual({ requests: [{ indexName: 'theIndexName' }] });
65+
expect(req.searchParams).toStrictEqual(undefined);
66+
});
67+
68+
it('allows searching for facet', async () => {
69+
const req = (await client.search([
70+
{
71+
indexName: 'theIndexName',
72+
type: 'facet',
73+
facet: 'theFacet',
74+
},
75+
])) as unknown as EchoResponse;
76+
77+
expect(req.path).toEqual('/1/indexes/*/queries');
78+
expect(req.method).toEqual('POST');
79+
expect(req.data).toEqual({
80+
requests: [
81+
{ indexName: 'theIndexName', type: 'facet', facet: 'theFacet' },
82+
],
83+
});
84+
expect(req.searchParams).toStrictEqual(undefined);
85+
});
86+
87+
it('accepts a `params` parameter for `searchParams`', async () => {
88+
const req = (await client.search([
89+
{
90+
indexName: 'theIndexName',
91+
params: {
92+
hitsPerPage: 42,
93+
},
94+
},
95+
])) as unknown as EchoResponse;
96+
97+
expect(req.path).toEqual('/1/indexes/*/queries');
98+
expect(req.method).toEqual('POST');
99+
expect(req.data).toEqual({
100+
requests: [{ indexName: 'theIndexName', hitsPerPage: 42 }],
101+
});
102+
expect(req.searchParams).toStrictEqual(undefined);
103+
});
104+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Config } from '@jest/types';
2+
3+
const config: Config.InitialOptions = {
4+
preset: 'ts-jest',
5+
testEnvironment: 'node',
6+
roots: ['__tests__'],
7+
};
8+
9+
export default config;

clients/algoliasearch-client-javascript/packages/algoliasearch/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"browser": "dist/algoliasearch.cjs.browser.js",
1313
"types": "index.d.ts",
1414
"scripts": {
15-
"clean": "rm -rf ./dist"
15+
"clean": "rm -rf ./dist",
16+
"test": "jest"
1617
},
1718
"dependencies": {
1819
"@experimental-api-clients-automation/client-analytics": "0.4.0",
@@ -23,8 +24,10 @@
2324
"@experimental-api-clients-automation/requester-node-http": "0.4.0"
2425
},
2526
"devDependencies": {
26-
"@types/node": "16.11.26",
27-
"typescript": "4.6.3"
27+
"@types/jest": "28.1.1",
28+
"@types/node": "16.11.39",
29+
"jest": "28.1.1",
30+
"typescript": "4.7.3"
2831
},
2932
"engines": {
3033
"node": ">= 14.0.0"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4+
"types": ["node", "jest"],
45
"outDir": "dist"
56
},
67
"include": ["builds/node.ts", "builds/browser.ts"],
7-
"exclude": ["dist", "node_modules"]
8+
"exclude": ["dist", "node_modules", "__tests__"]
89
}

clients/algoliasearch-client-javascript/packages/client-abtesting/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"@experimental-api-clients-automation/requester-node-http": "0.4.0"
2727
},
2828
"devDependencies": {
29-
"@types/node": "16.11.38",
30-
"typescript": "4.6.3"
29+
"@types/node": "16.11.39",
30+
"typescript": "4.7.3"
3131
},
3232
"engines": {
3333
"node": ">= 14.0.0"

clients/algoliasearch-client-javascript/packages/client-analytics/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"@experimental-api-clients-automation/requester-node-http": "0.4.0"
2727
},
2828
"devDependencies": {
29-
"@types/node": "16.11.38",
30-
"typescript": "4.6.3"
29+
"@types/node": "16.11.39",
30+
"typescript": "4.7.3"
3131
},
3232
"engines": {
3333
"node": ">= 14.0.0"

clients/algoliasearch-client-javascript/packages/client-common/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"test": "jest"
1414
},
1515
"devDependencies": {
16-
"@types/jest": "27.5.2",
17-
"@types/node": "16.11.38",
16+
"@types/jest": "28.1.1",
17+
"@types/node": "16.11.39",
1818
"jest": "28.1.1",
1919
"jest-environment-jsdom": "28.1.1",
20-
"typescript": "4.6.3"
20+
"typescript": "4.7.3"
2121
},
2222
"engines": {
2323
"node": ">= 14.0.0"

clients/algoliasearch-client-javascript/packages/client-insights/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"@experimental-api-clients-automation/requester-node-http": "0.4.0"
2727
},
2828
"devDependencies": {
29-
"@types/node": "16.11.38",
30-
"typescript": "4.6.3"
29+
"@types/node": "16.11.39",
30+
"typescript": "4.7.3"
3131
},
3232
"engines": {
3333
"node": ">= 14.0.0"

clients/algoliasearch-client-javascript/packages/client-personalization/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"@experimental-api-clients-automation/requester-node-http": "0.4.0"
2727
},
2828
"devDependencies": {
29-
"@types/node": "16.11.38",
30-
"typescript": "4.6.3"
29+
"@types/node": "16.11.39",
30+
"typescript": "4.7.3"
3131
},
3232
"engines": {
3333
"node": ">= 14.0.0"

0 commit comments

Comments
 (0)