go-mokapi 0.51.2 → 0.53.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/types/index.d.ts CHANGED
@@ -9,17 +9,6 @@
9
9
  * https://mokapi.io/docs/javascript-api/overview
10
10
  */
11
11
 
12
- import "./faker";
13
- import "./global";
14
- import "./http";
15
- import "./kafka";
16
- import "./mqtt";
17
- import "./mustache";
18
- import "./yaml";
19
- import "./encoding";
20
- import "./mail";
21
- import "./file";
22
-
23
12
  /**
24
13
  * Attaches an event handler for the given event.
25
14
  *
@@ -955,7 +944,7 @@ export enum LdapResultStatus {
955
944
  SizeLimitExceeded = 4,
956
945
  }
957
946
 
958
- export type SmtpEventHandler = (record: SmtpEventMessage) => void | Promise<void>;
947
+ export type SmtpEventHandler = (message: SmtpEventMessage) => void | Promise<void>;
959
948
 
960
949
  export interface SmtpEventMessage {
961
950
  server: string;
@@ -1227,18 +1216,6 @@ export interface ScheduledEventArgs {
1227
1216
  runFirstTimeImmediately?: boolean;
1228
1217
  }
1229
1218
 
1230
- /**
1231
- * JavaScript value representable with JSON.
1232
- */
1233
- export type JSONValue = null | undefined | boolean | number | string | JSONValue[] | JSONObject;
1234
-
1235
- /**
1236
- * Object representable with JSON.
1237
- */
1238
- export interface JSONObject {
1239
- [key: string]: JSONValue;
1240
- }
1241
-
1242
1219
  /**
1243
1220
  * Specifies the date-time format defined in [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339).
1244
1221
  * This constant can be used when defining or validating datetime strings.
@@ -1472,6 +1449,69 @@ export interface App {
1472
1449
  * }
1473
1450
  */
1474
1451
  http(): HttpRouter
1452
+
1453
+ /**
1454
+ * Returns a `KafkaRouter` not bound to any specific API.
1455
+ * Handlers and producers registered here will run for all Kafka APIs
1456
+ * that match the given topic name.
1457
+ *
1458
+ * Use this for cross-cutting concerns such as adding headers to all
1459
+ * messages, logging, or producing to a topic when only one Kafka API
1460
+ * is configured.
1461
+ *
1462
+ * Use `app.api('My API').kafka()` instead when multiple Kafka APIs
1463
+ * share the same topic name, to avoid unintended matches.
1464
+ *
1465
+ * @returns A `KafkaRouter` with no API scope.
1466
+ *
1467
+ * @example
1468
+ * // Add a correlation ID header to all incoming messages across all topics
1469
+ * import { app } from 'mokapi'
1470
+ * export default function() {
1471
+ * app.kafka().message((msg) => {
1472
+ * msg.headers = { ...msg.headers, correlationId: 'abc-123' }
1473
+ * })
1474
+ * }
1475
+ *
1476
+ * @example
1477
+ * // Produce a message without API scope
1478
+ * import { app } from 'mokapi'
1479
+ * export default function() {
1480
+ * app.kafka().produce('order-placed', { data: { id: 1 } })
1481
+ * }
1482
+ */
1483
+ kafka(): KafkaRouter
1484
+
1485
+ /**
1486
+ * Returns an `MqttRouter` not bound to any specific API.
1487
+ * Handlers and publishers registered here will run for all MQTT APIs
1488
+ * that match the given topic name.
1489
+ *
1490
+ * Use this for cross-cutting concerns such as logging incoming messages
1491
+ * or publishing to a topic when only one MQTT API is configured.
1492
+ *
1493
+ * Use `app.api('My API').mqtt()` instead when multiple MQTT APIs
1494
+ * share the same topic name, to avoid unintended matches.
1495
+ *
1496
+ * @returns An `MqttRouter` with no API scope.
1497
+ *
1498
+ * @example
1499
+ * // Handle all incoming MQTT messages across all topics
1500
+ * import { app } from 'mokapi'
1501
+ * export default function() {
1502
+ * app.mqtt().message((msg) => {
1503
+ * console.log(`[${msg.topic}] ${msg.value}`)
1504
+ * })
1505
+ * }
1506
+ *
1507
+ * @example
1508
+ * // Publish a message without API scope
1509
+ * import { app } from 'mokapi'
1510
+ * export default function() {
1511
+ * app.mqtt().publish({ value: 'hello' })
1512
+ * }
1513
+ */
1514
+ mqtt(): MqttRouter
1475
1515
  }
1476
1516
 
1477
1517
  /**
@@ -1507,6 +1547,90 @@ export interface ApiScope {
1507
1547
  * }
1508
1548
  */
1509
1549
  http(): HttpRouter
1550
+
1551
+ /**
1552
+ * Returns a `KafkaRouter` scoped to this API.
1553
+ *
1554
+ * Handlers and producers registered on this router will only run for
1555
+ * Kafka messages that belong to the API identified by this scope's title,
1556
+ * as defined in the AsyncAPI `info.title` field.
1557
+ *
1558
+ * Scoping is required when multiple Kafka APIs define the same topic name,
1559
+ * to avoid a handler or producer running for unintended APIs.
1560
+ *
1561
+ * @returns A `KafkaRouter` bound to this API scope.
1562
+ *
1563
+ * @example
1564
+ * // Handle messages scoped to a specific Kafka API
1565
+ * import { app } from 'mokapi'
1566
+ * export default function() {
1567
+ * app.api('Order Events').kafka()
1568
+ * .topic('order-placed')
1569
+ * .message((msg) => {
1570
+ * msg.headers = { ...msg.headers, processed: 'true' }
1571
+ * })
1572
+ * }
1573
+ *
1574
+ * @example
1575
+ * // Produce scoped to a specific Kafka API
1576
+ * import { app } from 'mokapi'
1577
+ * export default function() {
1578
+ * app.api('Order Events').kafka()
1579
+ * .produce('order-placed', { data: { id: 1 } })
1580
+ * }
1581
+ *
1582
+ * @example
1583
+ * // Two APIs with the same topic name — scoping avoids conflicts
1584
+ * import { app } from 'mokapi'
1585
+ * export default function() {
1586
+ * app.api('Order Events').kafka()
1587
+ * .topic('events')
1588
+ * .message((msg) => { msg.value = { ...msg.value, source: 'orders' } })
1589
+ *
1590
+ * app.api('Inventory Events').kafka()
1591
+ * .topic('events')
1592
+ * .message((msg) => { msg.value = { ...msg.value, source: 'inventory' } })
1593
+ * }
1594
+ */
1595
+ kafka(): KafkaRouter
1596
+
1597
+ /**
1598
+ * Returns an `MqttRouter` scoped to this API.
1599
+ *
1600
+ * Handlers and publishers registered on this router will only run for
1601
+ * MQTT messages that belong to the API identified by this scope's title,
1602
+ * as defined in the AsyncAPI `info.title` field.
1603
+ *
1604
+ * Scoping is required when multiple MQTT APIs define the same topic name,
1605
+ * to avoid a handler or publisher running for unintended APIs.
1606
+ *
1607
+ * @returns An `MqttRouter` bound to this API scope.
1608
+ *
1609
+ * @example
1610
+ * // Handle messages scoped to a specific MQTT API
1611
+ * import { app } from 'mokapi'
1612
+ * export default function() {
1613
+ * app.api('Smart Home').mqtt()
1614
+ * .topic('sensors/temperature')
1615
+ * .message((msg) => {
1616
+ * console.log(`Temperature: ${msg.value}`)
1617
+ * })
1618
+ * }
1619
+ *
1620
+ * @example
1621
+ * // Two APIs with the same topic name — scoping avoids conflicts
1622
+ * import { app } from 'mokapi'
1623
+ * export default function() {
1624
+ * app.api('Smart Home').mqtt()
1625
+ * .topic('sensors/temperature')
1626
+ * .message((msg) => { console.log(`Home: ${msg.value}`) })
1627
+ *
1628
+ * app.api('Factory Floor').mqtt()
1629
+ * .topic('sensors/temperature')
1630
+ * .message((msg) => { console.log(`Factory: ${msg.value}`) })
1631
+ * }
1632
+ */
1633
+ mqtt(): MqttRouter
1510
1634
  }
