forked from aws-powertools/powertools-lambda-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
100 lines (92 loc) · 3.08 KB
/
types.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import type {
Context,
DynamoDBRecord,
KinesisStreamRecord,
SQSRecord,
} from 'aws-lambda';
import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
import type { SqsFifoPartialProcessor } from './SqsFifoPartialProcessor.js';
import type { SqsFifoPartialProcessorAsync } from './SqsFifoPartialProcessorAsync.js';
/**
* Options for batch processing
*
* @template T The type of the batch processor, defaults to BasePartialBatchProcessor
* @property context The context object provided by the AWS Lambda runtime
* @property skipGroupOnError The option to group on error during processing
* @property throwOnFullBatchFailure The option to throw an error if the entire batch fails
* @property processInParallel Indicates whether the records should be processed in parallel
*/
type BatchProcessingOptions<T = BasePartialBatchProcessor> = {
/**
* The context object provided by the AWS Lambda runtime. When provided,
* it's made available to the handler function you specify
*/
context?: Context;
/**
* This option is only available for SqsFifoPartialProcessor & SqsFifoPartialProcessorAsync.
* If true skip the group on error during processing.
*/
skipGroupOnError?: T extends
| SqsFifoPartialProcessor
| SqsFifoPartialProcessorAsync
? boolean
: never;
/**
* Set this to false to prevent throwing an error if the entire batch fails.
*/
throwOnFullBatchFailure?: boolean;
/**
* Indicates whether the records should be processed in parallel.
* When set to `true`, the records will be processed in parallel using `Promise.all`.
* When set to `false`, the records will be processed sequentially.
*/
processInParallel?: T extends
| SqsFifoPartialProcessor
| SqsFifoPartialProcessorAsync
? never
: boolean;
};
/**
* The types of data that can be provided by an event source
*/
type EventSourceDataClassTypes =
| SQSRecord
| KinesisStreamRecord
| DynamoDBRecord;
/**
* Type representing a record from an event source
*/
type BaseRecord = { [key: string]: unknown } | EventSourceDataClassTypes;
/**
* Type representing a successful response
*
* The first element is the string literal 'success',
* the second element is the result of the handler function,
* and the third element is the type of data provided by the event source
*/
type SuccessResponse = ['success', unknown, EventSourceDataClassTypes];
/**
* Type representing a failure response
*
* The first element is the string literal 'fail',
* the second element is the error message,
* and the third element is the type of data provided by the event source
*/
type FailureResponse = ['fail', string, EventSourceDataClassTypes];
/**
* Type representing a partial failure response
*/
type PartialItemFailures = { itemIdentifier: string };
/**
* Type representing a partial failure response
*/
type PartialItemFailureResponse = { batchItemFailures: PartialItemFailures[] };
export type {
BatchProcessingOptions,
BaseRecord,
EventSourceDataClassTypes,
SuccessResponse,
FailureResponse,
PartialItemFailures,
PartialItemFailureResponse,
};