@@ -21,11 +21,15 @@ export function createIngestionClient(
2121 options : SearchClientOptions & ClientTransporterOptions & TransformationOptions
2222) : IngestionClient {
2323 if ( ! options || ! options . transformation || ! options . transformation . region ) {
24- throw new Error ( '`region` must be provided when leveraging the transformation pipeline' ) ;
24+ throw transformationConfigurationError (
25+ '`region` must be provided when leveraging the transformation pipeline'
26+ ) ;
2527 }
2628
2729 if ( options . transformation . region !== 'eu' && options . transformation . region !== 'us' ) {
28- throw new Error ( '`region` is required and must be one of the following: eu, us' ) ;
30+ throw transformationConfigurationError (
31+ '`region` is required and must be one of the following: eu, us'
32+ ) ;
2933 }
3034
3135 const appId = options . appId ;
@@ -66,29 +70,37 @@ export function createIngestionClient(
6670 transporter . responsesCache . clear ( ) ,
6771 ] ) . then ( ( ) => undefined ) ;
6872 } ,
69- async push (
73+ push (
7074 { indexName, pushTaskPayload, watch } : PushProps ,
7175 requestOptions ?: RequestOptions
72- ) : Promise < WatchResponse > {
76+ ) : Readonly < Promise < WatchResponse > > {
7377 if ( ! indexName ) {
74- throw new Error ( 'Parameter `indexName` is required when calling `push`.' ) ;
78+ throw transformationConfigurationError (
79+ 'Parameter `indexName` is required when calling `push`.'
80+ ) ;
7581 }
7682
7783 if ( ! pushTaskPayload ) {
78- throw new Error ( 'Parameter `pushTaskPayload` is required when calling `push`.' ) ;
84+ throw transformationConfigurationError (
85+ 'Parameter `pushTaskPayload` is required when calling `push`.'
86+ ) ;
7987 }
8088
8189 if ( ! pushTaskPayload . action ) {
82- throw new Error ( 'Parameter `pushTaskPayload.action` is required when calling `push`.' ) ;
90+ throw transformationConfigurationError (
91+ 'Parameter `pushTaskPayload.action` is required when calling `push`.'
92+ ) ;
8393 }
8494
8595 if ( ! pushTaskPayload . records ) {
86- throw new Error ( 'Parameter `pushTaskPayload.records` is required when calling `push`.' ) ;
96+ throw transformationConfigurationError (
97+ 'Parameter `pushTaskPayload.records` is required when calling `push`.'
98+ ) ;
8799 }
88100
89101 const opts : RequestOptions = requestOptions || { queryParameters : { } } ;
90102
91- return await transporter . write < WatchResponse > (
103+ return transporter . write < WatchResponse > (
92104 {
93105 method : MethodEnum . Post ,
94106 path : encode ( '1/push/%s' , indexName ) ,
@@ -107,12 +119,12 @@ export function createIngestionClient(
107119}
108120
109121export function saveObjectsWithTransformation ( indexName : string , client ?: IngestionClient ) {
110- return async (
122+ return (
111123 objects : ReadonlyArray < Readonly < Record < string , any > > > ,
112124 requestOptions ?: RequestOptions & ChunkOptions & SaveObjectsOptions & PushOptions
113- ) : Promise < WatchResponse > => {
125+ ) : Readonly < Promise < WatchResponse > > => {
114126 if ( ! client ) {
115- throw new Error (
127+ throw transformationConfigurationError (
116128 '`options.transformation.region` must be provided at client instantiation before calling this method.'
117129 ) ;
118130 }
@@ -124,7 +136,7 @@ export function saveObjectsWithTransformation(indexName: string, client?: Ingest
124136 : BatchActionEnum . UpdateObject ;
125137
126138 /* eslint functional/immutable-data: "off" */
127- return await client . push (
139+ return client . push (
128140 {
129141 indexName,
130142 pushTaskPayload : { action, records : objects } ,
@@ -139,12 +151,12 @@ export function partialUpdateObjectsWithTransformation(
139151 indexName : string ,
140152 client ?: IngestionClient
141153) {
142- return async (
154+ return (
143155 objects : ReadonlyArray < Readonly < Record < string , any > > > ,
144156 requestOptions ?: RequestOptions & ChunkOptions & PartialUpdateObjectsOptions & PushOptions
145- ) : Promise < WatchResponse > => {
157+ ) : Readonly < Promise < WatchResponse > > => {
146158 if ( ! client ) {
147- throw new Error (
159+ throw transformationConfigurationError (
148160 '`options.transformation.region` must be provided at client instantiation before calling this method.'
149161 ) ;
150162 }
@@ -156,7 +168,7 @@ export function partialUpdateObjectsWithTransformation(
156168 : BatchActionEnum . PartialUpdateObjectNoCreate ;
157169
158170 /* eslint functional/immutable-data: "off" */
159- return await client . push (
171+ return client . push (
160172 {
161173 indexName,
162174 pushTaskPayload : { action, records : objects } ,
@@ -166,3 +178,10 @@ export function partialUpdateObjectsWithTransformation(
166178 ) ;
167179 } ;
168180}
181+
182+ export function transformationConfigurationError ( message : string ) : Error {
183+ return {
184+ name : 'TransformationConfigurationError' ,
185+ message,
186+ } ;
187+ }
0 commit comments