1511
1635
 
1512
1636
  /**
@@ -1618,24 +1742,39 @@ export interface HttpRouter {
1618
1742
  route(path: string): HttpRoute
1619
1743
 
1620
1744
  /**
1621
- * Returns an `HttpRoute` matched by the given `operationId` as defined
1622
- * in the OpenAPI specification.
1745
+ * Registers a handler directly for the operation identified by the given
1746
+ * `operationId` as defined in the OpenAPI specification.
1747
+ *
1748
+ * Since an `operationId` already uniquely identifies both the path and the
1749
+ * HTTP method of an operation, no further method scoping is needed.
1750
+ * This makes it a concise alternative to `route(path).get(handler)` —
1751
+ * especially useful when paths are long or contain many parameters.
1623
1752
  *
1624
- * Use this as an alternative to `route()` when you prefer to reference
1625
- * operations by name rather than by path template.
1753
+ * Behaves identically to the method shorthand functions such as `get()` and
1754
+ * `post()` on `HttpRouter`: all registered handlers run in order, and
1755
+ * `res.stopPropagation()` can be used to prevent subsequent handlers
1756
+ * from running.
1626
1757
  *
1627
- * @param operationId The `operationId` defined in the OpenAPI operation.
1628
- * @returns An `HttpRoute` for the matching operation.
1758
+ * @param operationId The `operationId` as defined in the OpenAPI operation.
1759
+ * @param handler The event handler to invoke.
1760
+ * @param opts Optional handler configuration such as priority and tracking.
1761
+ * @returns This `HttpRouter` instance for chaining.
1629
1762
  *
1630
1763
  * @example
1764
+ * // Equivalent to: app.api('Petstore').http().route('/pets').get(handler)
1631
1765
  * import { app } from 'mokapi'
1632
1766
  * export default function() {
1633
1767
  * app.api('Petstore').http()
1634
- * .operation('listPets')
1635
- * .get((req, res) => { res.data = [] })
1768
+ * .operation('listPets', (req, res) => {
1769
+ * res.data = [{ id: 1, name: 'Bello' }]
1770
+ * })
1771
+ * .operation('createPet', (req, res) => {
1772
+ * res.statusCode = 201
1773
+ * res.data = { id: 2, name: req.body.name }
1774
+ * })
1636
1775
  * }
1637
1776
  */
1638
- operation(operationId: string): HttpRoute
1777
+ operation(operationId: string, handler: HttpEventHandler, opts?: HttpEventArgs): HttpRouter
1639
1778
 
1640
1779
  /**
1641
1780
  * Narrows this router to a specific API by title.
@@ -1895,4 +2034,965 @@ export interface HttpRoute {
1895
2034
  * router.route('/cache').purge((req, res) => { res.statusCode = 200 })
1896
2035
  */
1897
2036
  [method: string]: any
