burger-api 0.9.6 → 1.0.0-beta

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 (175) hide show
  1. package/README.md +84 -241
  2. package/dist/src/adapter/bun/index.d.ts +14 -0
  3. package/dist/src/adapter/bun/index.js +73 -0
  4. package/dist/src/adapter/bun/types.d.ts +15 -0
  5. package/dist/src/adapter/bun/types.js +1 -0
  6. package/dist/src/adapter/index.d.ts +1 -0
  7. package/dist/src/adapter/index.js +1 -0
  8. package/dist/src/adapter/types.d.ts +49 -0
  9. package/dist/src/adapter/types.js +1 -0
  10. package/dist/src/adapter/web-standard/fetch-handler.d.ts +39 -0
  11. package/dist/src/adapter/web-standard/fetch-handler.js +54 -0
  12. package/dist/src/adapter/web-standard/index.d.ts +8 -0
  13. package/dist/src/adapter/web-standard/index.js +7 -0
  14. package/dist/src/analysis/route-access-analyzer.d.ts +10 -0
  15. package/dist/src/analysis/route-access-analyzer.js +287 -0
  16. package/dist/src/chain/chain.d.ts +16 -0
  17. package/dist/src/chain/chain.js +17 -0
  18. package/dist/src/chain/flattener.d.ts +3 -0
  19. package/dist/src/chain/flattener.js +78 -0
  20. package/dist/src/chain/node.d.ts +25 -0
  21. package/dist/src/chain/node.js +1 -0
  22. package/dist/src/compiler/conventions.d.ts +67 -0
  23. package/dist/src/compiler/conventions.js +129 -0
  24. package/dist/src/compiler/index.d.ts +13 -0
  25. package/dist/src/compiler/index.js +11 -0
  26. package/dist/src/compiler/module-loader.d.ts +75 -0
  27. package/dist/src/compiler/module-loader.js +276 -0
  28. package/dist/src/compiler/route-module.d.ts +97 -0
  29. package/dist/src/compiler/route-module.js +1 -0
  30. package/dist/src/compiler/route-tree.d.ts +19 -0
  31. package/dist/src/compiler/route-tree.js +28 -0
  32. package/dist/src/compiler/scanner.d.ts +42 -0
  33. package/dist/src/compiler/scanner.js +201 -0
  34. package/dist/src/context/context-set.d.ts +26 -0
  35. package/dist/src/context/context-set.js +45 -0
  36. package/dist/src/context/context.d.ts +357 -0
  37. package/dist/src/context/context.js +401 -0
  38. package/dist/src/context/query-parser.d.ts +23 -0
  39. package/dist/src/context/query-parser.js +132 -0
  40. package/dist/src/context/route-access.d.ts +7 -0
  41. package/dist/src/context/route-access.js +18 -0
  42. package/dist/src/context/types.d.ts +62 -0
  43. package/dist/src/context/types.js +5 -0
  44. package/dist/src/core/asset-mime.d.ts +9 -0
  45. package/dist/src/core/asset-mime.js +35 -0
  46. package/dist/src/core/assets.d.ts +30 -0
  47. package/dist/src/core/assets.js +67 -0
  48. package/dist/src/core/docs-providers.d.ts +13 -0
  49. package/dist/src/core/docs-providers.js +89 -0
  50. package/dist/src/core/embedded-assets.d.ts +18 -0
  51. package/dist/src/core/embedded-assets.js +13 -0
  52. package/dist/src/core/openapi.d.ts +9 -10
  53. package/dist/src/core/openapi.js +333 -127
  54. package/dist/src/core/page-router.d.ts +13 -17
  55. package/dist/src/core/page-router.js +86 -55
  56. package/dist/src/core/server.d.ts +20 -11
  57. package/dist/src/core/server.js +41 -45
  58. package/dist/src/errors/forbidden.d.ts +14 -0
  59. package/dist/src/errors/forbidden.js +16 -0
  60. package/dist/src/errors/http-error.d.ts +47 -0
  61. package/dist/src/errors/http-error.js +146 -0
  62. package/dist/src/errors/method-not-allowed.d.ts +13 -0
  63. package/dist/src/errors/method-not-allowed.js +15 -0
  64. package/dist/src/errors/not-found.d.ts +14 -0
  65. package/dist/src/errors/not-found.js +16 -0
  66. package/dist/src/errors/unauthorized.d.ts +14 -0
  67. package/dist/src/errors/unauthorized.js +16 -0
  68. package/dist/src/index.d.ts +263 -50
  69. package/dist/src/index.js +919 -332
  70. package/dist/src/lifecycle/executor.d.ts +64 -0
  71. package/dist/src/lifecycle/executor.js +201 -0
  72. package/dist/src/lifecycle/hook-runner.d.ts +11 -0
  73. package/dist/src/lifecycle/hook-runner.js +156 -0
  74. package/dist/src/lifecycle/jit.d.ts +50 -0
  75. package/dist/src/lifecycle/jit.js +258 -0
  76. package/dist/src/lifecycle/transform.d.ts +26 -0
  77. package/dist/src/lifecycle/transform.js +99 -0
  78. package/dist/src/lifecycle/types.d.ts +135 -0
  79. package/dist/src/lifecycle/types.js +1 -0
  80. package/dist/src/plugin/composer.d.ts +3 -0
  81. package/dist/src/plugin/composer.js +28 -0
  82. package/dist/src/plugin/registry.d.ts +25 -0
  83. package/dist/src/plugin/registry.js +107 -0
  84. package/dist/src/plugin/types.d.ts +20 -0
  85. package/dist/src/plugin/types.js +1 -0
  86. package/dist/src/router/allow-cache.d.ts +20 -0
  87. package/dist/src/router/allow-cache.js +26 -0
  88. package/dist/src/router/compiler.d.ts +39 -0
  89. package/dist/src/router/compiler.js +817 -0
  90. package/dist/src/router/define.d.ts +67 -0
  91. package/dist/src/router/define.js +34 -0
  92. package/dist/src/router/index.d.ts +6 -0
  93. package/dist/src/router/index.js +5 -0
  94. package/dist/src/router/param-extract.d.ts +33 -0
  95. package/dist/src/router/param-extract.js +87 -0
  96. package/dist/src/router/regex-matcher.d.ts +42 -0
  97. package/dist/src/router/regex-matcher.js +216 -0
  98. package/dist/src/router/router.d.ts +201 -0
  99. package/dist/src/router/router.js +600 -0
  100. package/dist/src/router/static-map.d.ts +39 -0
  101. package/dist/src/router/static-map.js +48 -0
  102. package/dist/src/router/trie.d.ts +69 -0
  103. package/dist/src/router/trie.js +572 -0
  104. package/dist/src/router/types.d.ts +104 -0
  105. package/dist/src/router/types.js +1 -0
  106. package/dist/src/runtime/capabilities.d.ts +29 -0
  107. package/dist/src/runtime/capabilities.js +48 -0
  108. package/dist/src/types/index.d.ts +260 -109
  109. package/dist/src/types/index.js +1 -1
  110. package/dist/src/types/inference.d.ts +78 -0
  111. package/dist/src/types/inference.js +20 -0
  112. package/dist/src/types/openapi-config.d.ts +164 -0
  113. package/dist/src/types/openapi-config.js +8 -0
  114. package/dist/src/utils/env.d.ts +13 -0
  115. package/dist/src/utils/env.js +24 -0
  116. package/dist/src/utils/fs.d.ts +29 -0
  117. package/dist/src/utils/fs.js +75 -0
  118. package/dist/src/utils/index.d.ts +1 -1
  119. package/dist/src/utils/index.js +2 -2
  120. package/dist/src/utils/pathConversion.js +13 -7
  121. package/dist/src/utils/response.d.ts +42 -6
  122. package/dist/src/utils/response.js +172 -7
  123. package/dist/src/utils/routing.d.ts +32 -13
  124. package/dist/src/utils/routing.js +41 -18
  125. package/dist/src/utils/thenable.d.ts +8 -0
  126. package/dist/src/utils/thenable.js +12 -0
  127. package/dist/src/utils/timing-safe.d.ts +9 -0
  128. package/dist/src/utils/timing-safe.js +20 -0
  129. package/dist/src/utils/wildcard.d.ts +2 -9
  130. package/dist/src/utils/wildcard.js +20 -58
  131. package/dist/src/validation/adapter.d.ts +54 -0
  132. package/dist/src/validation/adapter.js +75 -0
  133. package/dist/src/validation/adapters/standard.d.ts +11 -0
  134. package/dist/src/validation/adapters/standard.js +110 -0
  135. package/dist/src/validation/adapters/zod.d.ts +9 -0
  136. package/dist/src/validation/adapters/zod.js +128 -0
  137. package/dist/src/validation/cache.d.ts +26 -0
  138. package/dist/src/validation/cache.js +35 -0
  139. package/dist/src/validation/coerce.d.ts +28 -0
  140. package/dist/src/validation/coerce.js +176 -0
  141. package/dist/src/validation/compiler.d.ts +27 -0
  142. package/dist/src/validation/compiler.js +191 -0
  143. package/dist/src/validation/error.d.ts +69 -0
  144. package/dist/src/validation/error.js +137 -0
  145. package/dist/src/validation/index.d.ts +16 -0
  146. package/dist/src/validation/index.js +12 -0
  147. package/dist/src/validation/response.d.ts +25 -0
  148. package/dist/src/validation/response.js +79 -0
  149. package/dist/src/validation/types.d.ts +148 -0
  150. package/dist/src/validation/types.js +6 -0
  151. package/dist/src/validation/validator.d.ts +39 -0
  152. package/dist/src/validation/validator.js +441 -0
  153. package/dist/src/ws/adapter.d.ts +219 -0
  154. package/dist/src/ws/adapter.js +623 -0
  155. package/dist/src/ws/compiler.d.ts +37 -0
  156. package/dist/src/ws/compiler.js +156 -0
  157. package/dist/src/ws/index.d.ts +11 -0
  158. package/dist/src/ws/index.js +8 -0
  159. package/dist/src/ws/platform.d.ts +81 -0
  160. package/dist/src/ws/platform.js +113 -0
  161. package/dist/src/ws/router.d.ts +48 -0
  162. package/dist/src/ws/router.js +174 -0
  163. package/dist/src/ws/scanner.d.ts +97 -0
  164. package/dist/src/ws/scanner.js +193 -0
  165. package/dist/src/ws/types.d.ts +380 -0
  166. package/dist/src/ws/types.js +213 -0
  167. package/package.json +72 -59
  168. package/dist/src/core/api-router.d.ts +0 -65
  169. package/dist/src/core/api-router.js +0 -264
  170. package/dist/src/core/swagger-ui.d.ts +0 -1
  171. package/dist/src/core/swagger-ui.js +0 -33
  172. package/dist/src/middleware/validator.d.ts +0 -14
  173. package/dist/src/middleware/validator.js +0 -133
  174. package/dist/src/utils/error.d.ts +0 -17
  175. package/dist/src/utils/error.js +0 -63
