burger-api 0.9.7 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -241
- package/dist/src/adapter/bun/index.d.ts +14 -0
- package/dist/src/adapter/bun/index.js +73 -0
- package/dist/src/adapter/bun/types.d.ts +15 -0
- package/dist/src/adapter/bun/types.js +1 -0
- package/dist/src/adapter/index.d.ts +1 -0
- package/dist/src/adapter/index.js +1 -0
- package/dist/src/adapter/types.d.ts +49 -0
- package/dist/src/adapter/types.js +1 -0
- package/dist/src/adapter/web-standard/fetch-handler.d.ts +39 -0
- package/dist/src/adapter/web-standard/fetch-handler.js +54 -0
- package/dist/src/adapter/web-standard/index.d.ts +8 -0
- package/dist/src/adapter/web-standard/index.js +7 -0
- package/dist/src/analysis/route-access-analyzer.d.ts +10 -0
- package/dist/src/analysis/route-access-analyzer.js +287 -0
- package/dist/src/chain/chain.d.ts +16 -0
- package/dist/src/chain/chain.js +17 -0
- package/dist/src/chain/flattener.d.ts +3 -0
- package/dist/src/chain/flattener.js +78 -0
- package/dist/src/chain/node.d.ts +25 -0
- package/dist/src/chain/node.js +1 -0
- package/dist/src/compiler/conventions.d.ts +67 -0
- package/dist/src/compiler/conventions.js +129 -0
- package/dist/src/compiler/index.d.ts +13 -0
- package/dist/src/compiler/index.js +11 -0
- package/dist/src/compiler/module-loader.d.ts +75 -0
- package/dist/src/compiler/module-loader.js +276 -0
- package/dist/src/compiler/route-module.d.ts +97 -0
- package/dist/src/compiler/route-module.js +1 -0
- package/dist/src/compiler/route-tree.d.ts +19 -0
- package/dist/src/compiler/route-tree.js +28 -0
- package/dist/src/compiler/scanner.d.ts +42 -0
- package/dist/src/compiler/scanner.js +240 -0
- package/dist/src/context/context-set.d.ts +26 -0
- package/dist/src/context/context-set.js +45 -0
- package/dist/src/context/context.d.ts +357 -0
- package/dist/src/context/context.js +401 -0
- package/dist/src/context/query-parser.d.ts +23 -0
- package/dist/src/context/query-parser.js +132 -0
- package/dist/src/context/route-access.d.ts +7 -0
- package/dist/src/context/route-access.js +18 -0
- package/dist/src/context/types.d.ts +62 -0
- package/dist/src/context/types.js +5 -0
- package/dist/src/core/asset-mime.d.ts +9 -0
- package/dist/src/core/asset-mime.js +35 -0
- package/dist/src/core/assets.d.ts +30 -0
- package/dist/src/core/assets.js +67 -0
- package/dist/src/core/docs-providers.d.ts +13 -0
- package/dist/src/core/docs-providers.js +89 -0
- package/dist/src/core/embedded-assets.d.ts +18 -0
- package/dist/src/core/embedded-assets.js +13 -0
- package/dist/src/core/openapi.d.ts +9 -10
- package/dist/src/core/openapi.js +333 -127
- package/dist/src/core/page-router.d.ts +13 -17
- package/dist/src/core/page-router.js +86 -55
- package/dist/src/core/server.d.ts +20 -11
- package/dist/src/core/server.js +41 -45
- package/dist/src/errors/forbidden.d.ts +14 -0
- package/dist/src/errors/forbidden.js +16 -0
- package/dist/src/errors/http-error.d.ts +49 -0
- package/dist/src/errors/http-error.js +155 -0
- package/dist/src/errors/method-not-allowed.d.ts +13 -0
- package/dist/src/errors/method-not-allowed.js +15 -0
- package/dist/src/errors/not-found.d.ts +14 -0
- package/dist/src/errors/not-found.js +16 -0
- package/dist/src/errors/unauthorized.d.ts +14 -0
- package/dist/src/errors/unauthorized.js +16 -0
- package/dist/src/index.d.ts +275 -50
- package/dist/src/index.js +974 -333
- package/dist/src/lifecycle/executor.d.ts +64 -0
- package/dist/src/lifecycle/executor.js +201 -0
- package/dist/src/lifecycle/hook-runner.d.ts +11 -0
- package/dist/src/lifecycle/hook-runner.js +156 -0
- package/dist/src/lifecycle/jit.d.ts +50 -0
- package/dist/src/lifecycle/jit.js +258 -0
- package/dist/src/lifecycle/transform.d.ts +26 -0
- package/dist/src/lifecycle/transform.js +99 -0
- package/dist/src/lifecycle/types.d.ts +135 -0
- package/dist/src/lifecycle/types.js +1 -0
- package/dist/src/plugin/composer.d.ts +3 -0
- package/dist/src/plugin/composer.js +28 -0
- package/dist/src/plugin/registry.d.ts +25 -0
- package/dist/src/plugin/registry.js +107 -0
- package/dist/src/plugin/types.d.ts +20 -0
- package/dist/src/plugin/types.js +1 -0
- package/dist/src/router/allow-cache.d.ts +20 -0
- package/dist/src/router/allow-cache.js +26 -0
- package/dist/src/router/compiler.d.ts +39 -0
- package/dist/src/router/compiler.js +867 -0
- package/dist/src/router/define.d.ts +67 -0
- package/dist/src/router/define.js +34 -0
- package/dist/src/router/index.d.ts +6 -0
- package/dist/src/router/index.js +5 -0
- package/dist/src/router/param-extract.d.ts +33 -0
- package/dist/src/router/param-extract.js +87 -0
- package/dist/src/router/regex-matcher.d.ts +42 -0
- package/dist/src/router/regex-matcher.js +216 -0
- package/dist/src/router/router.d.ts +214 -0
- package/dist/src/router/router.js +670 -0
- package/dist/src/router/static-map.d.ts +39 -0
- package/dist/src/router/static-map.js +48 -0
- package/dist/src/router/trie.d.ts +69 -0
- package/dist/src/router/trie.js +572 -0
- package/dist/src/router/types.d.ts +104 -0
- package/dist/src/router/types.js +1 -0
- package/dist/src/runtime/capabilities.d.ts +29 -0
- package/dist/src/runtime/capabilities.js +48 -0
- package/dist/src/types/index.d.ts +260 -109
- package/dist/src/types/index.js +1 -1
- package/dist/src/types/inference.d.ts +78 -0
- package/dist/src/types/inference.js +20 -0
- package/dist/src/types/openapi-config.d.ts +164 -0
- package/dist/src/types/openapi-config.js +8 -0
- package/dist/src/utils/env.d.ts +13 -0
- package/dist/src/utils/env.js +24 -0
- package/dist/src/utils/fs.d.ts +29 -0
- package/dist/src/utils/fs.js +75 -0
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +2 -2
- package/dist/src/utils/pathConversion.js +13 -7
- package/dist/src/utils/response.d.ts +42 -6
- package/dist/src/utils/response.js +189 -7
- package/dist/src/utils/routing.d.ts +32 -13
- package/dist/src/utils/routing.js +41 -18
- package/dist/src/utils/thenable.d.ts +8 -0
- package/dist/src/utils/thenable.js +12 -0
- package/dist/src/utils/timing-safe.d.ts +9 -0
- package/dist/src/utils/timing-safe.js +20 -0
- package/dist/src/utils/wildcard.d.ts +6 -7
- package/dist/src/utils/wildcard.js +38 -55
- package/dist/src/validation/adapter.d.ts +54 -0
- package/dist/src/validation/adapter.js +75 -0
- package/dist/src/validation/adapters/standard.d.ts +11 -0
- package/dist/src/validation/adapters/standard.js +110 -0
- package/dist/src/validation/adapters/zod.d.ts +9 -0
- package/dist/src/validation/adapters/zod.js +128 -0
- package/dist/src/validation/cache.d.ts +26 -0
- package/dist/src/validation/cache.js +35 -0
- package/dist/src/validation/coerce.d.ts +28 -0
- package/dist/src/validation/coerce.js +176 -0
- package/dist/src/validation/compiler.d.ts +27 -0
- package/dist/src/validation/compiler.js +191 -0
- package/dist/src/validation/error.d.ts +69 -0
- package/dist/src/validation/error.js +137 -0
- package/dist/src/validation/index.d.ts +16 -0
- package/dist/src/validation/index.js +12 -0
- package/dist/src/validation/response.d.ts +25 -0
- package/dist/src/validation/response.js +85 -0
- package/dist/src/validation/types.d.ts +148 -0
- package/dist/src/validation/types.js +6 -0
- package/dist/src/validation/validator.d.ts +39 -0
- package/dist/src/validation/validator.js +441 -0
- package/dist/src/ws/adapter.d.ts +230 -0
- package/dist/src/ws/adapter.js +660 -0
- package/dist/src/ws/compiler.d.ts +37 -0
- package/dist/src/ws/compiler.js +178 -0
- package/dist/src/ws/index.d.ts +11 -0
- package/dist/src/ws/index.js +8 -0
- package/dist/src/ws/platform.d.ts +82 -0
- package/dist/src/ws/platform.js +122 -0
- package/dist/src/ws/router.d.ts +47 -0
- package/dist/src/ws/router.js +183 -0
- package/dist/src/ws/scanner.d.ts +97 -0
- package/dist/src/ws/scanner.js +253 -0
- package/dist/src/ws/types.d.ts +381 -0
- package/dist/src/ws/types.js +213 -0
- package/package.json +72 -60
- package/dist/src/core/api-router.d.ts +0 -65
- package/dist/src/core/api-router.js +0 -264
- package/dist/src/core/swagger-ui.d.ts +0 -1
- package/dist/src/core/swagger-ui.js +0 -33
- package/dist/src/middleware/validator.d.ts +0 -14
- package/dist/src/middleware/validator.js +0 -133
- package/dist/src/utils/error.d.ts +0 -17
- 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
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,95 +1,320 @@
|
|
|
1
|
-
import
|
|
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
|
|
32
|
+
* The API path prefix (dev path).
|
|
10
33
|
*/
|
|
11
|
-
private
|
|
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
|
|
40
|
+
* The page path prefix (dev path).
|
|
14
41
|
*/
|
|
15
|
-
private
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
90
|
+
* WebSocket router
|
|
30
91
|
*/
|
|
31
|
-
private
|
|
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
|
|
108
|
+
private readonly notFound;
|
|
36
109
|
/**
|
|
37
110
|
* The OpenAPI error response
|
|
38
111
|
*/
|
|
39
|
-
private readonly
|
|
112
|
+
private readonly openApiError;
|
|
113
|
+
/**
|
|
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
|
+
/**
|
|
121
|
+
* Memoized API + WebSocket processing: concurrent `fetchHandler()` /
|
|
122
|
+
* `serve()` calls share one compilation and one plugins/providers run.
|
|
123
|
+
* A failed attempt clears the memo so a later call retries instead of
|
|
124
|
+
* replaying the rejection forever.
|
|
125
|
+
*/
|
|
126
|
+
private apiRoutesProcessed?;
|
|
127
|
+
private wsRoutesProcessed?;
|
|
128
|
+
/** Set when the scanned API directory contained no route files. */
|
|
129
|
+
private emptyApiDir?;
|
|
130
|
+
/** Set once convention directory defaults were applied. */
|
|
131
|
+
private conventionDefaultsApplied;
|
|
40
132
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* - middleware: An array of global middleware functions.
|
|
133
|
+
* App-level WebSocket hooks (`onOpen` / `onMessage` / `onClose`),
|
|
134
|
+
* applied to every WS route.
|
|
135
|
+
*/
|
|
136
|
+
private globalWsHooks?;
|
|
137
|
+
/**
|
|
138
|
+
* @param options Server + router options (port, apiDir, pageDir, wsDir, …).
|
|
48
139
|
*/
|
|
49
140
|
constructor(options: ServerOptions);
|
|
50
141
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
142
|
+
* Registers a plugin; its hooks compile into every route's hook chain with
|
|
143
|
+
* the plugin's scope. Duplicate registrations (same name + seed) are
|
|
144
|
+
* ignored with a warning.
|
|
145
|
+
*
|
|
146
|
+
* @param plugin The plugin object or a factory function returning one.
|
|
147
|
+
* @param scope Optional scope override (default: `'plugin'`).
|
|
148
|
+
* @param seed Optional disambiguation string (e.g. two JWT plugins).
|
|
149
|
+
* @returns `this` for chaining.
|
|
53
150
|
*/
|
|
151
|
+
usePlugin(plugin: Plugin | PluginFactory, scope?: Scope, seed?: string): this;
|
|
152
|
+
/**
|
|
153
|
+
* Registers an application service, injected into `ctx.services` for every
|
|
154
|
+
* request.
|
|
155
|
+
*
|
|
156
|
+
* @param name Service name (accessed as `ctx.services[name]`).
|
|
157
|
+
* @param service The service instance.
|
|
158
|
+
* @returns `this` for chaining.
|
|
159
|
+
*/
|
|
160
|
+
provide(name: string, service: unknown): this;
|
|
161
|
+
/**
|
|
162
|
+
* Register a WebSocket route programmatically.
|
|
163
|
+
* @param path Route path (e.g., "/chat", "/notifications/:room")
|
|
164
|
+
* @param handlers WebSocket handler functions
|
|
165
|
+
* @returns `this` for chaining.
|
|
166
|
+
*/
|
|
167
|
+
websocket(path: string, handlers: import('./ws/types.js').WebSocketHandlers): this;
|
|
168
|
+
/**
|
|
169
|
+
* Set global WebSocket configuration.
|
|
170
|
+
* @param config WebSocket configuration options
|
|
171
|
+
* @returns `this` for chaining.
|
|
172
|
+
*/
|
|
173
|
+
wsConfig(config: WebSocketConfig): this;
|
|
174
|
+
/**
|
|
175
|
+
* Filesystem mode only (no prebuilt `apiRoutes`): unconfigured directories
|
|
176
|
+
* default to the CLI build conventions (`src/api`, `src/pages`,
|
|
177
|
+
* `src/websocket`) when they exist, so dev and production match. Resolved
|
|
178
|
+
* lazily — `node:fs` is never loaded by AOT bundles.
|
|
179
|
+
*/
|
|
180
|
+
private applyConventionDefaults;
|
|
181
|
+
/**
|
|
182
|
+
* Wraps a non-API handler (page, asset, OpenAPI spec, docs UI) so
|
|
183
|
+
* global/plugin `onRequest` hooks run for it like for API routes.
|
|
184
|
+
* Registered on the native routes map → invoked with the raw `Request`.
|
|
185
|
+
*/
|
|
186
|
+
private withOnRequest;
|
|
187
|
+
/**
|
|
188
|
+
* Registers one route path, failing loud when two sources (API route,
|
|
189
|
+
* page, asset, docs UI, spec) resolve to the same path. Silent overwrites
|
|
190
|
+
* would make one of them unreachable.
|
|
191
|
+
*/
|
|
192
|
+
private registerRoute;
|
|
193
|
+
/** Registers page + asset routes once (shared by serve and fetchHandler). */
|
|
194
|
+
private processPageRoutesOnce;
|
|
195
|
+
/** Compiles API routes once (shared by serve and fetchHandler). */
|
|
196
|
+
private processApiRoutesOnce;
|
|
197
|
+
/** Processes WebSocket routes once (shared by serve and fetchHandler). */
|
|
198
|
+
private processWebSocketRoutesOnce;
|
|
199
|
+
/** Loads prebuilt or filesystem page routes. */
|
|
54
200
|
private processPageRoutes;
|
|
55
201
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
202
|
+
* Wraps every page handler with a real per-request `BurgerContext` — the
|
|
203
|
+
* same object API routes get — so `ctx.services`, `ctx.query`, `ctx.set`
|
|
204
|
+
* and the delegated `Request` surface work on static pages too. Dynamic
|
|
205
|
+
* pages (`:param`) also get `ctx.params`; static pages seed only the
|
|
206
|
+
* route pattern (`ctx.route.path` derives lazily).
|
|
207
|
+
*
|
|
208
|
+
* Cost per page request: one `BurgerContext` allocation (no parsing).
|
|
209
|
+
* When an onRequest/global-hook wrapper already created the context, the
|
|
210
|
+
* existing instance is re-bound instead of allocated.
|
|
58
211
|
*/
|
|
59
|
-
private
|
|
212
|
+
private wrapPageHandler;
|
|
60
213
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @returns A promise that resolves to a response
|
|
214
|
+
* Pages, assets, the docs UI and the OpenAPI spec answer GET and HEAD
|
|
215
|
+
* only. Every other method gets a 405 with `Allow: GET, HEAD` and the
|
|
216
|
+
* same RFC 9457 body route 405s use. Global/plugin response hooks and
|
|
217
|
+
* onRequest mappers still apply (this runs inside `withOnRequest`).
|
|
66
218
|
*/
|
|
67
|
-
private
|
|
219
|
+
private restrictToGetHead;
|
|
68
220
|
/**
|
|
69
|
-
*
|
|
221
|
+
* Registers static asset routes under `{pagePrefix}/assets/*`.
|
|
70
222
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
223
|
+
* Production AOT embeds base64 contents (`assetRoutes` from the CLI
|
|
224
|
+
* build); dev reads files from disk per request so edits show.
|
|
225
|
+
*/
|
|
226
|
+
private processAssetRoutes;
|
|
227
|
+
/**
|
|
228
|
+
* Compiles the API routes and merges them into the routes map. Static and
|
|
229
|
+
* dynamic (`:param` / `*`) routes both go on Bun's native map; unmatched or
|
|
230
|
+
* loose-trailing-slash requests fall through to `Router.fetch` (the trie).
|
|
231
|
+
* Both paths run the same compiled handler, so dispatch behavior is
|
|
232
|
+
* identical.
|
|
233
|
+
*/
|
|
234
|
+
private processApiRoutes;
|
|
235
|
+
/** Loads WebSocket routes (programmatic, prebuilt or file-based). */
|
|
236
|
+
private processWebSocketRoutes;
|
|
237
|
+
/**
|
|
238
|
+
* Builds the Web-Standard fetch handler for this app.
|
|
239
|
+
*
|
|
240
|
+
* Dispatches the raw `Request` through the compiled routes (static map
|
|
241
|
+
* first, then the trie fallback for dynamic/wildcard and loose
|
|
242
|
+
* trailing-slash variants). API routes must be provided AOT (`apiRoutes`)
|
|
243
|
+
* or discovered from the filesystem on first call — never per request.
|
|
244
|
+
*
|
|
245
|
+
* Runtime-agnostic: Bun.serve, Deno.serve, Vercel, Cloudflare Workers and
|
|
246
|
+
* Node 24+. WinterCG bindings (`env`, `executionCtx`) are bound onto the
|
|
247
|
+
* per-request `BurgerContext`. Pages (Bun-only) are not served here.
|
|
78
248
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { Burger, toFetchHandler } from 'burger-api';
|
|
251
|
+
* const burger = new Burger({ apiRoutes });
|
|
252
|
+
* export default { fetch: toFetchHandler(burger) };
|
|
253
|
+
* ```
|
|
84
254
|
*/
|
|
85
|
-
|
|
255
|
+
fetchHandler(): Promise<EnvFetchHandler>;
|
|
86
256
|
/**
|
|
87
|
-
* Starts the server and
|
|
88
|
-
* @param port
|
|
89
|
-
* @param cb
|
|
90
|
-
* @returns A Promise that resolves when the server has started listening.
|
|
257
|
+
* Starts the server and listens for requests.
|
|
258
|
+
* @param port Port to listen on (default `4000`).
|
|
259
|
+
* @param cb Called when the server is listening.
|
|
91
260
|
*/
|
|
92
261
|
serve(port?: number, cb?: () => void): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* The underlying `Server` instance, exposed so callers can stop the
|
|
264
|
+
* server cleanly.
|
|
265
|
+
*/
|
|
266
|
+
getServer(): Server | undefined;
|
|
267
|
+
/**
|
|
268
|
+
* Node WebSocket integration: returns a bridge that plugs the framework
|
|
269
|
+
* pipeline into node:http's `'upgrade'` event using a framing library's
|
|
270
|
+
* `WebSocketServer` (e.g. the `ws` package). Call `fetchHandler()` (or
|
|
271
|
+
* `serve()`) first — WebSocket routes are processed there.
|
|
272
|
+
*
|
|
273
|
+
* ```ts
|
|
274
|
+
* import http from 'node:http';
|
|
275
|
+
* import { WebSocketServer } from 'ws';
|
|
276
|
+
*
|
|
277
|
+
* const fetchHandler = await burger.fetchHandler();
|
|
278
|
+
* const bridge = burger.createNodeWsBridge({ WebSocketServer });
|
|
279
|
+
* http.createServer((req, res) => { ... })
|
|
280
|
+
* .on('upgrade', (req, socket, head) =>
|
|
281
|
+
* bridge.handleUpgrade(req, socket, head))
|
|
282
|
+
* .listen(3000);
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
createNodeWsBridge(options: NodeWsBridgeOptions): NodeWsBridge;
|
|
93
286
|
}
|
|
94
|
-
export {
|
|
95
|
-
export
|
|
287
|
+
export { BurgerContext, setRequestIP } from './context/context.js';
|
|
288
|
+
export { defineRoute, defineHooks } from './router/define.js';
|
|
289
|
+
export type { TypedRouteHooks, HookContext, PreValidationHookContext, } from './router/define.js';
|
|
290
|
+
export { RUNTIME_CAPABILITIES } from './runtime/capabilities.js';
|
|
291
|
+
export type { RuntimeTarget, RuntimeCapability } from './runtime/capabilities.js';
|
|
292
|
+
export type { BurgerServices, BurgerValidated, BurgerEnv, BurgerExecutionContext, BurgerAuthUser, } from './context/context.js';
|
|
293
|
+
export { setDir } from './utils/index.js';
|
|
294
|
+
export { cleanPrefix, normalizePath } from './utils/index.js';
|
|
295
|
+
export { timingSafeEqual } from './utils/timing-safe.js';
|
|
296
|
+
export { HTTPError, renderHTTPError } from './errors/http-error.js';
|
|
297
|
+
export { ASSET_MIME, contentTypeFor } from './core/asset-mime.js';
|
|
298
|
+
export type { EmbeddedAsset, DiskAssetRoute, } from './core/assets.js';
|
|
299
|
+
export { ValidationError } from './validation/error.js';
|
|
300
|
+
export { NotFoundError } from './errors/not-found.js';
|
|
301
|
+
export { UnauthorizedError } from './errors/unauthorized.js';
|
|
302
|
+
export { ForbiddenError } from './errors/forbidden.js';
|
|
303
|
+
export { MethodNotAllowedError } from './errors/method-not-allowed.js';
|
|
304
|
+
export { scalarDocs, swaggerDocs, redocDocs } from './core/docs-providers.js';
|
|
305
|
+
export { toFetchHandler } from './adapter/web-standard/index.js';
|
|
306
|
+
export type { FetchHandlerEntry } from './adapter/web-standard/index.js';
|
|
307
|
+
export type { RuntimeAdapter, AdapterStartOptions, ServerHandle, } from './adapter/types.js';
|
|
308
|
+
export type { BunAdapterStartOptions } from './adapter/bun/types.js';
|
|
309
|
+
export type { ServerInfo } from './types/index.js';
|
|
310
|
+
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';
|
|
311
|
+
export type { Server } from './core/server.js';
|
|
312
|
+
export type { HTTPMethod, LowercaseHTTPMethod } from './utils/routing.js';
|
|
313
|
+
export type { Hook, ForwardHook, ForwardHookResult, ResponseHook, ResponseHookResult, ErrorHook, } from './lifecycle/types.js';
|
|
314
|
+
export type { ValidationIssue } from './validation/types.js';
|
|
315
|
+
export type { Plugin, PluginFactory } from './plugin/types.js';
|
|
316
|
+
export type { Scope } from './chain/node.js';
|
|
317
|
+
export type { BurgerWS, WebSocketData, WebSocketConfig, WebSocketRouteDefinition, WebSocketHandlers, WebSocketHooks, CompiledWebSocketRoute, WebSocketModule, WebSocketHooksModule, WebSocketConfigModule, } from './ws/types.js';
|
|
318
|
+
export { WebSocketReadyState, WebSocketCloseCode, BurgerWSContext, } from './ws/types.js';
|
|
319
|
+
export { WebSocketAdapter } from './ws/adapter.js';
|
|
320
|
+
export type { WebSocketAdapterOptions } from './ws/adapter.js';
|