Skip to content

Commit 3621e21

Browse files
authored
chore: ie 11 support (#1591)
* chore: ie 11 support * chore: unit * chore: trigger
1 parent 4645992 commit 3621e21

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

packages/algoliasearch/src/__tests__/default.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,22 @@ describe('default preset', () => {
191191
expect(() =>
192192
// @ts-ignore
193193
algoliasearch('APP_ID', 'API_KEY', { transformation: { region: 'cn' } })
194-
).toThrow('`region` is required and must be one of the following: eu, us}`');
194+
).toThrow('`region` is required and must be one of the following: eu, us');
195195
});
196196

197-
test('throws when calling the transformation methods without init parameters', async () => {
198-
await expect(
197+
test('throws when calling the transformation methods without init parameters', () => {
198+
expect(() =>
199199
index.saveObjectsWithTransformation([{ objectID: 'bar', baz: 42 }], { waitForTasks: true })
200-
).rejects.toThrow(
201-
'`transformation.region` must be provided at client instantiation before calling this method.'
200+
).toThrow(
201+
'`options.transformation.region` must be provided at client instantiation before calling this method.'
202202
);
203203

204-
await expect(
204+
expect(() =>
205205
index.partialUpdateObjectsWithTransformation([{ objectID: 'bar', baz: 42 }], {
206206
waitForTasks: true,
207207
})
208-
).rejects.toThrow(
209-
'`transformation.region` must be provided at client instantiation before calling this method.'
208+
).toThrow(
209+
'`options.transformation.region` must be provided at client instantiation before calling this method.'
210210
);
211211
});
212212

packages/algoliasearch/src/builds/browser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ import {
207207
createIngestionClient,
208208
partialUpdateObjectsWithTransformation,
209209
saveObjectsWithTransformation,
210+
transformationConfigurationError,
210211
} from '../ingestion';
211212
import {
212213
AlgoliaSearchOptions,
@@ -261,7 +262,9 @@ export default function algoliasearch(
261262

262263
if (options && options.transformation) {
263264
if (!options.transformation.region) {
264-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
265+
throw transformationConfigurationError(
266+
'`region` must be provided when leveraging the transformation pipeline'
267+
);
265268
}
266269

267270
ingestionTransporter = createIngestionClient({ ...options, ...commonOptions });

packages/algoliasearch/src/builds/node.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ import {
209209
createIngestionClient,
210210
partialUpdateObjectsWithTransformation,
211211
saveObjectsWithTransformation,
212+
transformationConfigurationError,
212213
} from '../ingestion';
213214
import {
214215
AlgoliaSearchOptions,
@@ -261,7 +262,9 @@ export default function algoliasearch(
261262

262263
if (options && options.transformation) {
263264
if (!options.transformation.region) {
264-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
265+
throw transformationConfigurationError(
266+
'`region` must be provided when leveraging the transformation pipeline'
267+
);
265268
}
266269

267270
ingestionTransporter = createIngestionClient({ ...options, ...commonOptions });

packages/algoliasearch/src/ingestion.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

109121
export 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+
}

packages/algoliasearch/src/types/Ingestion.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type IngestionMethods = {
2525
readonly saveObjectsWithTransformation: (
2626
objects: ReadonlyArray<Readonly<Record<string, any>>>,
2727
requestOptions?: RequestOptions & ChunkOptions & SaveObjectsOptions & PushOptions
28-
) => Promise<WatchResponse>;
28+
) => Readonly<Promise<WatchResponse>>;
2929

3030
/**
3131
* Helper: Similar to the `partialUpdateObjects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. The `region` must've been passed to the client instantiation method.
@@ -36,7 +36,7 @@ export type IngestionMethods = {
3636
readonly partialUpdateObjectsWithTransformation: (
3737
objects: ReadonlyArray<Readonly<Record<string, any>>>,
3838
requestOptions?: RequestOptions & ChunkOptions & PartialUpdateObjectsOptions & PushOptions
39-
) => Promise<WatchResponse>;
39+
) => Readonly<Promise<WatchResponse>>;
4040
};
4141

4242
export type WatchResponse = {
@@ -108,5 +108,5 @@ export type IngestionClient = BaseSearchClient & {
108108
readonly push: (
109109
{ indexName, pushTaskPayload, watch }: PushProps,
110110
requestOptions?: RequestOptions
111-
) => Promise<WatchResponse>;
111+
) => Readonly<Promise<WatchResponse>>;
112112
};

0 commit comments

Comments
 (0)