@mokup/server 1.1.1 → 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 -1685
  34. package/dist/index.d.cts +3 -136
  35. package/dist/index.d.mts +3 -136
  36. package/dist/index.d.ts +3 -136
  37. package/dist/index.mjs +4 -1677
  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 +43 -3
package/README.md CHANGED
@@ -5,3 +5,12 @@ English | [Chinese](./README.zh-CN.md)
5
5
  ## Overview
6
6
 
7
7
  Server adapters for Mokup that integrate the runtime with popular Node frameworks and Workers. For detailed usage, see https://mokup.icebreaker.top.
8
+
9
+ This package is used internally by `mokup`. Prefer the public entrypoints below.
10
+
11
+ ## Entrypoints
12
+
13
+ - `mokup/server`: Node adapters and dev server helpers
14
+ - `mokup/server/node`: Node `serve` helper
15
+ - `mokup/server/fetch`: runtime-agnostic fetch handler + types
16
+ - `mokup/server/worker`: Worker helper that wraps `createFetchHandler` and returns 404 on `null`
package/README.zh-CN.md CHANGED
@@ -5,3 +5,12 @@
5
5
  ## 概览
6
6
 
7
7
  Mokup 的 Server 适配器集合,用于把运行时接入各类 Node 框架与 Worker。完整文档见 https://mokup.icebreaker.top。
