Skip to content

Commit a4f625b

Browse files
feat(javascript): add worker exports (#3680) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 8964352 commit a4f625b

File tree

36 files changed

+886
-68
lines changed

36 files changed

+886
-68
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import type { InitClientOptions, InitClientRegion } from './models';
1717
export * from './models';
1818

1919
export type Algoliasearch = SearchClient & {
20-
initRecommend: (initOptions: InitClientOptions) => RecommendClient;
21-
initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion>) => AnalyticsClient;
22-
initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion>) => AbtestingClient;
20+
initRecommend: (initOptions?: InitClientOptions) => RecommendClient;
21+
initAnalytics: (initOptions?: InitClientOptions & InitClientRegion<AnalyticsRegion>) => AnalyticsClient;
22+
initAbtesting: (initOptions?: InitClientOptions & InitClientRegion<AbtestingRegion>) => AbtestingClient;
2323
initPersonalization: (
2424
initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
2525
) => PersonalizationClient;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
2+
3+
import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client-abtesting';
4+
import { abtestingClient } from '@algolia/client-abtesting';
5+
import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics';
6+
import { analyticsClient } from '@algolia/client-analytics';
7+
import type { ClientOptions } from '@algolia/client-common';
8+
import type { PersonalizationClient, Region as PersonalizationRegion } from '@algolia/client-personalization';
9+
import { personalizationClient } from '@algolia/client-personalization';
10+
import type { SearchClient } from '@algolia/client-search';
11+
import { searchClient } from '@algolia/client-search';
12+
import type { RecommendClient } from '@algolia/recommend';
13+
import { recommendClient } from '@algolia/recommend';
14+
15+
import type { InitClientOptions, InitClientRegion } from './models';
16+
17+
export * from './models';
18+
19+
export type Algoliasearch = SearchClient & {
20+
initRecommend: (initOptions?: InitClientOptions) => RecommendClient;
21+
initAnalytics: (initOptions?: InitClientOptions & InitClientRegion<AnalyticsRegion>) => AnalyticsClient;
22+
initAbtesting: (initOptions?: InitClientOptions & InitClientRegion<AbtestingRegion>) => AbtestingClient;
23+
initPersonalization: (
24+
initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
25+
) => PersonalizationClient;
26+
};
27+
28+
export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch {
29+
if (!appId || typeof appId !== 'string') {
30+
throw new Error('`appId` is missing.');
31+
}
32+
33+
if (!apiKey || typeof apiKey !== 'string') {
34+
throw new Error('`apiKey` is missing.');
35+
}
36+
37+
const client = searchClient(appId, apiKey, options);
38+
39+
return {
40+
...client,
41+
/**
42+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
43+
*/
44+
get _ua(): string {
45+
return client.transporter.algoliaAgent.value;
46+
},
47+
initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => {
48+
return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
49+
},
50+
51+
initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion> = {}): AnalyticsClient => {
52+
return analyticsClient(
53+
initOptions.appId || appId,
54+
initOptions.apiKey || apiKey,
55+
initOptions.region,
56+
initOptions.options,
57+
);
58+
},
59+
60+
initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion> = {}): AbtestingClient => {
61+
return abtestingClient(
62+
initOptions.appId || appId,
63+
initOptions.apiKey || apiKey,
64+
initOptions.region,
65+
initOptions.options,
66+
);
67+
},
68+
69+
initPersonalization: (
70+
initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
71+
): PersonalizationClient => {
72+
return personalizationClient(
73+
initOptions.appId || appId,
74+
initOptions.apiKey || apiKey,
75+
initOptions.region,
76+
initOptions.options,
77+
);
78+
},
79+
};
80+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import type { InitClientOptions, InitClientRegion } from './models';
1717
export * from './models';
1818

