-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathprocessPartialResponse.ts
38 lines (33 loc) · 1.13 KB
/
processPartialResponse.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor';
import { EventType } from './constants';
import type {
BaseRecord,
BatchProcessingOptions,
PartialItemFailureResponse,
} from './types';
/**
* Higher level function to handle batch event processing
* @param event Lambda's original event
* @param recordHandler Callable function to process each record from the batch
* @param processor Batch processor to handle partial failure cases
* @returns Lambda Partial Batch Response
*/
const processPartialResponse = (
event: { Records: BaseRecord[] },
recordHandler: CallableFunction,
processor: BasePartialBatchProcessor,
options?: BatchProcessingOptions
): PartialItemFailureResponse => {
if (!event.Records) {
const eventTypes: string = Object.values(EventType).toString();
throw new Error(
'Failed to convert event to record batch for processing.\nPlease ensure batch event is a valid ' +
eventTypes +
' event.'
);
}
processor.register(event.Records, recordHandler, options);
processor.process();
return processor.response();
};
export { processPartialResponse };