@@ -0,0 +1,14 @@
1
+ import { HTTPError } from './http-error.js';
2
+ /**
3
+ * 401 Unauthorized — thrown when authentication is missing or invalid.
4
+ *
5
+ * @example
6
+ * throw new UnauthorizedError();
7
+ * throw new UnauthorizedError('Invalid token');
8
+ * throw new UnauthorizedError('Token expired', { cause: jwtError });
9
+ */
10
+ export declare class UnauthorizedError extends HTTPError {
11
+ readonly name = "UnauthorizedError";
12
+ readonly status: 401;
13
+ constructor(message?: string, options?: ErrorOptions);
14
+ }
@@ -0,0 +1,16 @@
1
+ import { HTTPError } from './http-error.js';
2
+ /**
3
+ * 401 Unauthorized — thrown when authentication is missing or invalid.
4
+ *
5
+ * @example
6
+ * throw new UnauthorizedError();
7
+ * throw new UnauthorizedError('Invalid token');
8
+ * throw new UnauthorizedError('Token expired', { cause: jwtError });
9
+ */
10
+ export class UnauthorizedError extends HTTPError {
11
+ name = 'UnauthorizedError';
12
+ status = 401;
13
+ constructor(message, options) {
14
+ super(401, message ?? 'Unauthorized', options);
15
+ }
16
+ }
@@ -1,95 +1,308 @@
1
- import type { ServerOptions } from './types/index';
1
+ import { Server } from './core/server.js';
2
+ import type { Plugin, PluginFactory } from './plugin/types.js';
3
+ import type { Scope } from './chain/node.js';
4
+ import type { ServerOptions, EnvFetchHandler } from './types/index.js';
5
+ import type { WebSocketConfig } from './ws/types.js';
6
+ import type { NodeWsBridge, NodeWsBridgeOptions } from './ws/platform.js';
7
+ /**
8
+ * The narrow surface passed to a `plugins.ts` default export: only
9
+ * `usePlugin()`. Registration runs mid-construction, so `serve()` /
10
+ * `fetchHandler()` etc. are deliberately excluded. Hand-written so `this`
11
+ * stays polymorphic for chained calls (a type-level restriction only).
12
+ */
13
+ export interface PluginRegistrar {
14
+ usePlugin(plugin: Plugin | PluginFactory, scope?: Scope, seed?: string): this;
15
+ }
16
+ /**
17
+ * The narrow surface passed to a `providers.ts` default export — see
18
+ * {@link PluginRegistrar}.
19
+ */
20
+ export interface ProviderRegistrar {
21
+ provide(name: string, service: unknown): this;
22
+ }
2
23
  export declare class Burger {
3
24
  private options;
4
25
  /**
5
26
  * The server instance
6
27
  */
7
28
  private server;
29
+ /** The resolved API directory (dev path). */
30
+ private apiDir?;
8
31
  /**
9
- * The API router instance
32
+ * The API path prefix (dev path).
10
33
  */
11
- private apiRouter?;
34
+ private apiPrefix;
35
+ /** Page router (dev path only, created lazily). */
36
+ private pageRouter?;
37
+ /** The page directory (dev path). */
38
+ private pageDir?;
12
39
  /**
13
- * The page router instance
40
+ * The page path prefix (dev path).
14
41
  */
15
- private pageRouter?;
42
+ private pagePrefix;
43
+ /**
44
+ * The compiled API router: static dispatch (Bun map) plus dynamic and
45
+ * wildcard dispatch (trie).
46
+ */
47
+ private dynamicRouter?;
48
+ /** Structural route tree for introspection/ordering; not on the hot path. */
49
+ private routeTree?;
50
+ /** Plugin registry, populated via `.usePlugin()` before `serve()`. */
51
+ private pluginRegistry;
52
+ /**
53
+ * Pre-routing onRequest hooks (Framework → Plugin → Global) resolved at
54
+ * compile time; shared with the WebSocket upgrade chain so both paths run
55
+ * the same hooks.
56
+ */
57
+ private onRequestHooks;
16
58
  /**
17
- * The global middleware
59
+ * App-level (`src/hooks.ts`) route hooks, retained so WebSocket upgrades
60
+ * run the same transform/beforeRoute chain as HTTP.
18
61
  */
19
- private globalMiddleware;
62
+ private globalRouteHooks?;
63
+ /** Services from `burger.provide()`, injected into `ctx.services`. */
64
+ private providers;
20
65
  /**
21
66
  * The OpenAPI document
22
67
  */
23
68
  private openApiDoc;
24
69
  /**
25
- * The routes object
70
+ * The loaded OpenAPI configuration from openapi.config.ts.
71
+ */
72
+ private openAPIConfig?;
73
+ /**
74
+ * The routes object. API routes are per-method objects (`{ GET, … }`);
75
+ * page/asset/docs routes are plain request handlers.
26
76
  */
27
77
  private routes;
78
+ /** Origin of every registered route path, for collision errors. */
79
+ private routeSources;
80
+ /**
81
+ * Every compiled API path (static + dynamic). Used by `fetchHandler()`
82
+ * to tell API routes apart from Bun-only page entries in `routes`.
83
+ */
84
+ private apiRoutePaths?;
85
+ /**
86
+ * WebSocket directory (dev path)
87
+ */
88
+ private wsDir?;
28
89
  /**
29
- * Pre-computed responses for reuse
90
+ * WebSocket router
30
91
  */
31
- private readonly METHOD_NOT_ALLOWED;
92
+ private wsRouter?;
93
+ /**
94
+ * WebSocket adapter
95
+ */
96
+ private wsAdapter?;
97
+ /**
98
+ * WebSocket config
99
+ */
100
+ private wsConfigOptions?;
101
+ /**
102
+ * Programmatic WebSocket routes
103
+ */
104
+ private programmaticWsRoutes;
32
105
  /**
33
106
  * The not found response
34
107
  */
35
- private readonly NOT_FOUND;
108
+ private readonly notFound;
36
109
  /**
37
110
  * The OpenAPI error response
38
111
  */
39
- private readonly OPENAPI_ERROR;
112
+ private readonly openApiError;
40
113
  /**
41
- * Constructor for the Burger class.
42
- * @param options - The options for the server and router.
43
- * The options object should contain the following properties:
44
- * - port: The port number to listen on.
45
- * - apiDir: The directory path to load API routes from.
46
- * - pageDir: The directory path to load page routes from.
47
- * - middleware: An array of global middleware functions.
114
+ * Set once API routes have been compiled. Guards `processApiRoutes()` from
115
+ * re-running when both `serve()` and `fetchHandler()` are used.
116
+ */
117
+ private routesProcessed;
118
+ /** Set once page + asset routes are registered (serve / fetchHandler). */
119
+ private pagesProcessed?;
120
+ /** Set when the scanned API directory contained no route files. */
121
+ private emptyApiDir?;
122
+ /** Set once convention directory defaults were applied. */
123
+ private conventionDefaultsApplied;
124
+ /**
125
+ * App-level WebSocket hooks (`onOpen` / `onMessage` / `onClose`),
126
+ * applied to every WS route.
127
+ */
128
+ private globalWsHooks?;
129
+ /**
130
+ * @param options Server + router options (port, apiDir, pageDir, wsDir, …).
48
131
  */
49
132
  constructor(options: ServerOptions);
50
133
  /**
51
- * Process the page routes and add them to the routes object
52
- * @returns A promise that resolves to a boolean
134
+ * Registers a plugin; its hooks compile into every route's hook chain with
135
+ * the plugin's scope. Duplicate registrations (same name + seed) are
136
+ * ignored with a warning.
137
+ *
138
+ * @param plugin The plugin object or a factory function returning one.
139
+ * @param scope Optional scope override (default: `'plugin'`).
140
+ * @param seed Optional disambiguation string (e.g. two JWT plugins).
141
+ * @returns `this` for chaining.
53
142
  */
143
+ usePlugin(plugin: Plugin | PluginFactory, scope?: Scope, seed?: string): this;
144
+ /**
145
+ * Registers an application service, injected into `ctx.services` for every
146
+ * request.
147
+ *
148
+ * @param name Service name (accessed as `ctx.services[name]`).
149
+ * @param service The service instance.
150
+ * @returns `this` for chaining.
151
+ */
152
+ provide(name: string, service: unknown): this;
153
+ /**
154
+ * Register a WebSocket route programmatically.
155
+ * @param path Route path (e.g., "/chat", "/notifications/:room")
156
+ * @param handlers WebSocket handler functions
157
+ * @returns `this` for chaining.
158
+ */
159
+ websocket(path: string, handlers: import('./ws/types.js').WebSocketHandlers): this;
160
+ /**
161
+ * Set global WebSocket configuration.
162
+ * @param config WebSocket configuration options
163
+ * @returns `this` for chaining.
164
+ */
165
+ wsConfig(config: WebSocketConfig): this;
166
+ /**
167
+ * Filesystem mode only (no prebuilt `apiRoutes`): unconfigured directories
168
+ * default to the CLI build conventions (`src/api`, `src/pages`,
169
+ * `src/websocket`) when they exist, so dev and production match. Resolved
170
+ * lazily — `node:fs` is never loaded by AOT bundles.
171
+ */
172
+ private applyConventionDefaults;
173
+ /**
174
+ * Wraps a non-API handler (page, asset, OpenAPI spec, docs UI) so
175
+ * global/plugin `onRequest` hooks run for it like for API routes.
176
+ * Registered on the native routes map → invoked with the raw `Request`.
177
+ */
178
+ private withOnRequest;
179
+ /**
180
+ * Registers one route path, failing loud when two sources (API route,
181
+ * page, asset, docs UI, spec) resolve to the same path. Silent overwrites
182
+ * would make one of them unreachable.
183
+ */
184
+ private registerRoute;
185
+ /** Registers page + asset routes once (shared by serve and fetchHandler). */
186
+ private processPageRoutesOnce;
187
+ /** Loads prebuilt or filesystem page routes. */
54
188
  private processPageRoutes;
55
189
  /**
56
- * Process the API routes and add them to the routes object
57
- * @returns A promise that resolves to a boolean
190
+ * Wraps every page handler with a real per-request `BurgerContext` — the
191
+ * same object API routes get — so `ctx.services`, `ctx.query`, `ctx.set`
192
+ * and the delegated `Request` surface work on static pages too. Dynamic
193
+ * pages (`:param`) also get `ctx.params`; static pages seed only the
194
+ * route pattern (`ctx.route.path` derives lazily).
195
+ *
196
+ * Cost per page request: one `BurgerContext` allocation (no parsing).
197
+ * When an onRequest/global-hook wrapper already created the context, the
198
+ * existing instance is re-bound instead of allocated.
58
199
  */
59
- private processApiRoutes;
200
+ private wrapPageHandler;
60
201
  /**
61
- * Process single middleware
62
- * @param request - The request object
63
- * @param middleware - The middleware function
64
- * @param handler - The handler function
65
- * @returns A promise that resolves to a response
202
+ * Pages, assets, the docs UI and the OpenAPI spec answer GET and HEAD
203
+ * only. Every other method gets a 405 with `Allow: GET, HEAD` and the
204
+ * same RFC 9457 body route 405s use. Global/plugin response hooks and
205
+ * onRequest mappers still apply (this runs inside `withOnRequest`).
66
206
  */
67
- private processSingleMiddleware;
207
+ private restrictToGetHead;
68
208
  /**
69
- * Process middleware and handler
209
+ * Registers static asset routes under `{pagePrefix}/assets/*`.
70
210
  *
71
- * How it works:
72
- * 1. Run each middleware in order
73
- * 2. If middleware returns Response → stop and send that response (but still apply "after" functions)
74
- * 3. If middleware returns undefined → continue to next middleware
75
- * 4. If middleware returns function → save it to transform the final response later
76
- * 5. After all middlewares, run the handler
77
- * 6. Apply all saved "after" functions to the response (in reverse order)
211
+ * Production AOT embeds base64 contents (`assetRoutes` from the CLI
212
+ * build); dev reads files from disk per request so edits show.
213
+ */
214
+ private processAssetRoutes;
215
+ /**
216
+ * Compiles the API routes and merges them into the routes map. Static and
217
+ * dynamic (`:param` / `*`) routes both go on Bun's native map; unmatched or
218
+ * loose-trailing-slash requests fall through to `Router.fetch` (the trie).
219
+ * Both paths run the same compiled handler, so dispatch behavior is
220
+ * identical.
221
+ */
222
+ private processApiRoutes;
223
+ /** Loads WebSocket routes (programmatic, prebuilt or file-based). */
224
+ private processWebSocketRoutes;
225
+ /**
226
+ * Builds the Web-Standard fetch handler for this app.
227
+ *
228
+ * Dispatches the raw `Request` through the compiled routes (static map
229
+ * first, then the trie fallback for dynamic/wildcard and loose
230
+ * trailing-slash variants). API routes must be provided AOT (`apiRoutes`)
231
+ * or discovered from the filesystem on first call — never per request.
232
+ *
233
+ * Runtime-agnostic: Bun.serve, Deno.serve, Vercel, Cloudflare Workers and
234
+ * Node 24+. WinterCG bindings (`env`, `executionCtx`) are bound onto the
235
+ * per-request `BurgerContext`. Pages (Bun-only) are not served here.
78
236
  *
79
- * Performance optimizations:
80
- * - Pre-allocated array for "after" functions (avoids dynamic resizing)
81
- * - Fast paths for 0, 1, and 2 middlewares (most common cases)
82
- * - Manual loop unrolling for small counts
83
- * - Minimal branching in hot path
237
+ * ```ts
238
+ * import { Burger, toFetchHandler } from 'burger-api';
239
+ * const burger = new Burger({ apiRoutes });
240
+ * export default { fetch: toFetchHandler(burger) };
241
+ * ```
84
242
  */
85
- private processMiddleware;
243
+ fetchHandler(): Promise<EnvFetchHandler>;
86
244
  /**
87
- * Starts the server and begins listening for incoming requests.
88
- * @param port - The port number to listen on. Defaults to `4000`.
89
- * @param cb - An optional cb function to be executed when the server is listening.
90
- * @returns A Promise that resolves when the server has started listening.
245
+ * Starts the server and listens for requests.
246
+ * @param port Port to listen on (default `4000`).
247
+ * @param cb Called when the server is listening.
91
248
  */
92
249
  serve(port?: number, cb?: () => void): Promise<void>;
250
+ /**
251
+ * The underlying `Server` instance, exposed so callers can stop the
252
+ * server cleanly.
253
+ */
254
+ getServer(): Server | undefined;
255
+ /**
256
+ * Node WebSocket integration: returns a bridge that plugs the framework
257
+ * pipeline into node:http's `'upgrade'` event using a framing library's
258
+ * `WebSocketServer` (e.g. the `ws` package). Call `fetchHandler()` (or
259
+ * `serve()`) first — WebSocket routes are processed there.
260
+ *
261
+ * ```ts
262
+ * import http from 'node:http';
263
+ * import { WebSocketServer } from 'ws';
264
+ *
265
+ * const fetchHandler = await burger.fetchHandler();
266
+ * const bridge = burger.createNodeWsBridge({ WebSocketServer });
267
+ * http.createServer((req, res) => { ... })
268
+ * .on('upgrade', (req, socket, head) =>
269
+ * bridge.handleUpgrade(req, socket, head))
270
+ * .listen(3000);
271
+ * ```
272
+ */
273
+ createNodeWsBridge(options: NodeWsBridgeOptions): NodeWsBridge;
93
274
  }
