Skip to content

fix(javascript): improve bundlesize, add check to CI #762

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 1 commit into from
Jun 28, 2022
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
4 changes: 4 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ jobs:
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language != 'php' }}
run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toBuild }}

- name: Test JavaScript bundle size
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
run: cd ${{ matrix.client.path }} && yarn test:size

- name: Run JavaScript 'algoliasearch' client tests
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
run: cd ${{ matrix.client.path }} && yarn workspace @experimental-api-clients-automation/algoliasearch test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"files": [
{
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
"maxSize": "7.60KB"
"maxSize": "7.80KB"
},
{
"path": "packages/algoliasearch/dist/lite/lite.umd.js",
Expand All @@ -18,7 +18,7 @@
},
{
"path": "packages/client-insights/dist/client-insights.umd.js",
"maxSize": "3.80KB"
"maxSize": "3.75KB"
},
{
"path": "packages/client-personalization/dist/client-personalization.umd.js",
Expand All @@ -30,7 +30,7 @@
},
{
"path": "packages/client-search/dist/client-search.umd.js",
"maxSize": "6.30KB"
"maxSize": "6.55KB"
},
{
"path": "packages/client-sources/dist/client-sources.umd.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getUrlParams({
host,
algoliaAgent,
searchParams:
Object.entries(searchParams).length === 0 ? undefined : searchParams,
Object.keys(searchParams).length === 0 ? undefined : searchParams,
};
}

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

return Promise.resolve({
content: JSON.stringify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ export function createTransporter({
};

if (requestOptions?.queryParameters) {
for (const [key, value] of Object.entries(
requestOptions.queryParameters
)) {
for (const key of Object.keys(requestOptions.queryParameters)) {
// We want to keep `undefined` and `null` values,
// but also avoid stringifying `object`s, as they are
// handled in the `serializeUrl` step right after.
if (
!value ||
Object.prototype.toString.call(value) === '[object Object]'
!requestOptions.queryParameters[key] ||
Object.prototype.toString.call(
requestOptions.queryParameters[key]
) === '[object Object]'
) {
queryParameters[key] = value;
queryParameters[key] = requestOptions.queryParameters[key];
} else {
queryParameters[key] = value.toString();
queryParameters[key] = requestOptions.queryParameters[key].toString();
}
}
}
Expand Down
21 changes: 14 additions & 7 deletions templates/javascript/clients/client/api/helpers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,30 @@ waitForApiKey({
...createRetryablePromiseOptions
}: WaitForApiKeyOptions): Promise<ApiError | Key> {
if (operation === 'update') {
if (!apiKey) {
throw new Error(
'`apiKey` is required when waiting for an `update` operation.'
);
}

return createRetryablePromise({
...createRetryablePromiseOptions,
func: () => this.getApiKey({ key }),
validate: (response) => {
for (const [entry, values] of Object.entries(apiKey)) {
if (Array.isArray(values)) {
validate: (response) => {
for (const field of Object.keys(apiKey)) {
if (Array.isArray(apiKey[field])) {
if (
values.length !== response[entry].length ||
values.some((val, index) => val !== response[entry][index])
apiKey[field].length !== response[field].length ||
(apiKey[field] as string[]).some(
(value, index) => value !== response[field][index]
)
) {
return false;
}
} else if (values !== response[entry]) {
} else if (response[field] !== apiKey[field]) {
return false;
}
}

return true;
},
});
Expand Down