@sprucelabs/mercury-chunking-emitter 2.0.3 → 2.2.0
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/chunkingEmitter/ChunkingEmitter.d.ts +1 -0
- package/build/chunkingEmitter/MockChunkingEmitter.d.ts +2 -0
- package/build/chunkingEmitter/MockChunkingEmitter.js +6 -1
- package/build/chunkingEmitter/SingleChunkEmitter.d.ts +2 -0
- package/build/chunkingEmitter/SingleChunkEmitter.js +4 -6
- package/build/esm/chunkingEmitter/ChunkingEmitter.d.ts +1 -0
- package/build/esm/chunkingEmitter/MockChunkingEmitter.d.ts +2 -0
- package/build/esm/chunkingEmitter/MockChunkingEmitter.js +6 -1
- package/build/esm/chunkingEmitter/SingleChunkEmitter.d.ts +2 -0
- package/build/esm/chunkingEmitter/SingleChunkEmitter.js +4 -6
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ export type ChunkingEmitterEmitOptions = {
|
|
|
23
23
|
items?: Record<string, any>[];
|
|
24
24
|
batchCursor?: BatchCursor<Record<string, any>>;
|
|
25
25
|
payloadKey: string;
|
|
26
|
+
payload?: Record<string, any>;
|
|
26
27
|
target?: Record<string, any>;
|
|
27
28
|
/** will kill any running operations that match the key */
|
|
28
29
|
uniqueKey?: string;
|
|
@@ -8,12 +8,14 @@ export default class MockChunkingEmitter implements ChunkingEmitter {
|
|
|
8
8
|
static lastInstance?: MockChunkingEmitter;
|
|
9
9
|
private emittedTarget?;
|
|
10
10
|
private emittedCursor?;
|
|
11
|
+
private emittedPayload?;
|
|
11
12
|
constructor();
|
|
12
13
|
static getLastInstance(): MockChunkingEmitter;
|
|
13
14
|
static reset(): void;
|
|
14
15
|
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
15
16
|
assertDidEmitTarget(target: Record<string, any>): void;
|
|
16
17
|
assertDidEmitPayloadKey(payloadKey: string): void;
|
|
18
|
+
assertEmittedPayloadIncludes(payload: Record<string, any>): void;
|
|
17
19
|
assertDidReceiveCursor(): void;
|
|
18
20
|
getTotalErrors(): number;
|
|
19
21
|
assertEmittedItems(items: Record<string, any>[]): void;
|
|
@@ -16,13 +16,14 @@ class MockChunkingEmitter {
|
|
|
16
16
|
this.lastInstance = undefined;
|
|
17
17
|
}
|
|
18
18
|
async emit(options) {
|
|
19
|
-
const { eventName, items, payloadKey, target, batchCursor: cursor, } = options;
|
|
19
|
+
const { eventName, items, payloadKey, target, batchCursor: cursor, payload, } = options;
|
|
20
20
|
this.didEmit = true;
|
|
21
21
|
this.emittedEventName = eventName;
|
|
22
22
|
this.emittedItems = items;
|
|
23
23
|
this.emittedPayloadKey = payloadKey;
|
|
24
24
|
this.emittedTarget = target;
|
|
25
25
|
this.emittedCursor = cursor;
|
|
26
|
+
this.emittedPayload = payload;
|
|
26
27
|
}
|
|
27
28
|
assertDidEmitTarget(target) {
|
|
28
29
|
test_utils_1.assert.isEqualDeep(this.emittedTarget, target, 'You did not chunkingEmitter.emit(...) the expected target!');
|
|
@@ -31,6 +32,10 @@ class MockChunkingEmitter {
|
|
|
31
32
|
this.assertDidEmit();
|
|
32
33
|
test_utils_1.assert.isEqual(this.emittedPayloadKey, payloadKey, `I expected chunkingEmitter.emit() with payloadKey '${payloadKey}'! But you emitted ${this.emittedPayloadKey || 'nothing'}`);
|
|
33
34
|
}
|
|
35
|
+
assertEmittedPayloadIncludes(payload) {
|
|
36
|
+
this.assertDidEmit();
|
|
37
|
+
test_utils_1.assert.doesInclude(this.emittedPayload, payload);
|
|
38
|
+
}
|
|
34
39
|
assertDidReceiveCursor() {
|
|
35
40
|
test_utils_1.assert.isTruthy(this.emittedCursor, 'You did not chunkingEmitter.emit(...) the expected batch cursor!');
|
|
36
41
|
}
|
|
@@ -15,6 +15,7 @@ export default class SingleChunkEmitter {
|
|
|
15
15
|
private log;
|
|
16
16
|
totalErrors: number;
|
|
17
17
|
private isKilled;
|
|
18
|
+
private payload?;
|
|
18
19
|
constructor(options: SingleChunkEmitterOptions);
|
|
19
20
|
matchesKey(key: string): boolean;
|
|
20
21
|
getTotalErrors(): number;
|
|
@@ -27,6 +28,7 @@ interface SingleChunkEmitterOptions {
|
|
|
27
28
|
batchCursor?: BatchCursor<Record<string, any>>;
|
|
28
29
|
items?: Record<string, any>[];
|
|
29
30
|
payloadKey: string;
|
|
31
|
+
payload?: Record<string, any>;
|
|
30
32
|
target?: Record<string, any>;
|
|
31
33
|
eventName: EventName;
|
|
32
34
|
chunkSize: number;
|
|
@@ -12,7 +12,7 @@ class SingleChunkEmitter {
|
|
|
12
12
|
constructor(options) {
|
|
13
13
|
this.totalErrors = 0;
|
|
14
14
|
this.isKilled = false;
|
|
15
|
-
const { batchCursor: cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, } = options;
|
|
15
|
+
const { batchCursor: cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, payload, } = options;
|
|
16
16
|
this.cursor = cursor;
|
|
17
17
|
this.uniqueKey = uniqueKey;
|
|
18
18
|
this.items = items;
|
|
@@ -21,6 +21,7 @@ class SingleChunkEmitter {
|
|
|
21
21
|
this.eventName = eventName;
|
|
22
22
|
this.chunkSize = chunkSize;
|
|
23
23
|
this.client = client;
|
|
24
|
+
this.payload = payload;
|
|
24
25
|
this.log = log.buildLog('Emitter');
|
|
25
26
|
}
|
|
26
27
|
matchesKey(key) {
|
|
@@ -70,13 +71,10 @@ class SingleChunkEmitter {
|
|
|
70
71
|
async emitChunk(options) {
|
|
71
72
|
const { chunk, current } = options;
|
|
72
73
|
let targetAndPayload = {
|
|
73
|
-
payload: {
|
|
74
|
-
[this.payloadKey]: chunk,
|
|
75
|
-
chunk: {
|
|
74
|
+
payload: Object.assign(Object.assign({ [this.payloadKey]: chunk }, this.payload), { chunk: {
|
|
76
75
|
current,
|
|
77
76
|
total: this.total,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
77
|
+
} }),
|
|
80
78
|
};
|
|
81
79
|
if (this.target) {
|
|
82
80
|
targetAndPayload.target = this.target;
|
|
@@ -23,6 +23,7 @@ export type ChunkingEmitterEmitOptions = {
|
|
|
23
23
|
items?: Record<string, any>[];
|
|
24
24
|
batchCursor?: BatchCursor<Record<string, any>>;
|
|
25
25
|
payloadKey: string;
|
|
26
|
+
payload?: Record<string, any>;
|
|
26
27
|
target?: Record<string, any>;
|
|
27
28
|
/** will kill any running operations that match the key */
|
|
28
29
|
uniqueKey?: string;
|
|
@@ -8,12 +8,14 @@ export default class MockChunkingEmitter implements ChunkingEmitter {
|
|
|
8
8
|
static lastInstance?: MockChunkingEmitter;
|
|
9
9
|
private emittedTarget?;
|
|
10
10
|
private emittedCursor?;
|
|
11
|
+
private emittedPayload?;
|
|
11
12
|
constructor();
|
|
12
13
|
static getLastInstance(): MockChunkingEmitter;
|
|
13
14
|
static reset(): void;
|
|
14
15
|
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
15
16
|
assertDidEmitTarget(target: Record<string, any>): void;
|
|
16
17
|
assertDidEmitPayloadKey(payloadKey: string): void;
|
|
18
|
+
assertEmittedPayloadIncludes(payload: Record<string, any>): void;
|
|
17
19
|
assertDidReceiveCursor(): void;
|
|
18
20
|
getTotalErrors(): number;
|
|
19
21
|
assertEmittedItems(items: Record<string, any>[]): void;
|
|
@@ -24,13 +24,14 @@ export default class MockChunkingEmitter {
|
|
|
24
24
|
}
|
|
25
25
|
emit(options) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const { eventName, items, payloadKey, target, batchCursor: cursor, } = options;
|
|
27
|
+
const { eventName, items, payloadKey, target, batchCursor: cursor, payload, } = options;
|
|
28
28
|
this.didEmit = true;
|
|
29
29
|
this.emittedEventName = eventName;
|
|
30
30
|
this.emittedItems = items;
|
|
31
31
|
this.emittedPayloadKey = payloadKey;
|
|
32
32
|
this.emittedTarget = target;
|
|
33
33
|
this.emittedCursor = cursor;
|
|
34
|
+
this.emittedPayload = payload;
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
assertDidEmitTarget(target) {
|
|
@@ -40,6 +41,10 @@ export default class MockChunkingEmitter {
|
|
|
40
41
|
this.assertDidEmit();
|
|
41
42
|
assert.isEqual(this.emittedPayloadKey, payloadKey, `I expected chunkingEmitter.emit() with payloadKey '${payloadKey}'! But you emitted ${this.emittedPayloadKey || 'nothing'}`);
|
|
42
43
|
}
|
|
44
|
+
assertEmittedPayloadIncludes(payload) {
|
|
45
|
+
this.assertDidEmit();
|
|
46
|
+
assert.doesInclude(this.emittedPayload, payload);
|
|
47
|
+
}
|
|
43
48
|
assertDidReceiveCursor() {
|
|
44
49
|
assert.isTruthy(this.emittedCursor, 'You did not chunkingEmitter.emit(...) the expected batch cursor!');
|
|
45
50
|
}
|
|
@@ -15,6 +15,7 @@ export default class SingleChunkEmitter {
|
|
|
15
15
|
private log;
|
|
16
16
|
totalErrors: number;
|
|
17
17
|
private isKilled;
|
|
18
|
+
private payload?;
|
|
18
19
|
constructor(options: SingleChunkEmitterOptions);
|
|
19
20
|
matchesKey(key: string): boolean;
|
|
20
21
|
getTotalErrors(): number;
|
|
@@ -27,6 +28,7 @@ interface SingleChunkEmitterOptions {
|
|
|
27
28
|
batchCursor?: BatchCursor<Record<string, any>>;
|
|
28
29
|
items?: Record<string, any>[];
|
|
29
30
|
payloadKey: string;
|
|
31
|
+
payload?: Record<string, any>;
|
|
30
32
|
target?: Record<string, any>;
|
|
31
33
|
eventName: EventName;
|
|
32
34
|
chunkSize: number;
|
|
@@ -19,7 +19,7 @@ export default class SingleChunkEmitter {
|
|
|
19
19
|
constructor(options) {
|
|
20
20
|
this.totalErrors = 0;
|
|
21
21
|
this.isKilled = false;
|
|
22
|
-
const { batchCursor: cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, } = options;
|
|
22
|
+
const { batchCursor: cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, payload, } = options;
|
|
23
23
|
this.cursor = cursor;
|
|
24
24
|
this.uniqueKey = uniqueKey;
|
|
25
25
|
this.items = items;
|
|
@@ -28,6 +28,7 @@ export default class SingleChunkEmitter {
|
|
|
28
28
|
this.eventName = eventName;
|
|
29
29
|
this.chunkSize = chunkSize;
|
|
30
30
|
this.client = client;
|
|
31
|
+
this.payload = payload;
|
|
31
32
|
this.log = log.buildLog('Emitter');
|
|
32
33
|
}
|
|
33
34
|
matchesKey(key) {
|
|
@@ -82,13 +83,10 @@ export default class SingleChunkEmitter {
|
|
|
82
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
84
|
const { chunk, current } = options;
|
|
84
85
|
let targetAndPayload = {
|
|
85
|
-
payload: {
|
|
86
|
-
[this.payloadKey]: chunk,
|
|
87
|
-
chunk: {
|
|
86
|
+
payload: Object.assign(Object.assign({ [this.payloadKey]: chunk }, this.payload), { chunk: {
|
|
88
87
|
current,
|
|
89
88
|
total: this.total,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
89
|
+
} }),
|
|
92
90
|
};
|
|
93
91
|
if (this.target) {
|
|
94
92
|
targetAndPayload.target = this.target;
|