Skip to content

Commit 4ffa629

Browse files
algolia-botshortcutsTorbjornHoltmon
committed
feat(javascript): add worker build (#4249) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]> Co-authored-by: Torbjørn Holtmon <[email protected]>
1 parent d6f48a4 commit 4ffa629

File tree

45 files changed

+862
-41
lines changed

Some content is hidden

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

45 files changed

+862
-41
lines changed

clients/algoliasearch-client-javascript/packages/algoliasearch/__tests__/algoliasearch.worker.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ test('sets the ua', () => {
99
const client = algoliasearch('APP_ID', 'API_KEY');
1010
expect(client.transporter.algoliaAgent).toEqual({
1111
add: expect.any(Function),
12-
value: expect.stringContaining(`Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion}); Worker`),
12+
value: expect.stringContaining(
13+
`Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion}); Worker`,
14+
),
1315
});
1416
});
1517

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
5+
import type { AbtestingClient } from '@algolia/client-abtesting';
6+
import { abtestingClient } from '@algolia/client-abtesting';
7+
import type { AnalyticsClient } from '@algolia/client-analytics';
8+
import { analyticsClient } from '@algolia/client-analytics';
9+
import type { InsightsClient } from '@algolia/client-insights';
10+
import { insightsClient } from '@algolia/client-insights';
11+
import type { PersonalizationClient } from '@algolia/client-personalization';
12+
import { personalizationClient } from '@algolia/client-personalization';
13+
import type { QuerySuggestionsClient } from '@algolia/client-query-suggestions';
14+
import { querySuggestionsClient } from '@algolia/client-query-suggestions';
15+
import type { SearchClient } from '@algolia/client-search';
16+
import { searchClient } from '@algolia/client-search';
17+
import type { IngestionClient } from '@algolia/ingestion';
18+
import { ingestionClient } from '@algolia/ingestion';
19+
import type { MonitoringClient } from '@algolia/monitoring';
20+
import { monitoringClient } from '@algolia/monitoring';
21+
import type { RecommendClient } from '@algolia/recommend';
22+
import { recommendClient } from '@algolia/recommend';
23+
24+
import type {
25+
AbtestingRegionOptions,
26+
AnalyticsRegionOptions,
27+
IngestionRegionOptions,
28+
InitClientOptions,
29+
InsightsRegionOptions,
30+
PersonalizationRegionOptions,
31+
QuerySuggestionsRegionOptions,
32+
} from './models';
33+
34+
export * from './models';
35+
36+
export type Algoliasearch = SearchClient & {
37+
initAbtesting: (initOptions: InitClientOptions & AbtestingRegionOptions) => AbtestingClient;
38+
initAnalytics: (initOptions: InitClientOptions & AnalyticsRegionOptions) => AnalyticsClient;
39+
initIngestion: (initOptions: InitClientOptions & IngestionRegionOptions) => IngestionClient;
40+
initInsights: (initOptions: InitClientOptions & InsightsRegionOptions) => InsightsClient;
41+
initMonitoring: (initOptions?: InitClientOptions) => MonitoringClient;
42+
initPersonalization: (initOptions: InitClientOptions & PersonalizationRegionOptions) => PersonalizationClient;
43+
initQuerySuggestions: (initOptions: InitClientOptions & QuerySuggestionsRegionOptions) => QuerySuggestionsClient;
44+
initRecommend: (initOptions?: InitClientOptions) => RecommendClient;
45+
};
46+
47+
export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch {
48+
if (!appId || typeof appId !== 'string') {
49+
throw new Error('`appId` is missing.');
50+
}
51+
52+
if (!apiKey || typeof apiKey !== 'string') {
53+
throw new Error('`apiKey` is missing.');
54+
}
55+
56+
const client = searchClient(appId, apiKey, options);
57+
58+
return {
59+
...client,
60+
61+
/**
62+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
63+
*/
64+
get _ua(): string {
65+
return client.transporter.algoliaAgent.value;
66+
},
67+
68+
initAbtesting: (initOptions: InitClientOptions & AbtestingRegionOptions): AbtestingClient => {
69+
return abtestingClient(
70+
initOptions.appId || appId,
71+
initOptions.apiKey || apiKey,
72+
initOptions.region,
73+
initOptions.options,
74+
);
75+
},
76+
77+
initAnalytics: (initOptions: InitClientOptions & AnalyticsRegionOptions): AnalyticsClient => {
78+
return analyticsClient(
79+
initOptions.appId || appId,
80+
initOptions.apiKey || apiKey,
81+
initOptions.region,
82+
initOptions.options,
83+
);
84+
},
85+
86+
initIngestion: (initOptions: InitClientOptions & IngestionRegionOptions): IngestionClient => {
87+
return ingestionClient(
88+
initOptions.appId || appId,
89+
initOptions.apiKey || apiKey,
90+
initOptions.region,
91+
initOptions.options,
92+
);
93+
},
94+
95+
initInsights: (initOptions: InitClientOptions & InsightsRegionOptions): InsightsClient => {
96+
return insightsClient(
97+
initOptions.appId || appId,
98+
initOptions.apiKey || apiKey,
99+
initOptions.region,
100+
initOptions.options,
101+
);
102+
},
103+
104+
initMonitoring: (initOptions: InitClientOptions = {}): MonitoringClient => {
105+
return monitoringClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
106+
},
107+
108+
initPersonalization: (initOptions: InitClientOptions & PersonalizationRegionOptions): PersonalizationClient => {
109+
return personalizationClient(
110+
initOptions.appId || appId,
111+
initOptions.apiKey || apiKey,
112+
initOptions.region,
113+
initOptions.options,
114+
);
115+
},
116+
117+
initQuerySuggestions: (initOptions: InitClientOptions & QuerySuggestionsRegionOptions): QuerySuggestionsClient => {
118+
return querySuggestionsClient(
119+
initOptions.appId || appId,
120+
initOptions.apiKey || apiKey,
121+
initOptions.region,
122+
initOptions.options,
123+
);
124+
},
125+
126+
initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => {
127+
return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
128+
},
129+
};
130+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"require": "./dist/node.cjs"
3030
},
3131
"worker": {
32-
"types": "./dist/fetch.d.ts",
33-
"default": "./dist/fetch.js"
32+
"types": "./dist/worker.d.ts",
33+
"default": "./dist/worker.js"
3434
},
3535
"default": {
3636
"types": "./dist/browser.d.ts",

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ const nodeConfigs: Options[] = [
4848
outDir: 'dist',
4949
external: getDependencies(pkg, 'fetch'),
5050
},
51+
{
52+
...nodeOptions,
53+
format: 'esm',
54+
name: 'worker algoliasearch esm',
55+
dts: { entry: { worker: 'builds/worker.ts' } },
56+
entry: ['builds/worker.ts'],
57+
outDir: 'dist',
58+
external: getDependencies(pkg, 'worker'),
59+
},
5160
];
5261

5362
const browserOptions: Options = {

clients/algoliasearch-client-javascript/packages/client-abtesting/builds/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export function abtestingClient(
4747
write: 30000,
4848
},
4949
logger: createNullLogger(),
50-
algoliaAgents: [{ segment: 'Fetch' }],
5150
requester: createFetchRequester(),
51+
algoliaAgents: [{ segment: 'Fetch' }],
5252
responsesCache: createNullCache(),
5353
requestsCache: createNullCache(),
5454
hostsCache: createMemoryCache(),
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
export type AbtestingClient = ReturnType<typeof createAbtestingClient>;
4+
5+
import { createMemoryCache, createNullCache, createNullLogger } from '@algolia/client-common';
6+
import { createFetchRequester } from '@algolia/requester-fetch';
7+
8+
import type { ClientOptions } from '@algolia/client-common';
9+
10+
import { createAbtestingClient } from '../src/abtestingClient';
11+
12+
import type { Region } from '../src/abtestingClient';
13+
import { REGIONS } from '../src/abtestingClient';
14+
15+
export type { Region, RegionOptions } from '../src/abtestingClient';
16+
17+
export { apiClientVersion } from '../src/abtestingClient';
18+
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: 2000,
46+
read: 5000,
47+
write: 30000,
48+
},
49+
logger: createNullLogger(),
50+
requester: createFetchRequester(),
51+
algoliaAgents: [{ segment: 'Worker' }],
52+
responsesCache: createNullCache(),
53+
requestsCache: createNullCache(),
54+
hostsCache: createMemoryCache(),
55+
...options,
56+
}),
57+
};
58+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"require": "./dist/builds/node.cjs"
2929
},
3030
"worker": {
31-
"types": "./dist/fetch.d.ts",
32-
"default": "./dist/builds/fetch.js"
31+
"types": "./dist/worker.d.ts",
32+
"default": "./dist/builds/worker.js"
3333
},
3434
"default": {
3535
"types": "./dist/browser.d.ts",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ const nodeConfigs: Options[] = [
3030
external: getDependencies(pkg, 'fetch'),
3131
entry: ['builds/fetch.ts', 'src/*.ts'],
3232
},
33+
{
34+
...nodeOptions,
35+
format: 'esm',
36+
name: `worker ${pkg.name} esm`,
37+
dts: { entry: { worker: 'builds/worker.ts' } },
38+
external: getDependencies(pkg, 'worker'),
39+
entry: ['builds/worker.ts', 'src/*.ts'],
40+
},
3341
];
3442

