@sprucelabs/mercury-chunking-emitter 1.5.3 → 2.0.1
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 +2 -2
- package/build/chunkingEmitter/ChunkingEmitter.js +10 -3
- package/build/chunkingEmitter/MockChunkingEmitter.d.ts +2 -0
- package/build/chunkingEmitter/MockChunkingEmitter.js +5 -1
- package/build/chunkingEmitter/SingleChunkEmitter.d.ts +1 -1
- package/build/chunkingEmitter/SingleChunkEmitter.js +1 -1
- package/build/esm/chunkingEmitter/ChunkingEmitter.d.ts +2 -2
- package/build/esm/chunkingEmitter/ChunkingEmitter.js +10 -3
- package/build/esm/chunkingEmitter/MockChunkingEmitter.d.ts +2 -0
- package/build/esm/chunkingEmitter/MockChunkingEmitter.js +5 -1
- package/build/esm/chunkingEmitter/SingleChunkEmitter.d.ts +1 -1
- package/build/esm/chunkingEmitter/SingleChunkEmitter.js +1 -1
- package/package.json +1 -1
|
@@ -21,10 +21,10 @@ interface ChunkingEmitterOptions {
|
|
|
21
21
|
export type ChunkingEmitterEmitOptions = {
|
|
22
22
|
eventName: EventName;
|
|
23
23
|
items?: Record<string, any>[];
|
|
24
|
-
|
|
24
|
+
batchCursor?: BatchCursor<Record<string, any>>;
|
|
25
25
|
payloadKey: string;
|
|
26
26
|
target?: Record<string, any>;
|
|
27
|
-
/** will
|
|
27
|
+
/** will kill any running operations that match the key */
|
|
28
28
|
uniqueKey?: string;
|
|
29
29
|
};
|
|
30
30
|
export interface ChunkingEmitter {
|
|
@@ -21,13 +21,20 @@ class ChunkingEmitterImpl {
|
|
|
21
21
|
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
|
|
22
22
|
}
|
|
23
23
|
async emit(options) {
|
|
24
|
-
const { items, cursor, uniqueKey: unqiueKey, } = (0, schema_1.assertOptions)(options, ['eventName', 'payloadKey']);
|
|
24
|
+
const { items, batchCursor: cursor, uniqueKey: unqiueKey, } = (0, schema_1.assertOptions)(options, ['eventName', 'payloadKey']);
|
|
25
25
|
this.totalErrors = 0;
|
|
26
26
|
if (!items && !cursor) {
|
|
27
27
|
throw new schema_1.SchemaError({
|
|
28
28
|
code: 'MISSING_PARAMETERS',
|
|
29
|
-
parameters: ['items', '
|
|
30
|
-
friendlyMessage: `You have to pass either 'items' or a '
|
|
29
|
+
parameters: ['items', 'batchCursor'],
|
|
30
|
+
friendlyMessage: `You have to pass either 'items' or a 'batchCursor' to emit.`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else if (items && cursor) {
|
|
34
|
+
throw new schema_1.SchemaError({
|
|
35
|
+
code: 'INVALID_PARAMETERS',
|
|
36
|
+
parameters: ['items', 'batchCursor'],
|
|
37
|
+
friendlyMessage: `You can only pass either 'items' or a 'batchCursor' to emit, not both.`,
|
|
31
38
|
});
|
|
32
39
|
}
|
|
33
40
|
const match = this.emitters.find((e) => unqiueKey && e.matchesKey(unqiueKey));
|
|
@@ -7,12 +7,14 @@ export default class MockChunkingEmitter implements ChunkingEmitter {
|
|
|
7
7
|
private emittedPayloadKey?;
|
|
8
8
|
static lastInstance?: MockChunkingEmitter;
|
|
9
9
|
private emittedTarget?;
|
|
10
|
+
private emittedCursor?;
|
|
10
11
|
constructor();
|
|
11
12
|
static getLastInstance(): MockChunkingEmitter;
|
|
12
13
|
static reset(): void;
|
|
13
14
|
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
14
15
|
assertDidEmitTarget(target: Record<string, any>): void;
|
|
15
16
|
assertDidEmitPayloadKey(payloadKey: string): void;
|
|
17
|
+
assertDidReceiveCursor(): void;
|
|
16
18
|
getTotalErrors(): number;
|
|
17
19
|
assertEmittedItems(items: Record<string, any>[]): void;
|
|
18
20
|
assertDidEmit(): void;
|
|
@@ -16,12 +16,13 @@ class MockChunkingEmitter {
|
|
|
16
16
|
this.lastInstance = undefined;
|
|
17
17
|
}
|
|
18
18
|
async emit(options) {
|
|
19
|
-
const { eventName, items, payloadKey, target } = options;
|
|
19
|
+
const { eventName, items, payloadKey, target, batchCursor: cursor, } = 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
|
+
this.emittedCursor = cursor;
|
|
25
26
|
}
|
|
26
27
|
assertDidEmitTarget(target) {
|
|
27
28
|
test_utils_1.assert.isEqualDeep(this.emittedTarget, target, 'You did not chunkingEmitter.emit(...) the expected target!');
|
|
@@ -30,6 +31,9 @@ class MockChunkingEmitter {
|
|
|
30
31
|
this.assertDidEmit();
|
|
31
32
|
test_utils_1.assert.isEqual(this.emittedPayloadKey, payloadKey, `I expected chunkingEmitter.emit() with payloadKey '${payloadKey}'! But you emitted ${this.emittedPayloadKey || 'nothing'}`);
|
|
32
33
|
}
|
|
34
|
+
assertDidReceiveCursor() {
|
|
35
|
+
test_utils_1.assert.isTruthy(this.emittedCursor, 'You did not chunkingEmitter.emit(...) the expected batch cursor!');
|
|
36
|
+
}
|
|
33
37
|
getTotalErrors() {
|
|
34
38
|
return 0;
|
|
35
39
|
}
|
|
@@ -24,7 +24,7 @@ export default class SingleChunkEmitter {
|
|
|
24
24
|
private Cursor;
|
|
25
25
|
}
|
|
26
26
|
interface SingleChunkEmitterOptions {
|
|
27
|
-
|
|
27
|
+
batchCursor?: BatchCursor<Record<string, any>>;
|
|
28
28
|
items?: Record<string, any>[];
|
|
29
29
|
payloadKey: string;
|
|
30
30
|
target?: Record<string, any>;
|
|
@@ -12,7 +12,7 @@ class SingleChunkEmitter {
|
|
|
12
12
|
constructor(options) {
|
|
13
13
|
this.totalErrors = 0;
|
|
14
14
|
this.isKilled = false;
|
|
15
|
-
const { cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, } = options;
|
|
15
|
+
const { batchCursor: cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, } = options;
|
|
16
16
|
this.cursor = cursor;
|
|
17
17
|
this.uniqueKey = uniqueKey;
|
|
18
18
|
this.items = items;
|
|
@@ -21,10 +21,10 @@ interface ChunkingEmitterOptions {
|
|
|
21
21
|
export type ChunkingEmitterEmitOptions = {
|
|
22
22
|
eventName: EventName;
|
|
23
23
|
items?: Record<string, any>[];
|
|
24
|
-
|
|
24
|
+
batchCursor?: BatchCursor<Record<string, any>>;
|
|
25
25
|
payloadKey: string;
|
|
26
26
|
target?: Record<string, any>;
|
|
27
|
-
/** will
|
|
27
|
+
/** will kill any running operations that match the key */
|
|
28
28
|
uniqueKey?: string;
|
|
29
29
|
};
|
|
30
30
|
export interface ChunkingEmitter {
|
|
@@ -28,13 +28,20 @@ export default class ChunkingEmitterImpl {
|
|
|
28
28
|
}
|
|
29
29
|
emit(options) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const { items, cursor, uniqueKey: unqiueKey, } = assertOptions(options, ['eventName', 'payloadKey']);
|
|
31
|
+
const { items, batchCursor: cursor, uniqueKey: unqiueKey, } = assertOptions(options, ['eventName', 'payloadKey']);
|
|
32
32
|
this.totalErrors = 0;
|
|
33
33
|
if (!items && !cursor) {
|
|
34
34
|
throw new SchemaError({
|
|
35
35
|
code: 'MISSING_PARAMETERS',
|
|
36
|
-
parameters: ['items', '
|
|
37
|
-
friendlyMessage: `You have to pass either 'items' or a '
|
|
36
|
+
parameters: ['items', 'batchCursor'],
|
|
37
|
+
friendlyMessage: `You have to pass either 'items' or a 'batchCursor' to emit.`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else if (items && cursor) {
|
|
41
|
+
throw new SchemaError({
|
|
42
|
+
code: 'INVALID_PARAMETERS',
|
|
43
|
+
parameters: ['items', 'batchCursor'],
|
|
44
|
+
friendlyMessage: `You can only pass either 'items' or a 'batchCursor' to emit, not both.`,
|
|
38
45
|
});
|
|
39
46
|
}
|
|
40
47
|
const match = this.emitters.find((e) => unqiueKey && e.matchesKey(unqiueKey));
|
|
@@ -7,12 +7,14 @@ export default class MockChunkingEmitter implements ChunkingEmitter {
|
|
|
7
7
|
private emittedPayloadKey?;
|
|
8
8
|
static lastInstance?: MockChunkingEmitter;
|
|
9
9
|
private emittedTarget?;
|
|
10
|
+
private emittedCursor?;
|
|
10
11
|
constructor();
|
|
11
12
|
static getLastInstance(): MockChunkingEmitter;
|
|
12
13
|
static reset(): void;
|
|
13
14
|
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
14
15
|
assertDidEmitTarget(target: Record<string, any>): void;
|
|
15
16
|
assertDidEmitPayloadKey(payloadKey: string): void;
|
|
17
|
+
assertDidReceiveCursor(): void;
|
|
16
18
|
getTotalErrors(): number;
|
|
17
19
|
assertEmittedItems(items: Record<string, any>[]): void;
|
|
18
20
|
assertDidEmit(): void;
|
|
@@ -24,12 +24,13 @@ 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 } = options;
|
|
27
|
+
const { eventName, items, payloadKey, target, batchCursor: cursor, } = 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
|
+
this.emittedCursor = cursor;
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
assertDidEmitTarget(target) {
|
|
@@ -39,6 +40,9 @@ export default class MockChunkingEmitter {
|
|
|
39
40
|
this.assertDidEmit();
|
|
40
41
|
assert.isEqual(this.emittedPayloadKey, payloadKey, `I expected chunkingEmitter.emit() with payloadKey '${payloadKey}'! But you emitted ${this.emittedPayloadKey || 'nothing'}`);
|
|
41
42
|
}
|
|
43
|
+
assertDidReceiveCursor() {
|
|
44
|
+
assert.isTruthy(this.emittedCursor, 'You did not chunkingEmitter.emit(...) the expected batch cursor!');
|
|
45
|
+
}
|
|
42
46
|
getTotalErrors() {
|
|
43
47
|
return 0;
|
|
44
48
|
}
|
|
@@ -24,7 +24,7 @@ export default class SingleChunkEmitter {
|
|
|
24
24
|
private Cursor;
|
|
25
25
|
}
|
|
26
26
|
interface SingleChunkEmitterOptions {
|
|
27
|
-
|
|
27
|
+
batchCursor?: BatchCursor<Record<string, any>>;
|
|
28
28
|
items?: Record<string, any>[];
|
|
29
29
|
payloadKey: string;
|
|
30
30
|
target?: Record<string, any>;
|
|
@@ -19,7 +19,7 @@ export default class SingleChunkEmitter {
|
|
|
19
19
|
constructor(options) {
|
|
20
20
|
this.totalErrors = 0;
|
|
21
21
|
this.isKilled = false;
|
|
22
|
-
const { cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, } = options;
|
|
22
|
+
const { batchCursor: cursor, items, payloadKey, target, eventName, chunkSize, client, uniqueKey, log, } = options;
|
|
23
23
|
this.cursor = cursor;
|
|
24
24
|
this.uniqueKey = uniqueKey;
|
|
25
25
|
this.items = items;
|