@mokup/server 1.1.1 → 1.1.3

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 (72) 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 +19 -0
  5. package/dist/connect.d.mts +19 -0
  6. package/dist/connect.d.ts +19 -0
  7. package/dist/connect.mjs +23 -0
  8. package/dist/express.cjs +11 -0
  9. package/dist/express.d.cts +18 -0
  10. package/dist/express.d.mts +18 -0
  11. package/dist/express.d.ts +18 -0
  12. package/dist/express.mjs +9 -0
  13. package/dist/fastify.cjs +39 -0
  14. package/dist/fastify.d.cts +29 -0
  15. package/dist/fastify.d.mts +29 -0
  16. package/dist/fastify.d.ts +29 -0
  17. package/dist/fastify.mjs +37 -0
  18. package/dist/fetch-server.cjs +1659 -0
  19. package/dist/fetch-server.d.cts +108 -0
  20. package/dist/fetch-server.d.mts +108 -0
  21. package/dist/fetch-server.d.ts +108 -0
  22. package/dist/fetch-server.mjs +1652 -0
  23. package/dist/fetch.cjs +26 -0
  24. package/dist/fetch.d.cts +17 -0
  25. package/dist/fetch.d.mts +17 -0
  26. package/dist/fetch.d.ts +17 -0
  27. package/dist/fetch.mjs +24 -0
  28. package/dist/hono.cjs +27 -0
  29. package/dist/hono.d.cts +32 -0
  30. package/dist/hono.d.mts +32 -0
  31. package/dist/hono.d.ts +32 -0
  32. package/dist/hono.mjs +25 -0
  33. package/dist/index.cjs +29 -1677
  34. package/dist/index.d.cts +42 -136
  35. package/dist/index.d.mts +42 -136
  36. package/dist/index.d.ts +42 -136
  37. package/dist/index.mjs +28 -1666
  38. package/dist/koa.cjs +38 -0
  39. package/dist/koa.d.cts +29 -0
  40. package/dist/koa.d.mts +29 -0
  41. package/dist/koa.d.ts +29 -0
  42. package/dist/koa.mjs +36 -0
  43. package/dist/node.cjs +26 -0
  44. package/dist/node.d.cts +13 -0
  45. package/dist/node.d.mts +13 -0
  46. package/dist/node.d.ts +13 -0
  47. package/dist/node.mjs +19 -0
  48. package/dist/shared/server.CyVIKPsp.d.cts +214 -0
  49. package/dist/shared/server.CyVIKPsp.d.mts +214 -0
  50. package/dist/shared/server.CyVIKPsp.d.ts +214 -0
  51. package/dist/shared/server.D0gAciOr.d.cts +46 -0
  52. package/dist/shared/server.D0gAciOr.d.mts +46 -0
  53. package/dist/shared/server.D0gAciOr.d.ts +46 -0
  54. package/dist/shared/server.DkerfsA-.d.cts +73 -0
  55. package/dist/shared/server.DkerfsA-.d.mts +73 -0
  56. package/dist/shared/server.DkerfsA-.d.ts +73 -0
  57. package/dist/shared/{server.Dje1y79O.mjs → server.LbftO9Jh.mjs} +58 -77
  58. package/dist/shared/{server.BdTl0qJd.cjs → server.aaygIV2Q.cjs} +59 -77
  59. package/dist/worker-node.cjs +74 -0
  60. package/dist/worker-node.d.cts +40 -0
  61. package/dist/worker-node.d.mts +40 -0
  62. package/dist/worker-node.d.ts +40 -0
  63. package/dist/worker-node.mjs +72 -0
  64. package/dist/worker.cjs +6 -2
  65. package/dist/worker.d.cts +24 -2
  66. package/dist/worker.d.mts +24 -2
  67. package/dist/worker.d.ts +24 -2
  68. package/dist/worker.mjs +6 -2
  69. package/package.json +44 -4
  70. package/dist/shared/server.DNITwCtQ.d.cts +0 -15
  71. package/dist/shared/server.DNITwCtQ.d.mts +0 -15
  72. package/dist/shared/server.DNITwCtQ.d.ts +0 -15
