Content-Length: 689449 | pFad | https://redirect.github.com/algolia/api-clients-automation/commit/00271b6ba0

E0 feat(javascript): add transformationOptions and fix ingestion config … · algolia/api-clients-automation@00271b6 · GitHub
Skip to content

Commit 00271b6

Browse files
authored
feat(javascript): add transformationOptions and fix ingestion config leak (#6252)
1 parent f0a3697 commit 00271b6

7 files changed

Lines changed: 76 additions & 29 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ describe('api', () => {
144144
});
145145

146146
describe('bridge methods', () => {
147-
test('throws when missing transformation.region', () => {
147+
test('throws when missing transformationOptions.region', () => {
148148
//@ts-expect-error
149-
expect(() => algoliasearch('APP_ID', 'API_KEY', { transformation: {} })).toThrow(
150-
'`region` must be provided when leveraging the transformation pipeline',
149+
expect(() => algoliasearch('APP_ID', 'API_KEY', { transformationOptions: {} })).toThrow(
150+
'`region` is required in `transformationOptions`.',
151151
);
152152
});
153153

@@ -158,15 +158,15 @@ describe('api', () => {
158158
objects: [{ objectID: 'bar', baz: 42 }],
159159
waitForTasks: true,
160160
}),
161-
).rejects.toThrow('`transformation.region` must be provided at client instantiation before calling this method.');
161+
).rejects.toThrow('`transformationOptions` must be set in the client config before calling this method.');
162162

163163
await expect(
164164
client.partialUpdateObjectsWithTransformation({
165165
indexName: 'foo',
166166
objects: [{ objectID: 'bar', baz: 42 }],
167167
waitForTasks: true,
168168
}),
169-
).rejects.toThrow('`transformation.region` must be provided at client instantiation before calling this method.');
169+
).rejects.toThrow('`transformationOptions` must be set in the client config before calling this method.');
170170
});
171171
});
172172
});

generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
102102
stepOut.put("transformationRegion", step.parameters.get("transformationRegion"));
103103
}
104104