2037
+ }
2038
+
2039
+ /**
2040
+ * Registers and organizes Kafka message handlers and producers by topic.
2041
+ *
2042
+ * Obtain a `KafkaRouter` via `app.kafka()` or `app.api('My API').kafka()`.
2043
+ *
2044
+ * Two styles are supported:
2045
+ * - **Shorthand**: `router.produce(topic, message)` — produces directly to a named topic.
2046
+ * - **Scoped**: `router.topic(name).produce(message)` — groups handlers and producers under one topic.
2047
+ *
2048
+ * When multiple APIs share the same topic name, use `app.api()` to scope the router
2049
+ * to a specific API title to avoid unintended matches.
2050
+ *
2051
+ * @example
2052
+ * // Shorthand style
2053
+ * import { app } from 'mokapi'
2054
+ * export default function() {
2055
+ * const router = app.api('Order Events').kafka()
2056
+ * router.produce('order-placed', { data: { id: 1 } })
2057
+ * router.message((msg) => { console.log(msg.value) })
2058
+ * }
2059
+ *
2060
+ * @example
2061
+ * // Scoped style
2062
+ * import { app } from 'mokapi'
2063
+ * export default function() {
2064
+ * app.api('Order Events').kafka()
2065
+ * .topic('order-placed')
2066
+ * .message((msg) => { msg.value = { ...msg.value, processed: true } })
2067
+ * .produce({ data: { id: 1 } })
2068
+ * }
2069
+ */
2070
+ export interface KafkaRouter {
2071
+ /**
2072
+ * Returns a `KafkaTopic` scoped to the given topic name.
2073
+ *
2074
+ * Use this to register message handlers or produce messages for a specific topic
2075
+ * using method chaining, without repeating the topic name on every call.
2076
+ *
2077
+ * @param name The Kafka topic name as defined in the AsyncAPI specification.
2078
+ * @returns A `KafkaTopic` scoped to the given topic name.
2079
+ *
2080
+ * @example
2081
+ * import { app } from 'mokapi'
2082
+ * export default function() {
2083
+ * app.api('Order Events').kafka()
2084
+ * .topic('order-placed')
2085
+ * .message((msg) => { console.log(msg.value) })
2086
+ * .produce({ data: { id: 1 } })
2087
+ * }
2088
+ */
2089
+ topic(name: string): KafkaTopic
2090
+
2091
+ /**
2092
+ * Registers a handler for incoming messages across all topics.
2093
+ *
2094
+ * The handler can read and modify the message before it is processed.
2095
+ * Use `topic()` to scope the handler to a specific topic.
2096
+ *
2097
+ * @param handler The event handler to invoke for each incoming message.
2098
+ * @param opts Optional handler configuration such as priority and tracking.
2099
+ * @returns This `KafkaRouter` instance for chaining.
2100
+ *
2101
+ * @example
2102
+ * import { app } from 'mokapi'
2103
+ * export default function() {
2104
+ * app.kafka().message((msg) => {
2105
+ * // Add a correlation ID to every message across all topics
2106
+ * msg.headers = { ...msg.headers, correlationId: 'abc-123' }
2107
+ * })
2108
+ * }
2109
+ */
2110
+ message(handler: KafkaEventHandler, opts?: KafkaEventArgs): KafkaRouter
2111
+
2112
+ /**
2113
+ * Produces one or more messages to the given Kafka topic synchronously.
2114
+ *
2115
+ * If neither `value` nor `data` is set on a message, Mokapi generates
2116
+ * a random valid value based on the AsyncAPI schema definition.
2117
+ *
2118
+ * Use `topic()` to scope the produce to a specific topic without
2119
+ * repeating the topic name.
2120
+ *
2121
+ * Use `produceAsync()` if you need to await the result.
2122
+ *
2123
+ * @param topic The Kafka topic name to produce to.
2124
+ * @param message One or more messages to produce.
2125
+ * @param opts Optional configuration including a result callback and retry settings.
2126
+ * @returns This `KafkaRouter` instance for chaining.
2127
+ *
2128
+ * @example
2129
+ * // Produce a single message with explicit data
2130
+ * app.kafka().produce('order-placed', { data: { id: 1 } })
2131
+ *
2132
+ * @example
2133
+ * // Produce a message with a result callback
2134
+ * app.kafka().produce('order-placed', { data: { id: 1 } }, {
2135
+ * result: (r) => console.log(r.messages[0].offset)
2136
+ * })
2137
+ *
2138
+ * @example
2139
+ * // Produce multiple messages
2140
+ * app.kafka().produce('order-placed', [
2141
+ * { data: { id: 1 } },
2142
+ * { data: { id: 2 } },
2143
+ * {} // random generated value
2144
+ * ])
2145
+ */
2146
+ produce(topic: string, message: KafkaProduceMessage | KafkaProduceMessage[], opts?: KafkaProduceArgs): KafkaRouter
2147
+
2148
+ /**
2149
+ * Produces one or more messages to the given Kafka topic asynchronously.
2150
+ *
2151
+ * Use this when you need to await the produce result, for example to
2152
+ * read the assigned offset before continuing.
2153
+ *
2154
+ * If neither `value` nor `data` is set on a message, Mokapi generates
2155
+ * a random valid value based on the AsyncAPI schema definition.
2156
+ *
2157
+ * @param topic The Kafka topic name to produce to.
2158
+ * @param message One or more messages to produce.
2159
+ * @param opts Optional configuration including a result callback and retry settings.
2160
+ * @returns A `Promise` resolving to this `KafkaRouter` instance for chaining.
2161
+ *
2162
+ * @example
2163
+ * import { app } from 'mokapi'
2164
+ * export default async function() {
2165
+ * await app.kafka().produceAsync('order-placed', { data: { id: 1 } }, {
2166
+ * result: (r) => console.log(r.messages[0].offset)
2167
+ * })
2168
+ * }
2169
+ */
2170
+ produceAsync(topic: string, message: KafkaProduceMessage | KafkaProduceMessage[], opts?: KafkaProduceArgs): Promise<KafkaRouter>
2171
+ }
2172
+
2173
+ /**
2174
+ * Represents a single Kafka topic within a `KafkaRouter`,
2175
+ * allowing message handlers and producers to be registered
2176
+ * via method chaining.
2177
+ *
2178
+ * Obtain a `KafkaTopic` via `router.topic(name)`.
2179
+ *
2180
+ * All methods return `this`, enabling fluent chaining:
2181
+ * ```ts
2182
+ * router.topic('order-placed')
2183
+ * .message(handler)
2184
+ * .produce({ data: { id: 1 } })
2185
+ * ```
2186
+ *
2187
+ * @example
2188
+ * import { app } from 'mokapi'
2189
+ * export default function() {
2190
+ * app.api('Order Events').kafka()
2191
+ * .topic('order-placed')
2192
+ * .message((msg) => {
2193
+ * // Modify incoming messages for this topic
2194
+ * msg.headers = { ...msg.headers, processed: 'true' }
2195
+ * })
2196
+ * .produce({ data: { id: 1 } })
2197
+ * }
2198
+ */
2199
+ export interface KafkaTopic {
2200
+
2201
+ /**
2202
+ * Registers a handler for incoming messages on this topic.
2203
+ *
2204
+ * The handler can read and modify the message before it is processed.
2205
+ * Multiple handlers can be registered and run in registration order.
2206
+ *
2207
+ * @param handler The event handler to invoke for each incoming message.
2208
+ * @param opts Optional handler configuration such as priority and tracking.
2209
+ * @returns This `KafkaTopic` instance for chaining.
2210
+ *
2211
+ * @example
2212
+ * app.api('Order Events').kafka()
2213
+ * .topic('order-placed')
2214
+ * .message((msg) => {
2215
+ * msg.headers = { ...msg.headers, correlationId: 'abc-123' }
2216
+ * })
2217
+ */
2218
+ message(handler: KafkaEventHandler, opts?: KafkaEventArgs): KafkaTopic
2219
+
2220
+ /**
2221
+ * Produces one or more messages to this topic synchronously.
2222
+ *
2223
+ * If neither `value` nor `data` is set on a message, Mokapi generates
2224
+ * a random valid value based on the AsyncAPI schema definition.
2225
+ *
2226
+ * Use `produceAsync()` if you need to await the result.
2227
+ *
2228
+ * @param message One or more messages to produce.
2229
+ * @param opts Optional configuration including a result callback and retry settings.
2230
+ * @returns This `KafkaTopic` instance for chaining.
2231
+ *
2232
+ * @example
2233
+ * app.api('Order Events').kafka()
2234
+ * .topic('order-placed')
2235
+ * .produce({ data: { id: 1 } })
2236
+ *
2237
+ * @example
2238
+ * // Produce with result callback
2239
+ * app.api('Order Events').kafka()
2240
+ * .topic('order-placed')
2241
+ * .produce({ data: { id: 1 } }, {
2242
+ * result: (r) => console.log(r.messages[0].offset)
2243
+ * })
2244
+ */
2245
+ produce(message: KafkaProduceMessage | KafkaProduceMessage[], opts?: KafkaProduceArgs): KafkaTopic
2246
+
2247
+ /**
2248
+ * Produces one or more messages to this topic asynchronously.
2249
+ *
2250
+ * Use this when you need to await the produce result, for example to
2251
+ * read the assigned offset before continuing.
2252
+ *
2253
+ * If neither `value` nor `data` is set on a message, Mokapi generates
2254
+ * a random valid value based on the AsyncAPI schema definition.
2255
+ *
2256
+ * @param message One or more messages to produce.
2257
+ * @param opts Optional configuration including a result callback and retry settings.
2258
+ * @returns A `Promise` resolving to this `KafkaTopic` instance for chaining.
2259
+ *
2260
+ * @example
2261
+ * import { app } from 'mokapi'
2262
+ * export default async function() {
2263
+ * await app.api('Order Events').kafka()
2264
+ * .topic('order-placed')
2265
+ * .produceAsync({ data: { id: 1 } }, {
2266
+ * result: (r) => console.log(r.messages[0].offset)
2267
+ * })
2268
+ * }
2269
+ */
2270
+ produceAsync(message: KafkaProduceMessage | KafkaProduceMessage[], opts?: KafkaProduceArgs): Promise<KafkaTopic>
2271
+ }
2272
+
2273
+ /**
2274
+ * Represents a single Kafka message to be produced via `produce()` or `produceAsync()`.
2275
+ *
2276
+ * At least one of `data` or `value` should be set. If neither is provided,
2277
+ * Mokapi generates a random valid value based on the AsyncAPI schema definition.
2278
+ *
2279
+ * Use `data` when the topic has a schema defined — Mokapi handles validation
2280
+ * and serialization. Use `value` when you need full control over the raw bytes
2281
+ * written to Kafka.
2282
+ *
2283
+ * @example
2284
+ * // Schema-based encoding via data
2285
+ * app.kafka().produce('order-placed', {
2286
+ * key: 'order-1',
2287
+ * data: { id: 1, item: 'Book' }
2288
+ * })
2289
+ *
2290
+ * @example
2291
+ * // Raw value — written as-is
2292
+ * app.kafka().produce('order-placed', {
2293
+ * key: 'order-1',
2294
+ * value: 'raw-string-payload'
2295
+ * })
2296
+ *
2297
+ * @example
2298
+ * // Random generated value — neither data nor value set
2299
+ * app.kafka().produce('order-placed', {})
2300
+ *
2301
+ * @example
2302
+ * // With headers and explicit partition
2303
+ * app.kafka().produce('order-placed', {
2304
+ * partition: 0,
2305
+ * key: 'order-1',
2306
+ * data: { id: 1 },
2307
+ * headers: { correlationId: 'abc-123' }
2308
+ * })
2309
+ */
2310
+ export interface KafkaProduceMessage {
2311
+ /**
2312
+ * The zero-based partition index to write the message to.
2313
+ * If not specified, Mokapi selects a partition automatically
2314
+ * based on the message key or topic configuration.
2315
+ */
2316
+ partition?: number;
2317
+
2318
+ /**
2319
+ * The message key used for partitioning and identification.
2320
+ *
2321
+ * If not specified, Mokapi generates a random valid key
2322
+ * based on the topic schema defined in the AsyncAPI specification.
2323
+ *
2324
+ * @example
2325
+ * app.kafka().produce('order-placed', { key: 'order-1', data: { id: 1 } })
2326
+ */
2327
+ key?: any;
2328
+
2329
+ /**
2330
+ * Structured data to be encoded and validated according to the
2331
+ * AsyncAPI schema definition for this topic.
2332
+ *
2333
+ * Mokapi serializes this value based on the topic's content type
2334
+ * (e.g. `application/json`) and validates it against the schema
2335
+ * before writing to Kafka.
2336
+ *
2337
+ * If neither `data` nor `value` is set, Mokapi generates a random
2338
+ * valid value based on the AsyncAPI schema definition.
2339
+ *
2340
+ * Prefer `data` over `value` when the topic has a schema defined,
2341
+ * as it ensures the message is valid according to your AsyncAPI contract.
2342
+ *
2343
+ * @example
2344
+ * app.kafka().produce('order-placed', {
2345
+ * data: { id: 1, item: 'Book', quantity: 2 }
2346
+ * })
2347
+ */
2348
+ data?: any;
2349
+
2350
+ /**
2351
+ * Raw value written directly to Kafka without schema validation or encoding.
2352
+ *
2353
+ * Primitives (`string`, `number`, `boolean`, `null`) and `ArrayBuffer`
2354
+ * are written as-is. Objects are JSON-serialized at runtime.
2355
+ *
2356
+ * If neither `value` nor `data` is set, Mokapi generates a random valid
2357
+ * value based on the AsyncAPI schema definition.
2358
+ *
2359
+ * Use `data` instead if you want schema-based encoding and validation.
2360
+ * Use `value` when you need full control over the raw bytes written to Kafka,
2361
+ * for example when testing consumers that expect a specific binary format.
2362
+ *
2363
+ * @example
2364
+ * // Raw string
2365
+ * app.kafka().produce('order-placed', { value: 'raw-payload' })
2366
+ *
2367
+ * @example
2368
+ * // Pre-encoded binary via ArrayBuffer
2369
+ * app.kafka().produce('order-placed', { value: myArrayBuffer })
2370
+ */
2371
+ value?: any;
2372
+
2373
+ /**
2374
+ * Key-value pairs attached to the Kafka message as metadata headers.
2375
+ *
2376
+ * Headers are forwarded as-is and are not validated against the
2377
+ * AsyncAPI specification. Use them for cross-cutting concerns such
2378
+ * as correlation IDs, tracing, or content type hints.
2379
+ *
2380
+ * @example
2381
+ * app.kafka().produce('order-placed', {
2382
+ * data: { id: 1 },
2383
+ * headers: { correlationId: 'abc-123', source: 'mokapi' }
2384
+ * })
2385
+ */
2386
+ headers?: Record<string, any>;
2387
+ }
2388
+
2389
+ /**
2390
+ * Optional configuration for `produce()` and `produceAsync()`.
2391
+ *
2392
+ * Use `result` to inspect the outcome of a produce operation such as
2393
+ * the assigned partition and offset. Use `retry` to configure retry
2394
+ * behavior when the Kafka topic is not yet available.
2395
+ *
2396
+ * @example
2397
+ * // Read the assigned offset after producing
2398
+ * app.kafka().produce('order-placed', { data: { id: 1 } }, {
2399
+ * result: (r) => console.log(`Written to offset ${r.messages[0].offset}`)
2400
+ * })
2401
+ *
2402
+ * @example
2403
+ * // Retry up to 10 times with a 5 second initial wait
2404
+ * app.kafka().produce('order-placed', { data: { id: 1 } }, {
2405
+ * retry: { retries: 10, initialRetryTime: '5s' }
2406
+ * })
2407
+ */
2408
+ export interface KafkaProduceArgs {
2409
+ /**
2410
+ * Callback invoked with the produce result after the message has been
2411
+ * successfully written to Kafka.
2412
+ *
2413
+ * Use this to read the assigned partition, offset, key, or value of
2414
+ * each produced message. The callback receives a single `KafkaProduceResult`
2415
+ * containing one `KafkaMessageResult` per produced message.
2416
+ *
2417
+ * @example
2418
+ * app.kafka().produce('order-placed', [
2419
+ * { data: { id: 1 } },
2420
+ * { data: { id: 2 } }
2421
+ * ], {
2422
+ * result: (r) => {
2423
+ * for (const msg of r.messages) {
2424
+ * console.log(`partition=${msg.partition} offset=${msg.offset}`)
2425
+ * }
2426
+ * }
2427
+ * })
2428
+ */
2429
+ result?: (result: KafkaProduceResult) => void
2430
+
2431
+ /**
2432
+ * Retry configuration applied when the script executes before the
2433
+ * Kafka topic is fully set up in Mokapi.
2434
+ *
2435
+ * Mokapi uses an exponential backoff strategy based on these settings.
2436
+ * If all retries are exhausted, the produce operation fails with an error.
2437
+ *
2438
+ * @example
2439
+ * app.kafka().produce('order-placed', { data: { id: 1 } }, {
2440
+ * retry: { retries: 10, maxRetryTime: '60s' }
2441
+ * })
2442
+ */
2443
+ retry?: Retry;
2444
+ }
2445
+
2446
+ /**
2447
+ * The result of a `produce()` or `produceAsync()` operation.
2448
+ *
2449
+ * Contains the cluster and topic where the messages were written,
2450
+ * along with a per-message result including the assigned partition and offset.
2451
+ *
2452
+ * Received via the `result` callback in `KafkaProduceArgs`:
2453
+ *
2454
+ * @example
2455
+ * app.kafka().produce('order-placed', { data: { id: 1 } }, {
2456
+ * result: (r) => {
2457
+ * console.log(r.cluster) // e.g. 'Order Events'
2458
+ * console.log(r.topic) // e.g. 'order-placed'
2459
+ * console.log(r.messages[0].offset) // e.g. 42
2460
+ * }
2461
+ * })
2462
+ *
2463
+ * https://mokapi.io/docs/javascript-api/mokapi-kafka/kafkaproduceresult
2464
+ */
2465
+ export interface KafkaProduceResult {
2466
+ /**
2467
+ * The name of the Kafka cluster (AsyncAPI `info.title`) where
2468
+ * the messages were written.
2469
+ */
2470
+ readonly api: string;
2471
+
2472
+ /**
2473
+ * The name of the Kafka topic where the messages were written.
2474
+ */
2475
+ readonly topic: string;
2476
+
2477
+ /**
2478
+ * One result entry per produced message, in the same order as the
2479
+ * input messages passed to `produce()`.
2480
+ */
2481
+ messages: KafkaMessageResult[];
2482
+ }
2483
+
2484
+ /**
2485
+ * Represents the outcome of producing a single Kafka message.
2486
+ *
2487
+ * One `KafkaMessageResult` is returned per message passed to `produce()`,
2488
+ * accessible via `KafkaProduceResult.messages`.
2489
+ *
2490
+ * @example
2491
+ * app.kafka().produce('order-placed', [
2492
+ * { data: { id: 1 } },
2493
+ * { data: { id: 2 } }
2494
+ * ], {
2495
+ * result: (r) => {
2496
+ * for (const msg of r.messages) {
2497
+ * console.log(`key=${msg.key} partition=${msg.partition} offset=${msg.offset}`)
2498
+ * }
2499
+ * }
2500
+ * })
2501
+ *
2502
+ * https://mokapi.io/docs/javascript-api/mokapi-kafka/kafkamessageresult
2503
+ */
2504
+ export interface KafkaMessageResult {
2505
+ /**
2506
+ * The zero-based index of the Kafka partition where the message was written.
2507
+ */
2508
+ readonly partition: number;
2509
+
2510
+ /**
2511
+ * The unique sequential identifier assigned to the message within its partition.
2512
+ * Use this to track or reference the message after it has been written.
2513
+ */
2514
+ readonly offset: number;
2515
+
2516
+ /**
2517
+ * The key of the written Kafka message as a string.
2518
+ * Reflects the key that was used for partitioning, whether explicitly
2519
+ * set or randomly generated by Mokapi.
2520
+ */
2521
+ readonly key: string;
2522
+
2523
+ /**
2524
+ * The serialized payload of the written Kafka message as a string.
2525
+ * Reflects the encoded form of `data` or `value` as written to Kafka.
2526
+ */
2527
+ readonly value: string;
2528
+
2529
+ /**
2530
+ * The metadata headers attached to the written Kafka message.
2531
+ * Reflects the headers passed in `KafkaProduceMessage.headers`.
2532
+ */
2533
+ readonly headers: { [name: string]: string };
2534
+ }
2535
+
2536
+ /**
2537
+ * Retry configuration for Kafka produce operations.
2538
+ *
2539
+ * Applied when `produce()` or `produceAsync()` is called before the target
2540
+ * Kafka topic is fully initialized in Mokapi. Mokapi retries using an
2541
+ * exponential backoff strategy based on these settings.
2542
+ *
2543
+ * The wait time before each retry is calculated as:
2544
+ * `min(initialRetryTime * factor^attempt, maxRetryTime)`
2545
+ *
2546
+ * @example
2547
+ * // Default retry behavior
2548
+ * app.kafka().produce('order-placed', { data: { id: 1 } }, {
2549
+ * retry: {}
2550
+ * })
2551
+ *
2552
+ * @example
2553
+ * // Custom retry — faster initial retry, more attempts
2554
+ * app.kafka().produce('order-placed', { data: { id: 1 } }, {
2555
+ * retry: {
2556
+ * retries: 10,
2557
+ * initialRetryTime: '500ms',
2558
+ * maxRetryTime: '60s',
2559
+ * factor: 2
2560
+ * }
2561
+ * })
2562
+ */
2563
+ export interface Retry {
2564
+ /**
2565
+ * Maximum total wait time across all retry attempts.
2566
+ *
2567
+ * Accepts milliseconds as a `number` or a duration string such as
2568
+ * `"30s"` or `"2h45m"`. Valid time units are `ns`, `us` (or `µs`),
2569
+ * `ms`, `s`, `m`, `h`.
2570
+ *
2571
+ * @default "30000ms"
2572
+ *
2573
+ * @example
2574
+ * app.kafka().produce('order-placed', {}, { retry: { maxRetryTime: '60s' } })
2575
+ */
2576
+ maxRetryTime?: string | number;
2577
+
2578
+ /**
2579
+ * Wait time before the first retry attempt. Subsequent retries multiply
2580
+ * this value by `factor` on each attempt until `maxRetryTime` is reached.
2581
+ *
2582
+ * Accepts milliseconds as a `number` or a duration string such as
2583
+ * `"200ms"` or `"2s"`. Valid time units are `ns`, `us` (or `µs`),
2584
+ * `ms`, `s`, `m`, `h`.
2585
+ *
2586
+ * @default "200ms"
2587
+ *
2588
+ * @example
2589
+ * app.kafka().produce('order-placed', {}, { retry: { initialRetryTime: '1s' } })
2590
+ */
2591
+ initialRetryTime?: string | number;
2592
+
2593
+ /**
2594
+ * Multiplier applied to the wait time after each retry attempt.
2595
+ *
2596
+ * With the default values, the wait times are:
2597
+ * - 1st retry: 200ms
2598
+ * - 2nd retry: 4 × 200ms = 800ms
2599
+ * - 3rd retry: 4 × 800ms = 3200ms
2600
+ * - ...capped at `maxRetryTime`
2601
+ *
2602
+ * @default 4
2603
+ */
2604
+ factor?: number;
2605
+
2606
+ /**
2607
+ * Maximum number of retry attempts before the produce operation fails.
2608
+ * Set to `0` to disable retries entirely.
2609
+ *
2610
+ * @default 5
2611
+ */
2612
+ retries?: number;
2613
+ }
2614
+
2615
+ /**
2616
+ * Registers and organizes MQTT message handlers and publishers by topic.
2617
+ *
2618
+ * Obtain an `MqttRouter` via `app.mqtt()` or `app.api('My API').mqtt()`.
2619
+ *
2620
+ * Two styles are supported:
2621
+ * - **Shorthand**: `router.publish(message)` — publishes directly without topic scope.
2622
+ * - **Scoped**: `router.topic(name).publish(message)` — groups handlers and publishers under one topic.
2623
+ *
2624
+ * When multiple APIs share the same topic name, use `app.api()` to scope the router
2625
+ * to a specific API title to avoid unintended matches.
2626
+ *
2627
+ * @example
2628
+ * // Shorthand style
2629
+ * import { app } from 'mokapi'
2630
+ * export default function() {
2631
+ * app.api('Smart Home').mqtt()
2632
+ * .message((msg) => { console.log(msg.value) })
2633
+ * .publish({ value: '21.5' })
2634
+ * }
2635
+ *
2636
+ * @example
2637
+ * // Scoped style
2638
+ * import { app } from 'mokapi'
2639
+ * export default function() {
2640
+ * app.api('Smart Home').mqtt()
2641
+ * .topic('sensors/temperature')
2642
+ * .message((msg) => { console.log(`Temperature: ${msg.value}`) })
2643
+ * .publish({ value: '21.5', retain: true })
2644
+ * }
2645
+ */
2646
+ export interface MqttRouter {
2647
+ /**
2648
+ * Returns an `MqttTopicRouter` scoped to the given topic name.
2649
+ *
2650
+ * Use this to register message handlers or publish messages for a specific
2651
+ * MQTT topic using method chaining, without repeating the topic name on every call.
2652
+ *
2653
+ * MQTT topic names support wildcards in subscriptions (`+` for single level,
2654
+ * `#` for multi-level), but for publishing an exact topic name is required.
2655
+ *
2656
+ * @param name The MQTT topic name as defined in the AsyncAPI specification.
2657
+ * @returns An `MqttTopicRouter` scoped to the given topic name.
2658
+ *
2659
+ * @example
2660
+ * import { app } from 'mokapi'
2661
+ * export default function() {
2662
+ * app.api('Smart Home').mqtt()
2663
+ * .topic('sensors/temperature')
2664
+ * .message((msg) => { console.log(`Temperature: ${msg.value}`) })
2665
+ * .publish({ value: '21.5', retain: true })
2666
+ * }
2667
+ */
2668
+ topic(name: string): MqttTopicRouter
2669
+
2670
+ /**
2671
+ * Registers a handler for incoming messages across all topics.
2672
+ *
2673
+ * The handler can read and modify the message before it is processed.
2674
+ * Use `topic()` to scope the handler to a specific topic.
2675
+ *
2676
+ * @param handler The event handler to invoke for each incoming message.
2677
+ * @param opts Optional handler configuration such as priority and tracking.
2678
+ * @returns This `MqttRouter` instance for chaining.
2679
+ *
2680
+ * @example
2681
+ * import { app } from 'mokapi'
2682
+ * export default function() {
2683
+ * app.mqtt().message((msg) => {
2684
+ * console.log(`[${msg.topic}] ${msg.value}`)
2685
+ * })
2686
+ * }
2687
+ */
2688
+ message(handler: MqttEventHandler, opts?: MqttEventArgs): MqttRouter
2689
+
2690
+ /**
2691
+ * Publishes a message to the MQTT broker.
2692
+ *
2693
+ * If neither `value` nor `data` is set, Mokapi generates a random valid
2694
+ * value based on the AsyncAPI schema definition for the topic.
2695
+ *
2696
+ * Use `topic()` to scope the publish to a specific topic without
2697
+ * repeating the topic name. Use `publishAsync()` if you need to await the result.
2698
+ *
2699
+ * @param topic The MQTT topic name to produce to.
2700
+ * @param message The message to publish.
2701
+ * @param opts Optional configuration including a result callback and retry settings.
2702
+ * @returns This `MqttRouter` instance for chaining.
2703
+ *
2704
+ * @example
2705
+ * // Publish a retained message
2706
+ * app.mqtt().publish('sensors/temperature', { value: '21.5', retain: true })
2707
+ *
2708
+ * @example
2709
+ * // Publish with result callback
2710
+ * app.mqtt().publish('sensors/temperature', { value: '21.5' }, {
2711
+ * result: (r) => console.log(`Published to ${r.topic}: ${r.value}`)
2712
+ * })
2713
+ */
2714
+ publish(topic: string, message: MqttPublishMessage, opts?: MqttPublishArgs): MqttRouter
2715
+
2716
+ /**
2717
+ * Publishes a message to the MQTT broker asynchronously.
2718
+ *
2719
+ * Use this when you need to await the publish result, for example to
2720
+ * confirm the topic and value before continuing.
2721
+ *
2722
+ * If neither `value` nor `data` is set, Mokapi generates a random valid
2723
+ * value based on the AsyncAPI schema definition for the topic.
2724
+ *
2725
+ * @param topic The MQTT topic name to publish to.
2726
+ * @param message The message to publish.
2727
+ * @param opts Optional configuration including a result callback and retry settings.
2728
+ * @returns A `Promise` resolving to this `MqttRouter` instance for chaining.
2729
+ *
2730
+ * @example
2731
+ * import { app } from 'mokapi'
2732
+ * export default async function() {
2733
+ * await app.api('Smart Home').mqtt()
2734
+ * .publishAsync('sensors/temperature', { value: '21.5' }, {
2735
+ * result: (r) => console.log(`Published to ${r.topic}: ${r.value}`)
2736
+ * })
2737
+ * }
2738
+ */
2739
+ publishAsync(topic: string, message: MqttPublishMessage, opts?: MqttPublishArgs): Promise<MqttRouter>
2740
+ }
2741
+
2742
+ /**
2743
+ * Represents a single MQTT topic within an `MqttRouter`,
2744
+ * allowing message handlers and publishers to be registered
2745
+ * via method chaining.
2746
+ *
2747
+ * Obtain an `MqttTopicRouter` via `router.topic(name)`.
2748
+ *
2749
+ * All methods return `this`, enabling fluent chaining:
2750
+ * ```ts
2751
+ * router.topic('sensors/temperature')
2752
+ * .message(handler)
2753
+ * .publish({ value: '21.5' })
2754
+ * ```
2755
+ *
2756
+ * @example
2757
+ * import { app } from 'mokapi'
2758
+ * export default function() {
2759
+ * app.api('Smart Home').mqtt()
2760
+ * .topic('sensors/temperature')
2761
+ * .message((msg) => {
2762
+ * console.log(`Temperature reading: ${msg.value}`)
2763
+ * })
2764
+ * .publish({ value: '21.5', retain: true })
2765
+ * }
2766
+ */
2767
+ export interface MqttTopicRouter {
2768
+ /**
2769
+ * Registers a handler for incoming messages on this topic.
2770
+ *
2771
+ * The handler can read and modify the message before it is processed.
2772
+ * Multiple handlers can be registered and run in registration order.
2773
+ *
2774
+ * @param handler The event handler to invoke for each incoming message.
2775
+ * @param opts Optional handler configuration such as priority and tracking.
2776
+ * @returns This `MqttTopicRouter` instance for chaining.
2777
+ *
2778
+ * @example
2779
+ * app.api('Smart Home').mqtt()
2780
+ * .topic('sensors/temperature')
2781
+ * .message((msg) => {
2782
+ * const temp = parseFloat(msg.value)
2783
+ * if (temp > 30) {
2784
+ * console.log('High temperature alert!')
2785
+ * }
2786
+ * })
2787
+ */
2788
+ message(handler: MqttEventHandler, opts?: MqttEventArgs): MqttTopicRouter
2789
+
2790
+ /**
2791
+ * Publishes a message to this topic synchronously.
2792
+ *
2793
+ * If neither `value` nor `data` is set, Mokapi generates a random valid
2794
+ * value based on the AsyncAPI schema definition for this topic.
2795
+ *
2796
+ * Use `publishAsync()` if you need to await the result.
2797
+ *
2798
+ * @param message The message to publish.
2799
+ * @param opts Optional configuration including a result callback and retry settings.
2800
+ * @returns This `MqttTopicRouter` instance for chaining.
2801
+ *
2802
+ * @example
2803
+ * app.api('Smart Home').mqtt()
2804
+ * .topic('sensors/temperature')
2805
+ * .publish({ value: '21.5', retain: true }, {
2806
+ * result: (r) => console.log(`Published to ${r.topic}: ${r.value}`)
2807
+ * })
2808
+ */
2809
+ publish(message: MqttPublishMessage, opts?: MqttPublishArgs): MqttTopicRouter
2810
+
2811
+ /**
2812
+ * Publishes a message to this topic asynchronously.
2813
+ *
2814
+ * Use this when you need to await the publish result, for example to
2815
+ * confirm the topic and value before continuing.
2816
+ *
2817
+ * If neither `value` nor `data` is set, Mokapi generates a random valid
2818
+ * value based on the AsyncAPI schema definition for this topic.
2819
+ *
2820
+ * @param message The message to publish.
2821
+ * @param opts Optional configuration including a result callback and retry settings.
2822
+ * @returns A `Promise` resolving to this `MqttTopicRouter` instance for chaining.
2823
+ *
2824
+ * @example
2825
+ * import { app } from 'mokapi'
2826
+ * export default async function() {
2827
+ * await app.api('Smart Home').mqtt()
2828
+ * .topic('sensors/temperature')
2829
+ * .publishAsync({ value: '21.5' }, {
2830
+ * result: (r) => console.log(`Published to ${r.topic}: ${r.value}`)
2831
+ * })
2832
+ * }
2833
+ */
2834
+ publishAsync(message: MqttPublishMessage, opts?: MqttPublishArgs): Promise<MqttTopicRouter>
2835
+ }
2836
+
2837
+ /**
2838
+ * Represents a single MQTT message to be published via `publish()`.
2839
+ *
2840
+ * At least one of `data` or `value` should be set. If neither is provided,
2841
+ * Mokapi generates a random valid value based on the AsyncAPI schema definition.
2842
+ *
2843
+ * Use `data` when the topic has a schema defined — Mokapi handles validation
2844
+ * and serialization. Use `value` when you need full control over the raw bytes
2845
+ * written to MQTT.
2846
+ *
2847
+ * @example
2848
+ * // Publish with explicit value
2849
+ * app.mqtt().topic('sensors/temperature').publish({ value: '21.5' })
2850
+ *
2851
+ * @example
2852
+ * // Publish a retained message
2853
+ * app.mqtt().topic('sensors/temperature').publish({ value: '21.5', retain: true })
2854
+ *
2855
+ * @example
2856
+ * // Random generated value — value not set
2857
+ * app.mqtt().topic('sensors/temperature').publish({})
2858
+ */
2859
+ export interface MqttPublishMessage {
2860
+ /**
2861
+ * Structured data to be encoded and validated according to the
2862
+ * AsyncAPI schema definition for this topic.
2863
+ *
2864
+ * Mokapi serializes this value based on the topic's content type
2865
+ * (e.g. `application/json`) and validates it against the schema
2866
+ * before writing to MQTT.
2867
+ *
2868
+ * If neither `data` nor `value` is set, Mokapi generates a random
2869
+ * valid value based on the AsyncAPI schema definition.
2870
+ *
2871
+ * Prefer `data` over `value` when the topic has a schema defined,
2872
+ * as it ensures the message is valid according to your AsyncAPI contract.
2873
+ *
2874
+ * @example
2875
+ * app.mqtt().publish('sensors/temperature', {
2876
+ * data: { id: 1, item: 'Book', quantity: 2 }
2877
+ * })
2878
+ */
2879
+ data?: any;
2880
+
2881
+ /**
2882
+ * Raw value written directly to MQTT without schema validation or encoding.
2883
+ *
2884
+ * Primitives (`string`, `number`, `boolean`, `null`) and `ArrayBuffer`
2885
+ * are written as-is. Objects are JSON-serialized at runtime.
2886
+ *
2887
+ * If neither `value` nor `data` is set, Mokapi generates a random valid
2888
+ * value based on the AsyncAPI schema definition.
2889
+ *
2890
+ * Use `data` instead if you want schema-based encoding and validation.
2891
+ * Use `value` when you need full control over the raw bytes written to MQTT,
2892
+ * for example when testing subscribers that expect a specific binary format.
2893
+ *
2894
+ * @example
2895
+ * // Raw string
2896
+ * app.mqtt().publish('sensors/temperature', { value: 'raw-payload' })
2897
+ *
2898
+ * @example
2899
+ * // Pre-encoded binary via ArrayBuffer
2900
+ * app.mqtt().publish('sensors/temperature', { value: myArrayBuffer })
2901
+ */
2902
+ value?: any
2903
+
2904
+ /**
2905
+ * Whether the MQTT broker should retain this message.
2906
+ *
2907
+ * When `true`, the broker stores the message and delivers it immediately
2908
+ * to any new subscriber on this topic. Only the last retained message
2909
+ * per topic is stored.
2910
+ *
2911
+ * @default false
2912
+ *
2913
+ * @example
2914
+ * app.mqtt().topic('sensors/temperature').publish({ value: '21.5', retain: true })
2915
+ */
2916
+ retain?: boolean
2917
+ }
2918
+
2919
+ /**
2920
+ * Optional configuration for `publish()`.
2921
+ *
2922
+ * Use `result` to inspect the outcome of a publish operation.
2923
+ * Use `retry` to configure retry behavior when the MQTT topic is not yet available.
2924
+ *
2925
+ * @example
2926
+ * app.mqtt().topic('sensors/temperature').publish({ value: '21.5' }, {
2927
+ * result: (r) => console.log(`Published to ${r.topic}: ${r.value}`)
2928
+ * })
2929
+ */
2930
+ export interface MqttPublishArgs {
2931
+ /**
2932
+ * Callback invoked with the publish result after the message has been
2933
+ * successfully delivered to the MQTT broker.
2934
+ *
2935
+ * Use this to confirm the topic and value of the published message.
2936
+ *
2937
+ * @example
2938
+ * app.mqtt().publish('sensors/temperature', { value: '21.5' }, {
2939
+ * result: (r) => {
2940
+ * console.log(r.api) // e.g. 'Smart Home'
2941
+ * console.log(r.topic) // e.g. 'sensors/temperature'
2942
+ * console.log(r.value) // e.g. '21.5'
2943
+ * }
2944
+ * })
2945
+ */
2946
+ result?: (result: MqttPublishResult) => void
2947
+
2948
+ /**
2949
+ * Retry configuration applied when the script executes before the
2950
+ * MQTT topic is fully set up in Mokapi.
2951
+ *
2952
+ * Mokapi uses an exponential backoff strategy based on these settings.
2953
+ * If all retries are exhausted, the publish operation fails with an error.
2954
+ *
2955
+ * @example
2956
+ * app.mqtt().publish('sensors/temperature', { value: '21.5' }, {
2957
+ * retry: { retries: 5, initialRetryTime: '1s' }
2958
+ * })
2959
+ */
2960
+ retry?: Retry;
2961
+ }
2962
+
2963
+ /**
2964
+ * The result of a `publish()` operation.
2965
+ *
2966
+ * Contains the API, topic, and value of the published message.
2967
+ * Received via the `result` callback in `MqttPublishArgs`.
2968
+ *
2969
+ * @example
2970
+ * app.mqtt().publish({ value: '21.5' }, {
2971
+ * result: (r) => {
2972
+ * console.log(r.api) // e.g. 'Smart Home'
2973
+ * console.log(r.topic) // e.g. 'sensors/temperature'
2974
+ * console.log(r.value) // e.g. '21.5'
2975
+ * }
2976
+ * })
2977
+ *
2978
+ * https://mokapi.io/docs/javascript-api/mokapi-mqtt/mqttpublishresult
2979
+ */
2980
+ export interface MqttPublishResult {
2981
+ /**
2982
+ * The name of the MQTT API (AsyncAPI `info.title`) where
2983
+ * the message was published.
2984
+ */
2985
+ readonly api: string;
2986
+
2987
+ /**
2988
+ * The name of the MQTT topic where the message was published.
2989
+ */
2990
+ readonly topic: string;
2991
+
2992
+ /**
2993
+ * The payload of the published message as a string.
2994
+ * Reflects the value that was written to the broker, whether
2995
+ * explicitly set or randomly generated by Mokapi.
2996
+ */
2997
+ readonly value: string;
1898
2998
  }