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,104 @@
1
+ import type { RouteDefinition } from '../types/index.js';
2
+ import type { CompiledRouteValidators, ValidatorConfig } from '../validation/types.js';
3
+ import type { ContextInit, RouteAccessInfo, RouteMeta } from '../context/types.js';
4
+ import type { HTTPMethod } from '../utils/routing.js';
5
+ /**
6
+ * A compiled route handler — the same shape for static (Bun-dispatched) and
7
+ * dynamic/wildcard (trie-dispatched) routes, so method dispatch, 405+Allow,
8
+ * auto-HEAD, and lifecycle behavior are identical on both paths.
9
+ *
10
+ * `prebuilt` is the pre-routing `BurgerContext` (created before routing so
11
+ * `onRequest` hooks can seed state); when provided, the handler binds it
12
+ * instead of allocating a second context. `env` / `executionCtx` are the
13
+ * platform bindings forwarded from the serving entry point.
14
+ */
15
+ export type CompiledHandler = (request: Request, ctxInit?: ContextInit, prebuilt?: import('../context/context.js').BurgerContext, env?: import('../context/context.js').BurgerEnv, executionCtx?: import('../context/context.js').BurgerExecutionContext) => Response | Promise<Response>;
16
+ /**
17
+ * A route+method executor specialized at compile time. May return
18
+ * synchronously — a route with an empty hook plan does not force a Promise.
19
+ *
20
+ * `ctxInit` is supplied by the `fetch` fallback (trie / loose-slash); the
21
+ * native Bun path omits it and derives params from Bun's already-decoded
22
+ * `request.params`.
23
+ */
24
+ export type RouteCore = (request: Request, ctxInit?: ContextInit, prebuilt?: import('../context/context.js').BurgerContext, env?: import('../context/context.js').BurgerEnv, executionCtx?: import('../context/context.js').BurgerExecutionContext) => Response | Promise<Response>;
25
+ /** Per-method executors for one route, keyed by HTTP method. */
26
+ export type NativeMethodCores = Partial<Record<HTTPMethod, RouteCore>>;
27
+ /**
28
+ * A Bun `routes` method object value: Bun invokes it with `(request, server)`.
29
+ */
30
+ export type NativeMethodHandler = (request: Request, server?: unknown) => Response | Promise<Response>;
31
+ /**
32
+ * A Bun `routes` method object: one specialized handler per defined method
33
+ * (including the framework's derived `HEAD` and auto `OPTIONS`). A method
34
+ * not present here falls through to the `fetch` fallback, where the
35
+ * trie/static dispatcher answers 405 + Allow.
36
+ */
37
+ export type NativeMethodHandlers = Partial<Record<HTTPMethod, NativeMethodHandler>>;
38
+ /**
39
+ * A route compiled into its dispatch structures.
40
+ */
41
+ export interface CompiledRoute {
42
+ def: RouteDefinition;
43
+ handler: CompiledHandler;
44
+ methods: string[];
45
+ allow: string;
46
+ /** The matched-route identity (`path` + `pattern`), retained for introspection. */
47
+ route?: RouteMeta;
48
+ /** The optional RouteAccessAnalyzer hint (unused at runtime). */
49
+ meta?: RouteAccessInfo;
50
+ /** The precompiled validators for this route. Undefined when the
51
+ * route has no `schema`. Consumed by the validation orchestrator. */
52
+ validators?: CompiledRouteValidators;
53
+ }
54
+ /**
55
+ * The output of a single RouterCompiler.compile pass.
56
+ */
57
+ export interface CompiledRouter {
58
+ staticMap: import('./static-map.js').StaticMap;
59
+ trie: import('./trie.js').Trie;
60
+ allowCache: import('./allow-cache.js').AllowCache;
61
+ /**
62
+ * Native dispatch table for `:param` / `*` routes, keyed by their Bun
63
+ * pattern (e.g. `/users/:id`). Consumed only by the Bun adapter, which
64
+ * registers them on `Bun.serve`'s `routes` map; non-Bun adapters ignore
65
+ * this and dispatch via the trie + `fetch` fallback.
66
+ */
67
+ nativeRoutes: Map<string, CompiledHandler>;
68
+ /**
69
+ * Per-route per-method specialized executors, keyed by path. Used by
70
+ * `Router.staticRoutes()` / `Router.nativeRoutes()` to build Bun method
71
+ * objects; the `fetch` fallback reuses them through `CompiledHandler`s.
72
+ */
73
+ methodCores: Map<string, NativeMethodCores>;
74
+ /**
75
+ * Retained compiled-route metadata (RouteAccessInfo + RouteMeta) keyed by
76
+ * path. Build-time only; never read on the request hot path.
77
+ */
78
+ routes?: Map<string, CompiledRoute>;
79
+ }
80
+ /**
81
+ * Configuration for the Router / RouterCompiler.
82
+ */
83
+ export interface RouterConfig {
84
+ /** When true, the optional RouteAccessAnalyzer is skipped at compile time. */
85
+ debug?: boolean;
86
+ /** validation configuration (coercion / response / errors). */
87
+ validation?: ValidatorConfig;
88
+ /**
89
+ * Dynamic-route dispatch engine for the `fetch` fallback path.
90
+ * - `'auto'` (default) and `'trie'`: the radix trie.
91
+ * - `'regex'`: opt-in RegExp matcher (trie-ordered); falls back to the
92
+ * trie if its build bails out.
93
+ *
94
+ * Static routes are unaffected — they never reach this dispatch.
95
+ */
96
+ engine?: 'auto' | 'regex' | 'trie';
97
+ /**
98
+ * JIT-compile each route's HookPlan into one async function
99
+ * (`lifecycle/jit.ts`). ON by default — capability-probed per process;
100
+ * runtimes without dynamic codegen keep the interpreter. Set `false` to
101
+ * force the interpreter everywhere.
102
+ */
103
+ jit?: boolean;
104
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Runtime-capability model: what each `burger-api build --target` platform
3
+ * supports. Pure data, zero platform imports.
4
+ *
5
+ * Capability is a build-time property, not reliably detectable at request
6
+ * time (Vercel and plain Node look identical via `globalThis`), so a build
7
+ * declares its target up front (`ServerOptions.runtimeTarget`).
8
+ *
9
+ * Single source of truth for the CLI's build-time validation (e.g. rejecting
10
+ * a WebSocket route on `--target=vercel`) and the docs compatibility page.
11
+ */
12
+ export type RuntimeTarget = 'bun' | 'node' | 'cloudflare' | 'deno' | 'vercel';
13
+ export interface RuntimeCapability {
14
+ /** Web-standard HTTP request/response handling. Every target speaks `fetch`. */
15
+ http: true;
16
+ /** Persistent WebSocket upgrades. */
17
+ websocket: boolean;
18
+ /**
19
+ * This target's static-asset story. `'disk'` targets can also serve
20
+ * `burger-api build`'s embedded assets (no fs needed); `'platform-native'`
21
+ * targets should prefer the platform's own static hosting.
22
+ */
23
+ staticFiles: 'disk' | 'platform-native';
24
+ /** Direct filesystem access at request time. */
25
+ filesystem: boolean;
26
+ /** A long-running process rather than a per-invocation cold start. */
27
+ persistentProcess: boolean;
28
+ }
29
+ export declare const RUNTIME_CAPABILITIES: Record<RuntimeTarget, RuntimeCapability>;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Runtime-capability model: what each `burger-api build --target` platform
3
+ * supports. Pure data, zero platform imports.
4
+ *
5
+ * Capability is a build-time property, not reliably detectable at request
6
+ * time (Vercel and plain Node look identical via `globalThis`), so a build
7
+ * declares its target up front (`ServerOptions.runtimeTarget`).
8
+ *
9
+ * Single source of truth for the CLI's build-time validation (e.g. rejecting
10
+ * a WebSocket route on `--target=vercel`) and the docs compatibility page.
11
+ */
12
+ export const RUNTIME_CAPABILITIES = {
13
+ bun: {
14
+ http: true,
15
+ websocket: true,
16
+ staticFiles: 'disk',
17
+ filesystem: true,
18
+ persistentProcess: true,
19
+ },
20
+ node: {
21
+ http: true,
22
+ websocket: true,
23
+ staticFiles: 'disk',
24
+ filesystem: true,
25
+ persistentProcess: true,
26
+ },
27
+ deno: {
28
+ http: true,
29
+ websocket: true,
30
+ staticFiles: 'disk',
31
+ filesystem: true,
32
+ persistentProcess: true,
33
+ },
34
+ cloudflare: {
35
+ http: true,
36
+ websocket: true,
37
+ staticFiles: 'platform-native',
38
+ filesystem: false,
39
+ persistentProcess: false,
40
+ },
41
+ vercel: {
42
+ http: true,
43
+ websocket: false,
44
+ staticFiles: 'platform-native',
45
+ filesystem: false,
46
+ persistentProcess: false,
47
+ },
48
+ };
@@ -1,9 +1,26 @@
1
- import type { BunRequest, Server } from 'bun';
2
- import type { serve } from 'bun';
3
- /** Options type for Bun.serve(); use this instead of deprecated ServeOptions. */
4
- type BunServerOptions = Parameters<typeof serve>[0];
5
- import { z } from 'zod';
6
- export interface ServerOptions extends Omit<BunServerOptions, 'fetch' | 'port' | 'reusePort' | 'ipv6Only' | 'unix' | 'error' | 'id' | 'development'> {
1
+ import type { BurgerContext, BurgerEnv, BurgerExecutionContext } from '../context/context.js';
2
+ import type { SchemaInput, ValidatorConfig } from '../validation/types.js';
3
+ import type { RouteHooks } from '../lifecycle/types.js';
4
+ export type { RouteHooks, GlobalHooks, TransformMap } from '../lifecycle/types.js';
5
+ import type { OpenAPIConfig } from './openapi-config.js';
6
+ import type { RuntimeAdapter } from '../adapter/types.js';
7
+ import type { WebSocketRouteDefinition } from '../ws/types.js';
8
+ import type { HTTPMethod, LowercaseHTTPMethod } from '../utils/routing.js';
9
+ import type { RuntimeTarget } from '../runtime/capabilities.js';
10
+ /**
11
+ * Minimal structural view of the running server exposed to `fetch` handlers.
12
+ * The web-standard surface: upgrade a WebSocket upgrade request (Bun) or stop
13
+ * the server. Never references Bun types.
14
+ */
15
+ export interface ServerInfo {
16
+ upgrade(request: Request, options?: Record<string, unknown>): boolean;
17
+ stop(): void;
18
+ }
19
+ /**
20
+ * Framework-level server options. Deliberately Web-Standard: no Bun types.
21
+ * Bun-specific tuning lives on the adapter (`BunAdapterStartOptions`).
22
+ */
23
+ export interface ServerOptions {
7
24
  /**
8
25
  * The title of the API. This is an optional property that can be used
9
26
  * to specify a custom title for the API documentation.
@@ -16,7 +33,7 @@ export interface ServerOptions extends Omit<BunServerOptions, 'fetch' | 'port' |
16
33
  description?: string;
17
34
  /**
18
35
  * The directory path to load API routes from.
19
- * If not specified, no API routes are loaded.
36
+ * If not specified, `src/api` is auto-resolved when it exists.
20
37
  */
21
38
  apiDir?: string;
22
39
  /**
@@ -25,20 +42,20 @@ export interface ServerOptions extends Omit<BunServerOptions, 'fetch' | 'port' |
25
42
  */
26
43
  apiPrefix?: string;
27
44
  /**
28
- * The directory path to load Page routes from.
29
- * If not specified, no Page routes are loaded.
30
- * Page routes are not yet supported, but will be supported in the future.
45
+ * The directory path to load page routes from.
46
+ * If not specified, `src/pages` is auto-resolved when it exists.
31
47
  */
32
48
  pageDir?: string;
33
49
  /**
34
- * The prefix for the Page routes.
35
- * If not specified, the default prefix is 'pages'.
50
+ * The prefix for the page routes.
51
+ * If not specified, pages mount at the root (no prefix).
36
52
  */
37
53
  pagePrefix?: string;
38
54
  /**
39
- * Global middleware to be executed before each request.
55
+ * The directory path to load WebSocket routes from.
56
+ * If not specified, no WebSocket routes are loaded.
40
57
  */
41
- globalMiddleware?: Middleware[];
58
+ wsDir?: string;
42
59
  /**
43
60
  * The version of the API. This is an optional property that can be used
44
61
  * to specify the version of the API.
@@ -60,78 +77,112 @@ export interface ServerOptions extends Omit<BunServerOptions, 'fetch' | 'port' |
60
77
  * and no runtime filesystem scanning is performed. Used for bundled/executable builds.
61
78
  */
62
79
  pageRoutes?: PageDefinition[];
63
- }
64
- type DefaultRequestProperties = {
65
- params?: Record<string, unknown>;
66
- query?: Record<string, unknown>;
67
- body?: Record<string, unknown>;
68
- };
69
- export interface BurgerRequest<RequestValidatedProperties extends DefaultRequestProperties = DefaultRequestProperties> extends Omit<BunRequest<string>, 'params'> {
70
80
  /**
71
- * Contains URL parameters extracted from the request path.
72
- * This property is only present if the request path matches a route
73
- * with dynamic parameters.
74
- *
75
- * For example, if the route is `/users/:id`, and the request path is
76
- * `/users/123`, then the `params` property will be `{ id: '123' }`.
81
+ * Pre-built static asset routes from the CLI build (files under
82
+ * `<pageDir>/assets/` embedded as base64). When present, assets are
83
+ * served from the embedded table; otherwise dev reads them from disk
84
+ * under `pageDir`.
77
85
  */
78
- params?: Record<string, string>;
86
+ assetRoutes?: import('../core/assets.js').EmbeddedAsset[];
79
87
  /**
80
- * Contains validated data for the request.
81
- * This is an optional property that will only be present if
82
- * a middleware has validated the request data and attached the
83
- * validated data to the request.
84
- *
85
- * Properties:
86
- * - `params`: Validated URL parameters.
87
- * - `query`: Validated query string parameters.
88
- * - `body`: Validated request body (if JSON).
88
+ * Pre-built WebSocket routes (e.g. from CLI build). When provided, wsDir is
89
+ * ignored and no runtime filesystem scanning is performed. Wired through
90
+ * both `serve()` (Bun) and `fetchHandler()`/`toFetchHandler()` (the
91
+ * WinterCG entry) — see `ws/platform.ts` for per-runtime upgrade support.
92
+ * Used for bundled/executable builds.
93
+ */
94
+ wsRoutes?: WebSocketRouteDefinition[];
95
+ /**
96
+ * Validation configuration: coercion, response-validation mode, and error
97
+ * rendering.
98
+ */
99
+ validation?: ValidatorConfig;
100
+ /**
101
+ * JIT-compile each route's HookPlan into a single async function.
102
+ * ON by default; capability-probed at startup, so runtimes that forbid
103
+ * dynamic code generation (Cloudflare Workers) silently keep the
104
+ * interpreter. Set `false` to opt out.
105
+ */
106
+ jit?: boolean;
107
+ /**
108
+ * Dynamic-route dispatch engine for the fetch-fallback path.
109
+ * `'auto'` (default) and `'trie'` use the radix trie; `'regex'` opts into
110
+ * a compiled regex alternation matcher. Static dispatch is unaffected.
111
+ */
112
+ engine?: 'auto' | 'regex' | 'trie';
113
+ /**
114
+ * OpenAPI configuration for production builds. When using pre-built
115
+ * `apiRoutes`, the convention file cannot be discovered from the filesystem,
116
+ * so the config must be passed here. In dev mode, `openapi.config.ts` is
117
+ * auto-discovered and this field is ignored.
118
+ */
119
+ openapi?: OpenAPIConfig;
120
+ /**
121
+ * Pre-resolved global hooks module (e.g. from `src/hooks.ts`).
122
+ * Only used in production builds (when `apiRoutes` is provided).
123
+ * In dev mode, `src/hooks.ts` is auto-discovered and this field is ignored.
89
124
  */
90
- validated: RequestValidatedProperties;
125
+ globalHooks?: Record<string, unknown>;
91
126
  /**
92
- * Contains the wildcard parameters.
93
- * This is an optional property that will only be present if
94
- * the request path matches a route with a wildcard parameter.
95
- * For example, if the route is `/users/[...]`, and the request path is
96
- * `/users/123/456`, then the `wildcardParams` property will be `['123', '456']`.
127
+ * Pre-resolved plugins module (e.g. from `src/plugins.ts`).
128
+ * Only used in production builds (when `apiRoutes` is provided).
129
+ * In dev mode, `src/plugins.ts` is auto-discovered and this field is ignored.
97
130
  */
98
- wildcardParams?: string[];
131
+ pluginsModule?: Record<string, unknown>;
132
+ /**
133
+ * Pre-resolved providers module (e.g. from `src/providers.ts`).
134
+ * Only used in production builds (when `apiRoutes` is provided).
135
+ * In dev mode, `src/providers.ts` is auto-discovered and this field is ignored.
136
+ */
137
+ providersModule?: Record<string, unknown>;
138
+ /**
139
+ * Optional hostname to bind for `serve()`. Web-standard; forwarded to the
140
+ * adapter.
141
+ */
142
+ hostname?: string;
143
+ /**
144
+ * Maximum request body size in bytes for `serve()` (Bun's default is
145
+ * 128 MB). Larger bodies are rejected by the runtime with 413.
146
+ */
147
+ maxRequestBodySize?: number;
148
+ /**
149
+ * Optional runtime adapter override (test/embed seam). Defaults to the Bun
150
+ * adapter, loaded lazily on first `serve()` so non-Bun bundles never
151
+ * import it.
152
+ */
153
+ adapter?: RuntimeAdapter;
154
+ /**
155
+ * The deployment target this build was produced for — set automatically
156
+ * by `burger-api build --target=<platform>`. When present, WebSocket
157
+ * upgrade handling trusts this over live runtime detection: some targets
158
+ * (Node, Vercel) are structurally indistinguishable via `globalThis`
159
+ * alone, so a declared target resolves the ambiguity that live
160
+ * detection cannot. See `runtime/capabilities.ts`.
161
+ */
162
+ runtimeTarget?: RuntimeTarget;
99
163
  }
100
- /**
101
- * Represents what a middleware can return to control the request flow:
102
- * - Response: Stop here, send this response back to the client
103
- * - Function(Response): Continue processing, but transform the final response after handler runs
104
- * - undefined: I'm done, continue to the next middleware or handler
105
- */
106
- export type BurgerNext = Response | ((response: Response) => Promise<Response>) | undefined;
107
- /**
108
- * A middleware function that processes HTTP requests.
109
- *
110
- * What middleware can do:
111
- * - Check if the request is valid (auth, validation, etc.)
112
- * - Stop the request by returning a Response
113
- * - Let the request continue by returning undefined
114
- * - Transform the final response by returning a function
115
- *
116
- * @param request - The HTTP request with Burger framework enhancements
117
- * @returns One of three things:
118
- * - Response: Stop here, send this response back
119
- * - Function: Transform the final response after handler runs
120
- * - undefined: Continue to the next middleware or handler
121
- */
122
- export type Middleware = ((request: BurgerRequest) => Promise<BurgerNext>) | ((request: BurgerRequest) => BurgerNext);
123
164
  /**
124
165
  * A request handler function that processes incoming HTTP requests.
125
- * @param request - The BurgerRequest object containing request object.
166
+ * @param ctx - The BurgerContext object containing request data and services.
126
167
  * @returns A Response object or a Promise that resolves to a Response object.
127
168
  */
128
- export type RequestHandler = (request: BurgerRequest) => Promise<Response> | Response;
169
+ export type RequestHandler = (ctx: BurgerContext) => Promise<Response> | Response;
129
170
  /**
130
171
  * A fetch handler function that can be used to handle a request.
131
172
  * This can be a function that returns a Promise of a Response,
132
173
  * or a function that returns a Response.
174
+ *
175
+ * `server` is an optional structural view of the running server (upgrade/stop)
176
+ * — Web-Standard, never Bun-specific.
177
+ */
178
+ export type FetchHandler = (request: Request, server?: ServerInfo, env?: BurgerEnv, executionCtx?: BurgerExecutionContext) => Promise<Response> | Response;
179
+ /**
180
+ * The handler returned by `burger.fetchHandler()` and wrapped by
181
+ * `toFetchHandler(burger)`: a Web-Standard dispatch entry that accepts the
182
+ * platform bindings (`env`, `executionCtx`) supplied by WinterCG runtimes
183
+ * (Cloudflare Workers, Vercel, Deno, Node 24+). On Bun both are `undefined`.
133
184
  */
134
- export type FetchHandler = (request: Request, server?: Server<{}>) => Promise<Response> | Response;
185
+ export type EnvFetchHandler = (request: Request, env?: BurgerEnv, executionCtx?: BurgerExecutionContext) => Promise<Response>;
135
186
  export interface RouteDefinition {
136
187
  /**
137
188
  * The path of the route.
@@ -139,17 +190,21 @@ export interface RouteDefinition {
139
190
  path: string;
140
191
  /**
141
192
  * An object containing the request handlers for each HTTP method.
142
- * The keys are the HTTP method names (e.g. "GET", "POST", etc.).
193
+ * The keys are the HTTP method names (e.g. "GET", "POST", etc.);
194
+ * only the methods in the {@link HTTPMethod} union are accepted —
195
+ * anything else fails at compile time and would 405 at runtime.
143
196
  * The values are the request handlers for that method.
144
197
  */
145
- handlers: {
146
- [method: string]: RequestHandler;
147
- };
198
+ handlers: Partial<Record<HTTPMethod, RequestHandler>>;
148
199
  /**
149
- * An array of middleware functions to run before the request handler.
150
- * The middleware functions will be run in the order they are specified.
200
+ * Lifecycle hooks declared in `hooks.ts`. Carried raw from the
201
+ * compiler and compiled into a frozen `HookPlan` by RouterCompiler. Mapped
202
+ * onto the single pipeline: `beforeRoute` (global → route) runs before
203
+ * the handler; `afterRoute` / `mapResponse` are response hooks.
204
+ * `route.ts` contains handlers only — there is no
205
+ * per-route `hooks` export.
151
206
  */
152
- middleware?: Middleware[];
207
+ hooks?: RouteHooks;
153
208
  /**
154
209
  * An optional route schema to validate the request data against.
155
210
  * This property is set by the user when defining a route.
@@ -171,50 +226,145 @@ export interface RouteDefinition {
171
226
  * This property is used internally to identify wildcard routes.
172
227
  */
173
228
  isWildcard?: boolean;
229
+ /**
230
+ * Route-specific configuration from `config.ts`. Available as `ctx.config`
231
+ * at runtime. Core reads only `responseValidation` ('off' | 'dev' |
232
+ * 'enforce' — overrides `ServerOptions.validation.responseValidation`
233
+ * for this route). Every other key (auth, cache, timeout, …) is plain
234
+ * data that core never acts on — hooks and plugins (e.g. an auth plugin
235
+ * reading `ctx.config.auth`) give it meaning.
236
+ *
237
+ * Uppercase method keys (`{ POST: { auth: { required: true } } }`) are
238
+ * per-method overrides, shallow-merged over the route-wide options for
239
+ * that method only.
240
+ */
241
+ config?: Record<string, unknown>;
174
242
  }
175
243
  /**
176
- * Define a type for the route schema.
177
- * For each HTTP method (in lowercase), you can optionally define:
244
+ * The per-method body of a route schema. For each HTTP method you can
245
+ * optionally define:
178
246
  * - params: for URL parameters,
179
247
  * - query: for query string parameters,
180
- * - body: for the request body.
248
+ * - headers / cookies / body: for the corresponding request data,
249
+ * - response: per-status response schemas validated after the handler.
181
250
  */
182
- export type RouteSchema = {
183
- [method: string]: {
184
- params?: z.ZodTypeAny;
185
- query?: z.ZodTypeAny;
186
- body?: z.ZodTypeAny;
187
- };
188
- };
251
+ export interface MethodSchema {
252
+ params?: SchemaInput;
253
+ query?: SchemaInput;
254
+ headers?: SchemaInput;
255
+ cookies?: SchemaInput;
256
+ body?: SchemaInput;
257
+ /** Per-route opt-in override for coercion. */
258
+ coerce?: boolean;
259
+ /** Per-status-code response schemas, validated after the handler. */
260
+ response?: Record<string, SchemaInput>;
261
+ }
189
262
  /**
190
- * Optional OpenAPI metadata to generate documentation for the route.
191
- * Each key is an HTTP method name (in lowercase) and the value is an object
192
- * containing the OpenAPI metadata for that method.
193
- *
194
- * If the `openapi` property is not defined, the route will not be included in
195
- * the generated OpenAPI documentation.
263
+ * Define a type for the route schema.
196
264
  *
197
- * See the OpenAPI specification for the possible properties and their
198
- * descriptions.
265
+ * Keys are HTTP method names; both lowercase (canonical, matching the
266
+ * compiled form) and uppercase (accepted by the compiler for programmatic
267
+ * routes) are legal at runtime, so both are accepted here. Anything else
268
+ * fails at compile time.
199
269
  */
200
- export type openapi = {
201
- [method: string]: {
202
- summary?: string;
270
+ export type RouteSchema = Partial<Record<LowercaseHTTPMethod | HTTPMethod, MethodSchema>> & {
271
+ /**
272
+ * `export const coerce = true` in `schema.ts`: default coercion for
273
+ * every method in the file. A per-method `coerce` overrides nothing —
274
+ * either flag enables coercion for that method.
275
+ */
276
+ coerce?: boolean;
277
+ };
278
+ /**
279
+ * Per-method OpenAPI metadata. Each key is an HTTP method name in lowercase
280
+ * (the compiled form the OpenAPI generator reads); uppercase keys are a
281
+ * silent no-op at runtime, so they are rejected at compile time.
282
+ */
283
+ export interface OpenAPIMeta {
284
+ summary?: string;
285
+ description?: string;
286
+ tags?: string[];
287
+ operationId?: string;
288
+ deprecated?: boolean;
289
+ responses?: Record<string, Record<string, unknown>>;
290
+ externalDocs?: {
203
291
  description?: string;
204
- tags?: string[];
205
- operationId?: string;
206
- deprecated?: boolean;
207
- responses?: Record<string, any>;
208
- externalDocs?: {
209
- description?: string;
210
- url?: string;
211
- };
292
+ url?: string;
212
293
  };
213
- };
294
+ }
295
+ /**
296
+ * Optional OpenAPI metadata to enrich the route's documentation.
297
+ * Keyed by lowercase HTTP method; see {@link OpenAPIMeta}.
298
+ *
299
+ * Routes without `openapi` metadata ARE included in the generated document:
300
+ * the operation is derived from the route path, handlers and schema.
301
+ */
302
+ export type openapi = Partial<Record<LowercaseHTTPMethod, OpenAPIMeta>>;
303
+ /**
304
+ * The shape of a `burger.build.ts` export — build-time settings read by the
305
+ * CLI (dirs, prefixes, debug). The dir/prefix fields are always present in
306
+ * a scaffolded file (convention defaults apply otherwise). Build-time only;
307
+ * runtime options belong in `new Burger({...})` (`ServerOptions`).
308
+ */
309
+ export interface BuildConfig {
310
+ /** Directory with API route files (e.g. `./src/api`). */
311
+ apiDir: string;
312
+ /** Directory with HTML page files (e.g. `./src/pages`). */
313
+ pageDir: string;
314
+ /** URL prefix for API routes (default `/api`). */
315
+ apiPrefix: string;
316
+ /** URL prefix for page routes (default `/`). */
317
+ pagePrefix: string;
318
+ /** Directory with WebSocket route files (e.g. `./src/websocket`). */
319
+ wsDir?: string;
320
+ /** Extra logging when true. */
321
+ debug?: boolean;
322
+ /**
323
+ * Deployment target for `burger-api build --target=<platform>`.
324
+ * Defaults to `'bun'`. See `RUNTIME_CAPABILITIES` for what each target
325
+ * supports.
326
+ */
327
+ target?: RuntimeTarget;
328
+ }
329
+ /**
330
+ * Empty interface for module augmentation. Extend this to type the route's
331
+ * `config.ts` options, so `ctx.config` is typed for hooks and plugins:
332
+ *
333
+ * ```ts
334
+ * declare module "burger-api" {
335
+ * interface RouteConfig {
336
+ * auth: boolean;
337
+ * timeout: number;
338
+ * }
339
+ * }
340
+ * ```
341
+ *
342
+ * Without augmentation, unknown keys read as `unknown`; augment to type
343
+ * them.
344
+ *
345
+ * Core itself only reads `responseValidation`; keys such as `auth`,
346
+ * `cache` or `timeout` do nothing unless a plugin or hook reads them.
347
+ */
348
+ export interface RouteConfig {
349
+ /**
350
+ * Response-validation mode for this route, overriding
351
+ * `ServerOptions.validation.responseValidation`:
352
+ * `'off'` (skip), `'dev'` (warn only), `'enforce'` (replace with an
353
+ * error response).
354
+ */
355
+ responseValidation?: 'off' | 'dev' | 'enforce';
356
+ /**
357
+ * Any other option (`auth`, `cache`, `timeout`, …) is plain data core
358
+ * never acts on. The index signature keeps `satisfies RouteConfig`
359
+ * compiling for them; augment `RouteConfig` to type them.
360
+ */
361
+ [key: string]: unknown;
362
+ }
214
363
  export interface PageDefinition {
215
364
  path: string;
216
365
  handler: RequestHandler;
217
- middleware?: Middleware[];
366
+ /** Origin of the page (file path) — used in collision errors. */
367
+ source?: string;
218
368
  }
219
369
  export interface TrieNode {
220
370
  children: Map<string, TrieNode>;
@@ -224,4 +374,5 @@ export interface TrieNode {
224
374
  isWildcard?: boolean;
225
375
  route?: RouteDefinition;
226
376
  }
227
- export {};
377
+ export type { ContextField, ContextInit, ContextSet, RouteAccessInfo, RouteMeta, } from '../context/types.js';
378
+ export type { OpenAPIConfig, DocsProvider, DocsProviderOptions, OpenAPIObject, JsonSchemaConverter, DocsAuth, OpenAPIServer, OpenAPIContact, OpenAPILicense, OpenAPIExternalDocs, } from './openapi-config.js';
@@ -1 +1 @@
1
- import { z } from 'zod';
1
+ export {};