balda 0.0.49 → 0.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +48 -42
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +54 -48
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +123 -50
- package/lib/index.d.ts +123 -50
- package/lib/index.js +54 -48
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -95,12 +95,18 @@ type InferBodyType<T> = T extends RequestSchema ? ValidatedData<T> : unknown;
|
|
|
95
95
|
type InferQueryType<T> = T extends RequestSchema ? ValidatedData<T> : Record<string, string>;
|
|
96
96
|
/**
|
|
97
97
|
* Extracts the body type for a specific HTTP status code from a response map.
|
|
98
|
-
* When the status code has a schema defined, enforces
|
|
98
|
+
* When the status code has a schema defined, enforces type matching with widened
|
|
99
|
+
* literals (string literals → string, number literals → number, etc.) so that
|
|
100
|
+
* natural TypeScript return values like `{ status: "ok" }` are accepted without
|
|
101
|
+
* requiring `as const`.
|
|
99
102
|
* Defaults to `any` when the status code is not present in the map.
|
|
100
103
|
*/
|
|
101
|
-
type
|
|
104
|
+
type WidenLiterals<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends (infer U)[] ? WidenLiterals<U>[] : T extends object ? {
|
|
105
|
+
[K in keyof T]: WidenLiterals<T[K]>;
|
|
106
|
+
} : T;
|
|
107
|
+
type ResponseBodyForStatus<TMap, TStatus extends number> = TStatus extends keyof TMap ? 0 extends 1 & TMap[TStatus] ? any : WidenLiterals<{
|
|
102
108
|
[K in keyof TMap[TStatus]]: TMap[TStatus][K];
|
|
103
|
-
} : any;
|
|
109
|
+
}> : any;
|
|
104
110
|
|
|
105
111
|
type SyncOrAsync<T = void> = T | Promise<T>;
|
|
106
112
|
|
|
@@ -322,14 +328,12 @@ declare class Request<Params extends Record<string, string> = any, TBody = unkno
|
|
|
322
328
|
* @fileParser middleware is required
|
|
323
329
|
*/
|
|
324
330
|
file(fieldName: string): FormFile | null;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
* @cookie middleware is required
|
|
328
|
-
*/
|
|
329
|
-
cookies: Record<string, string>;
|
|
331
|
+
get cookies(): Record<string, string>;
|
|
332
|
+
set cookies(value: Record<string, string>);
|
|
330
333
|
/**
|
|
331
334
|
* The cookie of the request.
|
|
332
335
|
* @cookie middleware is required
|
|
336
|
+
* @throws Error if cookie middleware is not registered
|
|
333
337
|
*/
|
|
334
338
|
cookie(name: string): string | undefined;
|
|
335
339
|
/**
|
|
@@ -337,27 +341,26 @@ declare class Request<Params extends Record<string, string> = any, TBody = unkno
|
|
|
337
341
|
* @timeout middleware is required
|
|
338
342
|
*/
|
|
339
343
|
timeout?: boolean;
|
|
344
|
+
get session(): Record<string, any> | undefined;
|
|
345
|
+
set session(value: Record<string, any> | undefined);
|
|
340
346
|
/**
|
|
341
|
-
*
|
|
342
|
-
* @cookie middleware is required
|
|
343
|
-
* @session middleware is required
|
|
344
|
-
*/
|
|
345
|
-
session?: Record<string, any>;
|
|
346
|
-
/**
|
|
347
|
-
* Shared no-op async function to avoid per-instance closure allocation.
|
|
347
|
+
* Shared throwing functions to avoid per-instance closure allocation.
|
|
348
348
|
* @internal
|
|
349
349
|
*/
|
|
350
|
-
private static readonly
|
|
350
|
+
private static readonly _throwSaveSession;
|
|
351
|
+
private static readonly _throwDestroySession;
|
|
351
352
|
/**
|
|
352
|
-
*
|
|
353
|
+
* Save the current session data.
|
|
353
354
|
* @cookie middleware is required
|
|
354
355
|
* @session middleware is required
|
|
356
|
+
* @throws Error if session middleware is not registered
|
|
355
357
|
*/
|
|
356
358
|
saveSession: () => Promise<void>;
|
|
357
359
|
/**
|
|
358
|
-
*
|
|
360
|
+
* Destroy the current session.
|
|
359
361
|
* @cookie middleware is required
|
|
360
362
|
* @session middleware is required
|
|
363
|
+
* @throws Error if session middleware is not registered
|
|
361
364
|
*/
|
|
362
365
|
destroySession: () => Promise<void>;
|
|
363
366
|
get ip(): string | undefined;
|
|
@@ -1590,6 +1593,67 @@ declare class NativeFs {
|
|
|
1590
1593
|
}
|
|
1591
1594
|
declare const nativeFs: NativeFs;
|
|
1592
1595
|
|
|
1596
|
+
/**
|
|
1597
|
+
* The next function.
|
|
1598
|
+
* This is the function that is passed to the handler function.
|
|
1599
|
+
* It has a pointer to the next middleware or handler function of the middleware chain.
|
|
1600
|
+
*/
|
|
1601
|
+
type NextFunction = () => SyncOrAsync;
|
|
1602
|
+
|
|
1603
|
+
/**
|
|
1604
|
+
* A middleware that carries type information about the properties it adds to the request.
|
|
1605
|
+
* Uses a phantom branded property to flow type info through the type system without runtime cost.
|
|
1606
|
+
*
|
|
1607
|
+
* @template TExtension - The properties this middleware adds to the request object
|
|
1608
|
+
*
|
|
1609
|
+
* @example
|
|
1610
|
+
* ```typescript
|
|
1611
|
+
* const auth = defineMiddleware<{ userId: number }>((req, res, next) => {
|
|
1612
|
+
* req.userId = getUserIdFromToken(req.headers);
|
|
1613
|
+
* return next();
|
|
1614
|
+
* });
|
|
1615
|
+
*
|
|
1616
|
+
* router.get("/profile", { middlewares: [auth] }, (req, res) => {
|
|
1617
|
+
* req.userId; // number — inferred from middleware!
|
|
1618
|
+
* });
|
|
1619
|
+
* ```
|
|
1620
|
+
*/
|
|
1621
|
+
type TypedMiddleware<TExtension extends Record<string, any> = Record<string, never>> = ((req: Request & TExtension, res: Response$1, next: NextFunction) => SyncOrAsync) & {
|
|
1622
|
+
readonly __middlewareExtension?: TExtension;
|
|
1623
|
+
};
|
|
1624
|
+
/**
|
|
1625
|
+
* Helper to create a typed middleware with correct request typing inside the middleware body.
|
|
1626
|
+
* The returned function is branded with the extension type so the router can infer it.
|
|
1627
|
+
*
|
|
1628
|
+
* @template TExtension - The properties this middleware adds to the request
|
|
1629
|
+
* @param fn - The middleware function with typed `req` parameter
|
|
1630
|
+
* @returns A branded middleware carrying the extension type
|
|
1631
|
+
*
|
|
1632
|
+
* @example
|
|
1633
|
+
* ```typescript
|
|
1634
|
+
* const auth = defineMiddleware<{ userId: number }>((req, res, next) => {
|
|
1635
|
+
* req.userId = 123;
|
|
1636
|
+
* return next();
|
|
1637
|
+
* });
|
|
1638
|
+
* ```
|
|
1639
|
+
*/
|
|
1640
|
+
declare function defineMiddleware<TExtension extends Record<string, any>>(fn: (req: Request & TExtension, res: Response$1, next: NextFunction) => SyncOrAsync): TypedMiddleware<TExtension>;
|
|
1641
|
+
/**
|
|
1642
|
+
* Extracts the extension type from a single middleware.
|
|
1643
|
+
* Returns `{}` for unbranded middlewares (backward compatibility).
|
|
1644
|
+
*/
|
|
1645
|
+
type InferMiddlewareExtension<T> = T extends TypedMiddleware<infer E> ? E : {};
|
|
1646
|
+
/**
|
|
1647
|
+
* Combines extension types from a tuple of middlewares into a single intersection type.
|
|
1648
|
+
*
|
|
1649
|
+
* @example
|
|
1650
|
+
* ```typescript
|
|
1651
|
+
* type Ext = InferMiddlewareExtensions<[TypedMiddleware<{ userId: number }>, TypedMiddleware<{ role: string }>]>;
|
|
1652
|
+
* // { userId: number } & { role: string }
|
|
1653
|
+
* ```
|
|
1654
|
+
*/
|
|
1655
|
+
type InferMiddlewareExtensions<T extends readonly any[]> = T extends readonly [infer First, ...infer Rest] ? InferMiddlewareExtension<First> & InferMiddlewareExtensions<Rest> : {};
|
|
1656
|
+
|
|
1593
1657
|
/**
|
|
1594
1658
|
* Singleton that handles the routing of requests to the appropriate handler(s).
|
|
1595
1659
|
*/
|
|
@@ -1607,25 +1671,25 @@ declare class Router {
|
|
|
1607
1671
|
* @param middlewares - Default middlewares to apply to all routes
|
|
1608
1672
|
* @param options - Router configuration options
|
|
1609
1673
|
*/
|
|
1610
|
-
constructor(basePath?: string, middlewares?: ServerRouteMiddleware[]);
|
|
1674
|
+
constructor(basePath?: string, middlewares?: (ServerRouteMiddleware | TypedMiddleware<any>)[]);
|
|
1611
1675
|
/** Returns a shallow copy of all registered routes. */
|
|
1612
1676
|
getRoutes(): Route[];
|
|
1613
1677
|
/**
|
|
1614
1678
|
* Add or update a route
|
|
1615
1679
|
* @internal
|
|
1616
1680
|
*/
|
|
1617
|
-
addOrUpdate(method: HttpMethod, path: string, middleware: ServerRouteMiddleware[], handler: ServerRouteHandler, validationSchemas?: {
|
|
1681
|
+
addOrUpdate(method: HttpMethod, path: string, middleware: (ServerRouteMiddleware | TypedMiddleware<any>)[], handler: ServerRouteHandler, validationSchemas?: {
|
|
1618
1682
|
body?: RequestSchema;
|
|
1619
1683
|
query?: RequestSchema;
|
|
1620
1684
|
all?: RequestSchema;
|
|
1621
|
-
}, swaggerOptions?: SwaggerRouteOptions, responses?: Record<number, RequestSchema
|
|
1685
|
+
}, swaggerOptions?: SwaggerRouteOptions, responses?: Record<number, RequestSchema>, allowUpdate?: boolean): void;
|
|
1622
1686
|
/**
|
|
1623
1687
|
* Find the matching route for the given HTTP method and path.
|
|
1624
1688
|
* Returns the resolved middleware chain, handler, extracted params, and response schemas; or null if not found.
|
|
1625
1689
|
* Uses O(1) cache lookup for static routes, falls back to O(k) tree traversal for dynamic routes.
|
|
1626
1690
|
*/
|
|
1627
1691
|
find(method: string, rawPath: string): {
|
|
1628
|
-
middleware: ServerRouteMiddleware[];
|
|
1692
|
+
middleware: (ServerRouteMiddleware | TypedMiddleware<any>)[];
|
|
1629
1693
|
handler: ServerRouteHandler;
|
|
1630
1694
|
params: Params;
|
|
1631
1695
|
responseSchemas?: RouteResponseSchemas;
|
|
@@ -1640,50 +1704,50 @@ declare class Router {
|
|
|
1640
1704
|
* Register a GET route under this router's base path with type-safe path parameters.
|
|
1641
1705
|
*/
|
|
1642
1706
|
get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1643
|
-
get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll
|
|
1707
|
+
get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1644
1708
|
/**
|
|
1645
1709
|
* Register a POST route under this router's base path with type-safe path parameters.
|
|
1646
1710
|
*/
|
|
1647
1711
|
post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1648
|
-
post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll
|
|
1712
|
+
post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1649
1713
|
/**
|
|
1650
1714
|
* Register a PATCH route under this router's base path with type-safe path parameters.
|
|
1651
1715
|
*/
|
|
1652
1716
|
patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1653
|
-
patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll
|
|
1717
|
+
patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1654
1718
|
/**
|
|
1655
1719
|
* Register a PUT route under this router's base path with type-safe path parameters.
|
|
1656
1720
|
*/
|
|
1657
1721
|
put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1658
|
-
put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll
|
|
1722
|
+
put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1659
1723
|
/**
|
|
1660
1724
|
* Register a DELETE route under this router's base path with type-safe path parameters.
|
|
1661
1725
|
*/
|
|
1662
1726
|
delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1663
|
-
delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll
|
|
1727
|
+
delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1664
1728
|
/**
|
|
1665
1729
|
* Register an OPTIONS route under this router's base path with type-safe path parameters.
|
|
1666
1730
|
*/
|
|
1667
1731
|
options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1668
|
-
options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll
|
|
1732
|
+
options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1669
1733
|
/**
|
|
1670
1734
|
* Register an HEAD route under this router's base path with type-safe path parameters.
|
|
1671
1735
|
*/
|
|
1672
1736
|
head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1673
|
-
head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll
|
|
1737
|
+
head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1674
1738
|
/**
|
|
1675
1739
|
* Create a grouped router that shares a base path and middlewares.
|
|
1676
1740
|
* The callback receives a child router where routes are defined; routes
|
|
1677
1741
|
* are then merged back into the parent with the composed base path and middlewares.
|
|
1678
1742
|
*/
|
|
1679
|
-
group(path: string, middleware: ServerRouteMiddleware[] | ServerRouteMiddleware
|
|
1743
|
+
group(path: string, middleware: (ServerRouteMiddleware | TypedMiddleware<any>)[] | ServerRouteMiddleware | TypedMiddleware<any>, cb: (router: Router) => void): void;
|
|
1680
1744
|
group(path: string, cb: (router: Router) => void): void;
|
|
1681
1745
|
/**
|
|
1682
1746
|
* Apply global middlewares to all routes
|
|
1683
1747
|
* @param middlewares - The middlewares to apply
|
|
1684
1748
|
* @internal
|
|
1685
1749
|
*/
|
|
1686
|
-
applyGlobalMiddlewaresToAllRoutes(middlewares: ServerRouteMiddleware[]): void;
|
|
1750
|
+
applyGlobalMiddlewaresToAllRoutes(middlewares: (ServerRouteMiddleware | TypedMiddleware<any>)[]): void;
|
|
1687
1751
|
private normalizeBasePath;
|
|
1688
1752
|
private joinPath;
|
|
1689
1753
|
/**
|
|
@@ -1702,7 +1766,7 @@ type RouteResponseSchemas = Record<number, RequestSchema>;
|
|
|
1702
1766
|
interface Route {
|
|
1703
1767
|
method: string;
|
|
1704
1768
|
path: string;
|
|
1705
|
-
middleware: ServerRouteMiddleware[];
|
|
1769
|
+
middleware: (ServerRouteMiddleware | TypedMiddleware<any>)[];
|
|
1706
1770
|
handler: ServerRouteHandler;
|
|
1707
1771
|
swaggerOptions?: SwaggerRouteOptions;
|
|
1708
1772
|
/**
|
|
@@ -1772,7 +1836,7 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1772
1836
|
on(event: string, cb: () => SyncOrAsync): void;
|
|
1773
1837
|
once(event: SignalEvent, cb: () => SyncOrAsync): void;
|
|
1774
1838
|
once(event: string, cb: () => SyncOrAsync): void;
|
|
1775
|
-
use(...middlewares: ServerRouteMiddleware[]): void;
|
|
1839
|
+
use(...middlewares: (ServerRouteMiddleware | TypedMiddleware<any>)[]): void;
|
|
1776
1840
|
useExpress(pathOrMiddleware: string | RequestHandler | Router$1, maybeMiddleware?: RequestHandler | Router$1): void;
|
|
1777
1841
|
expressMiddleware(middleware: RequestHandler): ServerRouteMiddleware;
|
|
1778
1842
|
mountExpressRouter(basePath: string, expressRouter: Router$1): void;
|
|
@@ -1780,7 +1844,11 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1780
1844
|
setNotFoundHandler(notFoundHandler?: ServerRouteHandler): void;
|
|
1781
1845
|
beforeStart(hook: ServerHook): void;
|
|
1782
1846
|
listen(cb?: ServerListenCallback): void;
|
|
1783
|
-
waitUntilListening(): Promise<
|
|
1847
|
+
waitUntilListening(): Promise<{
|
|
1848
|
+
port: number;
|
|
1849
|
+
host: string;
|
|
1850
|
+
url: string;
|
|
1851
|
+
}>;
|
|
1784
1852
|
/**
|
|
1785
1853
|
* Closes the server and frees the port
|
|
1786
1854
|
* This method is idempotent and can be called multiple times safely
|
|
@@ -2279,13 +2347,6 @@ type TrustProxyOptions = {
|
|
|
2279
2347
|
hop?: "first" | "last";
|
|
2280
2348
|
};
|
|
2281
2349
|
|
|
2282
|
-
/**
|
|
2283
|
-
* The next function.
|
|
2284
|
-
* This is the function that is passed to the handler function.
|
|
2285
|
-
* It has a pointer to the next middleware or handler function of the middleware chain.
|
|
2286
|
-
*/
|
|
2287
|
-
type NextFunction = () => SyncOrAsync;
|
|
2288
|
-
|
|
2289
2350
|
type ServerHandlerReturnType<TResponseMap extends Record<number, any> = Record<number, any>> = void | Promise<void> | ResponseBodyForStatus<TResponseMap, 200> | Promise<ResponseBodyForStatus<TResponseMap, 200>>;
|
|
2290
2351
|
type ServerPlugin = {
|
|
2291
2352
|
bodyParser?: BodyParserOptions;
|
|
@@ -2522,7 +2583,7 @@ interface ServerInterface {
|
|
|
2522
2583
|
/**
|
|
2523
2584
|
* Register a global middleware to be applied to all routes after the listener is bound, the middleware is applied in the order it is registered
|
|
2524
2585
|
*/
|
|
2525
|
-
use: (middleware: ServerRouteMiddleware) => void;
|
|
2586
|
+
use: (middleware: ServerRouteMiddleware | TypedMiddleware<any>) => void;
|
|
2526
2587
|
/**
|
|
2527
2588
|
* Set the error handler for the server
|
|
2528
2589
|
* @param errorHandler - The error handler to be applied to all routes
|
|
@@ -2564,7 +2625,11 @@ interface ServerInterface {
|
|
|
2564
2625
|
* Use `listen` instead if you want to initialize the server without blocking the event loop
|
|
2565
2626
|
* @warning All routes defined with decorators are defined on this method just before the server starts listening for requests
|
|
2566
2627
|
*/
|
|
2567
|
-
waitUntilListening: () => Promise<
|
|
2628
|
+
waitUntilListening: () => Promise<{
|
|
2629
|
+
port: number;
|
|
2630
|
+
host: string;
|
|
2631
|
+
url: string;
|
|
2632
|
+
}>;
|
|
2568
2633
|
/**
|
|
2569
2634
|
* Closes the server and frees the port
|
|
2570
2635
|
* This method is idempotent and can be called multiple times safely
|
|
@@ -2595,8 +2660,8 @@ interface ServerInterface {
|
|
|
2595
2660
|
*/
|
|
2596
2661
|
exit: (code?: number) => void;
|
|
2597
2662
|
}
|
|
2598
|
-
type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TPath extends string = string, TAll extends RequestSchema | unknown = unknown> = {
|
|
2599
|
-
middlewares?:
|
|
2663
|
+
type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TPath extends string = string, TAll extends RequestSchema | unknown = unknown, TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]> = {
|
|
2664
|
+
middlewares?: TMiddlewares | TypedMiddleware<any>;
|
|
2600
2665
|
body?: TBody;
|
|
2601
2666
|
query?: TQuery;
|
|
2602
2667
|
all?: TAll;
|
|
@@ -2607,7 +2672,7 @@ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Re
|
|
|
2607
2672
|
};
|
|
2608
2673
|
type ServerHook = () => SyncOrAsync;
|
|
2609
2674
|
type SignalEvent = Deno.Signal | NodeJS.Signals;
|
|
2610
|
-
type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TAll extends RequestSchema | unknown = unknown> = (req: Request<ExtractParams<TPath>, TBody extends RequestSchema ? InferBodyType<TBody> : InferBodyType<TAll>, InferQueryType<TQuery> extends Record<string, any> ? InferQueryType<TQuery> : Record<string, unknown
|
|
2675
|
+
type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, TAll extends RequestSchema | unknown = unknown, TMiddlewareExt extends Record<string, any> = Record<string, never>> = (req: Request<ExtractParams<TPath>, TBody extends RequestSchema ? InferBodyType<TBody> : InferBodyType<TAll>, InferQueryType<TQuery> extends Record<string, any> ? InferQueryType<TQuery> : Record<string, unknown>> & TMiddlewareExt, res: Response$1<InferResponseMap<TResponses>>) => ServerHandlerReturnType<InferResponseMap<TResponses>>;
|
|
2611
2676
|
|
|
2612
2677
|
type RunTimeType = "bun" | "node" | "deno";
|
|
2613
2678
|
|
|
@@ -4190,7 +4255,9 @@ declare const compression: (options?: CompressionOptions) => ServerRouteMiddlewa
|
|
|
4190
4255
|
*
|
|
4191
4256
|
* @param options Cookie middleware options
|
|
4192
4257
|
*/
|
|
4193
|
-
declare const cookie: (options?: CookieMiddlewareOptions) =>
|
|
4258
|
+
declare const cookie: (options?: CookieMiddlewareOptions) => TypedMiddleware<{
|
|
4259
|
+
cookies: Record<string, string>;
|
|
4260
|
+
}>;
|
|
4194
4261
|
|
|
4195
4262
|
/**
|
|
4196
4263
|
* CORS plugin
|
|
@@ -4287,7 +4354,11 @@ declare const rateLimiter: (keyOptions?: RateLimiterKeyOptions, storageOptions?:
|
|
|
4287
4354
|
* @param options.store The store to use for the session
|
|
4288
4355
|
* @param options.cookie The cookie options
|
|
4289
4356
|
*/
|
|
4290
|
-
declare const session: (options?: SessionOptions) =>
|
|
4357
|
+
declare const session: (options?: SessionOptions) => TypedMiddleware<{
|
|
4358
|
+
session: Record<string, any>;
|
|
4359
|
+
saveSession: () => Promise<void>;
|
|
4360
|
+
destroySession: () => Promise<void>;
|
|
4361
|
+
}>;
|
|
4291
4362
|
|
|
4292
4363
|
/**
|
|
4293
4364
|
* Creates a static file serving middleware and registers all routes for the given path
|
|
@@ -4311,7 +4382,9 @@ declare const serveStatic: (options: StaticPluginOptions, swaggerOptions?: Swagg
|
|
|
4311
4382
|
* @param options.status The status code to return if the request times out
|
|
4312
4383
|
* @param options.message The message to return if the request times out
|
|
4313
4384
|
*/
|
|
4314
|
-
declare const timeout: (options: TimeoutOptions) =>
|
|
4385
|
+
declare const timeout: (options: TimeoutOptions) => TypedMiddleware<{
|
|
4386
|
+
timeout: boolean;
|
|
4387
|
+
}>;
|
|
4315
4388
|
|
|
4316
4389
|
/**
|
|
4317
4390
|
* Trust proxy plugin middleware, used to trust the proxy headers to get the client ip
|
|
@@ -4532,4 +4605,4 @@ declare enum CacheStatus {
|
|
|
4532
4605
|
*/
|
|
4533
4606
|
declare const router: ClientRouter;
|
|
4534
4607
|
|
|
4535
|
-
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyProvider, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|
|
4608
|
+
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyProvider, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|