Skip to content

Commit b9c4145

Browse files
authored
fix(javascript): improve bundlesize, add check to CI (#762)
1 parent 0e10c86 commit b9c4145

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

.github/workflows/check.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ jobs:
225225
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language != 'php' }}
226226
run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toBuild }}
227227

228+
- name: Test JavaScript bundle size
229+
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
230+
run: cd ${{ matrix.client.path }} && yarn test:size
231+
228232
- name: Run JavaScript 'algoliasearch' client tests
229233
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
230234
run: cd ${{ matrix.client.path }} && yarn workspace @experimental-api-clients-automation/algoliasearch test

clients/algoliasearch-client-javascript/bundlesize.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"files": [
33
{
44
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
5-
"maxSize": "7.60KB"
5+
"maxSize": "7.80KB"
66
},
77
{
88
"path": "packages/algoliasearch/dist/lite/lite.umd.js",
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"path": "packages/client-insights/dist/client-insights.umd.js",
21-
"maxSize": "3.80KB"
21+
"maxSize": "3.75KB"
2222
},
2323
{
2424
"path": "packages/client-personalization/dist/client-personalization.umd.js",
@@ -30,7 +30,7 @@
3030
},
3131
{
3232
"path": "packages/client-search/dist/client-search.umd.js",
33-
"maxSize": "6.30KB"
33+
"maxSize": "6.55KB"
3434
},
3535
{
3636
"path": "packages/client-sources/dist/client-sources.umd.js",

clients/algoliasearch-client-javascript/packages/client-common/src/createEchoRequester.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function getUrlParams({
2424
host,
2525
algoliaAgent,
2626
searchParams:
27-
Object.entries(searchParams).length === 0 ? undefined : searchParams,
27+
Object.keys(searchParams).length === 0 ? undefined : searchParams,
2828
};
2929
}
3030

@@ -39,7 +39,7 @@ export function createEchoRequester({
3939
): Promise<Response> {
4040
const { host, searchParams, algoliaAgent } = getUrlParams(getURL(url));
4141
const originalData =
42-
data && Object.entries(data).length > 0 ? data : undefined;
42+
data && Object.keys(data).length > 0 ? data : undefined;
4343

4444
return Promise.resolve({
4545
content: JSON.stringify({

clients/algoliasearch-client-javascript/packages/client-common/src/transporter/createTransporter.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ export function createTransporter({
113113
};
114114

115115
if (requestOptions?.queryParameters) {
116-
for (const [key, value] of Object.entries(
117-
requestOptions.queryParameters
118-
)) {
116+
for (const key of Object.keys(requestOptions.queryParameters)) {
119117
// We want to keep `undefined` and `null` values,
120118
// but also avoid stringifying `object`s, as they are
121119
// handled in the `serializeUrl` step right after.
122120
if (
123-
!value ||
124-
Object.prototype.toString.call(value) === '[object Object]'
121+
!requestOptions.queryParameters[key] ||
122+
Object.prototype.toString.call(
123+
requestOptions.queryParameters[key]
124+
) === '[object Object]'
125125
) {
126-
queryParameters[key] = value;
126+
queryParameters[key] = requestOptions.queryParameters[key];
127127
} else {
128-
queryParameters[key] = value.toString();
128+
queryParameters[key] = requestOptions.queryParameters[key].toString();
129129
}
130130
}
131131
}

templates/javascript/clients/client/api/helpers.mustache

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,30 @@ waitForApiKey({
3434
...createRetryablePromiseOptions
3535
}: WaitForApiKeyOptions): Promise<ApiError | Key> {
3636
if (operation === 'update') {
37+
if (!apiKey) {
38+
throw new Error(
39+
'`apiKey` is required when waiting for an `update` operation.'
40+
);
41+
}
42+
3743
return createRetryablePromise({
3844
...createRetryablePromiseOptions,
3945
func: () => this.getApiKey({ key }),
40-
validate: (response) => {
41-
for (const [entry, values] of Object.entries(apiKey)) {
42-
if (Array.isArray(values)) {
46+
validate: (response) => {
47+
for (const field of Object.keys(apiKey)) {
48+
if (Array.isArray(apiKey[field])) {
4349
if (
44-
values.length !== response[entry].length ||
45-
values.some((val, index) => val !== response[entry][index])
50+
apiKey[field].length !== response[field].length ||
51+
(apiKey[field] as string[]).some(
52+
(value, index) => value !== response[field][index]
53+
)
4654
) {
4755
return false;
4856
}
49-
} else if (values !== response[entry]) {
57+
} else if (response[field] !== apiKey[field]) {
5058
return false;
5159
}
5260
}
53-
5461
return true;
5562
},
5663
});

0 commit comments

Comments
 (0)