8
+
9
+ 该包为 `mokup` 内部依赖,建议使用下方公开入口。
10
+
11
+ ## 入口说明
12
+
13
+ - `mokup/server`:Node 适配器与开发服务器
14
+ - `mokup/server/node`:Node `serve` 入口
15
+ - `mokup/server/fetch`:运行时无关的 fetch 入口 + 类型
16
+ - `mokup/server/worker`:Worker helper,封装 `createFetchHandler` 并在 `null` 时返回 404
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const runtime = require('@mokup/runtime');
4
+ const internal = require('./shared/server.3GcmR3Ev.cjs');
5
+
6
+ function createConnectMiddleware(options) {
7
+ const runtime$1 = runtime.createRuntime(internal.toRuntimeOptions(options));
8
+ const onNotFound = options.onNotFound ?? "next";
9
+ return async (req, res, next) => {
10
+ const runtimeRequest = await internal.toRuntimeRequestFromNode(req);
11
+ const result = await runtime$1.handle(runtimeRequest);
12
+ if (!result) {
13
+ if (onNotFound === "response") {
14
+ res.statusCode = 404;
15
+ res.end();
16
+ return;
17
+ }
18
+ next();
19
+ return;
20
+ }
21
+ internal.applyRuntimeResultToNode(res, result);
22
+ };
23
+ }
24
+
25
+ exports.createConnectMiddleware = createConnectMiddleware;
@@ -0,0 +1,8 @@
1
+ import { N as NodeRequestLike, a as NodeResponseLike } from './shared/server.Cb2eiCU2.cjs';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.cjs';
3
+ import '@mokup/runtime';
4
+
5
+ type NextFunction = (error?: unknown) => void;
6
+ declare function createConnectMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: NextFunction) => Promise<void>;
7
+
8
+ export { createConnectMiddleware };
@@ -0,0 +1,8 @@
1
+ import { N as NodeRequestLike, a as NodeResponseLike } from './shared/server.Cb2eiCU2.mjs';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.mjs';
3
+ import '@mokup/runtime';
4
+
5
+ type NextFunction = (error?: unknown) => void;
6
+ declare function createConnectMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: NextFunction) => Promise<void>;
7
+
8
+ export { createConnectMiddleware };
@@ -0,0 +1,8 @@
1
+ import { N as NodeRequestLike, a as NodeResponseLike } from './shared/server.Cb2eiCU2.js';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.js';
3
+ import '@mokup/runtime';
4
+
5
+ type NextFunction = (error?: unknown) => void;
6
+ declare function createConnectMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: NextFunction) => Promise<void>;
7
+
8
+ export { createConnectMiddleware };
@@ -0,0 +1,23 @@
1
+ import { createRuntime } from '@mokup/runtime';
2
+ import { t as toRuntimeOptions, a as toRuntimeRequestFromNode, b as applyRuntimeResultToNode } from './shared/server.tZ4R8aB2.mjs';
3
+
4
+ function createConnectMiddleware(options) {
5
+ const runtime = createRuntime(toRuntimeOptions(options));
6
+ const onNotFound = options.onNotFound ?? "next";
7
+ return async (req, res, next) => {
8
+ const runtimeRequest = await toRuntimeRequestFromNode(req);
9
+ const result = await runtime.handle(runtimeRequest);
10
+ if (!result) {
11
+ if (onNotFound === "response") {
12
+ res.statusCode = 404;
13
+ res.end();
14
+ return;
15
+ }
16
+ next();
17
+ return;
18
+ }
19
+ applyRuntimeResultToNode(res, result);
20
+ };
21
+ }
22
+
23
+ export { createConnectMiddleware };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const connect = require('./connect.cjs');
4
+ require('@mokup/runtime');
5
+ require('./shared/server.3GcmR3Ev.cjs');
6
+
7
+ function createExpressMiddleware(options) {
8
+ return connect.createConnectMiddleware(options);
9
+ }
10
+
11
+ exports.createExpressMiddleware = createExpressMiddleware;
@@ -0,0 +1,7 @@
1
+ import { N as NodeRequestLike, a as NodeResponseLike } from './shared/server.Cb2eiCU2.cjs';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.cjs';
3
+ import '@mokup/runtime';
4
+
5
+ declare function createExpressMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: (error?: unknown) => void) => Promise<void>;
6
+
7
+ export { createExpressMiddleware };
@@ -0,0 +1,7 @@
1
+ import { N as NodeRequestLike, a as NodeResponseLike } from './shared/server.Cb2eiCU2.mjs';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.mjs';
3
+ import '@mokup/runtime';
4
+
5
+ declare function createExpressMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: (error?: unknown) => void) => Promise<void>;
6
+
7
+ export { createExpressMiddleware };
@@ -0,0 +1,7 @@
1
+ import { N as NodeRequestLike, a as NodeResponseLike } from './shared/server.Cb2eiCU2.js';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.js';
3
+ import '@mokup/runtime';
4
+
5
+ declare function createExpressMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: (error?: unknown) => void) => Promise<void>;
6
+
7
+ export { createExpressMiddleware };
@@ -0,0 +1,9 @@
1
+ import { createConnectMiddleware } from './connect.mjs';
2
+ import '@mokup/runtime';
3
+ import './shared/server.tZ4R8aB2.mjs';
4
+
5
+ function createExpressMiddleware(options) {
6
+ return createConnectMiddleware(options);
7
+ }
8
+
9
+ export { createExpressMiddleware };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const runtime = require('@mokup/runtime');
4
+ const internal = require('./shared/server.3GcmR3Ev.cjs');
5
+
6
+ function createFastifyPlugin(options) {
7
+ const runtime$1 = runtime.createRuntime(internal.toRuntimeOptions(options));
8
+ const onNotFound = options.onNotFound ?? "next";
9
+ return async (instance) => {
10
+ instance.addHook("onRequest", async (request, reply) => {
11
+ const runtimeRequest = await internal.toRuntimeRequestFromNode(
12
+ request.raw ?? request,
13
+ request.body
14
+ );
15
+ const result = await runtime$1.handle(runtimeRequest);
16
+ if (!result) {
17
+ if (onNotFound === "response") {
18
+ reply.status(404).send();
19
+ }
20
+ return;
21
+ }
22
+ reply.status(result.status);
23
+ for (const [key, value] of Object.entries(result.headers)) {
24
+ reply.header(key, value);
25
+ }
26
+ if (result.body === null) {
27
+ reply.send();
28
+ return;
29
+ }
30
+ if (typeof result.body === "string") {
31
+ reply.send(result.body);
32
+ return;
33
+ }
34
+ reply.send(internal.toBinaryBody(result.body));
35
+ });
36
+ };
37
+ }
38
+
39
+ exports.createFastifyPlugin = createFastifyPlugin;
@@ -0,0 +1,18 @@
1
+ import { N as NodeRequestLike } from './shared/server.Cb2eiCU2.cjs';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.cjs';
3
+ import '@mokup/runtime';
4
+
5
+ interface FastifyRequestLike extends NodeRequestLike {
6
+ raw?: NodeRequestLike;
7
+ }
8
+ interface FastifyReplyLike {
9
+ status: (code: number) => FastifyReplyLike;
10
+ header: (name: string, value: string) => FastifyReplyLike;
11
+ send: (payload?: unknown) => void;
12
+ }
13
+ interface FastifyInstanceLike {
14
+ addHook: (name: 'onRequest' | 'preHandler', handler: (request: FastifyRequestLike, reply: FastifyReplyLike) => Promise<void> | void) => void;
15
+ }
16
+ declare function createFastifyPlugin(options: ServerOptions): (instance: FastifyInstanceLike) => Promise<void>;
17
+
18
+ export { createFastifyPlugin };
@@ -0,0 +1,18 @@
1
+ import { N as NodeRequestLike } from './shared/server.Cb2eiCU2.mjs';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.mjs';
3
+ import '@mokup/runtime';
4
+
5
+ interface FastifyRequestLike extends NodeRequestLike {
6
+ raw?: NodeRequestLike;
7
+ }
8
+ interface FastifyReplyLike {
9
+ status: (code: number) => FastifyReplyLike;
10
+ header: (name: string, value: string) => FastifyReplyLike;
11
+ send: (payload?: unknown) => void;
12
+ }
13
+ interface FastifyInstanceLike {
14
+ addHook: (name: 'onRequest' | 'preHandler', handler: (request: FastifyRequestLike, reply: FastifyReplyLike) => Promise<void> | void) => void;
15
+ }
16
+ declare function createFastifyPlugin(options: ServerOptions): (instance: FastifyInstanceLike) => Promise<void>;
17
+
18
+ export { createFastifyPlugin };
@@ -0,0 +1,18 @@
1
+ import { N as NodeRequestLike } from './shared/server.Cb2eiCU2.js';
2
+ import { S as ServerOptions } from './shared/server.B82hrXoo.js';
3
+ import '@mokup/runtime';
4
+
5
+ interface FastifyRequestLike extends NodeRequestLike {
6
+ raw?: NodeRequestLike;
7
+ }
8
+ interface FastifyReplyLike {
9
+ status: (code: number) => FastifyReplyLike;
10
+ header: (name: string, value: string) => FastifyReplyLike;
11
+ send: (payload?: unknown) => void;
12
+ }
13
+ interface FastifyInstanceLike {
14
+ addHook: (name: 'onRequest' | 'preHandler', handler: (request: FastifyRequestLike, reply: FastifyReplyLike) => Promise<void> | void) => void;
15
+ }
16
+ declare function createFastifyPlugin(options: ServerOptions): (instance: FastifyInstanceLike) => Promise<void>;
17
+
18
+ export { createFastifyPlugin };
@@ -0,0 +1,37 @@
1
+ import { createRuntime } from '@mokup/runtime';
2
+ import { t as toRuntimeOptions, a as toRuntimeRequestFromNode, c as toBinaryBody } from './shared/server.tZ4R8aB2.mjs';
3
+
4
+ function createFastifyPlugin(options) {
5
+ const runtime = createRuntime(toRuntimeOptions(options));
6
+ const onNotFound = options.onNotFound ?? "next";
7
+ return async (instance) => {
8
+ instance.addHook("onRequest", async (request, reply) => {
9
+ const runtimeRequest = await toRuntimeRequestFromNode(
10
+ request.raw ?? request,
11
+ request.body
12
+ );
13
+ const result = await runtime.handle(runtimeRequest);
14
+ if (!result) {
15
+ if (onNotFound === "response") {
16
+ reply.status(404).send();
17
+ }
18
+ return;
19
+ }
20
+ reply.status(result.status);
21
+ for (const [key, value] of Object.entries(result.headers)) {
22
+ reply.header(key, value);
23
+ }
24
+ if (result.body === null) {
25
+ reply.send();
26
+ return;
27
+ }
28
+ if (typeof result.body === "string") {
29
+ reply.send(result.body);
30
+ return;
31
+ }
32
+ reply.send(toBinaryBody(result.body));
33
+ });
34
+ };
35
+ }
36
+
37
+ export { createFastifyPlugin };