go-mokapi 0.50.0 → 0.51.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/package.json +1 -1
- package/types/index.d.ts +575 -1
- package/types/kafka.d.ts +2 -2
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -227,7 +227,63 @@ export interface HttpResponse {
|
|
|
227
227
|
* }
|
|
228
228
|
* })
|
|
229
229
|
*/
|
|
230
|
-
rebuild
|
|
230
|
+
rebuild(statusCode?: number, contentType?: string): void;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A request-scoped key-value store for passing data between handlers
|
|
234
|
+
* registered on the same route.
|
|
235
|
+
*
|
|
236
|
+
* Use `context` to share state between `use()` middleware and method handlers
|
|
237
|
+
* without relying on external variables. Values are only available for the
|
|
238
|
+
* lifetime of the current request.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* import { app } from 'mokapi'
|
|
242
|
+
* export default function() {
|
|
243
|
+
* app.api('Petstore').http()
|
|
244
|
+
* .route('/pets/{petId}')
|
|
245
|
+
* .use((req, res) => {
|
|
246
|
+
* res.context.user = parseToken(req.header['Authorization'])
|
|
247
|
+
* })
|
|
248
|
+
* .get((req, res) => {
|
|
249
|
+
* res.data = { id: req.path.petId, owner: res.context.user.name }
|
|
250
|
+
* })
|
|
251
|
+
* }
|
|
252
|
+
*/
|
|
253
|
+
context: Record<string, any>
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Stops the handler pipeline for the current route.
|
|
257
|
+
*
|
|
258
|
+
* By default, all handlers registered on a route run in order.
|
|
259
|
+
* Calling `stopPropagation()` prevents any subsequent handlers
|
|
260
|
+
* on the same route from being executed.
|
|
261
|
+
*
|
|
262
|
+
* This is useful for guard logic such as authentication checks,
|
|
263
|
+
* where further processing should be skipped if a condition is not met.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* import { app } from 'mokapi'
|
|
267
|
+
* export default function() {
|
|
268
|
+
* app.api('Petstore').http()
|
|
269
|
+
* .route('/pets/{petId}')
|
|
270
|
+
* .use((req, res) => {
|
|
271
|
+
* if (!req.header['Authorization']) {
|
|
272
|
+
* res.statusCode = 401
|
|
273
|
+
* res.stopPropagation() // get/delete will not run
|
|
274
|
+
* return
|
|
275
|
+
* }
|
|
276
|
+
* res.context.user = parseToken(req.header['Authorization'])
|
|
277
|
+
* })
|
|
278
|
+
* .get((req, res) => {
|
|
279
|
+
* res.data = { id: req.path.petId, owner: res.context.user.name }
|
|
280
|
+
* })
|
|
281
|
+
* .delete((req, res) => {
|
|
282
|
+
* res.statusCode = 204
|
|
283
|
+
* })
|
|
284
|
+
* }
|
|
285
|
+
*/
|
|
286
|
+
stopPropagation(): void
|
|
231
287
|
}
|
|
232
288
|
|
|
233
289
|
/**
|
|
@@ -750,6 +806,18 @@ export interface WebsocketChannel {
|
|
|
750
806
|
*/
|
|
751
807
|
readonly name: string;
|
|
752
808
|
|
|
809
|
+
/**
|
|
810
|
+
* The parameter values extracted from the channel address for this
|
|
811
|
+
* specific channel instance, keyed by parameter name.
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* // channel address: /doc/{roomId}
|
|
815
|
+
* on('websocket', function(event) {
|
|
816
|
+
* console.log(event.channel.params['roomId']) // e.g. "room-1"
|
|
817
|
+
* })
|
|
818
|
+
*/
|
|
819
|
+
readonly params: Record<string, string>;
|
|
820
|
+
|
|
753
821
|
/**
|
|
754
822
|
* All clients currently connected to this channel. Use this for
|
|
755
823
|
* custom fan-out logic beyond what `broadcast` provides — for
|
|
@@ -1322,3 +1390,509 @@ export interface SharedMemory {
|
|
|
1322
1390
|
* ```
|
|
1323
1391
|
*/
|
|
1324
1392
|
export const shared: SharedMemory;
|
|
1393
|
+
|
|
1394
|
+
/**
|
|
1395
|
+
* The central application object for registering HTTP (and future protocol) handlers
|
|
1396
|
+
* in a structured, route-oriented style.
|
|
1397
|
+
*
|
|
1398
|
+
* `app` is a singleton — the same instance is returned every time it is accessed.
|
|
1399
|
+
* Use `app.api()` to scope handlers to a specific API by its OpenAPI `info.title`,
|
|
1400
|
+
* which is required when multiple APIs share the same path.
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* // Without API scope — matches all APIs with this path
|
|
1404
|
+
* import { app } from 'mokapi'
|
|
1405
|
+
* export default function() {
|
|
1406
|
+
* app.http().get('/pets', (req, res) => {
|
|
1407
|
+
* res.data = [{ name: 'Bello' }]
|
|
1408
|
+
* })
|
|
1409
|
+
* }
|
|
1410
|
+
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* // With API scope — only matches the 'Petstore' API
|
|
1413
|
+
* import { app } from 'mokapi'
|
|
1414
|
+
* export default function() {
|
|
1415
|
+
* app.api('Petstore').http().get('/pets', (req, res) => {
|
|
1416
|
+
* res.data = [{ name: 'Bello' }]
|
|
1417
|
+
* })
|
|
1418
|
+
* }
|
|
1419
|
+
*/
|
|
1420
|
+
export const app: App
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* The top-level application interface providing access to protocol routers
|
|
1424
|
+
* and API scoping.
|
|
1425
|
+
*
|
|
1426
|
+
* Use `api()` to narrow handlers to a specific API by its OpenAPI `info.title`.
|
|
1427
|
+
* Use `http()` directly for handlers that apply across all APIs.
|
|
1428
|
+
*/
|
|
1429
|
+
export interface App {
|
|
1430
|
+
/**
|
|
1431
|
+
* Creates or returns a scoped context for the given API title.
|
|
1432
|
+
*
|
|
1433
|
+
* The title must match the `info.title` field in the OpenAPI specification.
|
|
1434
|
+
* Scoping is required when multiple APIs define the same path, to avoid
|
|
1435
|
+
* a handler running for unintended APIs.
|
|
1436
|
+
*
|
|
1437
|
+
* @param title The API title as defined in `info.title` of the OpenAPI spec.
|
|
1438
|
+
* @returns An `ApiScope` bound to the given API title.
|
|
1439
|
+
*
|
|
1440
|
+
* @example
|
|
1441
|
+
* import { app } from 'mokapi'
|
|
1442
|
+
* export default function() {
|
|
1443
|
+
* const petstore = app.api('Petstore')
|
|
1444
|
+
* petstore.http().get('/pets', (req, res) => {
|
|
1445
|
+
* res.data = [{ name: 'Bello' }]
|
|
1446
|
+
* })
|
|
1447
|
+
*
|
|
1448
|
+
* const zoo = app.api('Zoo API')
|
|
1449
|
+
* zoo.http().get('/pets', (req, res) => {
|
|
1450
|
+
* res.data = [{ name: 'Simba' }]
|
|
1451
|
+
* })
|
|
1452
|
+
* }
|
|
1453
|
+
*/
|
|
1454
|
+
api(title: string): ApiScope
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* Returns an `HttpRouter` not bound to any specific API.
|
|
1458
|
+
* Handlers registered here will run for all APIs that match
|
|
1459
|
+
* the given path and method.
|
|
1460
|
+
*
|
|
1461
|
+
* Use this for cross-cutting concerns such as logging, shared headers,
|
|
1462
|
+
* or common error responses.
|
|
1463
|
+
*
|
|
1464
|
+
* @returns An `HttpRouter` with no API scope.
|
|
1465
|
+
*
|
|
1466
|
+
* @example
|
|
1467
|
+
* import { app } from 'mokapi'
|
|
1468
|
+
* export default function() {
|
|
1469
|
+
* app.http().get('/pets', (req, res) => {
|
|
1470
|
+
* res.headers['X-Mock'] = 'true'
|
|
1471
|
+
* })
|
|
1472
|
+
* }
|
|
1473
|
+
*/
|
|
1474
|
+
http(): HttpRouter
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
/**
|
|
1478
|
+
* A scoped application context bound to a specific API by its `info.title`.
|
|
1479
|
+
*
|
|
1480
|
+
* Obtain an `ApiScope` via `app.api('My API')`. All handlers registered
|
|
1481
|
+
* through this scope will only run for requests matched to the named API.
|
|
1482
|
+
*
|
|
1483
|
+
* @example
|
|
1484
|
+
* import { app } from 'mokapi'
|
|
1485
|
+
* export default function() {
|
|
1486
|
+
* const petstore = app.api('Petstore')
|
|
1487
|
+
* petstore.http().route('/pets')
|
|
1488
|
+
* .get((req, res) => { res.data = [] })
|
|
1489
|
+
* .post((req, res) => { res.statusCode = 201 })
|
|
1490
|
+
* }
|
|
1491
|
+
*/
|
|
1492
|
+
export interface ApiScope {
|
|
1493
|
+
/**
|
|
1494
|
+
* Returns an `HttpRouter` scoped to this API.
|
|
1495
|
+
*
|
|
1496
|
+
* Handlers registered on this router will only run for HTTP requests
|
|
1497
|
+
* that are matched to the API identified by this scope's title.
|
|
1498
|
+
*
|
|
1499
|
+
* @returns An `HttpRouter` bound to this API scope.
|
|
1500
|
+
*
|
|
1501
|
+
* @example
|
|
1502
|
+
* import { app } from 'mokapi'
|
|
1503
|
+
* export default function() {
|
|
1504
|
+
* app.api('Petstore').http().get('/pets', (req, res) => {
|
|
1505
|
+
* res.data = [{ name: 'Bello' }]
|
|
1506
|
+
* })
|
|
1507
|
+
* }
|
|
1508
|
+
*/
|
|
1509
|
+
http(): HttpRouter
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
/**
|
|
1513
|
+
* Registers and organizes HTTP event handlers by path, operation, and method.
|
|
1514
|
+
*
|
|
1515
|
+
* Obtain an `HttpRouter` via `app.http()` or `app.api('My API').http()`.
|
|
1516
|
+
*
|
|
1517
|
+
* Two styles are supported:
|
|
1518
|
+
* - **Shorthand**: `router.get(path, handler)` — registers a handler directly for a path and method.
|
|
1519
|
+
* - **Chained**: `router.route(path).get(handler).post(handler)` — groups multiple methods under one path.
|
|
1520
|
+
*
|
|
1521
|
+
* Paths must match the path template defined in the OpenAPI specification,
|
|
1522
|
+
* not the absolute server URL. For example, use `/pets/{petId}`, not `/v1/pets/123`.
|
|
1523
|
+
*
|
|
1524
|
+
* When multiple APIs share the same path, use `app.api()` to scope the router
|
|
1525
|
+
* to a specific API title to avoid unintended matches.
|
|
1526
|
+
*
|
|
1527
|
+
* All methods return `this`, enabling fluent chaining:
|
|
1528
|
+
* ```ts
|
|
1529
|
+
* app.http()
|
|
1530
|
+
* .use(authMiddleware)
|
|
1531
|
+
* .get(listHandler)
|
|
1532
|
+
* .post(createHandler)
|
|
1533
|
+
* ```
|
|
1534
|
+
*
|
|
1535
|
+
* All handlers registered on the same path and method run in registration order
|
|
1536
|
+
* (or by `priority` if specified). The last handler to write wins.
|
|
1537
|
+
*
|
|
1538
|
+
* @example
|
|
1539
|
+
* // Shorthand style
|
|
1540
|
+
* import { app } from 'mokapi'
|
|
1541
|
+
* export default function() {
|
|
1542
|
+
* const router = app.http().api('Petstore')
|
|
1543
|
+
* router.get('/pets', (req, res) => { res.data = [] })
|
|
1544
|
+
* router.post('/pets', (req, res) => { res.statusCode = 201 })
|
|
1545
|
+
* }
|
|
1546
|
+
*
|
|
1547
|
+
* @example
|
|
1548
|
+
* // Chained style
|
|
1549
|
+
* import { app } from 'mokapi'
|
|
1550
|
+
* export default function() {
|
|
1551
|
+
* app.http().api('Petstore')
|
|
1552
|
+
* .route('/pets')
|
|
1553
|
+
* .get((req, res) => { res.data = [] })
|
|
1554
|
+
* .post((req, res) => { res.statusCode = 201 })
|
|
1555
|
+
* }
|
|
1556
|
+
*/
|
|
1557
|
+
export interface HttpRouter {
|
|
1558
|
+
|
|
1559
|
+
/**
|
|
1560
|
+
* Registers a middleware handler that runs for all methods.
|
|
1561
|
+
*
|
|
1562
|
+
* Middleware is useful for shared logic that should execute regardless
|
|
1563
|
+
* of the HTTP method — for example, authentication checks, setting up
|
|
1564
|
+
* `res.ctx`, or adding common response headers.
|
|
1565
|
+
*
|
|
1566
|
+
* Middleware handlers run in registration order relative to other handlers
|
|
1567
|
+
* on the same route. Use `opts.priority` to control ordering explicitly.
|
|
1568
|
+
*
|
|
1569
|
+
* @param handler The middleware handler to invoke.
|
|
1570
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1571
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1572
|
+
*
|
|
1573
|
+
* @example
|
|
1574
|
+
* router
|
|
1575
|
+
* .use((req, res) => {
|
|
1576
|
+
* const token = req.header['Authorization']
|
|
1577
|
+
* if (!token) {
|
|
1578
|
+
* res.statusCode = 401
|
|
1579
|
+
* return
|
|
1580
|
+
* }
|
|
1581
|
+
* res.ctx.user = parseToken(token)
|
|
1582
|
+
* })
|
|
1583
|
+
* .get((req, res) => {
|
|
1584
|
+
* res.data = { id: req.path.petId, owner: res.ctx.user.name }
|
|
1585
|
+
* })
|
|
1586
|
+
*/
|
|
1587
|
+
use(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1588
|
+
|
|
1589
|
+
/**
|
|
1590
|
+
* Returns an `HttpRoute` for the given OpenAPI path template.
|
|
1591
|
+
*
|
|
1592
|
+
* Use this to register multiple method handlers under the same path
|
|
1593
|
+
* using method chaining, or to attach middleware via `.use()`.
|
|
1594
|
+
*
|
|
1595
|
+
* The path must match the path template in the OpenAPI specification,
|
|
1596
|
+
* e.g. `/pets/{petId}`, not the absolute URL.
|
|
1597
|
+
*
|
|
1598
|
+
* @param path The OpenAPI path template, e.g. `/pets/{petId}`.
|
|
1599
|
+
* @returns An `HttpRoute` for the given path.
|
|
1600
|
+
*
|
|
1601
|
+
* @example
|
|
1602
|
+
* router.route('/pets/{petId}')
|
|
1603
|
+
* .use((req, res) => {
|
|
1604
|
+
* if (!req.header['Authorization']) {
|
|
1605
|
+
* res.statusCode = 401
|
|
1606
|
+
* res.stopPropagation() // get/delete will not run
|
|
1607
|
+
* return
|
|
1608
|
+
* }
|
|
1609
|
+
* res.context.user = parseToken(req.header['Authorization'])
|
|
1610
|
+
* })
|
|
1611
|
+
* .get((req, res) => {
|
|
1612
|
+
* res.data = { id: req.path.petId, owner: res.context.user.name }
|
|
1613
|
+
* })
|
|
1614
|
+
* .delete((req, res) => {
|
|
1615
|
+
* res.statusCode = 204
|
|
1616
|
+
* })
|
|
1617
|
+
*/
|
|
1618
|
+
route(path: string): HttpRoute
|
|
1619
|
+
|
|
1620
|
+
/**
|
|
1621
|
+
* Returns an `HttpRoute` matched by the given `operationId` as defined
|
|
1622
|
+
* in the OpenAPI specification.
|
|
1623
|
+
*
|
|
1624
|
+
* Use this as an alternative to `route()` when you prefer to reference
|
|
1625
|
+
* operations by name rather than by path template.
|
|
1626
|
+
*
|
|
1627
|
+
* @param operationId The `operationId` defined in the OpenAPI operation.
|
|
1628
|
+
* @returns An `HttpRoute` for the matching operation.
|
|
1629
|
+
*
|
|
1630
|
+
* @example
|
|
1631
|
+
* import { app } from 'mokapi'
|
|
1632
|
+
* export default function() {
|
|
1633
|
+
* app.api('Petstore').http()
|
|
1634
|
+
* .operation('listPets')
|
|
1635
|
+
* .get((req, res) => { res.data = [] })
|
|
1636
|
+
* }
|
|
1637
|
+
*/
|
|
1638
|
+
operation(operationId: string): HttpRoute
|
|
1639
|
+
|
|
1640
|
+
/**
|
|
1641
|
+
* Narrows this router to a specific API by title.
|
|
1642
|
+
*
|
|
1643
|
+
* This is an alternative to `app.api(title).http()` for cases where
|
|
1644
|
+
* the router is already obtained and you want to further scope it.
|
|
1645
|
+
*
|
|
1646
|
+
* @param title The API title as defined in `info.title` of the OpenAPI spec.
|
|
1647
|
+
* @returns A new `HttpRouter` scoped to the given API title.
|
|
1648
|
+
*
|
|
1649
|
+
* @example
|
|
1650
|
+
* import { app } from 'mokapi'
|
|
1651
|
+
* export default function() {
|
|
1652
|
+
* app.http().api('Petstore').get('/pets', (req, res) => {
|
|
1653
|
+
* res.data = []
|
|
1654
|
+
* })
|
|
1655
|
+
* }
|
|
1656
|
+
*/
|
|
1657
|
+
api(title: string): HttpRouter
|
|
1658
|
+
|
|
1659
|
+
/**
|
|
1660
|
+
* Registers a handler for `GET` requests to the given path.
|
|
1661
|
+
* @param path The OpenAPI path template, e.g. `/pets/{petId}`.
|
|
1662
|
+
* @param handler The event handler to invoke.
|
|
1663
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1664
|
+
*
|
|
1665
|
+
* @example
|
|
1666
|
+
* app.http().get('/pets', (req, res) => { res.data = [] })
|
|
1667
|
+
*/
|
|
1668
|
+
get(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1669
|
+
|
|
1670
|
+
/**
|
|
1671
|
+
* Registers a handler for `POST` requests to the given path.
|
|
1672
|
+
* @param path The OpenAPI path template.
|
|
1673
|
+
* @param handler The event handler to invoke.
|
|
1674
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1675
|
+
*
|
|
1676
|
+
* @example
|
|
1677
|
+
* app.http().post('/pets', (req, res) => { res.statusCode = 201 })
|
|
1678
|
+
*/
|
|
1679
|
+
post(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1680
|
+
|
|
1681
|
+
/**
|
|
1682
|
+
* Registers a handler for `PUT` requests to the given path.
|
|
1683
|
+
* @param path The OpenAPI path template.
|
|
1684
|
+
* @param handler The event handler to invoke.
|
|
1685
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1686
|
+
*/
|
|
1687
|
+
put(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1688
|
+
|
|
1689
|
+
/**
|
|
1690
|
+
* Registers a handler for `PATCH` requests to the given path.
|
|
1691
|
+
* @param path The OpenAPI path template.
|
|
1692
|
+
* @param handler The event handler to invoke.
|
|
1693
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1694
|
+
*/
|
|
1695
|
+
patch(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
* Registers a handler for `DELETE` requests to the given path.
|
|
1699
|
+
* @param path The OpenAPI path template.
|
|
1700
|
+
* @param handler The event handler to invoke.
|
|
1701
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1702
|
+
*/
|
|
1703
|
+
delete(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1704
|
+
|
|
1705
|
+
/**
|
|
1706
|
+
* Registers a handler for `HEAD` requests to the given path.
|
|
1707
|
+
* @param path The OpenAPI path template.
|
|
1708
|
+
* @param handler The event handler to invoke.
|
|
1709
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1710
|
+
*/
|
|
1711
|
+
head(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Registers a handler for `OPTIONS` requests to the given path.
|
|
1715
|
+
* @param path The OpenAPI path template.
|
|
1716
|
+
* @param handler The event handler to invoke.
|
|
1717
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1718
|
+
*/
|
|
1719
|
+
options(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1720
|
+
|
|
1721
|
+
/**
|
|
1722
|
+
* Registers a handler for `TRACE` requests to the given path.
|
|
1723
|
+
* @param path The OpenAPI path template.
|
|
1724
|
+
* @param handler The event handler to invoke.
|
|
1725
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1726
|
+
*/
|
|
1727
|
+
trace(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1728
|
+
|
|
1729
|
+
/**
|
|
1730
|
+
* Registers a handler for `QUERY` requests to the given path.
|
|
1731
|
+
* @param path The OpenAPI path template.
|
|
1732
|
+
* @param handler The event handler to invoke.
|
|
1733
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1734
|
+
*/
|
|
1735
|
+
query(path: string, handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1736
|
+
|
|
1737
|
+
/** Allows registering a handler for any HTTP method, including custom ones.
|
|
1738
|
+
* @example
|
|
1739
|
+
* app.http().purge('/cache', (req, res) => { res.statusCode = 200 })
|
|
1740
|
+
*/
|
|
1741
|
+
[method: string]: any
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
/**
|
|
1745
|
+
* Represents a single route (path or operation) within an `HttpRouter`,
|
|
1746
|
+
* allowing multiple method handlers and middleware to be registered
|
|
1747
|
+
* via method chaining.
|
|
1748
|
+
*
|
|
1749
|
+
* Obtain an `HttpRoute` via `router.route(path)` or `router.operation(operationId)`.
|
|
1750
|
+
*
|
|
1751
|
+
* All methods return `this`, enabling fluent chaining:
|
|
1752
|
+
* ```ts
|
|
1753
|
+
* router.route('/pets')
|
|
1754
|
+
* .use(authMiddleware)
|
|
1755
|
+
* .get(listHandler)
|
|
1756
|
+
* .post(createHandler)
|
|
1757
|
+
* ```
|
|
1758
|
+
*
|
|
1759
|
+
* Handlers registered on the same route run in registration order
|
|
1760
|
+
* (or by `priority`). The last handler to write a value wins.
|
|
1761
|
+
*
|
|
1762
|
+
* Middleware registered via `use()` runs for all methods on this route
|
|
1763
|
+
* and is well suited for shared logic such as authentication,
|
|
1764
|
+
* request context setup, or response enrichment.
|
|
1765
|
+
*
|
|
1766
|
+
* @example
|
|
1767
|
+
* import { app } from 'mokapi'
|
|
1768
|
+
* export default function() {
|
|
1769
|
+
* app.api('Petstore').http()
|
|
1770
|
+
* .route('/pets/{petId}')
|
|
1771
|
+
* .use((req, res) => {
|
|
1772
|
+
* // Runs before get and delete — set up shared context
|
|
1773
|
+
* res.ctx.requestedAt = Date.now()
|
|
1774
|
+
* })
|
|
1775
|
+
* .get((req, res) => {
|
|
1776
|
+
* res.data = { id: req.path.petId, requestedAt: res.ctx.requestedAt }
|
|
1777
|
+
* })
|
|
1778
|
+
* .delete((req, res) => {
|
|
1779
|
+
* res.statusCode = 204
|
|
1780
|
+
* })
|
|
1781
|
+
* }
|
|
1782
|
+
*/
|
|
1783
|
+
export interface HttpRoute {
|
|
1784
|
+
|
|
1785
|
+
/**
|
|
1786
|
+
* Registers a middleware handler that runs for all methods on this route.
|
|
1787
|
+
*
|
|
1788
|
+
* Middleware is useful for shared logic that should execute regardless
|
|
1789
|
+
* of the HTTP method — for example, authentication checks, setting up
|
|
1790
|
+
* `res.ctx`, or adding common response headers.
|
|
1791
|
+
*
|
|
1792
|
+
* Middleware handlers run in registration order relative to other handlers
|
|
1793
|
+
* on the same route. Use `opts.priority` to control ordering explicitly.
|
|
1794
|
+
*
|
|
1795
|
+
* @param handler The middleware handler to invoke.
|
|
1796
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1797
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1798
|
+
*
|
|
1799
|
+
* @example
|
|
1800
|
+
* router.route('/pets/{petId}')
|
|
1801
|
+
* .use((req, res) => {
|
|
1802
|
+
* const token = req.header['Authorization']
|
|
1803
|
+
* if (!token) {
|
|
1804
|
+
* res.statusCode = 401
|
|
1805
|
+
* return
|
|
1806
|
+
* }
|
|
1807
|
+
* res.ctx.user = parseToken(token)
|
|
1808
|
+
* })
|
|
1809
|
+
* .get((req, res) => {
|
|
1810
|
+
* res.data = { id: req.path.petId, owner: res.ctx.user.name }
|
|
1811
|
+
* })
|
|
1812
|
+
*/
|
|
1813
|
+
use(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* Registers a handler for `GET` requests on this route.
|
|
1817
|
+
* @param handler The event handler to invoke.
|
|
1818
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1819
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1820
|
+
*
|
|
1821
|
+
* @example
|
|
1822
|
+
* router.route('/pets').get((req, res) => { res.data = [] })
|
|
1823
|
+
*/
|
|
1824
|
+
get(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1825
|
+
|
|
1826
|
+
/**
|
|
1827
|
+
* Registers a handler for `POST` requests on this route.
|
|
1828
|
+
* @param handler The event handler to invoke.
|
|
1829
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1830
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1831
|
+
*
|
|
1832
|
+
* @example
|
|
1833
|
+
* router.route('/pets').post((req, res) => { res.statusCode = 201 })
|
|
1834
|
+
*/
|
|
1835
|
+
post(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1836
|
+
|
|
1837
|
+
/**
|
|
1838
|
+
* Registers a handler for `PUT` requests on this route.
|
|
1839
|
+
* @param handler The event handler to invoke.
|
|
1840
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1841
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1842
|
+
*/
|
|
1843
|
+
put(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1844
|
+
|
|
1845
|
+
/**
|
|
1846
|
+
* Registers a handler for `PATCH` requests on this route.
|
|
1847
|
+
* @param handler The event handler to invoke.
|
|
1848
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1849
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1850
|
+
*/
|
|
1851
|
+
patch(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* Registers a handler for `DELETE` requests on this route.
|
|
1855
|
+
* @param handler The event handler to invoke.
|
|
1856
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1857
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1858
|
+
*/
|
|
1859
|
+
delete(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1860
|
+
|
|
1861
|
+
/**
|
|
1862
|
+
* Registers a handler for `HEAD` requests on this route.
|
|
1863
|
+
* @param handler The event handler to invoke.
|
|
1864
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1865
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1866
|
+
*/
|
|
1867
|
+
head(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* Registers a handler for `OPTIONS` requests on this route.
|
|
1871
|
+
* @param handler The event handler to invoke.
|
|
1872
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1873
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1874
|
+
*/
|
|
1875
|
+
options(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1876
|
+
|
|
1877
|
+
/**
|
|
1878
|
+
* Registers a handler for `TRACE` requests on this route.
|
|
1879
|
+
* @param handler The event handler to invoke.
|
|
1880
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1881
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1882
|
+
*/
|
|
1883
|
+
trace(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* Registers a handler for `QUERY` requests on this route.
|
|
1887
|
+
* @param handler The event handler to invoke.
|
|
1888
|
+
* @param opts Optional handler configuration such as priority and tracking.
|
|
1889
|
+
* @returns This `HttpRoute` instance for chaining.
|
|
1890
|
+
*/
|
|
1891
|
+
query(handler: HttpEventHandler, opts?: HttpEventArgs): this
|
|
1892
|
+
|
|
1893
|
+
/** Allows registering a handler for any HTTP method, including custom ones such as `PURGE` or `SEARCH`.
|
|
1894
|
+
* @example
|
|
1895
|
+
* router.route('/cache').purge((req, res) => { res.statusCode = 200 })
|
|
1896
|
+
*/
|
|
1897
|
+
[method: string]: any
|
|
1898
|
+
}
|
package/types/kafka.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JSONValue } from ".";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Sends
|
|
4
|
+
* Sends messages to a Kafka topic.
|
|
5
5
|
* https://mokapi.io/docs/javascript-api/mokapi-kafka/produce
|
|
6
6
|
* @param args - ProduceArgs object contains Kafka produce arguments.
|
|
7
7
|
* @returns The produce result.
|
|
@@ -22,7 +22,7 @@ import { JSONValue } from ".";
|
|
|
22
22
|
export function produce(args?: ProduceArgs): ProduceResult;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Sends
|
|
25
|
+
* Sends messages to a Kafka topic asynchronously.
|
|
26
26
|
* https://mokapi.io/docs/javascript-api/mokapi-kafka/produce
|
|
27
27
|
* @param args - ProduceArgs object contains Kafka produce arguments.
|
|
28
28
|
* @returns The produce result.
|