@rhythmjs/router 0.0.9 → 0.0.11
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 +33 -92
- package/dist/context.d.ts +18 -2
- package/dist/context.js +10 -68
- package/dist/fetch.d.ts +2 -4
- package/dist/fetch.js +8 -16
- package/dist/rhythm-router-88dtq5mx.js +20 -0
- package/dist/rhythm-router-n08cmxbj.js +53 -0
- package/dist/rhythm-router-yj4ffyyg.js +70 -0
- package/dist/rhythm-router.d.ts +28 -28
- package/dist/rhythm-router.js +90 -88
- package/dist/serve.d.ts +29 -7
- package/dist/serve.js +64 -18
- package/dist/static.d.ts +10 -0
- package/dist/static.js +7 -0
- package/package.json +15 -42
- package/dist/adapters/aws-lambda.d.ts +0 -8
- package/dist/adapters/aws-lambda.js +0 -9
- package/dist/adapters/bun.d.ts +0 -5
- package/dist/adapters/bun.js +0 -5
- package/dist/adapters/cloudflare.d.ts +0 -5
- package/dist/adapters/cloudflare.js +0 -13
- package/dist/adapters/deno.d.ts +0 -5
- package/dist/adapters/deno.js +0 -5
- package/dist/adapters/netlify.d.ts +0 -5
- package/dist/adapters/netlify.js +0 -10
- package/dist/adapters/node.d.ts +0 -11
- package/dist/adapters/node.js +0 -9
- package/dist/adapters/service-worker.d.ts +0 -11
- package/dist/adapters/service-worker.js +0 -11
- package/dist/adapters/vercel.d.ts +0 -5
- package/dist/adapters/vercel.js +0 -5
- package/dist/base--TyruAfY.d.ts +0 -10
- package/dist/base-B8GEu3z4.js +0 -25
- package/dist/context-ChHlG-q0.d.ts +0 -24
- package/dist/radix-tree.d.ts +0 -18
- package/dist/radix-tree.js +0 -150
package/dist/rhythm-router.js
CHANGED
|
@@ -1,90 +1,92 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/rhythm-router.ts
|
|
2
3
|
import { compose } from "@rhythmjs/rhythm/compose";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
4
|
+
import { addRoute, createRouter, findRoute } from "rou3";
|
|
5
|
+
function joinPath(prefix, path) {
|
|
6
|
+
if (!prefix)
|
|
7
|
+
return path;
|
|
8
|
+
const trimmedPrefix = prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
9
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
10
|
+
return `${trimmedPrefix}${normalizedPath}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class RhythmRouter {
|
|
14
|
+
#options;
|
|
15
|
+
#entries = [];
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.#options = options;
|
|
18
|
+
}
|
|
19
|
+
get #prefix() {
|
|
20
|
+
return this.#options.prefix ?? "";
|
|
21
|
+
}
|
|
22
|
+
get entries() {
|
|
23
|
+
return [...this.#entries];
|
|
24
|
+
}
|
|
25
|
+
use(fn) {
|
|
26
|
+
if (typeof fn !== "function")
|
|
27
|
+
throw new TypeError("middleware must be a function!");
|
|
28
|
+
this.#entries.push({ kind: "middleware", fn });
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
#route(method, path, handlers) {
|
|
32
|
+
this.#entries.push({ kind: "route", method, path: joinPath(this.#prefix, path), handlers });
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
get(path, ...handlers) {
|
|
36
|
+
return this.#route("GET", path, handlers);
|
|
37
|
+
}
|
|
38
|
+
post(path, ...handlers) {
|
|
39
|
+
return this.#route("POST", path, handlers);
|
|
40
|
+
}
|
|
41
|
+
put(path, ...handlers) {
|
|
42
|
+
return this.#route("PUT", path, handlers);
|
|
43
|
+
}
|
|
44
|
+
patch(path, ...handlers) {
|
|
45
|
+
return this.#route("PATCH", path, handlers);
|
|
46
|
+
}
|
|
47
|
+
delete(path, ...handlers) {
|
|
48
|
+
return this.#route("DELETE", path, handlers);
|
|
49
|
+
}
|
|
50
|
+
#compile() {
|
|
51
|
+
const dispatchFor = (tree) => {
|
|
52
|
+
return async (ctx, next) => {
|
|
53
|
+
const match = findRoute(tree, ctx.request.method, new URL(ctx.request.url).pathname);
|
|
54
|
+
if (!match) {
|
|
55
|
+
await next();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
await match.data({ ...ctx, params: match.params ?? {} }, next);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const stack = [];
|
|
62
|
+
let i = 0;
|
|
63
|
+
while (i < this.#entries.length) {
|
|
64
|
+
const entry = this.#entries[i];
|
|
65
|
+
if (entry.kind === "middleware") {
|
|
66
|
+
stack.push(entry.fn);
|
|
67
|
+
i++;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const tree = createRouter();
|
|
71
|
+
while (i < this.#entries.length) {
|
|
72
|
+
const route = this.#entries[i];
|
|
73
|
+
if (route.kind !== "route")
|
|
74
|
+
break;
|
|
75
|
+
addRoute(tree, route.method, route.path, compose(route.handlers));
|
|
76
|
+
i++;
|
|
77
|
+
}
|
|
78
|
+
stack.push(dispatchFor(tree));
|
|
79
|
+
}
|
|
80
|
+
return compose(stack);
|
|
81
|
+
}
|
|
82
|
+
middleware() {
|
|
83
|
+
const fn = this.#compile();
|
|
84
|
+
return async (ctx, next) => {
|
|
85
|
+
await fn(ctx, next);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
RhythmRouter,
|
|
91
|
+
joinPath
|
|
88
92
|
};
|
|
89
|
-
//#endregion
|
|
90
|
-
export { RhythmRouter };
|
package/dist/serve.d.ts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export type
|
|
1
|
+
import type { Rhythm } from "@rhythmjs/rhythm";
|
|
2
|
+
import type { RhythmHttpContext } from "./context";
|
|
3
|
+
import { type StaticMiddlewareOptions } from "./static";
|
|
4
|
+
export type { StaticMiddlewareOptions };
|
|
5
|
+
export type Server = Bun.Server<unknown>;
|
|
6
|
+
export type ErrorHandler = (error: unknown) => Response | Promise<Response>;
|
|
7
|
+
export type ServeMiddleware = (request: Request, next: () => Promise<Response>) => Response | Promise<Response>;
|
|
8
|
+
export type UpgradeHandler = (request: Request, server: Server) => Response | undefined | null | Promise<Response | undefined> | null;
|
|
9
|
+
export interface RhythmServeOptions {
|
|
10
|
+
port?: number;
|
|
11
|
+
hostname?: string;
|
|
12
|
+
unix?: string;
|
|
13
|
+
reusePort?: boolean;
|
|
14
|
+
idleTimeout?: number;
|
|
15
|
+
development?: boolean;
|
|
16
|
+
maxRequestBodySize?: number;
|
|
17
|
+
tls?: Bun.TLSOptions;
|
|
18
|
+
error?: ErrorHandler;
|
|
19
|
+
middleware?: ServeMiddleware[];
|
|
20
|
+
static?: StaticMiddlewareOptions | StaticMiddlewareOptions[];
|
|
21
|
+
/** Bun websocket behavior; pair with `upgrade` to accept connections. */
|
|
22
|
+
websocket?: Bun.WebSocketHandler<never>;
|
|
23
|
+
/**
|
|
24
|
+
* Called for websocket upgrade requests — `RhythmWs.upgrade` fits directly.
|
|
25
|
+
* A Response rejects, undefined means `server.upgrade()` succeeded, and
|
|
26
|
+
* null falls through to the HTTP app.
|
|
27
|
+
*/
|
|
28
|
+
upgrade?: UpgradeHandler;
|
|
29
|
+
}
|
|
6
30
|
export declare const errorToResponse: ErrorHandler;
|
|
7
31
|
export declare function serve<TContext extends RhythmHttpContext, TProviders extends object = {}>(app: Rhythm<RhythmHttpContext, TContext, TProviders>, options?: RhythmServeOptions): Server;
|
|
8
|
-
//#endregion
|
|
9
|
-
export type { ErrorHandler, Server, ServerMiddleware, ServerPlugin };
|
package/dist/serve.js
CHANGED
|
@@ -1,21 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
import"./rhythm-router-yj4ffyyg.js";
|
|
3
|
+
import {
|
|
4
|
+
toFetchHandler2
|
|
5
|
+
} from "./rhythm-router-88dtq5mx.js";
|
|
6
|
+
import {
|
|
7
|
+
staticMiddleware2
|
|
8
|
+
} from "./rhythm-router-n08cmxbj.js";
|
|
9
|
+
|
|
10
|
+
// src/serve.ts
|
|
11
|
+
var errorToResponse = (error) => {
|
|
12
|
+
const status = error.status ?? error.statusCode ?? 500;
|
|
13
|
+
const message = status >= 500 ? "Internal Server Error" : error instanceof Error ? error.message : String(error);
|
|
14
|
+
if (status >= 500)
|
|
15
|
+
console.error(error);
|
|
16
|
+
return new Response(message, {
|
|
17
|
+
status,
|
|
18
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
19
|
+
});
|
|
12
20
|
};
|
|
13
21
|
function serve(app, options = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
const {
|
|
23
|
+
static: staticOptions,
|
|
24
|
+
middleware = [],
|
|
25
|
+
error = errorToResponse,
|
|
26
|
+
websocket,
|
|
27
|
+
upgrade,
|
|
28
|
+
...bunOptions
|
|
29
|
+
} = options;
|
|
30
|
+
const assets = staticOptions === undefined ? [] : [staticOptions].flat().map(staticMiddleware2);
|
|
31
|
+
const chain = [...middleware, ...assets];
|
|
32
|
+
const handler = toFetchHandler2(app);
|
|
33
|
+
const dispatch = (request) => {
|
|
34
|
+
let index = -1;
|
|
35
|
+
const next = async (step) => {
|
|
36
|
+
if (step <= index)
|
|
37
|
+
throw new Error("next() called multiple times");
|
|
38
|
+
index = step;
|
|
39
|
+
return step < chain.length ? chain[step](request, () => next(step + 1)) : handler(request);
|
|
40
|
+
};
|
|
41
|
+
return next(0);
|
|
42
|
+
};
|
|
43
|
+
return Bun.serve({
|
|
44
|
+
...bunOptions,
|
|
45
|
+
...websocket === undefined ? {} : { websocket },
|
|
46
|
+
async fetch(request, server) {
|
|
47
|
+
try {
|
|
48
|
+
Object.defineProperty(request, "ip", {
|
|
49
|
+
configurable: true,
|
|
50
|
+
get: () => server.requestIP(request)?.address
|
|
51
|
+
});
|
|
52
|
+
if (upgrade !== undefined && request.headers.get("upgrade")?.toLowerCase() === "websocket") {
|
|
53
|
+
const result = await upgrade(request, server);
|
|
54
|
+
if (result !== null)
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
return await dispatch(request);
|
|
58
|
+
} catch (thrown) {
|
|
59
|
+
return error(thrown);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
19
63
|
}
|
|
20
|
-
|
|
21
|
-
|
|
64
|
+
export {
|
|
65
|
+
errorToResponse,
|
|
66
|
+
serve
|
|
67
|
+
};
|
package/dist/static.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ServeMiddleware } from "./serve";
|
|
2
|
+
export interface StaticMiddlewareOptions {
|
|
3
|
+
dir: string;
|
|
4
|
+
prefix?: string;
|
|
5
|
+
index?: string;
|
|
6
|
+
maxAge?: number;
|
|
7
|
+
immutable?: boolean;
|
|
8
|
+
etag?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function staticMiddleware(options: StaticMiddlewareOptions): ServeMiddleware;
|
package/dist/static.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhythmjs/router",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "Bun-native HTTP router for the Rhythm middleware kernel, matching with rou3 and serving with Bun.serve.",
|
|
5
5
|
"homepage": "https://rhythm.js.org/router",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"repository": {
|
|
@@ -19,10 +19,6 @@
|
|
|
19
19
|
"types": "./dist/rhythm-router.d.ts",
|
|
20
20
|
"default": "./dist/rhythm-router.js"
|
|
21
21
|
},
|
|
22
|
-
"./radix-tree": {
|
|
23
|
-
"types": "./dist/radix-tree.d.ts",
|
|
24
|
-
"default": "./dist/radix-tree.js"
|
|
25
|
-
},
|
|
26
22
|
"./context": {
|
|
27
23
|
"types": "./dist/context.d.ts",
|
|
28
24
|
"default": "./dist/context.js"
|
|
@@ -35,37 +31,9 @@
|
|
|
35
31
|
"types": "./dist/serve.d.ts",
|
|
36
32
|
"default": "./dist/serve.js"
|
|
37
33
|
},
|
|
38
|
-
"./
|
|
39
|
-
"types": "./dist/
|
|
40
|
-
"default": "./dist/
|
|
41
|
-
},
|
|
42
|
-
"./adapters/bun": {
|
|
43
|
-
"types": "./dist/adapters/bun.d.ts",
|
|
44
|
-
"default": "./dist/adapters/bun.js"
|
|
45
|
-
},
|
|
46
|
-
"./adapters/deno": {
|
|
47
|
-
"types": "./dist/adapters/deno.d.ts",
|
|
48
|
-
"default": "./dist/adapters/deno.js"
|
|
49
|
-
},
|
|
50
|
-
"./adapters/vercel": {
|
|
51
|
-
"types": "./dist/adapters/vercel.d.ts",
|
|
52
|
-
"default": "./dist/adapters/vercel.js"
|
|
53
|
-
},
|
|
54
|
-
"./adapters/netlify": {
|
|
55
|
-
"types": "./dist/adapters/netlify.d.ts",
|
|
56
|
-
"default": "./dist/adapters/netlify.js"
|
|
57
|
-
},
|
|
58
|
-
"./adapters/cloudflare": {
|
|
59
|
-
"types": "./dist/adapters/cloudflare.d.ts",
|
|
60
|
-
"default": "./dist/adapters/cloudflare.js"
|
|
61
|
-
},
|
|
62
|
-
"./adapters/aws-lambda": {
|
|
63
|
-
"types": "./dist/adapters/aws-lambda.d.ts",
|
|
64
|
-
"default": "./dist/adapters/aws-lambda.js"
|
|
65
|
-
},
|
|
66
|
-
"./adapters/service-worker": {
|
|
67
|
-
"types": "./dist/adapters/service-worker.d.ts",
|
|
68
|
-
"default": "./dist/adapters/service-worker.js"
|
|
34
|
+
"./static": {
|
|
35
|
+
"types": "./dist/static.d.ts",
|
|
36
|
+
"default": "./dist/static.js"
|
|
69
37
|
},
|
|
70
38
|
"./adapters/context": {
|
|
71
39
|
"types": "./dist/context.d.ts",
|
|
@@ -77,15 +45,20 @@
|
|
|
77
45
|
"access": "public"
|
|
78
46
|
},
|
|
79
47
|
"dependencies": {
|
|
80
|
-
"
|
|
81
|
-
"@rhythmjs/rhythm": "0.0.
|
|
48
|
+
"rou3": "^0.11.0",
|
|
49
|
+
"@rhythmjs/rhythm": "0.0.11"
|
|
82
50
|
},
|
|
83
51
|
"devDependencies": {
|
|
52
|
+
"@types/bun": "^1.2.0",
|
|
84
53
|
"@types/node": "^26.6.3",
|
|
85
|
-
"typescript": "^7.0.2"
|
|
86
|
-
"vite-plus": "^1.0.0"
|
|
54
|
+
"typescript": "^7.0.2"
|
|
87
55
|
},
|
|
88
56
|
"engines": {
|
|
89
|
-
"
|
|
57
|
+
"bun": ">=1.2.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "bun build src/rhythm-router.ts src/context.ts src/fetch.ts src/serve.ts src/static.ts --outdir dist --root src --format esm --target bun --packages external --splitting && tsc -p tsconfig.build.json",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"test": "bun test"
|
|
90
63
|
}
|
|
91
64
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as RhythmHttpContext } from "../context-ChHlG-q0.js";
|
|
2
|
-
import { t as AdapterOptions } from "../base--TyruAfY.js";
|
|
3
|
-
import { AWSLambdaHandler } from "srvx/aws-lambda";
|
|
4
|
-
import { Rhythm } from "@rhythmjs/rhythm";
|
|
5
|
-
//#region src/adapters/aws-lambda.d.ts
|
|
6
|
-
export declare function handle<TContext extends RhythmHttpContext, TProviders extends object = {}>(app: Rhythm<RhythmHttpContext, TContext, TProviders>, options?: AdapterOptions): AWSLambdaHandler;
|
|
7
|
-
//#endregion
|
|
8
|
-
export type { AWSLambdaHandler, AdapterOptions };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { t as createFetchAdapter } from "../base-B8GEu3z4.js";
|
|
2
|
-
import { toLambdaHandler } from "srvx/aws-lambda";
|
|
3
|
-
//#region src/adapters/aws-lambda.ts
|
|
4
|
-
const fetchHandle = createFetchAdapter();
|
|
5
|
-
function handle(app, options = {}) {
|
|
6
|
-
return toLambdaHandler({ fetch: fetchHandle(app, options) });
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { handle };
|
package/dist/adapters/bun.d.ts
DELETED
package/dist/adapters/bun.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { n as setRuntime, t as createFetchAdapter } from "../base-B8GEu3z4.js";
|
|
2
|
-
//#region src/adapters/cloudflare.ts
|
|
3
|
-
const handle = createFetchAdapter((request, env, context) => {
|
|
4
|
-
if (env !== void 0 || context !== void 0) setRuntime(request, {
|
|
5
|
-
name: "cloudflare",
|
|
6
|
-
cloudflare: {
|
|
7
|
-
env,
|
|
8
|
-
context
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
//#endregion
|
|
13
|
-
export { handle };
|
package/dist/adapters/deno.d.ts
DELETED
package/dist/adapters/deno.js
DELETED
package/dist/adapters/netlify.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { n as setRuntime, t as createFetchAdapter } from "../base-B8GEu3z4.js";
|
|
2
|
-
//#region src/adapters/netlify.ts
|
|
3
|
-
const handle = createFetchAdapter((request, context) => {
|
|
4
|
-
if (context !== void 0) setRuntime(request, {
|
|
5
|
-
name: "netlify",
|
|
6
|
-
netlify: { context }
|
|
7
|
-
});
|
|
8
|
-
});
|
|
9
|
-
//#endregion
|
|
10
|
-
export { handle };
|
package/dist/adapters/node.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { t as RhythmHttpContext } from "../context-ChHlG-q0.js";
|
|
2
|
-
import { t as AdapterOptions } from "../base--TyruAfY.js";
|
|
3
|
-
import { NodeHttp1Handler, NodeHttp2Handler } from "srvx";
|
|
4
|
-
import { Rhythm } from "@rhythmjs/rhythm";
|
|
5
|
-
//#region src/adapters/node.d.ts
|
|
6
|
-
export interface NodeHandlerOptions extends AdapterOptions {
|
|
7
|
-
maxRequestBodySize?: number;
|
|
8
|
-
}
|
|
9
|
-
export type NodeHandler = NodeHttp1Handler & NodeHttp2Handler;
|
|
10
|
-
export declare function getRequestListener<TContext extends RhythmHttpContext, TProviders extends object = {}>(app: Rhythm<RhythmHttpContext, TContext, TProviders>, options?: NodeHandlerOptions): NodeHandler;
|
|
11
|
-
//#endregion
|
package/dist/adapters/node.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { t as createFetchAdapter } from "../base-B8GEu3z4.js";
|
|
2
|
-
import { toNodeHandler } from "srvx/node";
|
|
3
|
-
//#region src/adapters/node.ts
|
|
4
|
-
const fetchHandle = createFetchAdapter();
|
|
5
|
-
function getRequestListener(app, options = {}) {
|
|
6
|
-
return toNodeHandler(fetchHandle(app, options), options);
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { getRequestListener };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { t as RhythmHttpContext } from "../context-ChHlG-q0.js";
|
|
2
|
-
import { t as AdapterOptions } from "../base--TyruAfY.js";
|
|
3
|
-
import { Rhythm } from "@rhythmjs/rhythm";
|
|
4
|
-
//#region src/adapters/service-worker.d.ts
|
|
5
|
-
interface FetchEventLike {
|
|
6
|
-
readonly request: Request;
|
|
7
|
-
respondWith(response: Response | Promise<Response>): void;
|
|
8
|
-
}
|
|
9
|
-
export declare function handle<TContext extends RhythmHttpContext, TProviders extends object = {}>(app: Rhythm<RhythmHttpContext, TContext, TProviders>, options?: AdapterOptions): (event: FetchEventLike) => void;
|
|
10
|
-
//#endregion
|
|
11
|
-
export type { AdapterOptions };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { t as createFetchAdapter } from "../base-B8GEu3z4.js";
|
|
2
|
-
//#region src/adapters/service-worker.ts
|
|
3
|
-
const fetchHandle = createFetchAdapter();
|
|
4
|
-
function handle(app, options = {}) {
|
|
5
|
-
const handler = fetchHandle(app, options);
|
|
6
|
-
return (event) => {
|
|
7
|
-
event.respondWith(handler(event.request));
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
export { handle };
|
package/dist/adapters/vercel.js
DELETED
package/dist/base--TyruAfY.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { t as RhythmHttpContext } from "./context-ChHlG-q0.js";
|
|
2
|
-
import { ErrorHandler, ServerRuntimeContext } from "srvx";
|
|
3
|
-
import { Rhythm } from "@rhythmjs/rhythm";
|
|
4
|
-
//#region src/adapters/base.d.ts
|
|
5
|
-
interface AdapterOptions {
|
|
6
|
-
onError?: ErrorHandler;
|
|
7
|
-
}
|
|
8
|
-
type FetchAdapter<TExtra extends unknown[] = []> = <TContext extends RhythmHttpContext, TProviders extends object = {}>(app: Rhythm<RhythmHttpContext, TContext, TProviders>, options?: AdapterOptions) => (request: Request, ...extra: TExtra) => Promise<Response>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { FetchAdapter as n, AdapterOptions as t };
|
package/dist/base-B8GEu3z4.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { toFetchHandler } from "./fetch.js";
|
|
2
|
-
import { errorToResponse } from "./serve.js";
|
|
3
|
-
//#region src/adapters/base.ts
|
|
4
|
-
function setRuntime(request, runtime) {
|
|
5
|
-
Object.defineProperty(request, "runtime", {
|
|
6
|
-
value: runtime,
|
|
7
|
-
configurable: true
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
function createFetchAdapter(enrich) {
|
|
11
|
-
return (app, options = {}) => {
|
|
12
|
-
const handler = toFetchHandler(app);
|
|
13
|
-
const onError = options.onError ?? errorToResponse;
|
|
14
|
-
return async (request, ...extra) => {
|
|
15
|
-
try {
|
|
16
|
-
enrich?.(request, ...extra);
|
|
17
|
-
return await handler(request);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
return onError(error);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { setRuntime as n, createFetchAdapter as t };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ServerRuntimeContext } from "srvx";
|
|
2
|
-
//#region src/context.d.ts
|
|
3
|
-
type RhythmRuntime = ServerRuntimeContext;
|
|
4
|
-
declare function getRuntime(request: Request): RhythmRuntime | undefined;
|
|
5
|
-
type RhythmResponseBody = string | ArrayBuffer | Uint8Array | Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | null;
|
|
6
|
-
declare class RhythmResponse {
|
|
7
|
-
status: number;
|
|
8
|
-
statusText: string | undefined;
|
|
9
|
-
headers: Headers;
|
|
10
|
-
body: RhythmResponseBody;
|
|
11
|
-
}
|
|
12
|
-
interface RhythmHttpContext {
|
|
13
|
-
readonly request: Request;
|
|
14
|
-
readonly response: RhythmResponse;
|
|
15
|
-
json(data: unknown, status?: number): void;
|
|
16
|
-
text(body: string, status?: number): void;
|
|
17
|
-
html(body: string, status?: number): void;
|
|
18
|
-
error(status: number, message?: string): void;
|
|
19
|
-
redirect(url: string, status?: number): void;
|
|
20
|
-
}
|
|
21
|
-
declare function createHttpContext(request: Request): RhythmHttpContext;
|
|
22
|
-
declare function toResponse(response: RhythmResponse): Response;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { createHttpContext as a, RhythmRuntime as i, RhythmResponse as n, getRuntime as o, RhythmResponseBody as r, toResponse as s, RhythmHttpContext as t };
|
package/dist/radix-tree.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region src/radix-tree.d.ts
|
|
2
|
-
export declare class TreeNode<TMethod extends string = string, TPayload = unknown> {
|
|
3
|
-
path: string;
|
|
4
|
-
indices: string;
|
|
5
|
-
children: TreeNode<TMethod, TPayload>[];
|
|
6
|
-
paramChild: TreeNode<TMethod, TPayload> | null;
|
|
7
|
-
paramName: string;
|
|
8
|
-
wildcardChild: TreeNode<TMethod, TPayload> | null;
|
|
9
|
-
methods: Map<TMethod, TPayload> | null;
|
|
10
|
-
}
|
|
11
|
-
export declare function createNode<TMethod extends string = string, TPayload = unknown>(): TreeNode<TMethod, TPayload>;
|
|
12
|
-
export declare function insertRoute<TMethod extends string, TPayload>(root: TreeNode<TMethod, TPayload>, method: TMethod, path: string, payload: TPayload): void;
|
|
13
|
-
export declare function lookupRoute<TMethod extends string, TPayload>(root: TreeNode<TMethod, TPayload>, method: string, pathname: string): {
|
|
14
|
-
payload: TPayload;
|
|
15
|
-
params: Record<string, string>;
|
|
16
|
-
} | null;
|
|
17
|
-
export declare function joinPath(prefix: string, path: string): string;
|
|
18
|
-
//#endregion
|