@rhythmjs/router 0.0.10 → 0.0.12
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 +55 -115
- package/dist/context.d.ts +18 -2
- package/dist/context.js +10 -68
- package/dist/fetch.d.ts +3 -4
- package/dist/fetch.js +30 -14
- 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 +27 -28
- package/dist/rhythm-router.js +87 -89
- package/dist/serve.d.ts +29 -7
- package/dist/serve.js +64 -18
- package/dist/static.d.ts +13 -0
- package/dist/static.js +67 -0
- package/package.json +11 -43
- 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-BMFEzT_g.js +0 -26
- package/dist/base-DwJhCkwZ.d.ts +0 -14
- package/dist/context-ChHlG-q0.d.ts +0 -24
package/dist/rhythm-router.js
CHANGED
|
@@ -1,94 +1,92 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/rhythm-router.ts
|
|
1
3
|
import { compose } from "@rhythmjs/rhythm/compose";
|
|
2
4
|
import { addRoute, createRouter, findRoute } from "rou3";
|
|
3
|
-
//#region src/rhythm-router.ts
|
|
4
5
|
function joinPath(prefix, path) {
|
|
5
|
-
|
|
6
|
-
|
|
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}`;
|
|
7
11
|
}
|
|
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
|
-
|
|
88
|
-
return async (ctx, next) => {
|
|
89
|
-
await fn(ctx, next);
|
|
90
|
-
};
|
|
91
|
-
}
|
|
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
|
|
92
92
|
};
|
|
93
|
-
//#endregion
|
|
94
|
-
export { RhythmRouter, joinPath };
|
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,13 @@
|
|
|
1
|
+
export interface ServeStaticOptions {
|
|
2
|
+
dir: string;
|
|
3
|
+
/** URL mount point (default the site root). */
|
|
4
|
+
prefix?: string;
|
|
5
|
+
/** Directory index filename served for trailing-slash requests (default "index.html"). */
|
|
6
|
+
index?: string;
|
|
7
|
+
/** Emit `Cache-Control: max-age=<n>`, with ", immutable" appended when `immutable` is set. */
|
|
8
|
+
maxAge?: number;
|
|
9
|
+
immutable?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** A Response for a hit, null for a miss — chain with `??` into your app handler. */
|
|
12
|
+
export type StaticHandler = (request: Request) => Promise<Response | null>;
|
|
13
|
+
export declare function serveStatic(options: ServeStaticOptions): StaticHandler;
|
package/dist/static.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/static.ts
|
|
3
|
+
import { join, normalize, sep } from "path";
|
|
4
|
+
function normalizePrefix(prefix) {
|
|
5
|
+
const withLeading = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
6
|
+
return withLeading.endsWith("/") ? withLeading.slice(0, -1) : withLeading;
|
|
7
|
+
}
|
|
8
|
+
function serveStatic(options) {
|
|
9
|
+
const prefix = normalizePrefix(options.prefix ?? "/");
|
|
10
|
+
const index = options.index ?? "index.html";
|
|
11
|
+
const cacheControl = options.maxAge === undefined ? undefined : `max-age=${options.maxAge}${options.immutable ? ", immutable" : ""}`;
|
|
12
|
+
return async (request) => {
|
|
13
|
+
if (request.method !== "GET" && request.method !== "HEAD")
|
|
14
|
+
return null;
|
|
15
|
+
let pathname;
|
|
16
|
+
try {
|
|
17
|
+
pathname = decodeURIComponent(new URL(request.url).pathname);
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (prefix !== "" && pathname !== prefix && !pathname.startsWith(`${prefix}/`))
|
|
22
|
+
return null;
|
|
23
|
+
const relative = normalize(pathname.slice(prefix.length));
|
|
24
|
+
if (relative.includes("\x00") || relative === ".." || relative.startsWith(`..${sep}`))
|
|
25
|
+
return null;
|
|
26
|
+
const path = pathname.endsWith("/") ? join(options.dir, relative, index) : join(options.dir, relative);
|
|
27
|
+
const file = Bun.file(path);
|
|
28
|
+
if (!await file.exists())
|
|
29
|
+
return null;
|
|
30
|
+
const size = file.size;
|
|
31
|
+
const mtime = Math.floor(file.lastModified);
|
|
32
|
+
const etag = `W/"${size.toString(16)}-${mtime.toString(16)}"`;
|
|
33
|
+
const headers = new Headers({
|
|
34
|
+
etag,
|
|
35
|
+
"last-modified": new Date(mtime).toUTCString(),
|
|
36
|
+
"accept-ranges": "bytes"
|
|
37
|
+
});
|
|
38
|
+
if (cacheControl !== undefined)
|
|
39
|
+
headers.set("cache-control", cacheControl);
|
|
40
|
+
const ifNoneMatch = request.headers.get("if-none-match");
|
|
41
|
+
if (ifNoneMatch !== null) {
|
|
42
|
+
if (ifNoneMatch.split(/\s*,\s*/).includes(etag))
|
|
43
|
+
return new Response(null, { status: 304, headers });
|
|
44
|
+
} else {
|
|
45
|
+
const ifModifiedSince = request.headers.get("if-modified-since");
|
|
46
|
+
if (ifModifiedSince !== null && Date.parse(ifModifiedSince) >= mtime - mtime % 1000) {
|
|
47
|
+
return new Response(null, { status: 304, headers });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const range = request.method === "GET" ? request.headers.get("range") : null;
|
|
51
|
+
const match = range === null ? null : /^bytes=(\d*)-(\d*)$/.exec(range);
|
|
52
|
+
if (match !== null && (match[1] !== "" || match[2] !== "")) {
|
|
53
|
+
const start = match[1] === "" ? Math.max(size - Number(match[2]), 0) : Number(match[1]);
|
|
54
|
+
const end = match[1] !== "" && match[2] !== "" ? Math.min(Number(match[2]), size - 1) : size - 1;
|
|
55
|
+
if (start >= size || start > end) {
|
|
56
|
+
headers.set("content-range", `bytes */${size}`);
|
|
57
|
+
return new Response(null, { status: 416, headers });
|
|
58
|
+
}
|
|
59
|
+
headers.set("content-range", `bytes ${start}-${end}/${size}`);
|
|
60
|
+
return new Response(file.slice(start, end + 1), { status: 206, headers });
|
|
61
|
+
}
|
|
62
|
+
return new Response(file, { headers });
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
serveStatic
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhythmjs/router",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "HTTP router for the Rhythm middleware kernel, matching with rou3
|
|
3
|
+
"version": "0.0.12",
|
|
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": {
|
|
@@ -27,42 +27,6 @@
|
|
|
27
27
|
"types": "./dist/fetch.d.ts",
|
|
28
28
|
"default": "./dist/fetch.js"
|
|
29
29
|
},
|
|
30
|
-
"./serve": {
|
|
31
|
-
"types": "./dist/serve.d.ts",
|
|
32
|
-
"default": "./dist/serve.js"
|
|
33
|
-
},
|
|
34
|
-
"./adapters/node": {
|
|
35
|
-
"types": "./dist/adapters/node.d.ts",
|
|
36
|
-
"default": "./dist/adapters/node.js"
|
|
37
|
-
},
|
|
38
|
-
"./adapters/bun": {
|
|
39
|
-
"types": "./dist/adapters/bun.d.ts",
|
|
40
|
-
"default": "./dist/adapters/bun.js"
|
|
41
|
-
},
|
|
42
|
-
"./adapters/deno": {
|
|
43
|
-
"types": "./dist/adapters/deno.d.ts",
|
|
44
|
-
"default": "./dist/adapters/deno.js"
|
|
45
|
-
},
|
|
46
|
-
"./adapters/vercel": {
|
|
47
|
-
"types": "./dist/adapters/vercel.d.ts",
|
|
48
|
-
"default": "./dist/adapters/vercel.js"
|
|
49
|
-
},
|
|
50
|
-
"./adapters/netlify": {
|
|
51
|
-
"types": "./dist/adapters/netlify.d.ts",
|
|
52
|
-
"default": "./dist/adapters/netlify.js"
|
|
53
|
-
},
|
|
54
|
-
"./adapters/cloudflare": {
|
|
55
|
-
"types": "./dist/adapters/cloudflare.d.ts",
|
|
56
|
-
"default": "./dist/adapters/cloudflare.js"
|
|
57
|
-
},
|
|
58
|
-
"./adapters/aws-lambda": {
|
|
59
|
-
"types": "./dist/adapters/aws-lambda.d.ts",
|
|
60
|
-
"default": "./dist/adapters/aws-lambda.js"
|
|
61
|
-
},
|
|
62
|
-
"./adapters/service-worker": {
|
|
63
|
-
"types": "./dist/adapters/service-worker.d.ts",
|
|
64
|
-
"default": "./dist/adapters/service-worker.js"
|
|
65
|
-
},
|
|
66
30
|
"./adapters/context": {
|
|
67
31
|
"types": "./dist/context.d.ts",
|
|
68
32
|
"default": "./dist/context.js"
|
|
@@ -74,15 +38,19 @@
|
|
|
74
38
|
},
|
|
75
39
|
"dependencies": {
|
|
76
40
|
"rou3": "^0.11.0",
|
|
77
|
-
"
|
|
78
|
-
"@rhythmjs/rhythm": "0.0.10"
|
|
41
|
+
"@rhythmjs/rhythm": "0.0.12"
|
|
79
42
|
},
|
|
80
43
|
"devDependencies": {
|
|
44
|
+
"@types/bun": "^1.2.0",
|
|
81
45
|
"@types/node": "^26.6.3",
|
|
82
|
-
"typescript": "^7.0.2"
|
|
83
|
-
"vite-plus": "^1.0.0"
|
|
46
|
+
"typescript": "^7.0.2"
|
|
84
47
|
},
|
|
85
48
|
"engines": {
|
|
86
|
-
"
|
|
49
|
+
"bun": ">=1.2.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "bun build src/rhythm-router.ts src/context.ts src/fetch.ts --outdir dist --root src --format esm --target bun --packages external --splitting && tsc -p tsconfig.build.json",
|
|
53
|
+
"typecheck": "tsc --noEmit",
|
|
54
|
+
"test": "bun test"
|
|
87
55
|
}
|
|
88
56
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as RhythmHttpContext } from "../context-ChHlG-q0.js";
|
|
2
|
-
import { t as AdapterOptions } from "../base-DwJhCkwZ.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-BMFEzT_g.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-BMFEzT_g.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-BMFEzT_g.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-DwJhCkwZ.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-BMFEzT_g.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-DwJhCkwZ.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-BMFEzT_g.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-BMFEzT_g.js
DELETED
|
@@ -1,26 +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
|
-
if (options.websocket && request.headers.get("upgrade")?.toLowerCase() === "websocket") return options.websocket.handleUpgrade(request, ...extra);
|
|
16
|
-
try {
|
|
17
|
-
enrich?.(request, ...extra);
|
|
18
|
-
return await handler(request);
|
|
19
|
-
} catch (error) {
|
|
20
|
-
return onError(error);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { setRuntime as n, createFetchAdapter as t };
|