1919
export type Algoliasearch = SearchClient & {
20-
initRecommend: (initOptions: InitClientOptions) => RecommendClient;
21-
initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion>) => AnalyticsClient;
22-
initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion>) => AbtestingClient;
20+
initRecommend: (initOptions?: InitClientOptions) => RecommendClient;
21+
initAnalytics: (initOptions?: InitClientOptions & InitClientRegion<AnalyticsRegion>) => AnalyticsClient;
22+
initAbtesting: (initOptions?: InitClientOptions & InitClientRegion<AbtestingRegion>) => AbtestingClient;
2323
initPersonalization: (
2424
initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
2525
) => PersonalizationClient;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
"module": "./dist/node.js",
2828
"require": "./dist/node.cjs"
2929
},
30+
"worker": {
31+
"types": "./dist/fetch.d.ts",
32+
"default": "./dist/fetch.js"
33+
},
3034
"default": {
3135
"types": "./dist/browser.d.ts",
3236
"module": "./dist/browser.js",
@@ -72,6 +76,7 @@
7276
"@algolia/client-search": "5.3.2",
7377
"@algolia/recommend": "5.3.2",
7478
"@algolia/requester-browser-xhr": "5.3.2",
79+
"@algolia/requester-fetch": "5.3.2",
7580
"@algolia/requester-node-http": "5.3.2"
7681
},
7782
"devDependencies": {
@@ -81,6 +86,7 @@
8186
"@types/jest": "29.5.12",
8287
"@types/node": "22.5.1",
8388
"jest": "29.7.0",
89+
"jest-environment-miniflare": "2.14.3",
8490
"publint": "0.2.10",
8591
"rollup": "4.21.2",
8692
"tsup": "8.2.4",

clients/algoliasearch-client-javascript/packages/algoliasearch/tsup.config.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,49 @@ const nodeOptions: Options = {
99
...getBaseNodeOptions(pkg, __dirname),
1010
dts: { entry: { node: 'lite/builds/node.ts' } },
1111
entry: ['lite/builds/node.ts', 'lite/src/*.ts'],
12-
1312
outDir: 'dist/lite',
1413
};
1514

1615
const nodeConfigs: Options[] = [
1716
{
1817
...nodeOptions,
1918
format: 'cjs',
20-
name: 'node lite cjs',
19+
name: `node ${pkg.name} cjs`,
2120
},
2221
{
2322
...nodeOptions,
2423
format: 'esm',
25-
name: 'node lite esm',
24+
name: `node ${pkg.name} esm`,
2625
},
2726
{
2827
...nodeOptions,
2928
format: 'cjs',
30-
name: 'node cjs',
29+
name: 'node algoliasearch cjs',
3130
dts: { entry: { node: 'builds/node.ts' } },
3231
entry: ['builds/node.ts'],
3332
outDir: 'dist',
3433
},
3534
{
3635
...nodeOptions,
3736
format: 'esm',
38-
name: 'node esm',
37+
name: 'node algoliasearch esm',
3938
dts: { entry: { node: 'builds/node.ts' } },
4039
entry: ['builds/node.ts'],
4140
outDir: 'dist',
4241
},
42+
{
43+
...nodeOptions,
44+
format: 'esm',
45+
name: 'fetch algoliasearch esm',
46+
dts: { entry: { fetch: 'builds/fetch.ts' } },
47+
entry: ['builds/fetch.ts'],
48+
outDir: 'dist',
49+
external: getDependencies(pkg, 'fetch'),
50+
},
4351
];
4452

4553
const browserOptions: Options = {
4654
...getBaseBrowserOptions(pkg, __dirname),
47-
4855
globalName: 'lite',
4956
outDir: 'dist/lite',
5057
};
@@ -53,7 +60,7 @@ const browserConfigs: Options[] = [
5360
{
5461
...browserOptions,
5562
minify: false,
56-
name: 'browser esm',
63+
name: `browser ${pkg.name} esm`,
5764
dts: { entry: { browser: 'lite/builds/browser.ts' } },
5865
entry: ['lite/builds/browser.ts', 'lite/src/*.ts'],
5966
external: ['dom', '@algolia/client-common', '@algolia/requester-browser-xhr'],
@@ -62,7 +69,7 @@ const browserConfigs: Options[] = [
6269
...browserOptions,
6370
dts: false,
6471
minify: true,
65-
name: 'browser min esm',
72+
name: `browser ${pkg.name} min esm`,
6673
entry: { 'builds/browser.min': 'lite/builds/browser.ts' },
6774
external: [],
6875
noExternal: ['dom', '@algolia/client-common', '@algolia/requester-browser-xhr'],
@@ -85,7 +92,7 @@ const browserConfigs: Options[] = [
8592
entry: { 'browser.min': 'builds/browser.ts' },
8693
outDir: 'dist',
8794
external: [],
88-
noExternal: getDependencies(pkg, 'browser'),
95+
noExternal: getDependencies(pkg, 'xhr'),
8996
},
9097
];
9198

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
2+
3+
import type { ClientOptions } from '@algolia/client-common';
4+
import {
5+
createMemoryCache,
6+
createNullCache,
7+
DEFAULT_CONNECT_TIMEOUT_NODE,
8+
DEFAULT_READ_TIMEOUT_NODE,
9+
DEFAULT_WRITE_TIMEOUT_NODE,
10+
} from '@algolia/client-common';
11+
import { createFetchRequester } from '@algolia/requester-fetch';
12+
13+
import type { Region } from '../src/abtestingClient';
14+
import { createAbtestingClient, REGIONS } from '../src/abtestingClient';
15+
16+
export type AbtestingClient = ReturnType<typeof createAbtestingClient>;
17+
18+
export { apiClientVersion, Region } from '../src/abtestingClient';
19+
export * from '../model';
20+
21+
export function abtestingClient(
22+
appId: string,
23+
apiKey: string,
24+
region?: Region,
25+
options?: ClientOptions,
26+
): AbtestingClient {
27+
if (!appId || typeof appId !== 'string') {
28+
throw new Error('`appId` is missing.');
29+
}
30+
31+
if (!apiKey || typeof apiKey !== 'string') {
32+
throw new Error('`apiKey` is missing.');
33+
}
34+
35+
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
36+
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
37+
}
38+
39+
return {
40+
...createAbtestingClient({
41+
appId,
42+
apiKey,
43+
region,
44+
timeouts: {
45+
connect: DEFAULT_CONNECT_TIMEOUT_NODE,
46+
read: DEFAULT_READ_TIMEOUT_NODE,
47+
write: DEFAULT_WRITE_TIMEOUT_NODE,
48+
},
49+
algoliaAgents: [{ segment: 'Fetch' }],
50+
requester: createFetchRequester(),
51+
responsesCache: createNullCache(),
52+
requestsCache: createNullCache(),
53+
hostsCache: createMemoryCache(),
54+
...options,
55+
}),
56+
};
57+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"module": "./dist/builds/node.js",
2727
"require": "./dist/builds/node.cjs"
2828
},
29+
"worker": {
30+
"types": "./dist/fetch.d.ts",
31+
"default": "./dist/builds/fetch.js"
32+
},
2933
"default": {
3034
"types": "./dist/browser.d.ts",
3135
"module": "./dist/builds/browser.js",
@@ -46,6 +50,7 @@
4650
"dependencies": {
4751
"@algolia/client-common": "5.3.2",
4852
"@algolia/requester-browser-xhr": "5.3.2",
53+
"@algolia/requester-fetch": "5.3.2",
4954
"@algolia/requester-node-http": "5.3.2"
5055
},
5156
"devDependencies": {

clients/algoliasearch-client-javascript/packages/client-abtesting/tsup.config.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ const nodeConfigs: Options[] = [
1515
{
1616
...nodeOptions,
1717
format: 'cjs',
18-
name: 'node cjs',
18+
name: `node ${pkg.name} cjs`,
1919
},
2020
{
2121
...nodeOptions,
2222
format: 'esm',
23-
name: 'node esm',
23+
name: `node ${pkg.name} esm`,
24+
},
25+
{
26+
...nodeOptions,
27+
format: 'esm',
28+
name: `fetch ${pkg.name} esm`,
29+
dts: { entry: { fetch: 'builds/fetch.ts' } },
30+
external: getDependencies(pkg, 'fetch'),
31+
entry: ['builds/fetch.ts', 'src/*.ts'],
2432
},
2533
];
2634

@@ -33,18 +41,18 @@ const browserConfigs: Options[] = [
3341
{
3442
...browserOptions,
3543
minify: false,
36-
name: 'browser esm',
44+
name: `browser ${pkg.name} esm`,
3745
dts: { entry: { browser: 'builds/browser.ts' } },
3846
entry: ['builds/browser.ts', 'src/*.ts'],
3947
},
4048
{
4149
...browserOptions,
4250
dts: false,
4351
minify: true,
44-
name: 'browser min esm',
52+
name: `browser ${pkg.name} min esm`,
4553
entry: { 'builds/browser.min': 'builds/browser.ts' },
4654
external: [],
47-
noExternal: getDependencies(pkg, 'browser'),
55+
noExternal: getDependencies(pkg, 'xhr'),
4856
},
4957
];
5058

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
2+
3+
import type { ClientOptions } from '@algolia/client-common';
4+
import {
5+
createMemoryCache,
6+
createNullCache,
7+
DEFAULT_CONNECT_TIMEOUT_NODE,
8+
DEFAULT_READ_TIMEOUT_NODE,
9+
DEFAULT_WRITE_TIMEOUT_NODE,
10+
} from '@algolia/client-common';
11+
import { createFetchRequester } from '@algolia/requester-fetch';
12+
13+
import type { Region } from '../src/analyticsClient';
14+
import { createAnalyticsClient, REGIONS } from '../src/analyticsClient';
15+
16+
export type AnalyticsClient = ReturnType<typeof createAnalyticsClient>;
17+
18+
export { apiClientVersion, Region } from '../src/analyticsClient';
19+
export * from '../model';
20+
21+
export function analyticsClient(
22+
appId: string,
23+
apiKey: string,
24+
region?: Region,
25+
options?: ClientOptions,
26+
): AnalyticsClient {
27+
if (!appId || typeof appId !== 'string') {
28+
throw new Error('`appId` is missing.');
29+
}
30+
31+
if (!apiKey || typeof apiKey !== 'string') {
32+
throw new Error('`apiKey` is missing.');
33+
}
34+
35+
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
36+
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
37+
}
38+
39+
return {
40+
...createAnalyticsClient({
41+
appId,
42+
apiKey,
43+
region,
44+
timeouts: {
45+
connect: DEFAULT_CONNECT_TIMEOUT_NODE,
46+
read: DEFAULT_READ_TIMEOUT_NODE,
47+
write: DEFAULT_WRITE_TIMEOUT_NODE,
48+
},
49+
algoliaAgents: [{ segment: 'Fetch' }],
50+
requester: createFetchRequester(),
51+
responsesCache: createNullCache(),
52+
requestsCache: createNullCache(),
53+
hostsCache: createMemoryCache(),
54+
...options,
55+
}),
56+
};
57+
}

0 commit comments

Comments
 (0)