@mokup/server 1.1.0 → 1.1.2

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 (66) hide show
  1. package/README.md +9 -0
  2. package/README.zh-CN.md +9 -0
  3. package/dist/connect.cjs +25 -0
  4. package/dist/connect.d.cts +8 -0
  5. package/dist/connect.d.mts +8 -0
  6. package/dist/connect.d.ts +8 -0
  7. package/dist/connect.mjs +23 -0
  8. package/dist/express.cjs +11 -0
  9. package/dist/express.d.cts +7 -0
  10. package/dist/express.d.mts +7 -0
  11. package/dist/express.d.ts +7 -0
  12. package/dist/express.mjs +9 -0
  13. package/dist/fastify.cjs +39 -0
  14. package/dist/fastify.d.cts +18 -0
  15. package/dist/fastify.d.mts +18 -0
  16. package/dist/fastify.d.ts +18 -0
  17. package/dist/fastify.mjs +37 -0
  18. package/dist/fetch-server.cjs +1507 -0
  19. package/dist/fetch-server.d.cts +54 -0
  20. package/dist/fetch-server.d.mts +54 -0
  21. package/dist/fetch-server.d.ts +54 -0
  22. package/dist/fetch-server.mjs +1500 -0
  23. package/dist/fetch.cjs +26 -0
  24. package/dist/fetch.d.cts +6 -0
  25. package/dist/fetch.d.mts +6 -0
  26. package/dist/fetch.d.ts +6 -0
  27. package/dist/fetch.mjs +24 -0
  28. package/dist/hono.cjs +27 -0
  29. package/dist/hono.d.cts +21 -0
  30. package/dist/hono.d.mts +21 -0
  31. package/dist/hono.d.ts +21 -0
  32. package/dist/hono.mjs +25 -0
  33. package/dist/index.cjs +5 -1593
  34. package/dist/index.d.cts +3 -134
  35. package/dist/index.d.mts +3 -134
  36. package/dist/index.d.ts +3 -134
  37. package/dist/index.mjs +4 -1585
  38. package/dist/koa.cjs +38 -0
  39. package/dist/koa.d.cts +18 -0
  40. package/dist/koa.d.mts +18 -0
  41. package/dist/koa.d.ts +18 -0
  42. package/dist/koa.mjs +36 -0
  43. package/dist/node.cjs +26 -0
  44. package/dist/node.d.cts +12 -0
  45. package/dist/node.d.mts +12 -0
  46. package/dist/node.d.ts +12 -0
  47. package/dist/node.mjs +19 -0
  48. package/dist/shared/{server.BdTl0qJd.cjs → server.3GcmR3Ev.cjs} +2 -23
  49. package/dist/shared/{server.DNITwCtQ.d.cts → server.B82hrXoo.d.cts} +2 -2
  50. package/dist/shared/{server.DNITwCtQ.d.mts → server.B82hrXoo.d.mts} +2 -2
  51. package/dist/shared/{server.DNITwCtQ.d.ts → server.B82hrXoo.d.ts} +2 -2
  52. package/dist/shared/server.Cb2eiCU2.d.cts +17 -0
  53. package/dist/shared/server.Cb2eiCU2.d.mts +17 -0
  54. package/dist/shared/server.Cb2eiCU2.d.ts +17 -0
  55. package/dist/shared/{server.Dje1y79O.mjs → server.tZ4R8aB2.mjs} +1 -23
  56. package/dist/worker-node.cjs +74 -0
  57. package/dist/worker-node.d.cts +12 -0
  58. package/dist/worker-node.d.mts +12 -0
  59. package/dist/worker-node.d.ts +12 -0
  60. package/dist/worker-node.mjs +72 -0
  61. package/dist/worker.cjs +6 -2
  62. package/dist/worker.d.cts +2 -2
  63. package/dist/worker.d.mts +2 -2
  64. package/dist/worker.d.ts +2 -2
  65. package/dist/worker.mjs +6 -2
  66. package/package.json +44 -4
