@forklaunch/implementation-worker-kafka 0.6.3 → 0.6.4
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/lib/consumers/index.d.mts +28 -15
- package/lib/consumers/index.d.ts +28 -15
- package/lib/consumers/index.js +14 -11
- package/lib/consumers/index.mjs +3 -7
- package/lib/domain/schemas/index.d.mts +52 -8
- package/lib/domain/schemas/index.d.ts +52 -8
- package/lib/domain/schemas/index.js +579 -537
- package/lib/domain/schemas/index.mjs +543 -541
- package/lib/domain/types/index.d.mts +6 -6
- package/lib/domain/types/index.d.ts +6 -6
- package/lib/domain/types/index.js +8 -4
- package/lib/producers/index.d.mts +10 -7
- package/lib/producers/index.d.ts +10 -7
- package/lib/producers/index.js +13 -8
- package/lib/producers/index.mjs +2 -4
- package/package.json +6 -6
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
WorkerEventEntity,
|
|
4
|
+
WorkerProcessFunction,
|
|
5
|
+
WorkerFailureHandler
|
|
6
|
+
} from '@forklaunch/interfaces-worker/types';
|
|
3
7
|
import { KafkaWorkerOptions } from '../domain/types/index.mjs';
|
|
4
8
|
|
|
5
|
-
declare class KafkaWorkerConsumer<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
declare class KafkaWorkerConsumer<
|
|
10
|
+
EventEntity extends WorkerEventEntity,
|
|
11
|
+
Options extends KafkaWorkerOptions
|
|
12
|
+
> implements WorkerConsumer<EventEntity>
|
|
13
|
+
{
|
|
14
|
+
private kafka;
|
|
15
|
+
private producer;
|
|
16
|
+
private consumer;
|
|
17
|
+
private processedMessages;
|
|
18
|
+
protected readonly queueName: string;
|
|
19
|
+
protected readonly options: Options;
|
|
20
|
+
protected readonly processEventsFunction: WorkerProcessFunction<EventEntity>;
|
|
21
|
+
protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
|
|
22
|
+
constructor(
|
|
23
|
+
queueName: string,
|
|
24
|
+
options: Options,
|
|
25
|
+
processEventsFunction: WorkerProcessFunction<EventEntity>,
|
|
26
|
+
failureHandler: WorkerFailureHandler<EventEntity>
|
|
27
|
+
);
|
|
28
|
+
private setupConsumer;
|
|
29
|
+
peekEvents(): Promise<EventEntity[]>;
|
|
30
|
+
start(): Promise<void>;
|
|
31
|
+
close(): Promise<void>;
|
|
19
32
|
}
|
|
20
33
|
|
|
21
34
|
export { KafkaWorkerConsumer };
|
package/lib/consumers/index.d.ts
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
WorkerEventEntity,
|
|
4
|
+
WorkerProcessFunction,
|
|
5
|
+
WorkerFailureHandler
|
|
6
|
+
} from '@forklaunch/interfaces-worker/types';
|
|
3
7
|
import { KafkaWorkerOptions } from '../domain/types/index.js';
|
|
4
8
|
|
|
5
|
-
declare class KafkaWorkerConsumer<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
declare class KafkaWorkerConsumer<
|
|
10
|
+
EventEntity extends WorkerEventEntity,
|
|
11
|
+
Options extends KafkaWorkerOptions
|
|
12
|
+
> implements WorkerConsumer<EventEntity>
|
|
13
|
+
{
|
|
14
|
+
private kafka;
|
|
15
|
+
private producer;
|
|
16
|
+
private consumer;
|
|
17
|
+
private processedMessages;
|
|
18
|
+
protected readonly queueName: string;
|
|
19
|
+
protected readonly options: Options;
|
|
20
|
+
protected readonly processEventsFunction: WorkerProcessFunction<EventEntity>;
|
|
21
|
+
protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
|
|
22
|
+
constructor(
|
|
23
|
+
queueName: string,
|
|
24
|
+
options: Options,
|
|
25
|
+
processEventsFunction: WorkerProcessFunction<EventEntity>,
|
|
26
|
+
failureHandler: WorkerFailureHandler<EventEntity>
|
|
27
|
+
);
|
|
28
|
+
private setupConsumer;
|
|
29
|
+
peekEvents(): Promise<EventEntity[]>;
|
|
30
|
+
start(): Promise<void>;
|
|
31
|
+
close(): Promise<void>;
|
|
19
32
|
}
|
|
20
33
|
|
|
21
34
|
export { KafkaWorkerConsumer };
|
package/lib/consumers/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -8,14 +8,18 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from ===
|
|
11
|
+
if ((from && typeof from === 'object') || typeof from === 'function') {
|
|
12
12
|
for (let key of __getOwnPropNames(from))
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
15
18
|
}
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
18
|
-
var __toCommonJS = (mod) =>
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, '__esModule', { value: true }), mod);
|
|
19
23
|
|
|
20
24
|
// consumers/index.ts
|
|
21
25
|
var consumers_exports = {};
|
|
@@ -25,7 +29,7 @@ __export(consumers_exports, {
|
|
|
25
29
|
module.exports = __toCommonJS(consumers_exports);
|
|
26
30
|
|
|
27
31
|
// consumers/kafkaWorker.consumer.ts
|
|
28
|
-
var import_kafkajs = require(
|
|
32
|
+
var import_kafkajs = require('kafkajs');
|
|
29
33
|
var KafkaWorkerConsumer = class {
|
|
30
34
|
kafka;
|
|
31
35
|
producer;
|
|
@@ -135,9 +139,7 @@ var KafkaWorkerConsumer = class {
|
|
|
135
139
|
peekConsumer.run({
|
|
136
140
|
eachMessage: async ({ message }) => {
|
|
137
141
|
if (message.value && events.length < this.options.peekCount) {
|
|
138
|
-
const messageEvents = JSON.parse(
|
|
139
|
-
message.value.toString()
|
|
140
|
-
);
|
|
142
|
+
const messageEvents = JSON.parse(message.value.toString());
|
|
141
143
|
events.push(...messageEvents);
|
|
142
144
|
if (events.length >= this.options.peekCount) {
|
|
143
145
|
resolve();
|
|
@@ -172,6 +174,7 @@ var KafkaWorkerConsumer = class {
|
|
|
172
174
|
}
|
|
173
175
|
};
|
|
174
176
|
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
-
0 &&
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
0 &&
|
|
178
|
+
(module.exports = {
|
|
179
|
+
KafkaWorkerConsumer
|
|
180
|
+
});
|
package/lib/consumers/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// consumers/kafkaWorker.consumer.ts
|
|
2
|
-
import { Kafka } from
|
|
2
|
+
import { Kafka } from 'kafkajs';
|
|
3
3
|
var KafkaWorkerConsumer = class {
|
|
4
4
|
kafka;
|
|
5
5
|
producer;
|
|
@@ -109,9 +109,7 @@ var KafkaWorkerConsumer = class {
|
|
|
109
109
|
peekConsumer.run({
|
|
110
110
|
eachMessage: async ({ message }) => {
|
|
111
111
|
if (message.value && events.length < this.options.peekCount) {
|
|
112
|
-
const messageEvents = JSON.parse(
|
|
113
|
-
message.value.toString()
|
|
114
|
-
);
|
|
112
|
+
const messageEvents = JSON.parse(message.value.toString());
|
|
115
113
|
events.push(...messageEvents);
|
|
116
114
|
if (events.length >= this.options.peekCount) {
|
|
117
115
|
resolve();
|
|
@@ -145,6 +143,4 @@ var KafkaWorkerConsumer = class {
|
|
|
145
143
|
await this.consumer.disconnect();
|
|
146
144
|
}
|
|
147
145
|
};
|
|
148
|
-
export {
|
|
149
|
-
KafkaWorkerConsumer
|
|
150
|
-
};
|
|
146
|
+
export { KafkaWorkerConsumer };
|
|
@@ -3,22 +3,66 @@ import * as zod_v3 from 'zod/v3';
|
|
|
3
3
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
4
4
|
import * as _forklaunch_validator from '@forklaunch/validator';
|
|
5
5
|
|
|
6
|
-
declare const KafkaWorkerSchemas: <
|
|
6
|
+
declare const KafkaWorkerSchemas: <
|
|
7
|
+
SchemaValidator extends _forklaunch_validator.AnySchemaValidator
|
|
8
|
+
>(
|
|
9
|
+
options: Record<string, unknown> & {
|
|
7
10
|
validator: SchemaValidator;
|
|
8
|
-
}
|
|
11
|
+
}
|
|
12
|
+
) => _forklaunch_internal.SchemasByValidator<
|
|
13
|
+
SchemaValidator,
|
|
14
|
+
(options: Record<string, unknown>) => {
|
|
9
15
|
brokers: _sinclair_typebox.TArray<_sinclair_typebox.TString>;
|
|
10
16
|
clientId: _sinclair_typebox.TString;
|
|
11
17
|
groupId: _sinclair_typebox.TString;
|
|
12
|
-
retries: _sinclair_typebox.TTransform<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
retries: _sinclair_typebox.TTransform<
|
|
19
|
+
_sinclair_typebox.TUnion<
|
|
20
|
+
[
|
|
21
|
+
_sinclair_typebox.TNumber,
|
|
22
|
+
_sinclair_typebox.TString,
|
|
23
|
+
_sinclair_typebox.TBoolean,
|
|
24
|
+
_sinclair_typebox.TNull,
|
|
25
|
+
_sinclair_typebox.TBigInt,
|
|
26
|
+
_sinclair_typebox.TDate
|
|
27
|
+
]
|
|
28
|
+
>,
|
|
29
|
+
number
|
|
30
|
+
>;
|
|
31
|
+
interval: _sinclair_typebox.TTransform<
|
|
32
|
+
_sinclair_typebox.TUnion<
|
|
33
|
+
[
|
|
34
|
+
_sinclair_typebox.TNumber,
|
|
35
|
+
_sinclair_typebox.TString,
|
|
36
|
+
_sinclair_typebox.TBoolean,
|
|
37
|
+
_sinclair_typebox.TNull,
|
|
38
|
+
_sinclair_typebox.TBigInt,
|
|
39
|
+
_sinclair_typebox.TDate
|
|
40
|
+
]
|
|
41
|
+
>,
|
|
42
|
+
number
|
|
43
|
+
>;
|
|
44
|
+
peekCount: _sinclair_typebox.TTransform<
|
|
45
|
+
_sinclair_typebox.TUnion<
|
|
46
|
+
[
|
|
47
|
+
_sinclair_typebox.TNumber,
|
|
48
|
+
_sinclair_typebox.TString,
|
|
49
|
+
_sinclair_typebox.TBoolean,
|
|
50
|
+
_sinclair_typebox.TNull,
|
|
51
|
+
_sinclair_typebox.TBigInt,
|
|
52
|
+
_sinclair_typebox.TDate
|
|
53
|
+
]
|
|
54
|
+
>,
|
|
55
|
+
number
|
|
56
|
+
>;
|
|
57
|
+
},
|
|
58
|
+
(options: Record<string, unknown>) => {
|
|
59
|
+
brokers: zod_v3.ZodArray<zod_v3.ZodString, 'many'>;
|
|
17
60
|
clientId: zod_v3.ZodString;
|
|
18
61
|
groupId: zod_v3.ZodString;
|
|
19
62
|
retries: zod_v3.ZodEffects<zod_v3.ZodNumber, number, unknown>;
|
|
20
63
|
interval: zod_v3.ZodEffects<zod_v3.ZodNumber, number, unknown>;
|
|
21
64
|
peekCount: zod_v3.ZodEffects<zod_v3.ZodNumber, number, unknown>;
|
|
22
|
-
}
|
|
65
|
+
}
|
|
66
|
+
>;
|
|
23
67
|
|
|
24
68
|
export { KafkaWorkerSchemas };
|
|
@@ -3,22 +3,66 @@ import * as zod_v3 from 'zod/v3';
|
|
|
3
3
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
4
4
|
import * as _forklaunch_validator from '@forklaunch/validator';
|
|
5
5
|
|
|
6
|
-
declare const KafkaWorkerSchemas: <
|
|
6
|
+
declare const KafkaWorkerSchemas: <
|
|
7
|
+
SchemaValidator extends _forklaunch_validator.AnySchemaValidator
|
|
8
|
+
>(
|
|
9
|
+
options: Record<string, unknown> & {
|
|
7
10
|
validator: SchemaValidator;
|
|
8
|
-
}
|
|
11
|
+
}
|
|
12
|
+
) => _forklaunch_internal.SchemasByValidator<
|
|
13
|
+
SchemaValidator,
|
|
14
|
+
(options: Record<string, unknown>) => {
|
|
9
15
|
brokers: _sinclair_typebox.TArray<_sinclair_typebox.TString>;
|
|
10
16
|
clientId: _sinclair_typebox.TString;
|
|
11
17
|
groupId: _sinclair_typebox.TString;
|
|
12
|
-
retries: _sinclair_typebox.TTransform<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
retries: _sinclair_typebox.TTransform<
|
|
19
|
+
_sinclair_typebox.TUnion<
|
|
20
|
+
[
|
|
21
|
+
_sinclair_typebox.TNumber,
|
|
22
|
+
_sinclair_typebox.TString,
|
|
23
|
+
_sinclair_typebox.TBoolean,
|
|
24
|
+
_sinclair_typebox.TNull,
|
|
25
|
+
_sinclair_typebox.TBigInt,
|
|
26
|
+
_sinclair_typebox.TDate
|
|
27
|
+
]
|
|
28
|
+
>,
|
|
29
|
+
number
|
|
30
|
+
>;
|
|
31
|
+
interval: _sinclair_typebox.TTransform<
|
|
32
|
+
_sinclair_typebox.TUnion<
|
|
33
|
+
[
|
|
34
|
+
_sinclair_typebox.TNumber,
|
|
35
|
+
_sinclair_typebox.TString,
|
|
36
|
+
_sinclair_typebox.TBoolean,
|
|
37
|
+
_sinclair_typebox.TNull,
|
|
38
|
+
_sinclair_typebox.TBigInt,
|
|
39
|
+
_sinclair_typebox.TDate
|
|
40
|
+
]
|
|
41
|
+
>,
|
|
42
|
+
number
|
|
43
|
+
>;
|
|
44
|
+
peekCount: _sinclair_typebox.TTransform<
|
|
45
|
+
_sinclair_typebox.TUnion<
|
|
46
|
+
[
|
|
47
|
+
_sinclair_typebox.TNumber,
|
|
48
|
+
_sinclair_typebox.TString,
|
|
49
|
+
_sinclair_typebox.TBoolean,
|
|
50
|
+
_sinclair_typebox.TNull,
|
|
51
|
+
_sinclair_typebox.TBigInt,
|
|
52
|
+
_sinclair_typebox.TDate
|
|
53
|
+
]
|
|
54
|
+
>,
|
|
55
|
+
number
|
|
56
|
+
>;
|
|
57
|
+
},
|
|
58
|
+
(options: Record<string, unknown>) => {
|
|
59
|
+
brokers: zod_v3.ZodArray<zod_v3.ZodString, 'many'>;
|
|
17
60
|
clientId: zod_v3.ZodString;
|
|
18
61
|
groupId: zod_v3.ZodString;
|
|
19
62
|
retries: zod_v3.ZodEffects<zod_v3.ZodNumber, number, unknown>;
|
|
20
63
|
interval: zod_v3.ZodEffects<zod_v3.ZodNumber, number, unknown>;
|
|
21
64
|
peekCount: zod_v3.ZodEffects<zod_v3.ZodNumber, number, unknown>;
|
|
22
|
-
}
|
|
65
|
+
}
|
|
66
|
+
>;
|
|
23
67
|
|
|
24
68
|
export { KafkaWorkerSchemas };
|