@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/koa.cjs ADDED
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const runtime = require('@mokup/runtime');
4
+ const internal = require('./shared/server.3GcmR3Ev.cjs');
5
+
6
+ function createKoaMiddleware(options) {
7
+ const runtime$1 = runtime.createRuntime(internal.toRuntimeOptions(options));
8
+ const onNotFound = options.onNotFound ?? "next";
9
+ return async (ctx, next) => {
10
+ const runtimeRequest = await internal.toRuntimeRequestFromNode(
11
+ ctx.req,
12
+ ctx.request?.body
13
+ );
14
+ const result = await runtime$1.handle(runtimeRequest);
15
+ if (!result) {
16
+ if (onNotFound === "response") {
17
+ ctx.status = 404;
18
+ ctx.body = null;
19
+ return;
20
+ }
21
+ await next();
22
+ return;
23
+ }
24
+ ctx.status = result.status;
25
+ ctx.set(result.headers);
26
+ if (result.body === null) {
27
+ ctx.body = null;
28
+ return;
29
+ }
30
+ if (typeof result.body === "string") {
31
+ ctx.body = result.body;
32
+ return;
33
+ }
34
+ ctx.body = internal.toBinaryBody(result.body);
35
+ };
36
+ }
37
+
38
+ exports.createKoaMiddleware = createKoaMiddleware;
package/dist/koa.d.cts ADDED
@@ -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 KoaContextLike {
6
+ req: NodeRequestLike;
7
+ request?: {
8
+ body?: unknown;
9
+ headers?: Record<string, string | string[] | undefined>;
10
+ };
11
+ status?: number;
12
+ body?: unknown;
13
+ set: (header: Record<string, string>) => void;
14
+ }
15
+ type KoaNext = () => Promise<unknown>;
16
+ declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
17
+
18
+ export { createKoaMiddleware };
package/dist/koa.d.mts ADDED
@@ -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 KoaContextLike {
6
+ req: NodeRequestLike;
7
+ request?: {
8
+ body?: unknown;
9
+ headers?: Record<string, string | string[] | undefined>;
10
+ };
11
+ status?: number;
12
+ body?: unknown;
13
+ set: (header: Record<string, string>) => void;
14
+ }
15
+ type KoaNext = () => Promise<unknown>;
16
+ declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
17
+
18
+ export { createKoaMiddleware };
package/dist/koa.d.ts ADDED
@@ -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 KoaContextLike {
6
+ req: NodeRequestLike;
7
+ request?: {
8
+ body?: unknown;
9
+ headers?: Record<string, string | string[] | undefined>;
10
+ };
11
+ status?: number;
12
+ body?: unknown;
13
+ set: (header: Record<string, string>) => void;
14
+ }
15
+ type KoaNext = () => Promise<unknown>;
16
+ declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
17
+
18
+ export { createKoaMiddleware };
package/dist/koa.mjs ADDED
@@ -0,0 +1,36 @@
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 createKoaMiddleware(options) {
5
+ const runtime = createRuntime(toRuntimeOptions(options));
6
+ const onNotFound = options.onNotFound ?? "next";
7
+ return async (ctx, next) => {
8
+ const runtimeRequest = await toRuntimeRequestFromNode(
9
+ ctx.req,
10
+ ctx.request?.body
11
+ );
12
+ const result = await runtime.handle(runtimeRequest);
13
+ if (!result) {
14
+ if (onNotFound === "response") {
15
+ ctx.status = 404;
16
+ ctx.body = null;
17
+ return;
18
+ }
19
+ await next();
20
+ return;
21
+ }
22
+ ctx.status = result.status;
23
+ ctx.set(result.headers);
24
+ if (result.body === null) {
25
+ ctx.body = null;
26
+ return;
27
+ }
28
+ if (typeof result.body === "string") {
29
+ ctx.body = result.body;
30
+ return;
31
+ }
32
+ ctx.body = toBinaryBody(result.body);
33
+ };
34
+ }
35
+
36
+ export { createKoaMiddleware };
package/dist/node.cjs CHANGED
@@ -1,7 +1,33 @@
1
1
  'use strict';