package/dist/fetch.cjs ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const runtime = require('@mokup/runtime');
4
+ const internal = require('./shared/server.3GcmR3Ev.cjs');
5
+
6
+ function createFetchHandler(options) {
7
+ const runtime$1 = runtime.createRuntime(internal.toRuntimeOptions(options));
8
+ const onNotFound = options.onNotFound ?? "next";
9
+ return async (request) => {
10
+ const runtimeRequest = await internal.toRuntimeRequestFromFetch(request);
11
+ const result = await runtime$1.handle(runtimeRequest);
12
+ if (!result) {
13
+ if (onNotFound === "response") {
14
+ return new Response(null, { status: 404 });
15
+ }
16
+ return null;
17
+ }
18
+ const responseBody = result.body === null ? null : typeof result.body === "string" ? result.body : internal.toArrayBuffer(result.body);
19
+ return new Response(responseBody, {
20
+ status: result.status,
21
+ headers: result.headers
22
+ });
23
+ };
24
+ }
25
+
26
+ exports.createFetchHandler = createFetchHandler;
@@ -0,0 +1,6 @@
1
+ import { S as ServerOptions, F as FetchHandler } from './shared/server.B82hrXoo.cjs';
2
+ import '@mokup/runtime';
3
+
4
+ declare function createFetchHandler(options: ServerOptions): FetchHandler;
5
+
6
+ export { createFetchHandler };
@@ -0,0 +1,6 @@
1
+ import { S as ServerOptions, F as FetchHandler } from './shared/server.B82hrXoo.mjs';
2
+ import '@mokup/runtime';
3
+
4
+ declare function createFetchHandler(options: ServerOptions): FetchHandler;
5
+
6
+ export { createFetchHandler };
@@ -0,0 +1,6 @@
1
+ import { S as ServerOptions, F as FetchHandler } from './shared/server.B82hrXoo.js';
2
+ import '@mokup/runtime';
3
+
4
+ declare function createFetchHandler(options: ServerOptions): FetchHandler;
5
+
6
+ export { createFetchHandler };
package/dist/fetch.mjs ADDED
@@ -0,0 +1,24 @@
1
+ import { createRuntime } from '@mokup/runtime';
2
+ import { t as toRuntimeOptions, d as toRuntimeRequestFromFetch, e as toArrayBuffer } from './shared/server.tZ4R8aB2.mjs';
3
+
4
+ function createFetchHandler(options) {
5
+ const runtime = createRuntime(toRuntimeOptions(options));
6
+ const onNotFound = options.onNotFound ?? "next";
7
+ return async (request) => {
8
+ const runtimeRequest = await toRuntimeRequestFromFetch(request);
9
+ const result = await runtime.handle(runtimeRequest);
10
+ if (!result) {
11
+ if (onNotFound === "response") {
12
+ return new Response(null, { status: 404 });
13
+ }
14
+ return null;
15
+ }
16
+ const responseBody = result.body === null ? null : typeof result.body === "string" ? result.body : toArrayBuffer(result.body);
17
+ return new Response(responseBody, {
18
+ status: result.status,
19
+ headers: result.headers
20
+ });
21
+ };
22
+ }
23
+
24
+ export { createFetchHandler };
package/dist/hono.cjs ADDED
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const fetch = require('./fetch.cjs');
4
+ require('@mokup/runtime');
5
+ require('./shared/server.3GcmR3Ev.cjs');
6
+
7
+ function createHonoMiddleware(options) {
8
+ const handler = fetch.createFetchHandler(options);
9
+ const middleware = async (context, next) => {
10
+ const response = await handler(context.req.raw);
11
+ if (!response) {
12
+ return await next();
13
+ }
14
+ return response;
15
+ };
16
+ const route = {
17
+ basePath: "",
18
+ path: "*",
19
+ method: "ALL",
20
+ handler: middleware
21
+ };
22
+ const bridge = middleware;
23
+ bridge.routes = [route];
24
+ return bridge;
25
+ }
26
+
27
+ exports.createHonoMiddleware = createHonoMiddleware;
@@ -0,0 +1,21 @@
1
+ import { S as ServerOptions } from './shared/server.B82hrXoo.cjs';
2
+ import '@mokup/runtime';
3
+
4
+ interface HonoContextLike {
5
+ req: {
6
+ raw: Request;
7
+ };
8
+ }
9
+ type HonoNext = () => Promise<Response | void>;
10
+ type HonoMiddleware = (context: HonoContextLike, next: HonoNext) => Promise<Response | void>;
11
+ interface HonoRouteLike {
12
+ basePath: string;
13
+ path: string;
14
+ method: string;
15
+ handler: HonoMiddleware;
16
+ }
17
+ declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
18
+ routes: HonoRouteLike[];
19
+ };
20
+
21
+ export { createHonoMiddleware };
@@ -0,0 +1,21 @@
1
+ import { S as ServerOptions } from './shared/server.B82hrXoo.mjs';
2
+ import '@mokup/runtime';
3
+
4
+ interface HonoContextLike {
5
+ req: {
6
+ raw: Request;
7
+ };
8
+ }
9
+ type HonoNext = () => Promise<Response | void>;
10
+ type HonoMiddleware = (context: HonoContextLike, next: HonoNext) => Promise<Response | void>;
11
+ interface HonoRouteLike {
12
+ basePath: string;
13
+ path: string;
14
+ method: string;
15
+ handler: HonoMiddleware;
16
+ }
17
+ declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
18
+ routes: HonoRouteLike[];
19
+ };
20
+
21
+ export { createHonoMiddleware };
package/dist/hono.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { S as ServerOptions } from './shared/server.B82hrXoo.js';
2
+ import '@mokup/runtime';
3
+
4
+ interface HonoContextLike {
5
+ req: {
6
+ raw: Request;
7
+ };
8
+ }
9
+ type HonoNext = () => Promise<Response | void>;
10
+ type HonoMiddleware = (context: HonoContextLike, next: HonoNext) => Promise<Response | void>;
11
+ interface HonoRouteLike {
12
+ basePath: string;
13
+ path: string;
14
+ method: string;
15
+ handler: HonoMiddleware;
16
+ }
17
+ declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
18
+ routes: HonoRouteLike[];
19
+ };
20
+
21
+ export { createHonoMiddleware };
package/dist/hono.mjs ADDED
@@ -0,0 +1,25 @@
1
+ import { createFetchHandler } from './fetch.mjs';
2
+ import '@mokup/runtime';
3
+ import './shared/server.tZ4R8aB2.mjs';
4
+
5
+ function createHonoMiddleware(options) {
6
+ const handler = createFetchHandler(options);
7
+ const middleware = async (context, next) => {
8
+ const response = await handler(context.req.raw);
9
+ if (!response) {
10
+ return await next();
11
+ }
12
+ return response;
13
+ };
14
+ const route = {
15
+ basePath: "",
16
+ path: "*",
17
+ method: "ALL",
18
+ handler: middleware
19
+ };
20
+ const bridge = middleware;
21
+ bridge.routes = [route];
22
+ return bridge;
23
+ }
24
+
25
+ export { createHonoMiddleware };