package/dist/fetch.cjs ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const runtime = require('@mokup/runtime');
4
+ const runtime$1 = require('./shared/server.aaygIV2Q.cjs');
5
+
6
+ function createFetchHandler(options) {
7
+ const runtime$2 = runtime.createRuntime(runtime$1.toRuntimeOptions(options));
8
+ const onNotFound = options.onNotFound ?? "next";
9
+ return async (request) => {
10
+ const runtimeRequest = await runtime$1.toRuntimeRequestFromFetch(request);
11
+ const result = await runtime$2.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 : runtime$1.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,17 @@
1
+ import { S as ServerOptions, F as FetchHandler } from './shared/server.DkerfsA-.cjs';
2
+ import '@mokup/runtime';
3
+
4
+ /**
5
+ * Create a fetch handler that executes mokup routes.
6
+ *
7
+ * @param options - Server options.
8
+ * @returns Fetch handler for use in adapters.
9
+ *
10
+ * @example
11
+ * import { createFetchHandler } from '@mokup/server/fetch'
12
+ *
13
+ * const handler = createFetchHandler({ manifest: { version: 1, routes: [] } })
14
+ */
15
+ declare function createFetchHandler(options: ServerOptions): FetchHandler;
16
+
17
+ export { createFetchHandler };
@@ -0,0 +1,17 @@
1
+ import { S as ServerOptions, F as FetchHandler } from './shared/server.DkerfsA-.mjs';
2
+ import '@mokup/runtime';
3
+
4
+ /**
5
+ * Create a fetch handler that executes mokup routes.
6
+ *
7
+ * @param options - Server options.
8
+ * @returns Fetch handler for use in adapters.
9
+ *
10
+ * @example
11
+ * import { createFetchHandler } from '@mokup/server/fetch'
12
+ *
13
+ * const handler = createFetchHandler({ manifest: { version: 1, routes: [] } })
14
+ */
15
+ declare function createFetchHandler(options: ServerOptions): FetchHandler;
16
+
17
+ export { createFetchHandler };
@@ -0,0 +1,17 @@
1
+ import { S as ServerOptions, F as FetchHandler } from './shared/server.DkerfsA-.js';
2
+ import '@mokup/runtime';
3
+
4
+ /**
5
+ * Create a fetch handler that executes mokup routes.
6
+ *
7
+ * @param options - Server options.
8
+ * @returns Fetch handler for use in adapters.
9
+ *
10
+ * @example
11
+ * import { createFetchHandler } from '@mokup/server/fetch'
12
+ *
13
+ * const handler = createFetchHandler({ manifest: { version: 1, routes: [] } })
14
+ */
15
+ declare function createFetchHandler(options: ServerOptions): FetchHandler;
16
+
17
+ 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.LbftO9Jh.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.aaygIV2Q.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,32 @@
1
+ import { S as ServerOptions } from './shared/server.DkerfsA-.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
+ /**
18
+ * Create a Hono middleware from server options.
19
+ *
20
+ * @param options - Server options.
21
+ * @returns Hono middleware handler.
22
+ *
23
+ * @example
24
+ * import { createHonoMiddleware } from '@mokup/server'
25
+ *
26
+ * const middleware = createHonoMiddleware({ manifest: { version: 1, routes: [] } })
27
+ */
28
+ declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
29
+ routes: HonoRouteLike[];
30
+ };
31
+
32
+ export { createHonoMiddleware };
@@ -0,0 +1,32 @@
1
+ import { S as ServerOptions } from './shared/server.DkerfsA-.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
+ /**
18
+ * Create a Hono middleware from server options.
19
+ *
20
+ * @param options - Server options.
21
+ * @returns Hono middleware handler.
22
+ *
23
+ * @example
24
+ * import { createHonoMiddleware } from '@mokup/server'
25
+ *
26
+ * const middleware = createHonoMiddleware({ manifest: { version: 1, routes: [] } })
27
+ */
28
+ declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
29
+ routes: HonoRouteLike[];
30
+ };
31
+
32
+ export { createHonoMiddleware };
package/dist/hono.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { S as ServerOptions } from './shared/server.DkerfsA-.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
+ /**
18
+ * Create a Hono middleware from server options.
19
+ *
20
+ * @param options - Server options.
21
+ * @returns Hono middleware handler.
22
+ *
23
+ * @example
24
+ * import { createHonoMiddleware } from '@mokup/server'
25
+ *
26
+ * const middleware = createHonoMiddleware({ manifest: { version: 1, routes: [] } })
27
+ */
28
+ declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
29
+ routes: HonoRouteLike[];
30
+ };
31
+
32
+ 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.LbftO9Jh.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 };