@@ -21,11 +21,15 @@ export function createIngestionClient(
21
21
options : SearchClientOptions & ClientTransporterOptions & TransformationOptions
22
22
) : IngestionClient {
23
23
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
+ ) ;
25
27
}
26
28
27
29
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
+ ) ;
29
33
}
30
34
31
35
const appId = options . appId ;
@@ -66,29 +70,37 @@ export function createIngestionClient(
66
70
transporter . responsesCache . clear ( ) ,
67
71
] ) . then ( ( ) => undefined ) ;
68
72
} ,
69
- async push (
73
+ push (
70
74
{ indexName, pushTaskPayload, watch } : PushProps ,
71
75
requestOptions ?: RequestOptions
72
- ) : Promise < WatchResponse > {
76
+ ) : Readonly < Promise < WatchResponse > > {
73
77
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
+ ) ;
75
81
}
76
82
77
83
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
+ ) ;
79
87
}
80
88
81
89
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
+ ) ;
83
93
}
84
94
85
95
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
+ ) ;
87
99
}
88
100
89
101
const opts : RequestOptions = requestOptions || { queryParameters : { } } ;
90
102
91
- return await transporter . write < WatchResponse > (
103
+ return transporter . write < WatchResponse > (
92
104
{
93
105
method : MethodEnum . Post ,
94
106
path : encode ( '1/push/%s' , indexName ) ,
@@ -107,12 +119,12 @@ export function createIngestionClient(
107
119
}
108
120
109
121
export function saveObjectsWithTransformation ( indexName : string , client ?: IngestionClient ) {
110
- return async (
122
+ return (
111
123
objects : ReadonlyArray < Readonly < Record < string , any > > > ,
112
124
requestOptions ?: RequestOptions & ChunkOptions & SaveObjectsOptions & PushOptions
113
- ) : Promise < WatchResponse > => {
125
+ ) : Readonly < Promise < WatchResponse > > => {
114
126
if ( ! client ) {
115
- throw new Error (
127
+ throw transformationConfigurationError (
116
128
'`options.transformation.region` must be provided at client instantiation before calling this method.'
117
129
) ;
118
130
}
@@ -124,7 +136,7 @@ export function saveObjectsWithTransformation(indexName: string, client?: Ingest
124
136
: BatchActionEnum . UpdateObject ;
125
137
126
138
/* eslint functional/immutable-data: "off" */
127
- return await client . push (
139
+ return client . push (
128
140
{
129
141
indexName,
130
142
pushTaskPayload : { action, records : objects } ,
@@ -139,12 +151,12 @@ export function partialUpdateObjectsWithTransformation(
139
151
indexName : string ,
140
152
client ?: IngestionClient
141
153
) {
142
- return async (
154
+ return (
143
155
objects : ReadonlyArray < Readonly < Record < string , any > > > ,
144
156
requestOptions ?: RequestOptions & ChunkOptions & PartialUpdateObjectsOptions & PushOptions
145
- ) : Promise < WatchResponse > => {
157
+ ) : Readonly < Promise < WatchResponse > > => {
146
158
if ( ! client ) {
147
- throw new Error (
159
+ throw transformationConfigurationError (
148
160
'`options.transformation.region` must be provided at client instantiation before calling this method.'
149
161
) ;
150
162
}
@@ -156,7 +168,7 @@ export function partialUpdateObjectsWithTransformation(
156
168
: BatchActionEnum . PartialUpdateObjectNoCreate ;
157
169
158
170
/* eslint functional/immutable-data: "off" */
159
- return await client . push (
171
+ return client . push (
160
172
{
161
173
indexName,
162
174
pushTaskPayload : { action, records : objects } ,
@@ -166,3 +178,10 @@ export function partialUpdateObjectsWithTransformation(
166
178
) ;
167
179
} ;
168
180
}
181
+
182
+ export function transformationConfigurationError ( message : string ) : Error {
183
+ return {
184
+ name : 'TransformationConfigurationError' ,
185
+ message,
186
+ } ;
187
+ }
0 commit comments