@rudderstack/integrations-lib 0.2.33 → 0.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/sdks/sfmc/index.d.ts +26 -3
- package/build/sdks/sfmc/index.d.ts.map +1 -1
- package/build/sdks/sfmc/index.js +108 -16
- package/build/sdks/sfmc/type.d.ts +44 -24
- package/build/sdks/sfmc/type.d.ts.map +1 -1
- package/build/sdks/sfmc/type.js +1 -1
- package/build/utils/batch-processing.bench.d.ts +2 -0
- package/build/utils/batch-processing.bench.d.ts.map +1 -0
- package/build/utils/batch-processing.bench.js +96 -0
- package/build/utils/batch-processing.d.ts +75 -83
- package/build/utils/batch-processing.d.ts.map +1 -1
- package/build/utils/batch-processing.js +240 -161
- package/build/utils/benchmark.d.ts +180 -0
- package/build/utils/benchmark.d.ts.map +1 -0
- package/build/utils/benchmark.js +288 -0
- package/package.json +1 -1
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Options for batch processing operations
|
|
3
3
|
*/
|
|
4
|
-
export interface
|
|
4
|
+
export interface BatchProcessingOptions {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Number of items to process in each batch (default: 10)
|
|
7
|
+
* Must be a positive integer.
|
|
7
8
|
*/
|
|
8
9
|
batchSize?: number;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Time threshold in milliseconds (default: 10) before yielding control back to the event loop.
|
|
12
|
+
* Set to 0 to yield after every batch. Must be a non-negative integer.
|
|
11
13
|
*/
|
|
12
14
|
yieldThreshold?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to process items sequentially within each batch. When true (default), each item in a batch
|
|
17
|
+
* will be processed one at a time. When false, all items in a batch will be processed concurrently.
|
|
18
|
+
* Consider the implications of concurrency on your processing logic before setting this to false, e.g. race conditions, rate limits, memory pressure, etc.
|
|
19
|
+
*/
|
|
20
|
+
sequentialProcessing?: boolean;
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
23
|
* Configure global defaults for batch processing operations
|
|
@@ -25,11 +33,14 @@ export interface BatchProcessingDefaults {
|
|
|
25
33
|
* // Set only batch size
|
|
26
34
|
* configureBatchProcessingDefaults({ batchSize: 50 });
|
|
27
35
|
*
|
|
36
|
+
* // Enable concurrent processing within batches
|
|
37
|
+
* configureBatchProcessingDefaults({ sequentialProcessing: false });
|
|
38
|
+
*
|
|
28
39
|
* // Get current configuration
|
|
29
40
|
* const currentConfig = configureBatchProcessingDefaults();
|
|
30
41
|
* ```
|
|
31
42
|
*/
|
|
32
|
-
export declare function configureBatchProcessingDefaults(config?:
|
|
43
|
+
export declare function configureBatchProcessingDefaults(config?: BatchProcessingOptions): BatchProcessingOptions;
|
|
33
44
|
/**
|
|
34
45
|
* Maps over an array in batches to avoid blocking the event loop.
|
|
35
46
|
* Processes items in chunks and yields control back to the event loop between batches
|
|
@@ -39,26 +50,20 @@ export declare function configureBatchProcessingDefaults(config?: BatchProcessin
|
|
|
39
50
|
* @template R - The type of items in the result array
|
|
40
51
|
* @param items - The array to map over
|
|
41
52
|
* @param mapFn - The mapping function to apply to each item. Receives the item and its index.
|
|
42
|
-
* @param
|
|
43
|
-
* @param yieldThreshold - Time threshold in milliseconds before yielding control (default: @see defaultYieldThreshold)
|
|
53
|
+
* @param options - Batch processing options
|
|
44
54
|
* @returns A promise that resolves to the mapped array
|
|
45
55
|
* @throws {Error} When batchSize is not a positive integer
|
|
46
56
|
*
|
|
47
57
|
* @example
|
|
48
58
|
* ```typescript
|
|
49
|
-
* // Synchronous mapping
|
|
50
|
-
* const doubled = await mapInBatches([1, 2, 3, 4], (x) => x * 2
|
|
51
|
-
* // Result: [2, 4, 6, 8]
|
|
52
|
-
*
|
|
53
|
-
* // Asynchronous mapping
|
|
54
|
-
* const fetched = await mapInBatches(urls, async (url) => fetch(url), 3);
|
|
59
|
+
* // Synchronous mapping with default options (sequential processing)
|
|
60
|
+
* const doubled = await mapInBatches([1, 2, 3, 4], (x) => x * 2);
|
|
55
61
|
*
|
|
56
|
-
* // With
|
|
57
|
-
* const
|
|
58
|
-
* // Result: ['a-0', 'b-1']
|
|
62
|
+
* // With concurrent processing within batches
|
|
63
|
+
* const doubled = await mapInBatches([1, 2, 3, 4], (x) => x * 2, { sequentialProcessing: false });
|
|
59
64
|
* ```
|
|
60
65
|
*/
|
|
61
|
-
export declare function mapInBatches<T, R>(items: T[], mapFn: (item: T, index: number) => R | Promise<R>,
|
|
66
|
+
export declare function mapInBatches<T, R>(items: T[], mapFn: (item: T, index: number) => R | Promise<R>, options?: BatchProcessingOptions): Promise<R[]>;
|
|
62
67
|
/**
|
|
63
68
|
* Filters an array in batches to avoid blocking the event loop.
|
|
64
69
|
* Processes items in chunks and yields control back to the event loop between batches
|
|
@@ -67,29 +72,21 @@ export declare function mapInBatches<T, R>(items: T[], mapFn: (item: T, index: n
|
|
|
67
72
|
* @template T - The type of items in the array
|
|
68
73
|
* @param items - The array to filter
|
|
69
74
|
* @param predicate - The predicate function to test each item. Receives the item and its index.
|
|
70
|
-
* @param
|
|
71
|
-
* @param yieldThreshold - Time threshold in milliseconds before yielding control (default: @see defaultYieldThreshold)
|
|
75
|
+
* @param options - Batch processing options
|
|
72
76
|
* @returns A promise that resolves to the filtered array
|
|
73
77
|
* @throws {Error} When batchSize is not a positive integer
|
|
74
78
|
*
|
|
75
79
|
* @example
|
|
76
80
|
* ```typescript
|
|
77
|
-
* // Synchronous filtering
|
|
78
|
-
* const evens = await filterInBatches([1, 2, 3, 4, 5], (x) => x % 2 === 0
|
|
81
|
+
* // Synchronous filtering with default options
|
|
82
|
+
* const evens = await filterInBatches([1, 2, 3, 4, 5], (x) => x % 2 === 0);
|
|
79
83
|
* // Result: [2, 4]
|
|
80
84
|
*
|
|
81
|
-
* //
|
|
82
|
-
* const
|
|
83
|
-
* const response = await fetch(url);
|
|
84
|
-
* return response.ok;
|
|
85
|
-
* }, 3);
|
|
86
|
-
*
|
|
87
|
-
* // With index
|
|
88
|
-
* const evenIndices = await filterInBatches(['a', 'b', 'c'], (_, index) => index % 2 === 0);
|
|
89
|
-
* // Result: ['a', 'c']
|
|
85
|
+
* // With custom batch size
|
|
86
|
+
* const evens = await filterInBatches([1, 2, 3, 4, 5], (x) => x % 2 === 0, { batchSize: 2 });
|
|
90
87
|
* ```
|
|
91
88
|
*/
|
|
92
|
-
export declare function filterInBatches<T>(items: T[], predicate: (item: T, index: number) => boolean | Promise<boolean>,
|
|
89
|
+
export declare function filterInBatches<T>(items: T[], predicate: (item: T, index: number) => boolean | Promise<boolean>, options?: BatchProcessingOptions): Promise<T[]>;
|
|
93
90
|
/**
|
|
94
91
|
* Groups an array by a key function in batches to avoid blocking the event loop.
|
|
95
92
|
* Processes items in chunks and yields control back to the event loop between batches
|
|
@@ -99,73 +96,54 @@ export declare function filterInBatches<T>(items: T[], predicate: (item: T, inde
|
|
|
99
96
|
* @template K - The type of the grouping key (must extend PropertyKey)
|
|
100
97
|
* @param items - The array to group
|
|
101
98
|
* @param keyFn - The function to extract the grouping key from each item. Receives the item and its index.
|
|
102
|
-
* @param
|
|
103
|
-
* @param yieldThreshold - Time threshold in milliseconds before yielding control (default: @see defaultYieldThreshold)
|
|
99
|
+
* @param options - Batch processing options
|
|
104
100
|
* @returns A promise that resolves to an object with grouped items
|
|
105
101
|
* @throws {Error} When batchSize is not a positive integer
|
|
106
102
|
*
|
|
107
103
|
* @example
|
|
108
104
|
* ```typescript
|
|
109
|
-
* // Group by property
|
|
105
|
+
* // Group by property with default options
|
|
110
106
|
* const byType = await groupByInBatches(
|
|
111
107
|
* [{type: 'A', value: 1}, {type: 'B', value: 2}, {type: 'A', value: 3}],
|
|
112
|
-
* (item) => item.type
|
|
113
|
-
* 2
|
|
108
|
+
* (item) => item.type
|
|
114
109
|
* );
|
|
115
110
|
* // Result: {A: [{type: 'A', value: 1}, {type: 'A', value: 3}], B: [{type: 'B', value: 2}]}
|
|
116
111
|
*
|
|
117
|
-
* //
|
|
118
|
-
* const
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* return await getCategoryForItem(item);
|
|
124
|
-
* });
|
|
112
|
+
* // With custom batch size
|
|
113
|
+
* const byType = await groupByInBatches(
|
|
114
|
+
* [{type: 'A', value: 1}, {type: 'B', value: 2}, {type: 'A', value: 3}],
|
|
115
|
+
* (item) => item.type,
|
|
116
|
+
* { batchSize: 2 }
|
|
117
|
+
* );
|
|
125
118
|
* ```
|
|
126
119
|
*/
|
|
127
|
-
export declare function groupByInBatches<T, K extends PropertyKey>(items: T[], keyFn: (item: T, index: number) => K | Promise<K>,
|
|
120
|
+
export declare function groupByInBatches<T, K extends PropertyKey>(items: T[], keyFn: (item: T, index: number) => K | Promise<K>, options?: BatchProcessingOptions): Promise<Record<K, T[]>>;
|
|
128
121
|
/**
|
|
129
122
|
* Reduces an array in batches to avoid blocking the event loop.
|
|
130
123
|
* Processes items in chunks and yields control back to the event loop between batches
|
|
131
|
-
* when the processing time exceeds the threshold.
|
|
124
|
+
* when the processing time exceeds the threshold. Sequential processing is always used for the reducer function,
|
|
125
|
+
* irrespective of the `sequentialProcessing` option.
|
|
132
126
|
*
|
|
133
127
|
* @template T - The type of items in the array
|
|
134
128
|
* @template R - The type of the accumulator/result
|
|
135
129
|
* @param items - The array to reduce
|
|
136
130
|
* @param reducer - The reducer function. Receives the accumulator, current item, and index.
|
|
137
131
|
* @param initialValue - The initial value for the accumulator
|
|
138
|
-
* @param
|
|
139
|
-
* @param yieldThreshold - Time threshold in milliseconds before yielding control (default: @see defaultYieldThreshold)
|
|
132
|
+
* @param options - Batch processing options
|
|
140
133
|
* @returns A promise that resolves to the reduced value
|
|
141
134
|
* @throws {Error} When batchSize is not a positive integer
|
|
142
135
|
*
|
|
143
136
|
* @example
|
|
144
137
|
* ```typescript
|
|
145
|
-
* // Sum numbers
|
|
146
|
-
* const sum = await reduceInBatches([1, 2, 3, 4], (acc, x) => acc + x, 0
|
|
138
|
+
* // Sum numbers with default options
|
|
139
|
+
* const sum = await reduceInBatches([1, 2, 3, 4], (acc, x) => acc + x, 0);
|
|
147
140
|
* // Result: 10
|
|
148
141
|
*
|
|
149
|
-
* //
|
|
150
|
-
* const
|
|
151
|
-
* // Result: 'abc'
|
|
152
|
-
*
|
|
153
|
-
* // Build object with index
|
|
154
|
-
* const indexed = await reduceInBatches(
|
|
155
|
-
* ['x', 'y'],
|
|
156
|
-
* (acc, item, index) => ({ ...acc, [index]: item }),
|
|
157
|
-
* {}
|
|
158
|
-
* );
|
|
159
|
-
* // Result: {0: 'x', 1: 'y'}
|
|
160
|
-
*
|
|
161
|
-
* // Asynchronous reducer
|
|
162
|
-
* const processed = await reduceInBatches(urls, async (acc, url) => {
|
|
163
|
-
* const data = await fetch(url).then(r => r.json());
|
|
164
|
-
* return [...acc, data];
|
|
165
|
-
* }, []);
|
|
142
|
+
* // With custom batch size
|
|
143
|
+
* const sum = await reduceInBatches([1, 2, 3, 4], (acc, x) => acc + x, 0, { batchSize: 2 });
|
|
166
144
|
* ```
|
|
167
145
|
*/
|
|
168
|
-
export declare function reduceInBatches<T, R>(items: T[], reducer: (acc: R, item: T, index: number) => R | Promise<R>, initialValue: R,
|
|
146
|
+
export declare function reduceInBatches<T, R>(items: T[], reducer: (acc: R, item: T, index: number) => R | Promise<R>, initialValue: R, options?: BatchProcessingOptions): Promise<R>;
|
|
169
147
|
/**
|
|
170
148
|
* FlatMaps an array in batches to avoid blocking the event loop.
|
|
171
149
|
* Processes items in chunks, flattens the results, and yields control back to the event loop between batches
|
|
@@ -175,31 +153,45 @@ export declare function reduceInBatches<T, R>(items: T[], reducer: (acc: R, item
|
|
|
175
153
|
* @template R - The type of items in the flattened result array
|
|
176
154
|
* @param items - The array to flatMap over
|
|
177
155
|
* @param mapFn - The mapping function that returns an array for each item. Receives the item and its index.
|
|
178
|
-
* @param
|
|
179
|
-
* @param yieldThreshold - Time threshold in milliseconds before yielding control (default: @see defaultYieldThreshold)
|
|
156
|
+
* @param options - Batch processing options
|
|
180
157
|
* @returns A promise that resolves to the flattened mapped array
|
|
181
158
|
* @throws {Error} When batchSize is not a positive integer
|
|
182
159
|
*
|
|
183
160
|
* @example
|
|
184
161
|
* ```typescript
|
|
185
|
-
* // Duplicate each item
|
|
186
|
-
* const duplicated = await flatMapInBatches([1, 2, 3], (x) => [x, x]
|
|
162
|
+
* // Duplicate each item with default options
|
|
163
|
+
* const duplicated = await flatMapInBatches([1, 2, 3], (x) => [x, x]);
|
|
187
164
|
* // Result: [1, 1, 2, 2, 3, 3]
|
|
188
165
|
*
|
|
189
|
-
* //
|
|
190
|
-
* const
|
|
191
|
-
*
|
|
166
|
+
* // With custom batch size
|
|
167
|
+
* const duplicated = await flatMapInBatches([1, 2, 3], (x) => [x, x], { batchSize: 2 });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function flatMapInBatches<T, R>(items: T[], mapFn: (item: T, index: number) => R[] | Promise<R[]>, options?: BatchProcessingOptions): Promise<R[]>;
|
|
171
|
+
/**
|
|
172
|
+
* forEach over an array in batches to avoid blocking the event loop.
|
|
173
|
+
* Processes items in chunks and yields control back to the event loop between batches
|
|
174
|
+
* when the processing time exceeds the threshold.
|
|
192
175
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
176
|
+
* @template T - The type of items in the input array
|
|
177
|
+
* @param items - The array to iterate over
|
|
178
|
+
* @param fn - The function to apply to each item. Receives the item and its index. Can be async.
|
|
179
|
+
* @param options - Batch processing options
|
|
180
|
+
* @returns A promise that resolves when all items have been processed
|
|
181
|
+
* @throws {Error} When batchSize is not a positive integer
|
|
196
182
|
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* // Process items in batches with default options
|
|
186
|
+
* await forEachInBatches([1, 2, 3, 4], async (x) => {
|
|
187
|
+
* await doSomething(x);
|
|
201
188
|
* });
|
|
189
|
+
*
|
|
190
|
+
* // With custom batch size
|
|
191
|
+
* await forEachInBatches([1, 2, 3, 4], async (x) => {
|
|
192
|
+
* await doSomething(x);
|
|
193
|
+
* }, { batchSize: 2 });
|
|
202
194
|
* ```
|
|
203
195
|
*/
|
|
204
|
-
export declare function
|
|
196
|
+
export declare function forEachInBatches<T>(items: T[], fn: (item: T, index: number) => void | Promise<void>, options?: BatchProcessingOptions): Promise<void>;
|
|
205
197
|
//# sourceMappingURL=batch-processing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-processing.d.ts","sourceRoot":"","sources":["../../src/utils/batch-processing.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"batch-processing.d.ts","sourceRoot":"","sources":["../../src/utils/batch-processing.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAOD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gCAAgC,CAC9C,MAAM,CAAC,EAAE,sBAAsB,GAC9B,sBAAsB,CA0BxB;AAoFD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,KAAK,EAAE,CAAC,EAAE,EACV,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACjD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,CAAC,EAAE,CAAC,CAqBd;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAA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