3543
const browserOptions: Options = {

clients/algoliasearch-client-javascript/packages/client-analytics/builds/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export function analyticsClient(
4747
write: 30000,
4848
},
4949
logger: createNullLogger(),
50-
algoliaAgents: [{ segment: 'Fetch' }],
5150
requester: createFetchRequester(),
51+
algoliaAgents: [{ segment: 'Fetch' }],
5252
responsesCache: createNullCache(),
5353
requestsCache: createNullCache(),
5454
hostsCache: createMemoryCache(),
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
export type AnalyticsClient = ReturnType<typeof createAnalyticsClient>;
4+
5+
import { createMemoryCache, createNullCache, createNullLogger } from '@algolia/client-common';
6+
import { createFetchRequester } from '@algolia/requester-fetch';
7+
8+
import type { ClientOptions } from '@algolia/client-common';
9+
10+
import { createAnalyticsClient } from '../src/analyticsClient';
11+
12+
import type { Region } from '../src/analyticsClient';
13+
import { REGIONS } from '../src/analyticsClient';
14+
15+
export type { Region, RegionOptions } from '../src/analyticsClient';
16+
17+
export { apiClientVersion } from '../src/analyticsClient';
18+
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: 2000,
46+
read: 5000,
47+
write: 30000,
48+
},
49+
logger: createNullLogger(),
50+
requester: createFetchRequester(),
51+
algoliaAgents: [{ segment: 'Worker' }],
52+
responsesCache: createNullCache(),
53+
requestsCache: createNullCache(),
54+
hostsCache: createMemoryCache(),
55+
...options,
56+
}),
57+
};
58+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"require": "./dist/builds/node.cjs"
2929
},
3030
"worker": {
31-
"types": "./dist/fetch.d.ts",
32-
"default": "./dist/builds/fetch.js"
31+
"types": "./dist/worker.d.ts",
32+
"default": "./dist/builds/worker.js"
3333
},
3434
"default": {
3535
"types": "./dist/browser.d.ts",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ const nodeConfigs: Options[] = [
3030
external: getDependencies(pkg, 'fetch'),
3131
entry: ['builds/fetch.ts', 'src/*.ts'],
3232
},
33+
{
34+
...nodeOptions,
35+
format: 'esm',
36+
name: `worker ${pkg.name} esm`,
37+
dts: { entry: { worker: 'builds/worker.ts' } },
38+
external: getDependencies(pkg, 'worker'),
39+
entry: ['builds/worker.ts', 'src/*.ts'],
40+
},
3341
];
3442

3543
const browserOptions: Options = {

clients/algoliasearch-client-javascript/packages/client-composition/builds/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export function compositionClient(appId: string, apiKey: string, options?: Clien
3232
write: 30000,
3333
},
3434
logger: createNullLogger(),
35-
algoliaAgents: [{ segment: 'Fetch' }],
3635
requester: createFetchRequester(),
36+
algoliaAgents: [{ segment: 'Fetch' }],
3737
responsesCache: createNullCache(),
3838
requestsCache: createNullCache(),
3939
hostsCache: createMemoryCache(),

0 commit comments

Comments
 (0)