94
- export { setDir } from './utils/index';
95
- export type { ServerOptions, RequestHandler, BurgerRequest, BurgerNext, Middleware, openapi, RouteDefinition, PageDefinition, } from './types/index';
275
+ export { BurgerContext, setRequestIP } from './context/context.js';
276
+ export { defineRoute, defineHooks } from './router/define.js';
277
+ export type { TypedRouteHooks, HookContext, PreValidationHookContext, } from './router/define.js';
278
+ export { RUNTIME_CAPABILITIES } from './runtime/capabilities.js';
279
+ export type { RuntimeTarget, RuntimeCapability } from './runtime/capabilities.js';
280
+ export type { BurgerServices, BurgerValidated, BurgerEnv, BurgerExecutionContext, BurgerAuthUser, } from './context/context.js';
281
+ export { setDir } from './utils/index.js';
282
+ export { cleanPrefix, normalizePath } from './utils/index.js';
283
+ export { timingSafeEqual } from './utils/timing-safe.js';
284
+ export { HTTPError, renderHTTPError } from './errors/http-error.js';
285
+ export { ASSET_MIME, contentTypeFor } from './core/asset-mime.js';
286
+ export type { EmbeddedAsset, DiskAssetRoute, } from './core/assets.js';
287
+ export { ValidationError } from './validation/error.js';
288
+ export { NotFoundError } from './errors/not-found.js';
289
+ export { UnauthorizedError } from './errors/unauthorized.js';
290
+ export { ForbiddenError } from './errors/forbidden.js';
291
+ export { MethodNotAllowedError } from './errors/method-not-allowed.js';
292
+ export { scalarDocs, swaggerDocs, redocDocs } from './core/docs-providers.js';
293
+ export { toFetchHandler } from './adapter/web-standard/index.js';
294
+ export type { FetchHandlerEntry } from './adapter/web-standard/index.js';
295
+ export type { RuntimeAdapter, AdapterStartOptions, ServerHandle, } from './adapter/types.js';
296
+ export type { BunAdapterStartOptions } from './adapter/bun/types.js';
297
+ export type { ServerInfo } from './types/index.js';
298
+ export type { ServerOptions, RequestHandler, RouteDefinition, RouteSchema, MethodSchema, RouteConfig, BuildConfig, FetchHandler, EnvFetchHandler, PageDefinition, openapi, OpenAPIMeta, RouteHooks, GlobalHooks, TransformMap, ContextSet, RouteMeta, OpenAPIConfig, DocsAuth, DocsProvider, DocsProviderOptions, OpenAPIObject, } from './types/index.js';
299
+ export type { Server } from './core/server.js';
300
+ export type { HTTPMethod, LowercaseHTTPMethod } from './utils/routing.js';
301
+ export type { Hook, ForwardHook, ForwardHookResult, ResponseHook, ResponseHookResult, ErrorHook, } from './lifecycle/types.js';
302
+ export type { ValidationIssue } from './validation/types.js';
303
+ export type { Plugin, PluginFactory } from './plugin/types.js';
304
+ export type { Scope } from './chain/node.js';
305
+ export type { BurgerWS, WebSocketData, WebSocketConfig, WebSocketRouteDefinition, WebSocketHandlers, WebSocketHooks, CompiledWebSocketRoute, WebSocketModule, WebSocketHooksModule, WebSocketConfigModule, } from './ws/types.js';
306
+ export { WebSocketReadyState, WebSocketCloseCode, BurgerWSContext, } from './ws/types.js';
307
+ export { WebSocketAdapter } from './ws/adapter.js';
308
+ export type { WebSocketAdapterOptions } from './ws/adapter.js';