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,39 @@
|
|
|
1
|
+
import type { CompiledHandler, NativeMethodCores } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* One static route's framework-side entry: the method-dispatching compiled
|
|
4
|
+
* handler plus the per-method specialized cores (used by the `fetch` fallback
|
|
5
|
+
* to dispatch a known method without re-entering the dispatching wrapper).
|
|
6
|
+
*/
|
|
7
|
+
export interface StaticEntry {
|
|
8
|
+
handler: CompiledHandler;
|
|
9
|
+
cores: NativeMethodCores | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Static dispatch table.
|
|
13
|
+
*
|
|
14
|
+
* Static API routes are served by Bun's native `routes` map (the fast path);
|
|
15
|
+
* this holds the framework-side copy so the Router can enumerate them into
|
|
16
|
+
* Bun's map and resolve loose-trailing-slash variants Bun did not match.
|
|
17
|
+
* Keyed by path; one compiled handler serves all methods, with dispatch and
|
|
18
|
+
* 405+Allow inside it.
|
|
19
|
+
*/
|
|
20
|
+
export declare class StaticMap {
|
|
21
|
+
private map;
|
|
22
|
+
/**
|
|
23
|
+
* Registers a compiled handler for a static path.
|
|
24
|
+
* @throws if a *different* handler is already registered at the same path
|
|
25
|
+
* (duplicate static route). Re-setting the same handler reference
|
|
26
|
+
* (used for loose trailing-slash variants) is allowed.
|
|
27
|
+
*/
|
|
28
|
+
set(path: string, handler: CompiledHandler, cores?: NativeMethodCores): void;
|
|
29
|
+
get(path: string): CompiledHandler | undefined;
|
|
30
|
+
/** The full entry (handler + method cores) for a static path. */
|
|
31
|
+
getEntry(path: string): StaticEntry | undefined;
|
|
32
|
+
has(path: string): boolean;
|
|
33
|
+
/** Registered static paths, in insertion order. */
|
|
34
|
+
keys(): IterableIterator<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Yields `[path, handler]` pairs for feeding Bun's `routes` map.
|
|
37
|
+
*/
|
|
38
|
+
entries(): IterableIterator<[string, CompiledHandler]>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static dispatch table.
|
|
3
|
+
*
|
|
4
|
+
* Static API routes are served by Bun's native `routes` map (the fast path);
|
|
5
|
+
* this holds the framework-side copy so the Router can enumerate them into
|
|
6
|
+
* Bun's map and resolve loose-trailing-slash variants Bun did not match.
|
|
7
|
+
* Keyed by path; one compiled handler serves all methods, with dispatch and
|
|
8
|
+
* 405+Allow inside it.
|
|
9
|
+
*/
|
|
10
|
+
export class StaticMap {
|
|
11
|
+
map = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Registers a compiled handler for a static path.
|
|
14
|
+
* @throws if a *different* handler is already registered at the same path
|
|
15
|
+
* (duplicate static route). Re-setting the same handler reference
|
|
16
|
+
* (used for loose trailing-slash variants) is allowed.
|
|
17
|
+
*/
|
|
18
|
+
set(path, handler, cores) {
|
|
19
|
+
const existing = this.map.get(path);
|
|
20
|
+
if (existing !== undefined && existing.handler !== handler) {
|
|
21
|
+
throw new Error(`Duplicate static route registered: ${path}`);
|
|
22
|
+
}
|
|
23
|
+
this.map.set(path, { handler, cores });
|
|
24
|
+
}
|
|
25
|
+
get(path) {
|
|
26
|
+
return this.map.get(path)?.handler;
|
|
27
|
+
}
|
|
28
|
+
/** The full entry (handler + method cores) for a static path. */
|
|
29
|
+
getEntry(path) {
|
|
30
|
+
return this.map.get(path);
|
|
31
|
+
}
|
|
32
|
+
has(path) {
|
|
33
|
+
return this.map.has(path);
|
|
34
|
+
}
|
|
35
|
+
/** Registered static paths, in insertion order. */
|
|
36
|
+
keys() {
|
|
37
|
+
return this.map.keys();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Yields `[path, handler]` pairs for feeding Bun's `routes` map.
|
|
41
|
+
*/
|
|
42
|
+
entries() {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const [path, entry] of this.map)
|
|
45
|
+
out.push([path, entry.handler]);
|
|
46
|
+
return out[Symbol.iterator]();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { CompiledHandler } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Result of a successful trie match.
|
|
4
|
+
*/
|
|
5
|
+
export interface TrieMatch {
|
|
6
|
+
handler: CompiledHandler;
|
|
7
|
+
methods: Set<string>;
|
|
8
|
+
params: Record<string, string>;
|
|
9
|
+
wildcardParams?: string[];
|
|
10
|
+
isWildcard: boolean;
|
|
11
|
+
/** The route-definition path (for `RouteMeta.pattern`). */
|
|
12
|
+
pattern: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Optimized dynamic-route matcher.
|
|
16
|
+
*
|
|
17
|
+
* Per node the priority is literal continuation > `:param` > `*`, with
|
|
18
|
+
* backtracking when a literal prefix dead-ends. A `*` route also matches
|
|
19
|
+
* its own base path (`/files/*` matches `/files`, `wildcardParams: []`).
|
|
20
|
+
* A trailing slash is preserved: `/users/` binds `:id === ""` (the Router
|
|
21
|
+
* rejects empty params — the loose-slash retry then runs). Ambiguous param
|
|
22
|
+
* folders at one level and non-terminal wildcards throw at insert time.
|
|
23
|
+
*/
|
|
24
|
+
export declare class Trie {
|
|
25
|
+
private root;
|
|
26
|
+
/**
|
|
27
|
+
* Segment matcher retaining the exact decoding semantics for
|
|
28
|
+
* percent-encoded or non-absolute pathnames. Every route is inserted
|
|
29
|
+
* into both structures; the hot path never touches this one when the
|
|
30
|
+
* pathname is absolute and percent-free.
|
|
31
|
+
*/
|
|
32
|
+
private legacy;
|
|
33
|
+
/**
|
|
34
|
+
* Inserts a compiled route into the trie.
|
|
35
|
+
* @throws on ambiguous param folders (two different param names at the same level)
|
|
36
|
+
* or a wildcard segment that is not the last segment (unmatchable by design).
|
|
37
|
+
*/
|
|
38
|
+
insert(path: string, handler: CompiledHandler, methods: Set<string>, isWildcard: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Matches a pathname against the trie.
|
|
41
|
+
* @param pathname A pathname. A single trailing slash is preserved so that
|
|
42
|
+
* `:param` routes can capture an empty value (e.g. `/users/` → `:id`
|
|
43
|
+
* with `id === ""`), matching Bun's native behavior.
|
|
44
|
+
* @returns the match result, or `null` if no route matches.
|
|
45
|
+
*/
|
|
46
|
+
match(pathname: string): TrieMatch | null;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the allowed methods for a pathname, or `null` if it does not match.
|
|
49
|
+
*/
|
|
50
|
+
allowedMethods(pathname: string): Set<string> | null;
|
|
51
|
+
/**
|
|
52
|
+
* Emits every registered pattern in strict match-priority order: a
|
|
53
|
+
* pre-order DFS following the matcher's per-node priority (static
|
|
54
|
+
* continuations, then `:param`, then `*`). The first emitted pattern that
|
|
55
|
+
* can match a path is exactly the one the trie would select — the
|
|
56
|
+
* authoritative ordering source for the RegExp matcher.
|
|
57
|
+
*/
|
|
58
|
+
orderedPatterns(): string[];
|
|
59
|
+
private visitRadix;
|
|
60
|
+
private insertRadix;
|
|
61
|
+
/**
|
|
62
|
+
* Descends `part` into the radix subtree, splitting nodes where the
|
|
63
|
+
* existing literal run and `part` diverge. Returns the node whose
|
|
64
|
+
* `part` ends where `part` ends.
|
|
65
|
+
*/
|
|
66
|
+
private insertPart;
|
|
67
|
+
private matchRadix;
|
|
68
|
+
private matchNode;
|
|
69
|
+
}
|