2
2
 
3
+ const connect = require('./connect.cjs');
4
+ const express = require('./express.cjs');
5
+ const fastify = require('./fastify.cjs');
6
+ const fetchServer = require('./fetch-server.cjs');
7
+ const hono = require('./hono.cjs');
8
+ const koa = require('./koa.cjs');
9
+ const workerNode = require('./worker-node.cjs');
3
10
  const nodeServer = require('@hono/node-server');
11
+ require('@mokup/runtime');
12
+ require('./shared/server.3GcmR3Ev.cjs');
13
+ require('node:process');
14
+ require('@mokup/shared/hono');
15
+ require('@mokup/shared/pathe');
16
+ require('node:fs');
17
+ require('node:module');
18
+ require('node:buffer');
19
+ require('node:url');
20
+ require('@mokup/shared/esbuild');
21
+ require('@mokup/shared/jsonc-parser');
22
+ require('./fetch.cjs');
4
23
 
5
24
 
6
25
 
26
+ exports.createConnectMiddleware = connect.createConnectMiddleware;
27
+ exports.createExpressMiddleware = express.createExpressMiddleware;
28
+ exports.createFastifyPlugin = fastify.createFastifyPlugin;
29
+ exports.createFetchServer = fetchServer.createFetchServer;
30
+ exports.createHonoMiddleware = hono.createHonoMiddleware;
31
+ exports.createKoaMiddleware = koa.createKoaMiddleware;
32
+ exports.createMokupWorker = workerNode.createMokupWorker;
7
33
  exports.serve = nodeServer.serve;
package/dist/node.d.cts CHANGED
@@ -1 +1,13 @@
1
+ export { createConnectMiddleware } from './connect.cjs';
2
+ export { createExpressMiddleware } from './express.cjs';
3
+ export { createFastifyPlugin } from './fastify.cjs';
4
+ export { FetchServer, FetchServerOptions, FetchServerOptionsConfig, FetchServerOptionsInput, createFetchServer } from './fetch-server.cjs';
5
+ export { createHonoMiddleware } from './hono.cjs';
6
+ export { createKoaMiddleware } from './koa.cjs';
7
+ export { NodeWorkerInput, createMokupWorker } from './worker-node.cjs';
1
8
  export { serve } from '@hono/node-server';
9
+ import './shared/server.Cb2eiCU2.cjs';
10
+ import './shared/server.B82hrXoo.cjs';
11
+ import '@mokup/runtime';
12
+ import '@mokup/shared/hono';
13
+ import '@mokup/shared';
package/dist/node.d.mts CHANGED
@@ -1 +1,13 @@
1
+ export { createConnectMiddleware } from './connect.mjs';
2
+ export { createExpressMiddleware } from './express.mjs';
3
+ export { createFastifyPlugin } from './fastify.mjs';
4
+ export { FetchServer, FetchServerOptions, FetchServerOptionsConfig, FetchServerOptionsInput, createFetchServer } from './fetch-server.mjs';
5
+ export { createHonoMiddleware } from './hono.mjs';
6
+ export { createKoaMiddleware } from './koa.mjs';
7
+ export { NodeWorkerInput, createMokupWorker } from './worker-node.mjs';
1
8
  export { serve } from '@hono/node-server';
