@@ -205,12 +205,24 @@ import { Destroyable } from '@algolia/requester-common';
205
205
import { createNodeHttpRequester } from '@algolia/requester-node-http' ;
206
206
import { createUserAgent , Request , RequestOptions } from '@algolia/transporter' ;
207
207
208
- import { AlgoliaSearchOptions , InitAnalyticsOptions , InitPersonalizationOptions } from '../types' ;
208
+ import {
209
+ createIngestionClient ,
210
+ partialUpdateObjectsWithTransformation ,
211
+ saveObjectsWithTransformation ,
212
+ } from '../ingestion' ;
213
+ import {
214
+ AlgoliaSearchOptions ,
215
+ IngestionClient ,
216
+ IngestionMethods ,
217
+ InitAnalyticsOptions ,
218
+ InitPersonalizationOptions ,
219
+ TransformationOptions ,
220
+ } from '../types' ;
209
221
210
222
export default function algoliasearch (
211
223
appId : string ,
212
224
apiKey : string ,
213
- options ?: AlgoliaSearchOptions
225
+ options ?: AlgoliaSearchOptions & TransformationOptions
214
226
) : SearchClient {
215
227
const commonOptions = {
216
228
appId,
@@ -244,6 +256,17 @@ export default function algoliasearch(
244
256
} ) ;
245
257
} ;
246
258
259
+ /* eslint functional/no-let: "off" */
260
+ let ingestionTransporter : IngestionClient | undefined ;
261
+
262
+ if ( options && options . transformation ) {
263
+ if ( ! options . transformation . region ) {
264
+ throw new Error ( '`region` must be provided when leveraging the transformation pipeline' ) ;
265
+ }
266
+
267
+ ingestionTransporter = createIngestionClient ( { ...options , ...commonOptions } ) ;
268
+ }
269
+
247
270
return createSearchClient ( {
248
271
...searchClientOptions ,
249
272
methods : {
@@ -288,50 +311,60 @@ export default function algoliasearch(
288
311
setDictionarySettings,
289
312
waitAppTask,
290
313
customRequest,
291
- initIndex : base => ( indexName : string ) : SearchIndex => {
292
- return initIndex ( base ) ( indexName , {
293
- methods : {
294
- batch,
295
- delete : deleteIndex ,
296
- findAnswers,
297
- getObject,
298
- getObjects,
299
- saveObject,
300
- saveObjects,
301
- search,
302
- searchForFacetValues,
303
- waitTask,
304
- setSettings,
305
- getSettings,
306
- partialUpdateObject,
307
- partialUpdateObjects,
308
- deleteObject,
309
- deleteObjects,
310
- deleteBy,
311
- clearObjects,
312
- browseObjects,
313
- getObjectPosition,
314
- findObject,
315
- exists,
316
- saveSynonym,
317
- saveSynonyms,
318
- getSynonym,
319
- searchSynonyms,
320
- browseSynonyms,
321
- deleteSynonym,
322
- clearSynonyms,
323
- replaceAllObjects,
324
- replaceAllSynonyms,
325
- searchRules,
326
- getRule,
327
- deleteRule,
328
- saveRule,
329
- saveRules,
330
- replaceAllRules,
331
- browseRules,
332
- clearRules,
333
- } ,
334
- } ) ;
314
+ initIndex : base => ( indexName : string ) : SearchIndex & IngestionMethods => {
315
+ return {
316
+ ...initIndex ( base ) ( indexName , {
317
+ methods : {
318
+ batch,
319
+ delete : deleteIndex ,
320
+ findAnswers,
321
+ getObject,
322
+ getObjects,
323
+ saveObject,
324
+ saveObjects,
325
+ search,
326
+ searchForFacetValues,
327
+ waitTask,
328
+ setSettings,
329
+ getSettings,
330
+ partialUpdateObject,
331
+ partialUpdateObjects,
332
+ deleteObject,
333
+ deleteObjects,
334
+ deleteBy,
335
+ clearObjects,
336
+ browseObjects,
337
+ getObjectPosition,
338
+ findObject,
339
+ exists,
340
+ saveSynonym,
341
+ saveSynonyms,
342
+ getSynonym,
343
+ searchSynonyms,
344
+ browseSynonyms,
345
+ deleteSynonym,
346
+ clearSynonyms,
347
+ replaceAllObjects,
348
+ replaceAllSynonyms,
349
+ searchRules,
350
+ getRule,
351
+ deleteRule,
352
+ saveRule,
353
+ saveRules,
354
+ replaceAllRules,
355
+ browseRules,
356
+ clearRules,
357
+ } ,
358
+ } ) ,
359
+ saveObjectsWithTransformation : saveObjectsWithTransformation (
360
+ indexName ,
361
+ ingestionTransporter
362
+ ) ,
363
+ partialUpdateObjectsWithTransformation : partialUpdateObjectsWithTransformation (
364
+ indexName ,
365
+ ingestionTransporter
366
+ ) ,
367
+ } ;
335
368
} ,
336
369
initAnalytics : ( ) => ( clientOptions ?: InitAnalyticsOptions ) : AnalyticsClient => {
337
370
return createAnalyticsClient ( {
@@ -549,7 +582,7 @@ export type SearchIndex = BaseSearchIndex & {
549
582
} ;
550
583
551
584
export type SearchClient = BaseSearchClient & {
552
- readonly initIndex : ( indexName : string ) => SearchIndex ;
585
+ readonly initIndex : ( indexName : string ) => SearchIndex & IngestionMethods ;
553
586
readonly search : < TObject > (
554
587
queries : readonly MultipleQueriesQuery [ ] ,
555
588
requestOptions ?: RequestOptions & MultipleQueriesOptions
0 commit comments