@forklaunch/implementation-worker-kafka 0.3.1 → 0.3.3

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.
@@ -1,21 +1,34 @@
1
1
  import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
- import { WorkerEventEntity, WorkerProcessFunction, WorkerFailureHandler } from '@forklaunch/interfaces-worker/types';
3
- import { KafkaWorkerOptions } from '../types/index.mjs';
2
+ import {
3
+ WorkerEventEntity,
4
+ WorkerProcessFunction,
5
+ WorkerFailureHandler
6
+ } from '@forklaunch/interfaces-worker/types';
7
+ import { KafkaWorkerOptions } from '../domain/types/index.mjs';
4
8
 
5
- declare class KafkaWorkerConsumer<EventEntity extends WorkerEventEntity, Options extends KafkaWorkerOptions> implements WorkerConsumer<EventEntity> {
6
- protected readonly queueName: string;
7
- protected readonly options: Options;
8
- protected readonly processEventsFunction: WorkerProcessFunction<EventEntity>;
9
- protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
10
- private kafka;
11
- private producer;
12
- private consumer;
13
- private processedMessages;
14
- constructor(queueName: string, options: Options, processEventsFunction: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
15
- private setupConsumer;
16
- peekEvents(): Promise<EventEntity[]>;
17
- start(): Promise<void>;
18
- close(): Promise<void>;
9
+ declare class KafkaWorkerConsumer<
10
+ EventEntity extends WorkerEventEntity,
11
+ Options extends KafkaWorkerOptions
12
+ > implements WorkerConsumer<EventEntity>
13
+ {
14
+ protected readonly queueName: string;
15
+ protected readonly options: Options;
16
+ protected readonly processEventsFunction: WorkerProcessFunction<EventEntity>;
17
+ protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
18
+ private kafka;
19
+ private producer;
20
+ private consumer;
21
+ private processedMessages;
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 };
@@ -1,21 +1,34 @@
1
1
  import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
- import { WorkerEventEntity, WorkerProcessFunction, WorkerFailureHandler } from '@forklaunch/interfaces-worker/types';
3
- import { KafkaWorkerOptions } from '../types/index.js';
2
+ import {
3
+ WorkerEventEntity,
4
+ WorkerProcessFunction,
5
+ WorkerFailureHandler
6
+ } from '@forklaunch/interfaces-worker/types';
7
+ import { KafkaWorkerOptions } from '../domain/types/index.js';
4
8
 
5
- declare class KafkaWorkerConsumer<EventEntity extends WorkerEventEntity, Options extends KafkaWorkerOptions> implements WorkerConsumer<EventEntity> {
6
- protected readonly queueName: string;
7
- protected readonly options: Options;
8
- protected readonly processEventsFunction: WorkerProcessFunction<EventEntity>;
9
- protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
10
- private kafka;
11
- private producer;
12
- private consumer;
13
- private processedMessages;
14
- constructor(queueName: string, options: Options, processEventsFunction: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
15
- private setupConsumer;
16
- peekEvents(): Promise<EventEntity[]>;
17
- start(): Promise<void>;
18
- close(): Promise<void>;
9
+ declare class KafkaWorkerConsumer<
10
+ EventEntity extends WorkerEventEntity,
11
+ Options extends KafkaWorkerOptions
12
+ > implements WorkerConsumer<EventEntity>
13
+ {
14
+ protected readonly queueName: string;
15
+ protected readonly options: Options;
16
+ protected readonly processEventsFunction: WorkerProcessFunction<EventEntity>;
17
+ protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
18
+ private kafka;
19
+ private producer;
20
+ private consumer;
21
+ private processedMessages;
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 };
@@ -1,4 +1,4 @@
1
- "use strict";
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 === "object" || typeof from === "function") {
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, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
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) => __copyProps(__defProp({}, "__esModule", { value: true }), 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("kafkajs");
32
+ var import_kafkajs = require('kafkajs');
29
33
  var KafkaWorkerConsumer = class {
30
34
  constructor(queueName, options, processEventsFunction, failureHandler) {
31
35
  this.queueName = queueName;
@@ -131,9 +135,7 @@ var KafkaWorkerConsumer = class {
131
135
  peekConsumer.run({
132
136
  eachMessage: async ({ message }) => {
133
137
  if (message.value && events.length < this.options.peekCount) {
134
- const messageEvents = JSON.parse(
135
- message.value.toString()
136
- );
138
+ const messageEvents = JSON.parse(message.value.toString());
137
139
  events.push(...messageEvents);
138
140
  if (events.length >= this.options.peekCount) {
139
141
  resolve();
@@ -168,6 +170,7 @@ var KafkaWorkerConsumer = class {
168
170
  }
169
171
  };
170
172
  // Annotate the CommonJS export names for ESM import in node:
171
- 0 && (module.exports = {
172
- KafkaWorkerConsumer
173
- });
173
+ 0 &&
174
+ (module.exports = {
175
+ KafkaWorkerConsumer
176
+ });
@@ -1,5 +1,5 @@
1
1
  // consumers/kafkaWorker.consumer.ts
2
- import { Kafka } from "kafkajs";
2
+ import { Kafka } from 'kafkajs';
3
3
  var KafkaWorkerConsumer = class {
4
4
  constructor(queueName, options, processEventsFunction, failureHandler) {
5
5
  this.queueName = queueName;
@@ -105,9 +105,7 @@ var KafkaWorkerConsumer = class {
105
105
  peekConsumer.run({
106
106
  eachMessage: async ({ message }) => {
107
107
  if (message.value && events.length < this.options.peekCount) {
108
- const messageEvents = JSON.parse(
109
- message.value.toString()
110
- );
108
+ const messageEvents = JSON.parse(message.value.toString());
111
109
  events.push(...messageEvents);
112
110
  if (events.length >= this.options.peekCount) {
113
111
  resolve();
@@ -141,6 +139,4 @@ var KafkaWorkerConsumer = class {
141
139
  await this.consumer.disconnect();
142
140
  }
143
141
  };
144
- export {
145
- KafkaWorkerConsumer
146
- };
142
+ export { KafkaWorkerConsumer };
@@ -0,0 +1,68 @@
1
+ import * as _forklaunch_internal from '@forklaunch/internal';
2
+ import * as zod from 'zod';
3
+ import * as _sinclair_typebox from '@sinclair/typebox';
4
+ import * as _forklaunch_validator from '@forklaunch/validator';
5
+
6
+ declare const KafkaWorkerSchemas: <
7
+ SchemaValidator extends _forklaunch_validator.AnySchemaValidator
8
+ >(
9
+ options: Record<string, unknown> & {
10
+ validator: SchemaValidator;
11
+ }
12
+ ) => _forklaunch_internal.SchemasByValidator<
13
+ SchemaValidator,
14
+ (options: Record<string, unknown>) => {
15
+ brokers: _sinclair_typebox.TArray<_sinclair_typebox.TString>;
16
+ clientId: _sinclair_typebox.TString;
17
+ groupId: _sinclair_typebox.TString;
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.ZodArray<zod.ZodString, 'many'>;
60
+ clientId: zod.ZodString;
61
+ groupId: zod.ZodString;
62
+ retries: zod.ZodEffects<zod.ZodNumber, number, unknown>;
63
+ interval: zod.ZodEffects<zod.ZodNumber, number, unknown>;
64
+ peekCount: zod.ZodEffects<zod.ZodNumber, number, unknown>;
65
+ }
66
+ >;
67
+
68
+ export { KafkaWorkerSchemas };
@@ -0,0 +1,68 @@
1
+ import * as _forklaunch_internal from '@forklaunch/internal';
2
+ import * as zod from 'zod';
3
+ import * as _sinclair_typebox from '@sinclair/typebox';
4
+ import * as _forklaunch_validator from '@forklaunch/validator';
5
+
6
+ declare const KafkaWorkerSchemas: <
7
+ SchemaValidator extends _forklaunch_validator.AnySchemaValidator
8
+ >(
9
+ options: Record<string, unknown> & {
10
+ validator: SchemaValidator;
11
+ }
12
+ ) => _forklaunch_internal.SchemasByValidator<
13
+ SchemaValidator,
14
+ (options: Record<string, unknown>) => {
15
+ brokers: _sinclair_typebox.TArray<_sinclair_typebox.TString>;
16
+ clientId: _sinclair_typebox.TString;
17
+ groupId: _sinclair_typebox.TString;
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.ZodArray<zod.ZodString, 'many'>;
60
+ clientId: zod.ZodString;
61
+ groupId: zod.ZodString;
62
+ retries: zod.ZodEffects<zod.ZodNumber, number, unknown>;
63
+ interval: zod.ZodEffects<zod.ZodNumber, number, unknown>;
64
+ peekCount: zod.ZodEffects<zod.ZodNumber, number, unknown>;
65
+ }
66
+ >;
67
+
68
+ export { KafkaWorkerSchemas };