Skip to content

Commit 2a1f30c

Browse files
authored
fix(javascript): remove factory from build (#639)
1 parent 6acaa20 commit 2a1f30c

File tree

10 files changed

+89
-49
lines changed

10 files changed

+89
-49
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@
22
"files": [
33
{
44
"path": "packages/algoliasearch/dist/algoliasearch.umd.browser.js",
5-
"maxSize": "7.40KB"
5+
"maxSize": "7.50KB"
66
},
77
{
88
"path": "packages/algoliasearch-lite/dist/algoliasearch-lite.umd.browser.js",
9-
"maxSize": "3.70KB"
9+
"maxSize": "3.75KB"
1010
},
1111
{
1212
"path": "packages/client-abtesting/dist/client-abtesting.umd.browser.js",
13-
"maxSize": "3.85KB"
13+
"maxSize": "3.90KB"
1414
},
1515
{
1616
"path": "packages/client-analytics/dist/client-analytics.umd.browser.js",
17-
"maxSize": "4.45KB"
17+
"maxSize": "4.50KB"
1818
},
1919
{
2020
"path": "packages/client-insights/dist/client-insights.umd.browser.js",
21-
"maxSize": "3.70KB"
21+
"maxSize": "3.75KB"
2222
},
2323
{
2424
"path": "packages/client-personalization/dist/client-personalization.umd.browser.js",
25-
"maxSize": "3.85KB"
25+
"maxSize": "3.95KB"
2626
},
2727
{
2828
"path": "packages/client-query-suggestions/dist/client-query-suggestions.umd.browser.js",
29-
"maxSize": "3.90KB"
29+
"maxSize": "4.00KB"
3030
},
3131
{
3232
"path": "packages/client-search/dist/client-search.umd.browser.js",
33-
"maxSize": "6.30KB"
33+
"maxSize": "6.25KB"
3434
},
3535
{
3636
"path": "packages/client-sources/dist/client-sources.umd.browser.js",
37-
"maxSize": "3.70KB"
37+
"maxSize": "3.85KB"
3838
},
3939
{
4040
"path": "packages/recommend/dist/recommend.umd.browser.js",
41-
"maxSize": "3.80KB"
41+
"maxSize": "3.85KB"
4242
}
4343
]
4444
}

