@@ -205,12 +205,24 @@ import { Destroyable } from '@algolia/requester-common';
205205import { createNodeHttpRequester } from '@algolia/requester-node-http' ;
206206import { createUserAgent , Request , RequestOptions } from '@algolia/transporter' ;
207207
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' ;
209221
210222export default function algoliasearch (
211223 appId : string ,
212224 apiKey : string ,
213- options ?: AlgoliaSearchOptions
225+ options ?: AlgoliaSearchOptions & TransformationOptions
214226) : SearchClient {
215227 const commonOptions = {
216228 appId,
@@ -244,6 +256,17 @@ export default function algoliasearch(
244256 } ) ;
245257 } ;
246258
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+
247270 return createSearchClient ( {
248271 ...searchClientOptions ,
249272 methods : {
@@ -288,50 +311,60 @@ export default function algoliasearch(
288311 setDictionarySettings,
289312 waitAppTask,
290313 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+ } ;
335368 } ,
336369 initAnalytics : ( ) => ( clientOptions ?: InitAnalyticsOptions ) : AnalyticsClient => {
337370 return createAnalyticsClient ( {
@@ -549,7 +582,7 @@ export type SearchIndex = BaseSearchIndex & {
549582} ;
550583
551584export type SearchClient = BaseSearchClient & {
552- readonly initIndex : ( indexName : string ) => SearchIndex ;
585+ readonly initIndex : ( indexName : string ) => SearchIndex & IngestionMethods ;
553586 readonly search : < TObject > (
554587 queries : readonly MultipleQueriesQuery [ ] ,
555588 requestOptions ?: RequestOptions & MultipleQueriesOptions
0 commit comments