9
+ import './shared/server.Cb2eiCU2.mjs';
10
+ import './shared/server.B82hrXoo.mjs';
11
+ import '@mokup/runtime';
12
+ import '@mokup/shared/hono';
13
+ import '@mokup/shared';
package/dist/node.d.ts CHANGED
@@ -1 +1,13 @@
1
+ export { createConnectMiddleware } from './connect.js';
2
+ export { createExpressMiddleware } from './express.js';
3
+ export { createFastifyPlugin } from './fastify.js';
4
+ export { FetchServer, FetchServerOptions, FetchServerOptionsConfig, FetchServerOptionsInput, createFetchServer } from './fetch-server.js';
5
+ export { createHonoMiddleware } from './hono.js';
6
+ export { createKoaMiddleware } from './koa.js';
7
+ export { NodeWorkerInput, createMokupWorker } from './worker-node.js';
1
8
  export { serve } from '@hono/node-server';
9
+ import './shared/server.Cb2eiCU2.js';
10
+ import './shared/server.B82hrXoo.js';
11
+ import '@mokup/runtime';
12
+ import '@mokup/shared/hono';
13
+ import '@mokup/shared';
package/dist/node.mjs CHANGED
@@ -1 +1,20 @@
1
+ export { createConnectMiddleware } from './connect.mjs';
2
+ export { createExpressMiddleware } from './express.mjs';
3
+ export { createFastifyPlugin } from './fastify.mjs';
4
+ export { createFetchServer } from './fetch-server.mjs';
5
+ export { createHonoMiddleware } from './hono.mjs';
6
+ export { createKoaMiddleware } from './koa.mjs';
7
+ export { createMokupWorker } from './worker-node.mjs';
1
8
  export { serve } from '@hono/node-server';
9
+ import '@mokup/runtime';
10
+ import './shared/server.tZ4R8aB2.mjs';
11
+ import 'node:process';
12
+ import '@mokup/shared/hono';
13
+ import '@mokup/shared/pathe';
14
+ import 'node:fs';
15
+ import 'node:module';
16
+ import 'node:buffer';
17
+ import 'node:url';
18
+ import '@mokup/shared/esbuild';
19
+ import '@mokup/shared/jsonc-parser';
20
+ import './fetch.mjs';
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const runtime = require('@mokup/runtime');
4
-
5
3
  const textDecoder = new TextDecoder();
6
4
  const textEncoder = new TextEncoder();