clients/algoliasearch-client-javascript/packages/algoliasearch/builds/browser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import type {
2020
import { createPersonalizationClient } from '@experimental-api-clients-automation/client-personalization/src/personalizationClient';
2121
import {
2222
createSearchClient,
23-
apiClientVersion,
23+
apiClientVersion as searchClientVersion,
2424
} from '@experimental-api-clients-automation/client-search/src/searchClient';
2525
import { createXhrRequester } from '@experimental-api-clients-automation/requester-browser-xhr';
2626

27+
export const apiClientVersion = searchClientVersion;
28+
2729
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
2830
export function algoliasearch(
2931
appId: string,
@@ -98,3 +100,5 @@ export function algoliasearch(
98100
initPersonalization,
99101
};
100102
}
103+
104+
export type Algoliasearch = ReturnType<typeof algoliasearch>;

clients/algoliasearch-client-javascript/packages/algoliasearch/builds/node.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ import type {
1717
Region as PersonalizationRegion,
1818
} from '@experimental-api-clients-automation/client-personalization/src/personalizationClient';
1919
import { createPersonalizationClient } from '@experimental-api-clients-automation/client-personalization/src/personalizationClient';
20-
import { createSearchClient } from '@experimental-api-clients-automation/client-search/src/searchClient';
20+
import {
21+
createSearchClient,
22+
apiClientVersion as searchClientVersion,
23+
} from '@experimental-api-clients-automation/client-search/src/searchClient';
2124
import { createHttpRequester } from '@experimental-api-clients-automation/requester-node-http';
2225

26+
export const apiClientVersion = searchClientVersion;
27+
2328
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
2429
export function algoliasearch(
2530
appId: string,
@@ -88,3 +93,5 @@ export function algoliasearch(
8893
initPersonalization,
8994
};
9095
}
96+
97+
export type Algoliasearch = ReturnType<typeof algoliasearch>;

generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void processOpts() {
3333
// clear all supported files to avoid unwanted ones
3434
supportingFiles.clear();
3535

36+
supportingFiles.add(new SupportingFile("clientMethodProps.mustache", "model", "clientMethodProps.ts"));
3637
supportingFiles.add(new SupportingFile("modelBarrel.mustache", "model", "index.ts"));
3738
supportingFiles.add(new SupportingFile("browser.mustache", "builds", "browser.ts"));
3839
supportingFiles.add(new SupportingFile("node.mustache", "builds", "node.ts"));

playground/javascript/node/algoliasearch.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { algoliasearch } from '@experimental-api-clients-automation/algoliasearc
22
import { ApiError } from '@experimental-api-clients-automation/client-common';
33
import dotenv from 'dotenv';
44

5-
import type { SearchResponse } from '@experimental-api-clients-automation/client-search';
5+
import type { SearchResponses } from '@experimental-api-clients-automation/client-search';
66

77
dotenv.config({ path: '../../.env' });
88

@@ -31,9 +31,14 @@ client.addAlgoliaAgent('algoliasearch node playground', '0.0.1');
3131

3232
async function testAlgoliasearch() {
3333
try {
34-
const res: SearchResponse = await client.search({
35-
indexName: searchIndex,
36-
searchParams: { query: searchQuery },
34+
const res: SearchResponses = await client.search({
35+
requests: [
36+
{
37+
indexName: searchIndex,
38+
query: searchQuery,
39+
hitsPerPage: 50,
40+
},
41+
],
3742
});
3843

3944
console.log(`[OK search]`, res);

templates/javascript/api-single.mustache

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ import type {
2323
import { {{classname}} } from '{{filename}}';
2424
{{/imports}}
2525

26-
export * from '../model';
26+
{{#operations}}
27+
import type {
28+
{{#operation}}
29+
{{#vendorExtensions.x-create-wrapping-object}}
30+
{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
31+
{{/vendorExtensions.x-create-wrapping-object}}
32+
{{/operation}}
33+
} from '../model/clientMethodProps';
34+
{{/operations}}
35+
2736
export const apiClientVersion = '{{packageVersion}}';
2837

2938
{{#operations}}
30-
{{#description}}
31-
/**
32-
* {{&description}}
33-
*/
34-
{{/description}}
35-
3639
{{#hasRegionalHost}}
3740
export const REGIONS = [{{#allowedRegions}}'{{.}}'{{^-last}},{{/-last}}{{/allowedRegions}}] as const;
3841
export type Region = typeof REGIONS[number];
@@ -244,20 +247,4 @@ export function create{{capitalizedApiName}}({
244247

245248
export type {{capitalizedApiName}} = ReturnType<typeof create{{capitalizedApiName}}>;
246249

247-
{{#operation}}
248-
{{#vendorExtensions.x-create-wrapping-object}}
249-
export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props = {
250-
{{#allParams}}
251-
{{#description}}
252-
/**
253-
* {{{description}}}
254-
*/
255-
{{/description}}
256-
{{paramName}}{{^required}}?{{/required}}: {{{dataType}}};
257-
{{/allParams}}
258-
}
259-
{{/vendorExtensions.x-create-wrapping-object}}
260-
261-
{{/operation}}
262-
263250
{{/operations}}

templates/javascript/browser.mustache

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import type { {{capitalizedApiName}} } from '../src/{{apiName}}';
99
import { Region, REGIONS } from '../src/{{apiName}}';
1010
{{/hasRegionalHost}}
1111

12-
export * from '../src/{{apiName}}';
12+
{{! We don't use `export *` to prevent exposing the factory, to avoid confusion for the user }}
13+
export {
14+
apiClientVersion,
15+
{{capitalizedApiName}},
16+
} from '../src/{{apiName}}';
17+
export * from '../model';
1318

1419
export function {{apiName}}(
1520
appId: string,
@@ -24,16 +29,15 @@ export function {{apiName}}(
2429
throw new Error("`apiKey` is missing.");
2530
}
2631

27-
{{#hasRegionalHost}}
28-
{{^fallbackToAliasHost}}
32+
{{#hasRegionalHost}}{{^fallbackToAliasHost}}
2933
if (!region) {
3034
throw new Error("`region` is missing.");
3135
}
36+
3237
if (typeof region !== 'string' || !REGIONS.includes(region)) {
3338
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
3439
}
35-
{{/fallbackToAliasHost}}
36-
{{/hasRegionalHost}}
40+
{{/fallbackToAliasHost}}{{/hasRegionalHost}}
3741

3842
return create{{capitalizedApiName}}({
3943
appId,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{{#apiInfo.apis.0}}
2+
3+
{{#imports}}
4+
import { {{classname}} } from '{{filename}}';
5+
{{/imports}}
6+
7+
{{#operations}}
8+
{{#operation}}
9+
{{#vendorExtensions.x-create-wrapping-object}}
10+
/**
11+
* Properties for the `{{nickname}}` method.
12+
*/
13+
export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props = {
14+
{{#allParams}}
15+
{{#description}}
16+
/**
17+
* {{{description}}}
18+
*/
19+
{{/description}}
20+
{{paramName}}{{^required}}?{{/required}}: {{{dataType}}};
21+
{{/allParams}}
22+
}
23+
{{/vendorExtensions.x-create-wrapping-object}}
24+
25+
{{/operation}}
26+
{{/operations}}
27+
{{/apiInfo.apis.0}}

templates/javascript/modelBarrel.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
export * from '{{{ classFilename }}}';
44
{{/model}}
55
{{/models}}
6+
export * from './clientMethodProps'

templates/javascript/node.mustache

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import type { {{capitalizedApiName}} } from '../src/{{apiName}}';
99
import { Region, REGIONS } from '../src/{{apiName}}';
1010
{{/hasRegionalHost}}
1111

12-
export * from '../src/{{apiName}}';
12+
{{! We don't use `export *` to prevent exposing the factory, to avoid confusion for the user }}
13+
export {
14+
apiClientVersion,
15+
{{capitalizedApiName}},
16+
} from '../src/{{apiName}}';
17+
export * from '../model';
1318

1419
export function {{apiName}}(
1520
appId: string,
@@ -24,16 +29,15 @@ export function {{apiName}}(
2429
throw new Error("`apiKey` is missing.");
2530
}
2631

27-
{{#hasRegionalHost}}
28-
{{^fallbackToAliasHost}}
32+
{{#hasRegionalHost}}{{^fallbackToAliasHost}}
2933
if (!region) {
3034
throw new Error("`region` is missing.");
3135
}
36+
3237
if (typeof region !== 'string' || !REGIONS.includes(region)) {
3338
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
3439
}
35-
{{/fallbackToAliasHost}}
36-
{{/hasRegionalHost}}
40+
{{/fallbackToAliasHost}}{{/hasRegionalHost}}
3741

3842
return create{{capitalizedApiName}}({
3943
appId,

0 commit comments

Comments
 (0)