go-mokapi 0.44.1 → 0.48.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/package.json +1 -1
- package/types/index.d.ts +81 -6
- package/types/kafka.d.ts +10 -6
- package/types/mqtt.d.ts +125 -0
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
import "./faker";
|
|
13
13
|
import "./global";
|
|
14
14
|
import "./http";
|
|
15
|
+
import "./kafka";
|
|
16
|
+
import "./mqtt";
|
|
15
17
|
import "./mustache";
|
|
16
18
|
import "./yaml";
|
|
17
19
|
import "./encoding";
|
|
@@ -115,6 +117,7 @@ export type Interval = string;
|
|
|
115
117
|
export interface EventHandler {
|
|
116
118
|
http: HttpEventHandler;
|
|
117
119
|
kafka: KafkaEventHandler;
|
|
120
|
+
mqtt: MqttEventHandler;
|
|
118
121
|
ldap: LdapEventHandler;
|
|
119
122
|
smtp: SmtpEventHandler;
|
|
120
123
|
}
|
|
@@ -256,7 +259,7 @@ export interface Url {
|
|
|
256
259
|
* export default function() {
|
|
257
260
|
* on('kafka', function(msg) {
|
|
258
261
|
* // add header 'foo' to every Kafka message
|
|
259
|
-
*
|
|
262
|
+
* message.headers['correlationId'] = 'abc-123'
|
|
260
263
|
* })
|
|
261
264
|
* }
|
|
262
265
|
*/
|
|
@@ -267,17 +270,67 @@ export type KafkaEventHandler = (message: KafkaEventMessage) => void | Promise<v
|
|
|
267
270
|
* https://mokapi.io/docs/javascript-api/mokapi/eventhandler/KafkaEventMessage
|
|
268
271
|
*/
|
|
269
272
|
export interface KafkaEventMessage {
|
|
270
|
-
/**
|
|
273
|
+
/** The name of the API, matching the `info.title` field in the AsyncAPI specification */
|
|
274
|
+
readonly api: string;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The name of the Kafka topic where this message originates.
|
|
278
|
+
*/
|
|
279
|
+
readonly topic: string;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The partition index within the Kafka topic.
|
|
283
|
+
*/
|
|
284
|
+
readonly partition: string;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The unique sequential offset assigned to the message within its partition.
|
|
288
|
+
*/
|
|
271
289
|
readonly offset: number;
|
|
272
290
|
|
|
273
|
-
/**
|
|
291
|
+
/**
|
|
292
|
+
* The key of the Kafka message, used for partitioning and identification.
|
|
293
|
+
*/
|
|
274
294
|
key: string;
|
|
275
295
|
|
|
276
|
-
/** Kafka message value */
|
|
296
|
+
/** The Kafka message value */
|
|
277
297
|
value: string;
|
|
278
298
|
|
|
279
|
-
/** Kafka message headers */
|
|
299
|
+
/** Key-value pairs representing optional Kafka message headers. */
|
|
280
300
|
headers: { [name: string]: string } | null;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The identifier of the schema used to validate or serialize this message payload.
|
|
304
|
+
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* * This property is **only set** automatically if the schema ID is embedded within the
|
|
307
|
+
* message payload itself (matching `SchemaIdLocation: "payload"`).
|
|
308
|
+
* * If the ID is transmitted via message metadata instead (matching `SchemaIdLocation: "header"`),
|
|
309
|
+
* it will **not** populate this field and must instead be extracted manually from the {@link headers} object.
|
|
310
|
+
*/
|
|
311
|
+
schemaId: number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export type MqttEventHandler = (message: MqttEventMessage) => void | Promise<void>;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* KafkaEventMessage is an object used by KafkaEventHandler that contains Kafka-specific message data.
|
|
318
|
+
* https://mokapi.io/docs/javascript-api/mokapi/eventhandler/KafkaEventMessage
|
|
319
|
+
*/
|
|
320
|
+
export interface MqttEventMessage {
|
|
321
|
+
/** The name of the API, matching the `info.title` field in the AsyncAPI specification */
|
|
322
|
+
readonly api: string;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* The name of the MQTT topic where this message originates.
|
|
326
|
+
*/
|
|
327
|
+
readonly topic: string;
|
|
328
|
+
|
|
329
|
+
/** Specifies whether message should be retained */
|
|
330
|
+
retain: boolean;
|
|
331
|
+
|
|
332
|
+
/** MQTT message value */
|
|
333
|
+
value: string;
|
|
281
334
|
}
|
|
282
335
|
|
|
283
336
|
/**
|
|
@@ -517,6 +570,10 @@ export interface TypedEventArgs {
|
|
|
517
570
|
* Arguments for Kafka event handlers.
|
|
518
571
|
*/
|
|
519
572
|
kafka: KafkaEventArgs;
|
|
573
|
+
/**
|
|
574
|
+
* Arguments for MQTT event handlers.
|
|
575
|
+
*/
|
|
576
|
+
mqtt: MqttEventArgs;
|
|
520
577
|
/**
|
|
521
578
|
* Arguments for LDAP event handlers.
|
|
522
579
|
*/
|
|
@@ -563,6 +620,24 @@ export interface KafkaEventArgs extends EventArgs {
|
|
|
563
620
|
track?: boolean | ((message: KafkaEventMessage) => boolean);
|
|
564
621
|
}
|
|
565
622
|
|
|
623
|
+
/**
|
|
624
|
+
* Configuration options for MQTT event handlers.
|
|
625
|
+
*
|
|
626
|
+
* These arguments control execution behavior such as
|
|
627
|
+
* priority, tagging, and dashboard tracking.
|
|
628
|
+
*/
|
|
629
|
+
export interface MqttEventArgs extends EventArgs {
|
|
630
|
+
/**
|
|
631
|
+
* Controls whether this event handler is tracked in the dashboard.
|
|
632
|
+
*
|
|
633
|
+
* - true: always track this handler
|
|
634
|
+
* - false: never track this handler
|
|
635
|
+
* - undefined: Mokapi determines tracking automatically based on
|
|
636
|
+
* whether the message was modified or acknowledged by the handler
|
|
637
|
+
*/
|
|
638
|
+
track?: boolean | ((message: MqttEventMessage) => boolean);
|
|
639
|
+
}
|
|
640
|
+
|
|
566
641
|
/**
|
|
567
642
|
* Configuration options for LDAP event handlers.
|
|
568
643
|
*
|
|
@@ -791,7 +866,7 @@ export interface SharedMemory {
|
|
|
791
866
|
*
|
|
792
867
|
* // Retrieve the current counter value
|
|
793
868
|
* const count = mokapi.shared.get("counter")
|
|
794
|
-
*
|
|
869
|
+
* console.log(`Current counter: ${count}`)
|
|
795
870
|
* ```
|
|
796
871
|
*/
|
|
797
872
|
export const shared: SharedMemory;
|
package/types/kafka.d.ts
CHANGED
|
@@ -165,32 +165,36 @@ export interface ProduceResult {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
|
-
*
|
|
168
|
+
* Represents the outcome of producing a Kafka message in Mokapi.
|
|
169
|
+
*
|
|
170
|
+
* Provides details about the target topic location, message payloads,
|
|
171
|
+
* and schema validation outcomes.
|
|
172
|
+
*
|
|
169
173
|
* https://mokapi.io/docs/javascript-api/mokapi-kafka/kafkamessageresult
|
|
170
174
|
*/
|
|
171
175
|
export interface MessageResult {
|
|
172
176
|
/**
|
|
173
|
-
*
|
|
177
|
+
* The zero-based index of the Kafka partition where the message was written.
|
|
174
178
|
*/
|
|
175
179
|
readonly partition: number;
|
|
176
180
|
|
|
177
181
|
/**
|
|
178
|
-
*
|
|
182
|
+
* The unique sequential identifier (offset) assigned to the message within its partition.
|
|
179
183
|
*/
|
|
180
184
|
readonly offset: number;
|
|
181
185
|
|
|
182
186
|
/**
|
|
183
|
-
*
|
|
187
|
+
* The key of the written Kafka message, typically used for partitioning.
|
|
184
188
|
*/
|
|
185
189
|
readonly key: string;
|
|
186
190
|
|
|
187
191
|
/**
|
|
188
|
-
*
|
|
192
|
+
* The main payload data of the written Kafka message.
|
|
189
193
|
*/
|
|
190
194
|
readonly value: string;
|
|
191
195
|
|
|
192
196
|
/**
|
|
193
|
-
*
|
|
197
|
+
* Key-value pairs representing the metadata headers attached to the Kafka message.
|
|
194
198
|
*/
|
|
195
199
|
readonly headers: { [name: string]: string };
|
|
196
200
|
}
|
package/types/mqtt.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sends a single message to a MQTT topic.
|
|
3
|
+
* https://mokapi.io/docs/javascript-api/mokapi-mqtt/publish
|
|
4
|
+
* @param args - PublishArgs object contains MQTT publish arguments.
|
|
5
|
+
* @returns The publish result.
|
|
6
|
+
* @example
|
|
7
|
+
* export default function() {
|
|
8
|
+
* publish({
|
|
9
|
+
* topic: 'foo',
|
|
10
|
+
* value: JSON.stringify({ foo: bar })
|
|
11
|
+
* });
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
export function produce(args?: PublishArgs): PublishResult;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sends a single message to a MQTT topic asynchronously.
|
|
18
|
+
* https://mokapi.io/docs/javascript-api/mokapi-mqtt/publishAsync
|
|
19
|
+
* @param args - PublishArgs object contains MQTT publish arguments.
|
|
20
|
+
* @returns The publish result.
|
|
21
|
+
* @example
|
|
22
|
+
* export default function() {
|
|
23
|
+
* publish({
|
|
24
|
+
* topic: 'foo',
|
|
25
|
+
* value: JSON.stringify({ foo: bar })
|
|
26
|
+
* });
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
export function publishAsync(args?: PublishArgs): Promise<PublishResult>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Contains publish-specific arguments.
|
|
33
|
+
* https://mokapi.io/docs/javascript-api/mokapi-mqtt/publishargs
|
|
34
|
+
* @example
|
|
35
|
+
* export default function() {
|
|
36
|
+
* const res = publish({
|
|
37
|
+
* topic: 'foo',
|
|
38
|
+
* value: `{"foo": "bar"}`
|
|
39
|
+
* });
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
export interface PublishArgs {
|
|
43
|
+
/** MQTT cluster name. Used when topic name is not unique. */
|
|
44
|
+
cluster?: string;
|
|
45
|
+
|
|
46
|
+
/** MQTT topic name. If not specified, message will be written to a random topic. */
|
|
47
|
+
|
|
48
|
+
/** MQTT message value. If not specified, a random value will be generated based on the topic configuration. */
|
|
49
|
+
value: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The retry option is used if script is executed before Kafka topic is set up.
|
|
53
|
+
*/
|
|
54
|
+
retry?: ProduceRetry;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Contains information of the written Kafka message.
|
|
59
|
+
* https://mokapi.io/docs/javascript-api/mokapi-kafka/produceresult
|
|
60
|
+
* @example
|
|
61
|
+
* export default function() {
|
|
62
|
+
* const res = produce({ topic: 'foo' })
|
|
63
|
+
* console.log(`new kafka message written with offset: ${res.offset}`)
|
|
64
|
+
* }
|
|
65
|
+
*/
|
|
66
|
+
export interface PublishResult {
|
|
67
|
+
/** Name of the Kafka cluster where the message was written. */
|
|
68
|
+
readonly cluster: string;
|
|
69
|
+
|
|
70
|
+
/** Kafka topic name where the message was written. */
|
|
71
|
+
readonly topic: string;
|
|
72
|
+
|
|
73
|
+
/** The value of the written message. */
|
|
74
|
+
readonly value: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The retry option can be used to customize the configuration of the retry mechanism.
|
|
79
|
+
*/
|
|
80
|
+
export interface ProduceRetry {
|
|
81
|
+
/**
|
|
82
|
+
* Maximum wait time for a retry
|
|
83
|
+
* MaxRetryTime number express the wait time in milliseconds.
|
|
84
|
+
* MaxRetryTime string is a possibly signed sequence of
|
|
85
|
+
* decimal numbers, each with optional fraction and a unit suffix,
|
|
86
|
+
* such as "300ms", "-1.5h" or "2h45m".
|
|
87
|
+
* Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
|
|
88
|
+
* @default 30000ms
|
|
89
|
+
* @example
|
|
90
|
+
* export default function() {
|
|
91
|
+
* produce({ topic: 'foo', messages: [{ value: 'value-1' }], retry: { maxRetryTime: '30s' } })
|
|
92
|
+
* }
|
|
93
|
+
*/
|
|
94
|
+
maxRetryTime: string | number;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Initial value used to calculate the wait time
|
|
98
|
+
* InitialRetryTime number express the wait time in milliseconds.
|
|
99
|
+
* InitialRetryTime string is a possibly signed sequence of
|
|
100
|
+
* decimal numbers, each with optional fraction and a unit suffix,
|
|
101
|
+
* such as "300ms", "-1.5h" or "2h45m".
|
|
102
|
+
* Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
|
|
103
|
+
* @default 200ms
|
|
104
|
+
* @example
|
|
105
|
+
* export default function() {
|
|
106
|
+
* produce({ topic: 'foo', messages: [{ value: 'value-1' }], retry: { initialRetryTime: '2s' } })
|
|
107
|
+
* }
|
|
108
|
+
*/
|
|
109
|
+
initialRetryTime: string | number;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Factor for increasing the wait time for next retry.
|
|
113
|
+
* 1st retry: 200ms
|
|
114
|
+
* 2nd retry: 4 * 200ms = 800ms
|
|
115
|
+
* 3th retry: 4 * 800ms = 3200ms
|
|
116
|
+
* @default 4
|
|
117
|
+
*/
|
|
118
|
+
factor: number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Max number of retries
|
|
122
|
+
* @default 5
|
|
123
|
+
*/
|
|
124
|
+
retries: number;
|
|
125
|
+
}
|