7
5
  function toRuntimeOptions(options) {
@@ -237,28 +235,9 @@ function applyRuntimeResultToNode(res, result) {
237
235
  res.end(toBinaryBody(result.body));
238
236
  }
239
237
 
240
- function createFetchHandler(options) {
241
- const runtime$1 = runtime.createRuntime(toRuntimeOptions(options));
242
- const onNotFound = options.onNotFound ?? "next";
243
- return async (request) => {
244
- const runtimeRequest = await toRuntimeRequestFromFetch(request);
245
- const result = await runtime$1.handle(runtimeRequest);
246
- if (!result) {
247
- if (onNotFound === "response") {
248
- return new Response(null, { status: 404 });
249
- }
250
- return null;
251
- }
252
- const responseBody = result.body === null ? null : typeof result.body === "string" ? result.body : toArrayBuffer(result.body);
253
- return new Response(responseBody, {
254
- status: result.status,
255
- headers: result.headers
256
- });
257
- };
258
- }
259
-
260
238
  exports.applyRuntimeResultToNode = applyRuntimeResultToNode;
261
- exports.createFetchHandler = createFetchHandler;
239
+ exports.toArrayBuffer = toArrayBuffer;
262
240
  exports.toBinaryBody = toBinaryBody;
263
241
  exports.toRuntimeOptions = toRuntimeOptions;
242
+ exports.toRuntimeRequestFromFetch = toRuntimeRequestFromFetch;
264
243
  exports.toRuntimeRequestFromNode = toRuntimeRequestFromNode;
@@ -10,6 +10,6 @@ interface WorkerBundle {
10
10
  moduleBase?: string | URL;
11
11
  onNotFound?: 'next' | 'response';
12
12
  }
13
- type WorkerInput = string | Manifest | WorkerBundle;
13
+ type WorkerInput = Manifest | WorkerBundle;
14
14
 
15
- export type { FetchHandler as F, ServerOptions as S, WorkerInput as W, WorkerBundle as a };
15
+ export type { FetchHandler as F, ServerOptions as S, WorkerBundle as W, WorkerInput as a };
@@ -10,6 +10,6 @@ interface WorkerBundle {
10
10
  moduleBase?: string | URL;
11
11
  onNotFound?: 'next' | 'response';
12
12
  }
13
- type WorkerInput = string | Manifest | WorkerBundle;
13
+ type WorkerInput = Manifest | WorkerBundle;
14
14
 
15
- export type { FetchHandler as F, ServerOptions as S, WorkerInput as W, WorkerBundle as a };
15
+ export type { FetchHandler as F, ServerOptions as S, WorkerBundle as W, WorkerInput as a };
@@ -10,6 +10,6 @@ interface WorkerBundle {
10
10
  moduleBase?: string | URL;
11
11
  onNotFound?: 'next' | 'response';
12
12
  }
13
- type WorkerInput = string | Manifest | WorkerBundle;
13
+ type WorkerInput = Manifest | WorkerBundle;
14
14
 
15
- export type { FetchHandler as F, ServerOptions as S, WorkerInput as W, WorkerBundle as a };
15
+ export type { FetchHandler as F, ServerOptions as S, WorkerBundle as W, WorkerInput as a };
@@ -0,0 +1,17 @@
1
+ interface ReadableStreamLike {
2
+ on: (event: string, listener: (...args: unknown[]) => void) => void;
3
+ }
4
+ interface NodeRequestLike extends ReadableStreamLike {
5
+ method?: string;
6
+ url?: string;
7
+ originalUrl?: string;
8
+ headers?: Record<string, string | string[] | undefined>;
9
+ body?: unknown;
10
+ }
11
+ interface NodeResponseLike {
12
+ statusCode?: number;
13
+ setHeader: (name: string, value: string) => void;
14
+ end: (data?: string | Uint8Array | ArrayBuffer | null) => void;
15
+ }
16
+
17
+ export type { NodeRequestLike as N, NodeResponseLike as a };
@@ -0,0 +1,17 @@
1
+ interface ReadableStreamLike {
2
+ on: (event: string, listener: (...args: unknown[]) => void) => void;
3
+ }
4
+ interface NodeRequestLike extends ReadableStreamLike {
5
+ method?: string;
6
+ url?: string;
7
+ originalUrl?: string;
8
+ headers?: Record<string, string | string[] | undefined>;
9
+ body?: unknown;
10
+ }
11
+ interface NodeResponseLike {
12
+ statusCode?: number;
13
+ setHeader: (name: string, value: string) => void;
14
+ end: (data?: string | Uint8Array | ArrayBuffer | null) => void;
15
+ }
16
+
17
+ export type { NodeRequestLike as N, NodeResponseLike as a };
@@ -0,0 +1,17 @@
1
+ interface ReadableStreamLike {
2
+ on: (event: string, listener: (...args: unknown[]) => void) => void;
3
+ }
4
+ interface NodeRequestLike extends ReadableStreamLike {
5
+ method?: string;
6
+ url?: string;
7
+ originalUrl?: string;
8
+ headers?: Record<string, string | string[] | undefined>;
9
+ body?: unknown;
10
+ }
11
+ interface NodeResponseLike {
12
+ statusCode?: number;
13
+ setHeader: (name: string, value: string) => void;
14
+ end: (data?: string | Uint8Array | ArrayBuffer | null) => void;
15
+ }
16
+
17
+ export type { NodeRequestLike as N, NodeResponseLike as a };
@@ -1,5 +1,3 @@
1
- import { createRuntime } from '@mokup/runtime';
2
-
3
1
  const textDecoder = new TextDecoder();
4
2
  const textEncoder = new TextEncoder();
5
3
  function toRuntimeOptions(options) {
@@ -235,24 +233,4 @@ function applyRuntimeResultToNode(res, result) {
235
233
  res.end(toBinaryBody(result.body));
236
234
  }
237
235
 
238
- function createFetchHandler(options) {
239
- const runtime = createRuntime(toRuntimeOptions(options));
240
- const onNotFound = options.onNotFound ?? "next";
241
- return async (request) => {
242
- const runtimeRequest = await toRuntimeRequestFromFetch(request);
243
- const result = await runtime.handle(runtimeRequest);
244
- if (!result) {
245
- if (onNotFound === "response") {
246
- return new Response(null, { status: 404 });
247
- }
248
- return null;
249
- }
250
- const responseBody = result.body === null ? null : typeof result.body === "string" ? result.body : toArrayBuffer(result.body);
251
- return new Response(responseBody, {
252
- status: result.status,
253
- headers: result.headers
254
- });
255
- };
256
- }
257
-
258
- export { toRuntimeRequestFromNode as a, applyRuntimeResultToNode as b, createFetchHandler as c, toBinaryBody as d, toRuntimeOptions as t };
236
+ export { toRuntimeRequestFromNode as a, applyRuntimeResultToNode as b, toBinaryBody as c, toRuntimeRequestFromFetch as d, toArrayBuffer as e, toRuntimeOptions as t };
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ const fetch = require('./fetch.cjs');
4
+ require('@mokup/runtime');
5
+ require('./shared/server.3GcmR3Ev.cjs');
6
+
7
+ function isManifest(value) {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value) && "version" in value && "routes" in value;
9
+ }
10
+ function normalizeWorkerOptions(bundle) {
11
+ const options = {
12
+ manifest: bundle.manifest,
13
+ onNotFound: bundle.onNotFound ?? "response"
14
+ };
15
+ if (typeof bundle.moduleBase !== "undefined") {
16
+ options.moduleBase = bundle.moduleBase;
17
+ }
18
+ if (typeof bundle.moduleMap !== "undefined") {
19
+ options.moduleMap = bundle.moduleMap;
20
+ }
21
+ return options;
22
+ }
23
+ async function loadBundleFromDir(dir) {
24
+ const nodeProcess = await import('node:process');
25
+ const isNode = typeof nodeProcess !== "undefined" && !!nodeProcess.versions?.node;
26
+ if (!isNode) {
27
+ throw new TypeError("createMokupWorker(dir) is only supported in Node runtimes.");
28
+ }
29
+ const { readFile, access } = await import('node:fs/promises');
30
+ const { resolve, join } = await import('node:path');
31
+ const { pathToFileURL } = await import('node:url');
32
+ const manifestPath = resolve(dir, "mokup.manifest.json");
33
+ const manifestRaw = await readFile(manifestPath, "utf8");
34
+ const manifest = JSON.parse(manifestRaw);
35
+ const handlersIndexPath = resolve(dir, "mokup-handlers", "index.mjs");
36
+ let moduleMap;
37
+ try {
38
+ await access(handlersIndexPath);
39
+ const module = await import(pathToFileURL(handlersIndexPath).href);
40
+ moduleMap = module.mokupModuleMap;
41
+ } catch {
42
+ moduleMap = void 0;
43
+ }
44
+ const bundle = {
45
+ manifest,
46
+ moduleBase: join(dir, "/")
47
+ };
48
+ if (typeof moduleMap !== "undefined") {
49
+ bundle.moduleMap = moduleMap;
50
+ }
51
+ return bundle;
52
+ }
53
+ function createWorker(handlerOptions) {
54
+ const handler = fetch.createFetchHandler(handlerOptions);
55
+ return {
56
+ fetch: async (request) => {
57
+ return await handler(request) ?? new Response("Not Found", { status: 404 });
58
+ }
59
+ };
60
+ }
61
+ function createMokupWorker(input) {
62
+ if (typeof input === "string") {
63
+ return loadBundleFromDir(input).then((bundle) => createWorker(normalizeWorkerOptions(bundle)));
64
+ }
65
+ if (isManifest(input)) {
66
+ return createWorker({
67
+ manifest: input,
68
+ onNotFound: "response"
69
+ });
70
+ }
71
+ return createWorker(normalizeWorkerOptions(input));
72
+ }
73
+
74
+ exports.createMokupWorker = createMokupWorker;
@@ -0,0 +1,12 @@
1
+ import { a as WorkerInput } from './shared/server.B82hrXoo.cjs';
2
+ import '@mokup/runtime';
3
+
4
+ interface FetchWorker {
5
+ fetch: (request: Request) => Promise<Response>;
6
+ }
7
+ type NodeWorkerInput = string | WorkerInput;
8
+ declare function createMokupWorker(input: string): Promise<FetchWorker>;
9
+ declare function createMokupWorker(input: WorkerInput): FetchWorker;
10
+
11
+ export { createMokupWorker };
12
+ export type { FetchWorker, NodeWorkerInput };
@@ -0,0 +1,12 @@
1
+ import { a as WorkerInput } from './shared/server.B82hrXoo.mjs';
2
+ import '@mokup/runtime';
3
+
4
+ interface FetchWorker {
5
+ fetch: (request: Request) => Promise<Response>;
6
+ }
7
+ type NodeWorkerInput = string | WorkerInput;
8
+ declare function createMokupWorker(input: string): Promise<FetchWorker>;
9
+ declare function createMokupWorker(input: WorkerInput): FetchWorker;
10
+
11
+ export { createMokupWorker };
12
+ export type { FetchWorker, NodeWorkerInput };
@@ -0,0 +1,12 @@
1
+ import { a as WorkerInput } from './shared/server.B82hrXoo.js';
2
+ import '@mokup/runtime';
3
+
4
+ interface FetchWorker {
5
+ fetch: (request: Request) => Promise<Response>;
6
+ }
7
+ type NodeWorkerInput = string | WorkerInput;
8
+ declare function createMokupWorker(input: string): Promise<FetchWorker>;
9
+ declare function createMokupWorker(input: WorkerInput): FetchWorker;
10
+
11
+ export { createMokupWorker };
12
+ export type { FetchWorker, NodeWorkerInput };
@@ -0,0 +1,72 @@
1
+ import { createFetchHandler } from './fetch.mjs';
2
+ import '@mokup/runtime';
3
+ import './shared/server.tZ4R8aB2.mjs';
4
+
5
+ function isManifest(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value) && "version" in value && "routes" in value;
7
+ }
8
+ function normalizeWorkerOptions(bundle) {
9
+ const options = {
10
+ manifest: bundle.manifest,
11
+ onNotFound: bundle.onNotFound ?? "response"
12
+ };
13
+ if (typeof bundle.moduleBase !== "undefined") {
14
+ options.moduleBase = bundle.moduleBase;
15
+ }
16
+ if (typeof bundle.moduleMap !== "undefined") {
17
+ options.moduleMap = bundle.moduleMap;
18
+ }
19
+ return options;
20
+ }
21
+ async function loadBundleFromDir(dir) {
22
+ const nodeProcess = await import('node:process');
23
+ const isNode = typeof nodeProcess !== "undefined" && !!nodeProcess.versions?.node;
24
+ if (!isNode) {
25
+ throw new TypeError("createMokupWorker(dir) is only supported in Node runtimes.");
26
+ }
27
+ const { readFile, access } = await import('node:fs/promises');
28
+ const { resolve, join } = await import('node:path');
29
+ const { pathToFileURL } = await import('node:url');
30
+ const manifestPath = resolve(dir, "mokup.manifest.json");
31
+ const manifestRaw = await readFile(manifestPath, "utf8");
32
+ const manifest = JSON.parse(manifestRaw);
33
+ const handlersIndexPath = resolve(dir, "mokup-handlers", "index.mjs");
34
+ let moduleMap;
35
+ try {
36
+ await access(handlersIndexPath);
37
+ const module = await import(pathToFileURL(handlersIndexPath).href);
38
+ moduleMap = module.mokupModuleMap;
39
+ } catch {
40
+ moduleMap = void 0;
41
+ }
42
+ const bundle = {
43
+ manifest,
44
+ moduleBase: join(dir, "/")
45
+ };
46
+ if (typeof moduleMap !== "undefined") {
47
+ bundle.moduleMap = moduleMap;
48
+ }
49
+ return bundle;
50
+ }
51
+ function createWorker(handlerOptions) {
52
+ const handler = createFetchHandler(handlerOptions);
53
+ return {
54
+ fetch: async (request) => {
55
+ return await handler(request) ?? new Response("Not Found", { status: 404 });
56
+ }
57
+ };
58
+ }
59
+ function createMokupWorker(input) {
60
+ if (typeof input === "string") {
61
+ return loadBundleFromDir(input).then((bundle) => createWorker(normalizeWorkerOptions(bundle)));
62
+ }
63
+ if (isManifest(input)) {
64
+ return createWorker({
65
+ manifest: input,
66
+ onNotFound: "response"
67
+ });
68
+ }
69
+ return createWorker(normalizeWorkerOptions(input));
70
+ }
71
+
72
+ export { createMokupWorker };
package/dist/worker.cjs CHANGED
@@ -1,8 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const fetch = require('./shared/server.BdTl0qJd.cjs');
3
+ const fetch = require('./fetch.cjs');
4
4
  require('@mokup/runtime');