105+
boolean hasTransformationOptions = step.parameters != null && step.parameters.containsKey("transformationOptions");
106+
if (hasTransformationOptions) {
107+
testOut.put("useEchoRequester", false);
108+
Map<String, Object> transformationOptions = (Map<String, Object>) step.parameters.get("transformationOptions");
109+
stepOut.put("transformationRegion", transformationOptions.get("region"));
110+
stepOut.put("hasTransformationRegion", true);
111+
112+
boolean hasTransformationCustomHosts = transformationOptions.containsKey("customHosts");
113+
stepOut.put("hasTransformationCustomHosts", hasTransformationCustomHosts);
114+
if (hasTransformationCustomHosts) {
115+
stepOut.put("transformationCustomHosts", transformationOptions.get("customHosts"));
116+
}
117+
}
118+
stepOut.put("hasTransformationOptions", hasTransformationOptions);
119+
105120
boolean gzipEncoding = step.parameters != null && step.parameters.getOrDefault("gzip", false).equals(true);
106121
stepOut.put("gzipEncoding", gzipEncoding);
107122
} else if (step.type.equals("method")) {

templates/javascript/clients/algoliasearch/builds/definition.mustache

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export type Algoliasearch = SearchClient & {
7979

8080
export type TransformationOptions = {
8181
// When provided, a second transporter will be created in order to leverage the `*WithTransformation` methods exposed by the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
82+
transformationOptions?: {
83+
region: IngestionRegion;
84+
} & ClientOptions;
85+
86+
/** @deprecated Use `transformationOptions` instead. */
8287
transformation?: {
8388
// The region of your Algolia application ID, used to target the correct hosts of the transformation service.
8489
region: IngestionRegion;
@@ -100,26 +105,30 @@ export function algoliasearch(
100105

101106
const client = searchClient(appId, apiKey, options);
102107

103-
let ingestionTransporter: IngestionClient | undefined;
108+
let transformationConfig: { region: IngestionRegion } & ClientOptions | undefined;
104109

105-
if (options?.transformation) {
106-
if (!options.transformation.region) {
107-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
110+
if (options?.transformationOptions) {
111+
transformationConfig = options.transformationOptions;
112+
} else if (options?.transformation) {
113+
transformationConfig = { region: options.transformation.region };
114+
}
115+
116+
let ingestionTransporter: IngestionClient | undefined;
117+
if (transformationConfig) {
118+
if (!transformationConfig.region) {
119+
throw new Error('`region` is required in `transformationOptions`. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/');
108120
}
109121

110-
ingestionTransporter = ingestionClient(appId, apiKey, options.transformation.region, options);
122+
const { region, ...ingestionOptions } = transformationConfig;
123+
ingestionTransporter = ingestionClient(appId, apiKey, region, ingestionOptions);
111124
}
112125

113126
return {
114127
...client,
115128
116129
async saveObjectsWithTransformation({ indexName, objects, waitForTasks }, requestOptions): Promise<Array<WatchResponse>> {
117130
if (!ingestionTransporter) {
118-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
119-
}
120-
121-
if (!options?.transformation?.region) {
122-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
131+
throw new Error('`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/');
123132
}
124133

125134
return ingestionTransporter.chunkedPush({ indexName, objects, action: 'addObject', waitForTasks }, requestOptions);
@@ -130,11 +139,7 @@ export function algoliasearch(
130139
requestOptions,
131140
): Promise<Array<WatchResponse>> {
132141
if (!ingestionTransporter) {
133-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
134-
}
135-
136-
if (!options?.transformation?.region) {
137-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
142+
throw new Error('`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/');
138143
}
139144

140145
return ingestionTransporter.chunkedPush({ indexName, objects, action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate', waitForTasks }, requestOptions);
@@ -145,11 +150,7 @@ export function algoliasearch(
145150
requestOptions?: RequestOptions | undefined,
146151
): Promise<ReplaceAllObjectsWithTransformationResponse> {
147152
if (!ingestionTransporter) {
148-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
149-
}
150-
151-
if (!options?.transformation?.region) {
152-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
153+
throw new Error('`transformationOptions` must be set in the client config before calling this method. It defaults to the Ingestion API defaults. See https://www.algolia.com/doc/libraries/sdk/methods/ingestion/');
153154
}
154155

155156
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;

templates/javascript/tests/client/createClient.mustache

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@
2323
compression: 'gzip',
2424
{{/gzipEncoding}}
2525
{{#hasTransformationRegion}}
26-
transformation: { region : "{{{transformationRegion}}}" },
26+
transformationOptions: {
27+
region : "{{{transformationRegion}}}",
28+
{{#hasTransformationCustomHosts}}
29+
hosts:[
30+
{{#transformationCustomHosts}}
31+
{
32+
url: 'localhost',
33+
port: {{port}},
34+
accept: 'readWrite',
35+
protocol: 'http'
36+
},
37+
{{/transformationCustomHosts}}
38+
],
39+
{{/hasTransformationCustomHosts}}
40+
},
2741
{{/hasTransformationRegion}}
2842
}
2943
{{/isStandaloneClient}}

tests/CTS/client/search/partialUpdateObjectsWithTransformation.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
"port": 6689
1717
}
1818
],
19-
"transformationRegion": "us"
19+
"transformationOptions": {
20+
"region": "us",
21+
"customHosts": [
22+
{ "port": 6688 },
23+
{ "port": 6689 }
24+
]
25+
}
2026
}
2127
},
2228
{

tests/CTS/client/search/replaceAllObjectsWithTransformation.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
"port": 6690
1414
}
1515
],
16-
"transformationRegion": "us"
16+
"transformationOptions": {
17+
"region": "us",
18+
"customHosts": [
19+
{ "port": 6690 }
20+
]
21+
}
1722
}
1823
},
1924
{

tests/CTS/client/search/saveObjectsWithTransformation.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
"port": 6689
1717
}
1818
],
19-
"transformationRegion": "us"
19+
"transformationOptions": {
20+
"region": "us",
21+
"customHosts": [
22+
{ "port": 6688 },
23+
{ "port": 6689 }
24+
]
25+
}
2026
}
2127
},
2228
{

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://redirect.github.com/algolia/api-clients-automation/commit/00271b6ba0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy