@mednours/backon 0.6.0 → 0.7.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.
Files changed (68) hide show
  1. package/README.md +9 -6
  2. package/dist/auth-core.d.ts +25 -0
  3. package/dist/auth-core.d.ts.map +1 -0
  4. package/dist/create-app.d.ts +24 -0
  5. package/dist/create-app.d.ts.map +1 -0
  6. package/dist/define-route.d.ts +38 -0
  7. package/dist/define-route.d.ts.map +1 -0
  8. package/dist/error.d.ts +21 -0
  9. package/dist/error.d.ts.map +1 -0
  10. package/dist/express/create-app.d.ts +36 -0
  11. package/dist/express/create-app.d.ts.map +1 -0
  12. package/dist/express/define-route.d.ts +39 -0
  13. package/dist/express/define-route.d.ts.map +1 -0
  14. package/dist/express/index.d.ts +32 -0
  15. package/dist/express/index.d.ts.map +1 -0
  16. package/dist/express/index.js +496 -0
  17. package/dist/express/logger.d.ts +10 -0
  18. package/dist/express/logger.d.ts.map +1 -0
  19. package/dist/express/openapi.d.ts +21 -0
  20. package/dist/express/openapi.d.ts.map +1 -0
  21. package/dist/express/rate-limit.d.ts +17 -0
  22. package/dist/express/rate-limit.d.ts.map +1 -0
  23. package/dist/express/require-auth.d.ts +17 -0
  24. package/dist/express/require-auth.d.ts.map +1 -0
  25. package/dist/express/router-registry.d.ts +34 -0
  26. package/dist/express/router-registry.d.ts.map +1 -0
  27. package/dist/express/router.d.ts +11 -0
  28. package/dist/express/router.d.ts.map +1 -0
  29. package/dist/express/serve.d.ts +14 -0
  30. package/dist/express/serve.d.ts.map +1 -0
  31. package/dist/express/stream.d.ts +18 -0
  32. package/dist/express/stream.d.ts.map +1 -0
  33. package/dist/express/types.d.ts +33 -0
  34. package/dist/express/types.d.ts.map +1 -0
  35. package/dist/express/upload.d.ts +26 -0
  36. package/dist/express/upload.d.ts.map +1 -0
  37. package/dist/express/websocket.d.ts +25 -0
  38. package/dist/express/websocket.d.ts.map +1 -0
  39. package/dist/index.d.ts +32 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +429 -0
  42. package/dist/logger.d.ts +17 -0
  43. package/dist/logger.d.ts.map +1 -0
  44. package/dist/openapi-core.d.ts +51 -0
  45. package/dist/openapi-core.d.ts.map +1 -0
  46. package/dist/openapi.d.ts +22 -0
  47. package/dist/openapi.d.ts.map +1 -0
  48. package/dist/rate-limit-core.d.ts +27 -0
  49. package/dist/rate-limit-core.d.ts.map +1 -0
  50. package/dist/rate-limit.d.ts +27 -0
  51. package/dist/rate-limit.d.ts.map +1 -0
  52. package/dist/require-auth.d.ts +21 -0
  53. package/dist/require-auth.d.ts.map +1 -0
  54. package/dist/require-env.d.ts +22 -0
  55. package/dist/require-env.d.ts.map +1 -0
  56. package/dist/serve.d.ts +34 -0
  57. package/dist/serve.d.ts.map +1 -0
  58. package/dist/stream.d.ts +17 -0
  59. package/dist/stream.d.ts.map +1 -0
  60. package/dist/types.d.ts +26 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/dist/upload.d.ts +25 -0
  63. package/dist/upload.d.ts.map +1 -0
  64. package/dist/websocket.d.ts +35 -0
  65. package/dist/websocket.d.ts.map +1 -0
  66. package/package.json +55 -24
  67. package/src/serve.ts +62 -12
  68. package/src/websocket.ts +34 -9
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # @mednours/backon
2
2
 
3
- Opinionated backend framework wrapper for Bun. Two adapters, same names,
4
- same JSON error shape, same defaults — pick per project:
3
+ Opinionated backend framework wrapper, Bun-first but Node-compatible. Two
4
+ adapters, same names, same JSON error shape, same defaults — pick per
5
+ project:
5
6
 
6
7
  - `@mednours/backon` (default export) — wraps [Hono](https://hono.dev)
7
8
  - `@mednours/backon/express` — wraps [Express](https://expressjs.com); requires `express`, `cors`, `helmet`, and `compression` as peer dependencies in the consuming project
@@ -27,7 +28,7 @@ app.get(
27
28
  )
28
29
  );
29
30
 
30
- serve(app);
31
+ await serve(app);
31
32
  ```
32
33
 
33
34
  ## What `createApp()` wires in by default
@@ -55,7 +56,9 @@ app.post(
55
56
 
56
57
  ## `serve(app)`
57
58
 
58
- Runs on Bun's native server (Express adapter: Node's http server via Express's own `app.listen`) with graceful shutdown wired to `SIGTERM`/`SIGINT` — new connections stop being accepted and in-flight requests finish before exit.
59
+ Async now (`await` it) — see why below. Runs on `Bun.serve()` when the process is running under Bun (the default, and the faster of the two), or [`@hono/node-server`](https://github.com/honojs/node-server) when it's running under Node instead, detected automatically at call time; the Express adapter always runs on Node's http server via Express's own `app.listen`, since Express has no separate Bun-native path to begin with. Either way, graceful shutdown is wired to `SIGTERM`/`SIGINT` — new connections stop being accepted and in-flight requests finish before exit.
60
+
61
+ `@hono/node-server` is an optional peer dependency — install it yourself (`npm install @hono/node-server` or your package manager's equivalent) only if this app actually runs on Node; Bun-only projects never need it. `serve()` had to become `async` to support this: it dynamically imports whichever of `hono/bun` or `@hono/node-server` the current runtime needs, rather than a static import that would otherwise crash at module-load time under whichever runtime it *doesn't* match (`hono/bun` touches Bun's global at import time, which throws immediately under Node — this used to make importing `@mednours/backon` at all fail under Node, not just calling `serve()`).
59
62
 
60
63
  **Express-specific:** `serve(app)` also registers the central error handler. Do this *after* every route is registered, not inside `createApp()` — Express's error-handling middleware only catches errors from routes registered *before* it, the opposite of Hono's `onError()`. When not using this `serve()` (wrapping the app for a serverless platform, or a `supertest` suite), call `attachErrorHandler(app)` directly, after every route.
61
64
 
@@ -120,7 +123,7 @@ app.use("/auth/login", rateLimit({ windowMs: 60_000, max: 5 })); // tighter limi
120
123
 
121
124
  Registers a WebSocket route with `onOpen`/`onMessage`/`onClose` handlers, each getting a `ws` handle with `.send()`/`.close()`.
122
125
 
123
- On Hono, the handshake happens at `Bun.serve()`'s own level (an HTTP upgrade, not an ordinary request/response cycle), so this only works with the `serve()` this package exports — it passes `hono/bun`'s websocket handler into `Bun.serve()` under the hood. Register it like any other route:
126
+ On Hono, the handshake happens at `Bun.serve()`'s own level (an HTTP upgrade, not an ordinary request/response cycle), so this only works when the app is actually running on Bun with the `serve()` this package exports — it passes `hono/bun`'s websocket handler into `Bun.serve()` under the hood. There's no Node equivalent wired up yet: a `defineWebSocket()` route registered in an app that ends up running under Node (see `serve(app)` above) throws a clear error the moment that specific route is hit, rather than failing at import time or in some more confusing way — the rest of the app is unaffected. Register it like any other route:
124
127
 
125
128
  ```ts
126
129
  app.get("/ws", defineWebSocket({
@@ -212,6 +215,6 @@ serve(app);
212
215
 
213
216
  ## Requirements
214
217
 
215
- Bun >= 1.3. This package ships TypeScript source directly (no build step) since it's Bun-only by design.
218
+ Bun >= 1.3, or Node >= 18.14.1 with [`@hono/node-server`](https://github.com/honojs/node-server) installed (only needed for `serve()` on the Hono adapter — see above; the Express adapter needs nothing extra on Node, it always ran there). Bun consumers resolve straight to this package's TypeScript source with zero build step, via package.json's `"bun"` export condition; Node consumers get a prebuilt `dist/` instead, since Node can't execute this package's `.ts` source directly the way Bun can (Node's own native TypeScript support explicitly excludes anything under `node_modules`).
216
219
 
217
220
  Part of the [backon monorepo](https://github.com/mednours/backon) — see [`create-backon`](https://www.npmjs.com/package/create-backon) to scaffold a new project on top of this.
@@ -0,0 +1,25 @@
1
+ import type { JWTPayload } from "hono/utils/jwt/types";
2
+ import type { SignatureAlgorithm } from "hono/utils/jwt/jwa";
3
+ /**
4
+ * Shared by the Hono and Express requireAuth() middleware — the actual JWT
5
+ * verification is identical, only how each framework reads the incoming
6
+ * request and reports failure differs. Built on hono/jwt's verify() rather
7
+ * than a new dependency, since hono is already a hard dependency of backon
8
+ * regardless of which framework (Hono or Express) a project picked.
9
+ */
10
+ export interface VerifyJwtOptions {
11
+ /** Secret used to verify the token's signature. */
12
+ secret: string;
13
+ /**
14
+ * Algorithm to verify with. Defaults to HS256. Deliberately not inferred
15
+ * from the token's own header — trusting that is how "alg: none" and
16
+ * algorithm-confusion attacks work, so backon always verifies against an
17
+ * algorithm the server chose, never one the token claims for itself.
18
+ */
19
+ alg?: SignatureAlgorithm;
20
+ }
21
+ /** Verifies a JWT's signature and standard claims (exp/nbf/iat), returns its payload. Throws on any failure. */
22
+ export declare function verifyJwt(token: string, options: VerifyJwtOptions): Promise<JWTPayload>;
23
+ /** Pulls the token out of a `Bearer <token>` Authorization header, or undefined if it's missing/malformed. */
24
+ export declare function extractBearerToken(header: string | undefined): string | undefined;
25
+ //# sourceMappingURL=auth-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-core.d.ts","sourceRoot":"","sources":["../src/auth-core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,GAAG,CAAC,EAAE,kBAAkB,CAAC;CAC1B;AAID,gHAAgH;AAChH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAEvF;AAED,8GAA8G;AAC9G,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKjF"}
@@ -0,0 +1,24 @@
1
+ import { Hono } from "hono";
2
+ import type { Env } from "./types";
3
+ export interface CreateAppOptions {
4
+ /**
5
+ * Allowed CORS origins. Defaults to the ALLOWED_ORIGINS env var
6
+ * (comma-separated), and to no origins at all if that's unset — closed by
7
+ * default rather than wide open.
8
+ */
9
+ allowedOrigins?: string[];
10
+ /** Max request body size in bytes. Defaults to 1mb. */
11
+ bodyLimitBytes?: number;
12
+ }
13
+ /**
14
+ * Builds a Hono app pre-wired with backon's opinionated defaults: request
15
+ * logging, secure headers, CORS locked to an allowlist, response
16
+ * compression, a body size cap, a /health route, and a central error handler
17
+ * that turns AppError (or anything else) into a consistent JSON shape.
18
+ *
19
+ * This is the "small opinionated helpers" layer agreed on for v1 — enough to
20
+ * justify a dedicated package instead of importing hono directly, without
21
+ * trying to cover every possible use case up front.
22
+ */
23
+ export declare function createApp(options?: CreateAppOptions): Hono<Env, import("hono/types").BlankSchema, "/">;
24
+ //# sourceMappingURL=create-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAUD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,oDA+CvD"}
@@ -0,0 +1,38 @@
1
+ import type { ZodType } from "zod";
2
+ import type { BackonContext } from "./types";
3
+ /** Zod schemas for the parts of a request worth validating. All optional — skip whatever isn't needed. */
4
+ export interface RouteSchema<B = undefined, Q = undefined, P = undefined> {
5
+ body?: ZodType<B>;
6
+ query?: ZodType<Q>;
7
+ params?: ZodType<P>;
8
+ }
9
+ export interface RouteData<B, Q, P> {
10
+ body: B;
11
+ query: Q;
12
+ params: P;
13
+ }
14
+ export type RouteHandler<B, Q, P> = (c: BackonContext, data: RouteData<B, Q, P>) => Response | Promise<Response>;
15
+ /** A defineRoute()-wrapped handler, carrying its own schema for generateOpenApiSpec() to read back later. */
16
+ export interface RouteHandlerFn {
17
+ (c: BackonContext): Promise<Response>;
18
+ __backonRouteSchema?: RouteSchema<unknown, unknown, unknown>;
19
+ }
20
+ /**
21
+ * Wraps a handler with request validation against zod schemas. On failure,
22
+ * throws AppError(400, ...) with the zod error attached as `details` —
23
+ * createApp()'s error handler turns that into the standard error JSON shape,
24
+ * so individual routes never write their own "if invalid, return 400" code.
25
+ *
26
+ * The schema is also attached to the returned function as
27
+ * `__backonRouteSchema`, purely for generateOpenApiSpec() to read back —
28
+ * nothing about validation depends on it.
29
+ *
30
+ * Usage in a *.controller.ts file:
31
+ *
32
+ * const getTelemetry = defineRoute(
33
+ * { query: z.object({ deviceId: z.string() }) },
34
+ * async (c, { query }) => c.json({ deviceId: query.deviceId })
35
+ * );
36
+ */
37
+ export declare function defineRoute<B = undefined, Q = undefined, P = undefined>(schema: RouteSchema<B, Q, P>, handler: RouteHandler<B, Q, P>): RouteHandlerFn;
38
+ //# sourceMappingURL=define-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../src/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,0GAA0G;AAC1G,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS;IACtE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,CAAC,CAAC;CACX;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAClC,CAAC,EAAE,aAAa,EAChB,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACrB,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAElC,6GAA6G;AAC7G,MAAM,WAAW,cAAc;IAC7B,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtC,mBAAmB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CAC9D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EACrE,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC7B,cAAc,CAqChB"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * AppError is the one type of error backon's error middleware understands as
3
+ * "expected" — it knows the right HTTP status and produces a stable JSON
4
+ * shape. Anything else thrown is treated as a bug: logged at error level and
5
+ * turned into a generic 500 so internals never leak to a client.
6
+ */
7
+ export declare class AppError extends Error {
8
+ readonly statusCode: number;
9
+ readonly code: string;
10
+ readonly details?: unknown;
11
+ constructor(statusCode: number, code: string, message: string, details?: unknown);
12
+ }
13
+ /** Shape every error response is normalized to, expected or not. */
14
+ export interface ErrorResponseBody {
15
+ error: {
16
+ code: string;
17
+ message: string;
18
+ details?: unknown;
19
+ };
20
+ }
21
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEf,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAOjF;AAED,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH"}
@@ -0,0 +1,36 @@
1
+ import { type Express } from "express";
2
+ export interface CreateAppOptions {
3
+ /** Allowed CORS origins. Defaults to ALLOWED_ORIGINS env var (comma-separated), closed by default. */
4
+ allowedOrigins?: string[];
5
+ /** Max request body size in bytes. Defaults to 1mb. */
6
+ bodyLimitBytes?: number;
7
+ }
8
+ /**
9
+ * Builds an Express app pre-wired with the same defaults as the Hono
10
+ * createApp(): request logging, secure headers, an allowlisted CORS policy,
11
+ * compression, a body size cap, and a /health route.
12
+ *
13
+ * NOTABLE DIFFERENCE FROM THE HONO VERSION: the central error handler is
14
+ * NOT registered here. Express identifies error-handling middleware by its
15
+ * 4-argument signature and only lets it catch errors from routes/middleware
16
+ * registered BEFORE it — the opposite of Hono's onError(), which is
17
+ * registration-order-independent. If the error handler were added here,
18
+ * inside createApp(), it would never see errors from routes added
19
+ * afterward in the project's own app.ts, exactly the routes it exists to
20
+ * catch. `serve()` calls attachErrorHandler() automatically, right before
21
+ * starting the server, once every route is guaranteed to already be
22
+ * registered. When not using backon's serve() — e.g. wrapping this app for
23
+ * a serverless handler or a supertest suite — call attachErrorHandler(app)
24
+ * directly, after every route, before the app is used.
25
+ */
26
+ export declare function createApp(options?: CreateAppOptions): Express;
27
+ /**
28
+ * The central error handler, kept separate from createApp() — see the
29
+ * NOTABLE DIFFERENCE note above for why. Turns AppError into the standard
30
+ * `{ error: { code, message, details? } }` shape with its own status code,
31
+ * maps express.json()'s built-in payload-too-large error onto the same
32
+ * shape as the Hono adapter's 413, and turns anything else into a generic
33
+ * 500 without leaking internals.
34
+ */
35
+ export declare function attachErrorHandler(app: Express): void;
36
+ //# sourceMappingURL=create-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/express/create-app.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,OAAO,EAAkD,MAAM,SAAS,CAAC;AAShG,MAAM,WAAW,gBAAgB;IAC/B,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAUD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAuBjE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAwBrD"}
@@ -0,0 +1,39 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ import type { ZodType } from "zod";
3
+ import { type BackonContext } from "./types";
4
+ export interface RouteSchema<B = undefined, Q = undefined, P = undefined> {
5
+ body?: ZodType<B>;
6
+ query?: ZodType<Q>;
7
+ params?: ZodType<P>;
8
+ }
9
+ export interface RouteData<B, Q, P> {
10
+ body: B;
11
+ query: Q;
12
+ params: P;
13
+ }
14
+ /**
15
+ * Unlike the Hono version, an Express handler doesn't return a Response —
16
+ * it sends one as a side effect via ctx.json()/ctx.text() (which call
17
+ * res.json()/res.send() under the hood) and the return value is ignored.
18
+ * Handler bodies still read the same either way — `(c, { body }) =>
19
+ * c.json({...})` — because ctx.json() does the right thing for whichever
20
+ * engine is underneath, even though what "the right thing" means differs.
21
+ */
22
+ export type RouteHandler<B, Q, P> = (c: BackonContext, data: RouteData<B, Q, P>) => unknown | Promise<unknown>;
23
+ /** A defineRoute()-wrapped Express handler, carrying its own schema for generateOpenApiSpec() to read back later. */
24
+ export interface RouteHandlerFn {
25
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
26
+ __backonRouteSchema?: RouteSchema<unknown, unknown, unknown>;
27
+ }
28
+ /**
29
+ * Same contract as the Hono defineRoute: validates body/query/params
30
+ * against zod schemas and throws AppError(400, ...) on failure. Requires
31
+ * createApp()'s express.json() middleware to have already run so
32
+ * req.body is parsed — see create-app.ts.
33
+ *
34
+ * The schema is also attached to the returned function as
35
+ * `__backonRouteSchema`, purely for generateOpenApiSpec() to read back —
36
+ * nothing about validation depends on it.
37
+ */
38
+ export declare function defineRoute<B = undefined, Q = undefined, P = undefined>(schema: RouteSchema<B, Q, P>, handler: RouteHandler<B, Q, P>): RouteHandlerFn;
39
+ //# sourceMappingURL=define-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../../src/express/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS;IACtE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,CAAC,CAAC;CACX;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAClC,CAAC,EAAE,aAAa,EAChB,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACrB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,qHAAqH;AACrH,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,mBAAmB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CAC9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EACrE,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC7B,cAAc,CAuChB"}
@@ -0,0 +1,32 @@
1
+ export { createApp, attachErrorHandler } from "./create-app";
2
+ export type { CreateAppOptions } from "./create-app";
3
+ export { serve } from "./serve";
4
+ export { defineRoute } from "./define-route";
5
+ export type { RouteSchema, RouteData, RouteHandler } from "./define-route";
6
+ export { AppError } from "../error";
7
+ export type { ErrorResponseBody } from "../error";
8
+ export { logger } from "../logger";
9
+ export { requireEnv } from "../require-env";
10
+ export { requireAuth } from "./require-auth";
11
+ export type { VerifyJwtOptions } from "../auth-core";
12
+ export { rateLimit } from "./rate-limit";
13
+ export type { RateLimitOptions } from "./rate-limit";
14
+ export type { BackonContext } from "./types";
15
+ export { Router } from "./router";
16
+ /**
17
+ * Request/Response/NextFunction are for writing plain Express middleware
18
+ * itself — BackonContext only exists inside defineRoute() handlers,
19
+ * middleware always operates at the framework's own req/res/next layer,
20
+ * there's no getting around that by wrapping it.
21
+ */
22
+ export type { Request, Response, NextFunction } from "express";
23
+ export { defineWebSocket } from "./websocket";
24
+ export type { WebSocketHandlers } from "./websocket";
25
+ export { defineStream } from "./stream";
26
+ export type { StreamWriter } from "./stream";
27
+ export { defineUpload } from "./upload";
28
+ export type { UploadOptions, UploadHandler } from "./upload";
29
+ export { generateOpenApiSpec, serveApiDocs } from "./openapi";
30
+ export type { OpenApiOptions } from "../openapi-core";
31
+ export { apiReferenceHtml, apiReferenceHtmlInline } from "../openapi-core";
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;GAKG;AACH,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9D,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC"}