5
+ require('./shared/server.3GcmR3Ev.cjs');
5
6
 
7
+ function isStringInput(value) {
8
+ return typeof value === "string";
9
+ }
6
10
  function isManifest(value) {
7
11
  return typeof value === "object" && value !== null && !Array.isArray(value) && "version" in value && "routes" in value;
8
12
  }
@@ -28,7 +32,7 @@ function createWorker(handlerOptions) {
28
32
  };
29
33
  }
30
34
  function createMokupWorker(input) {
31
- if (typeof input === "string") {
35
+ if (isStringInput(input)) {
32
36
  throw new TypeError("createMokupWorker(dir) is only supported in Node runtimes.");
33
37
  }
34
38
  if (isManifest(input)) {
package/dist/worker.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import { W as WorkerInput } from './shared/server.DNITwCtQ.cjs';
1
+ import { a as WorkerInput } from './shared/server.B82hrXoo.cjs';
2
2
  import '@mokup/runtime';
3
3
 
4
4
  interface FetchWorker {
5
5
  fetch: (request: Request) => Promise<Response>;
6
6
  }
7
- declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
7
+ declare function createMokupWorker(input: WorkerInput): FetchWorker;
8
8
 
9
9
  export { createMokupWorker };
10
10
  export type { FetchWorker };
package/dist/worker.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import { W as WorkerInput } from './shared/server.DNITwCtQ.mjs';
1
+ import { a as WorkerInput } from './shared/server.B82hrXoo.mjs';
2
2
  import '@mokup/runtime';
3
3
 
4
4
  interface FetchWorker {
5
5
  fetch: (request: Request) => Promise<Response>;
6
6
  }
7
- declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
7
+ declare function createMokupWorker(input: WorkerInput): FetchWorker;
8
8
 
9
9
  export { createMokupWorker };
10
10
  export type { FetchWorker };
package/dist/worker.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { W as WorkerInput } from './shared/server.DNITwCtQ.js';
1
+ import { a as WorkerInput } from './shared/server.B82hrXoo.js';
2
2
  import '@mokup/runtime';
3
3
 
4
4
  interface FetchWorker {
5
5
  fetch: (request: Request) => Promise<Response>;
6
6
  }
7
- declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
7
+ declare function createMokupWorker(input: WorkerInput): FetchWorker;
8
8
 
9
9
  export { createMokupWorker };
10
10
  export type { FetchWorker };