@mokup/server 1.1.2 → 1.1.4
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/dist/connect.cjs +5 -5
- package/dist/connect.d.cts +13 -2
- package/dist/connect.d.mts +13 -2
- package/dist/connect.d.ts +13 -2
- package/dist/connect.mjs +1 -1
- package/dist/express.cjs +1 -1
- package/dist/express.d.cts +13 -2
- package/dist/express.d.mts +13 -2
- package/dist/express.d.ts +13 -2
- package/dist/express.mjs +1 -1
- package/dist/fastify.cjs +5 -5
- package/dist/fastify.d.cts +13 -2
- package/dist/fastify.d.mts +13 -2
- package/dist/fastify.d.ts +13 -2
- package/dist/fastify.mjs +1 -1
- package/dist/fetch-server.cjs +599 -447
- package/dist/fetch-server.d.cts +81 -27
- package/dist/fetch-server.d.mts +81 -27
- package/dist/fetch-server.d.ts +81 -27
- package/dist/fetch-server.mjs +601 -449
- package/dist/fetch.cjs +5 -5
- package/dist/fetch.d.cts +12 -1
- package/dist/fetch.d.mts +12 -1
- package/dist/fetch.d.ts +12 -1
- package/dist/fetch.mjs +1 -1
- package/dist/hono.cjs +1 -1
- package/dist/hono.d.cts +12 -1
- package/dist/hono.d.mts +12 -1
- package/dist/hono.d.ts +12 -1
- package/dist/hono.mjs +1 -1
- package/dist/index.cjs +34 -2
- package/dist/index.d.cts +40 -1
- package/dist/index.d.mts +40 -1
- package/dist/index.d.ts +40 -1
- package/dist/index.mjs +36 -1
- package/dist/koa.cjs +5 -5
- package/dist/koa.d.cts +13 -2
- package/dist/koa.d.mts +13 -2
- package/dist/koa.d.ts +13 -2
- package/dist/koa.mjs +1 -1
- package/dist/node.cjs +3 -3
- package/dist/node.d.cts +3 -2
- package/dist/node.d.mts +3 -2
- package/dist/node.d.ts +3 -2
- package/dist/node.mjs +3 -3
- package/dist/shared/server.CyVIKPsp.d.cts +214 -0
- package/dist/shared/server.CyVIKPsp.d.mts +214 -0
- package/dist/shared/server.CyVIKPsp.d.ts +214 -0
- package/dist/shared/server.D0gAciOr.d.cts +46 -0
- package/dist/shared/server.D0gAciOr.d.mts +46 -0
- package/dist/shared/server.D0gAciOr.d.ts +46 -0
- package/dist/shared/server.DkerfsA-.d.cts +73 -0
- package/dist/shared/server.DkerfsA-.d.mts +73 -0
- package/dist/shared/server.DkerfsA-.d.ts +73 -0
- package/dist/shared/{server.tZ4R8aB2.mjs → server.LbftO9Jh.mjs} +57 -54
- package/dist/shared/{server.3GcmR3Ev.cjs → server.aaygIV2Q.cjs} +57 -54
- package/dist/worker-node.cjs +1 -1
- package/dist/worker-node.d.cts +29 -1
- package/dist/worker-node.d.mts +29 -1
- package/dist/worker-node.d.ts +29 -1
- package/dist/worker-node.mjs +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +23 -1
- package/dist/worker.d.mts +23 -1
- package/dist/worker.d.ts +23 -1
- package/dist/worker.mjs +1 -1
- package/package.json +4 -4
- package/dist/shared/server.B82hrXoo.d.cts +0 -15
- package/dist/shared/server.B82hrXoo.d.mts +0 -15
- package/dist/shared/server.B82hrXoo.d.ts +0 -15
- package/dist/shared/server.Cb2eiCU2.d.cts +0 -17
- package/dist/shared/server.Cb2eiCU2.d.mts +0 -17
- package/dist/shared/server.Cb2eiCU2.d.ts +0 -17
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal readable stream shape used by adapters.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* import type { ReadableStreamLike } from '@mokup/server'
|
|
6
|
+
*
|
|
7
|
+
* const stream: ReadableStreamLike = {
|
|
8
|
+
* on: () => {},
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
interface ReadableStreamLike {
|
|
12
|
+
on: (event: string, listener: (...args: unknown[]) => void) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Minimal Node request shape used by adapters.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import type { NodeRequestLike } from '@mokup/server'
|
|
19
|
+
*
|
|
20
|
+
* const req: NodeRequestLike = { method: 'GET', url: '/api/ping' }
|
|
21
|
+
*/
|
|
22
|
+
interface NodeRequestLike extends ReadableStreamLike {
|
|
23
|
+
method?: string;
|
|
24
|
+
url?: string;
|
|
25
|
+
originalUrl?: string;
|
|
26
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
27
|
+
body?: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Minimal Node response shape used by adapters.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* import type { NodeResponseLike } from '@mokup/server'
|
|
34
|
+
*
|
|
35
|
+
* const res: NodeResponseLike = {
|
|
36
|
+
* setHeader: () => {},
|
|
37
|
+
* end: () => {},
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
interface NodeResponseLike {
|
|
41
|
+
statusCode?: number;
|
|
42
|
+
setHeader: (name: string, value: string) => void;
|
|
43
|
+
end: (data?: string | Uint8Array | ArrayBuffer | null) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type { NodeRequestLike as N, NodeResponseLike as a };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal readable stream shape used by adapters.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* import type { ReadableStreamLike } from '@mokup/server'
|
|
6
|
+
*
|
|
7
|
+
* const stream: ReadableStreamLike = {
|
|
8
|
+
* on: () => {},
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
interface ReadableStreamLike {
|
|
12
|
+
on: (event: string, listener: (...args: unknown[]) => void) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Minimal Node request shape used by adapters.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import type { NodeRequestLike } from '@mokup/server'
|
|
19
|
+
*
|
|
20
|
+
* const req: NodeRequestLike = { method: 'GET', url: '/api/ping' }
|
|
21
|
+
*/
|
|
22
|
+
interface NodeRequestLike extends ReadableStreamLike {
|
|
23
|
+
method?: string;
|
|
24
|
+
url?: string;
|
|
25
|
+
originalUrl?: string;
|
|
26
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
27
|
+
body?: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Minimal Node response shape used by adapters.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* import type { NodeResponseLike } from '@mokup/server'
|
|
34
|
+
*
|
|
35
|
+
* const res: NodeResponseLike = {
|
|
36
|
+
* setHeader: () => {},
|
|
37
|
+
* end: () => {},
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
interface NodeResponseLike {
|
|
41
|
+
statusCode?: number;
|
|
42
|
+
setHeader: (name: string, value: string) => void;
|
|
43
|
+
end: (data?: string | Uint8Array | ArrayBuffer | null) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type { NodeRequestLike as N, NodeResponseLike as a };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { RuntimeOptions, Manifest, ModuleMap } from '@mokup/runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for server adapters built on top of the runtime.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import type { ServerOptions } from '@mokup/server'
|
|
8
|
+
*
|
|
9
|
+
* const options: ServerOptions = {
|
|
10
|
+
* manifest: { version: 1, routes: [] },
|
|
11
|
+
* onNotFound: 'next',
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
interface ServerOptions extends RuntimeOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Behavior when no route matches.
|
|
17
|
+
*
|
|
18
|
+
* @default "next"
|
|
19
|
+
*/
|
|
20
|
+
onNotFound?: 'next' | 'response';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fetch handler signature used by server adapters.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import type { FetchHandler } from '@mokup/server'
|
|
27
|
+
*
|
|
28
|
+
* const handler: FetchHandler = async (request) => new Response('ok')
|
|
29
|
+
*/
|
|
30
|
+
type FetchHandler = (request: Request) => Promise<Response | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Bundle input for Worker helpers.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* import type { WorkerBundle } from '@mokup/server'
|
|
36
|
+
*
|
|
37
|
+
* const bundle: WorkerBundle = {
|
|
38
|
+
* manifest: { version: 1, routes: [] },
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
interface WorkerBundle {
|
|
42
|
+
/** Manifest for runtime execution. */
|
|
43
|
+
manifest: Manifest;
|
|
44
|
+
/**
|
|
45
|
+
* In-memory module map for handler execution.
|
|
46
|
+
*
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
moduleMap?: ModuleMap;
|
|
50
|
+
/**
|
|
51
|
+
* Base directory for module resolution.
|
|
52
|
+
*
|
|
53
|
+
* @default undefined
|
|
54
|
+
*/
|
|
55
|
+
moduleBase?: string | URL;
|
|
56
|
+
/**
|
|
57
|
+
* Behavior when no route matches.
|
|
58
|
+
*
|
|
59
|
+
* @default "response"
|
|
60
|
+
*/
|
|
61
|
+
onNotFound?: 'next' | 'response';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Worker input accepted by createMokupWorker.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* import type { WorkerInput } from '@mokup/server'
|
|
68
|
+
*
|
|
69
|
+
* const input: WorkerInput = { version: 1, routes: [] }
|
|
70
|
+
*/
|
|
71
|
+
type WorkerInput = Manifest | WorkerBundle;
|
|
72
|
+
|
|
73
|
+
export type { FetchHandler as F, ServerOptions as S, WorkerBundle as W, WorkerInput as a };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { RuntimeOptions, Manifest, ModuleMap } from '@mokup/runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for server adapters built on top of the runtime.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import type { ServerOptions } from '@mokup/server'
|
|
8
|
+
*
|
|
9
|
+
* const options: ServerOptions = {
|
|
10
|
+
* manifest: { version: 1, routes: [] },
|
|
11
|
+
* onNotFound: 'next',
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
interface ServerOptions extends RuntimeOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Behavior when no route matches.
|
|
17
|
+
*
|
|
18
|
+
* @default "next"
|
|
19
|
+
*/
|
|
20
|
+
onNotFound?: 'next' | 'response';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fetch handler signature used by server adapters.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import type { FetchHandler } from '@mokup/server'
|
|
27
|
+
*
|
|
28
|
+
* const handler: FetchHandler = async (request) => new Response('ok')
|
|
29
|
+
*/
|
|
30
|
+
type FetchHandler = (request: Request) => Promise<Response | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Bundle input for Worker helpers.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* import type { WorkerBundle } from '@mokup/server'
|
|
36
|
+
*
|
|
37
|
+
* const bundle: WorkerBundle = {
|
|
38
|
+
* manifest: { version: 1, routes: [] },
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
interface WorkerBundle {
|
|
42
|
+
/** Manifest for runtime execution. */
|
|
43
|
+
manifest: Manifest;
|
|
44
|
+
/**
|
|
45
|
+
* In-memory module map for handler execution.
|
|
46
|
+
*
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
moduleMap?: ModuleMap;
|
|
50
|
+
/**
|
|
51
|
+
* Base directory for module resolution.
|
|
52
|
+
*
|
|
53
|
+
* @default undefined
|
|
54
|
+
*/
|
|
55
|
+
moduleBase?: string | URL;
|
|
56
|
+
/**
|
|
57
|
+
* Behavior when no route matches.
|
|
58
|
+
*
|
|
59
|
+
* @default "response"
|
|
60
|
+
*/
|
|
61
|
+
onNotFound?: 'next' | 'response';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Worker input accepted by createMokupWorker.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* import type { WorkerInput } from '@mokup/server'
|
|
68
|
+
*
|
|
69
|
+
* const input: WorkerInput = { version: 1, routes: [] }
|
|
70
|
+
*/
|
|
71
|
+
type WorkerInput = Manifest | WorkerBundle;
|
|
72
|
+
|
|
73
|
+
export type { FetchHandler as F, ServerOptions as S, WorkerBundle as W, WorkerInput as a };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { RuntimeOptions, Manifest, ModuleMap } from '@mokup/runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for server adapters built on top of the runtime.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import type { ServerOptions } from '@mokup/server'
|
|
8
|
+
*
|
|
9
|
+
* const options: ServerOptions = {
|
|
10
|
+
* manifest: { version: 1, routes: [] },
|
|
11
|
+
* onNotFound: 'next',
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
interface ServerOptions extends RuntimeOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Behavior when no route matches.
|
|
17
|
+
*
|
|
18
|
+
* @default "next"
|
|
19
|
+
*/
|
|
20
|
+
onNotFound?: 'next' | 'response';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fetch handler signature used by server adapters.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import type { FetchHandler } from '@mokup/server'
|
|
27
|
+
*
|
|
28
|
+
* const handler: FetchHandler = async (request) => new Response('ok')
|
|
29
|
+
*/
|
|
30
|
+
type FetchHandler = (request: Request) => Promise<Response | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Bundle input for Worker helpers.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* import type { WorkerBundle } from '@mokup/server'
|
|
36
|
+
*
|
|
37
|
+
* const bundle: WorkerBundle = {
|
|
38
|
+
* manifest: { version: 1, routes: [] },
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
interface WorkerBundle {
|
|
42
|
+
/** Manifest for runtime execution. */
|
|
43
|
+
manifest: Manifest;
|
|
44
|
+
/**
|
|
45
|
+
* In-memory module map for handler execution.
|
|
46
|
+
*
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
moduleMap?: ModuleMap;
|
|
50
|
+
/**
|
|
51
|
+
* Base directory for module resolution.
|
|
52
|
+
*
|
|
53
|
+
* @default undefined
|
|
54
|
+
*/
|
|
55
|
+
moduleBase?: string | URL;
|
|
56
|
+
/**
|
|
57
|
+
* Behavior when no route matches.
|
|
58
|
+
*
|
|
59
|
+
* @default "response"
|
|
60
|
+
*/
|
|
61
|
+
onNotFound?: 'next' | 'response';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Worker input accepted by createMokupWorker.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* import type { WorkerInput } from '@mokup/server'
|
|
68
|
+
*
|
|
69
|
+
* const input: WorkerInput = { version: 1, routes: [] }
|
|
70
|
+
*/
|
|
71
|
+
type WorkerInput = Manifest | WorkerBundle;
|
|
72
|
+
|
|
73
|
+
export type { FetchHandler as F, ServerOptions as S, WorkerBundle as W, WorkerInput as a };
|
|
@@ -1,51 +1,5 @@
|
|
|
1
1
|
const textDecoder = new TextDecoder();
|
|
2
2
|
const textEncoder = new TextEncoder();
|
|
3
|
-
function toRuntimeOptions(options) {
|
|
4
|
-
const runtimeOptions = {
|
|
5
|
-
manifest: options.manifest
|
|
6
|
-
};
|
|
7
|
-
if (typeof options.moduleBase !== "undefined") {
|
|
8
|
-
runtimeOptions.moduleBase = options.moduleBase;
|
|
9
|
-
}
|
|
10
|
-
if (typeof options.moduleMap !== "undefined") {
|
|
11
|
-
runtimeOptions.moduleMap = options.moduleMap;
|
|
12
|
-
}
|
|
13
|
-
return runtimeOptions;
|
|
14
|
-
}
|
|
15
|
-
function normalizeQuery(params) {
|
|
16
|
-
const query = {};
|
|
17
|
-
for (const [key, value] of params.entries()) {
|
|
18
|
-
const current = query[key];
|
|
19
|
-
if (typeof current === "undefined") {
|
|
20
|
-
query[key] = value;
|
|
21
|
-
} else if (Array.isArray(current)) {
|
|
22
|
-
current.push(value);
|
|
23
|
-
} else {
|
|
24
|
-
query[key] = [current, value];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return query;
|
|
28
|
-
}
|
|
29
|
-
function normalizeHeaders(headers) {
|
|
30
|
-
const record = {};
|
|
31
|
-
headers.forEach((value, key) => {
|
|
32
|
-
record[key.toLowerCase()] = value;
|
|
33
|
-
});
|
|
34
|
-
return record;
|
|
35
|
-
}
|
|
36
|
-
function normalizeNodeHeaders(headers) {
|
|
37
|
-
if (!headers) {
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
const record = {};
|
|
41
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
42
|
-
if (typeof value === "undefined") {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
record[key.toLowerCase()] = Array.isArray(value) ? value.join(",") : String(value);
|
|
46
|
-
}
|
|
47
|
-
return record;
|
|
48
|
-
}
|
|
49
3
|
function parseBody(rawText, contentType) {
|
|
50
4
|
if (!rawText) {
|
|
51
5
|
return void 0;
|
|
@@ -78,14 +32,6 @@ function toArrayBuffer(body) {
|
|
|
78
32
|
copy.set(body);
|
|
79
33
|
return copy.buffer;
|
|
80
34
|
}
|
|
81
|
-
function resolveUrl(input, headers) {
|
|
82
|
-
if (/^https?:\/\//.test(input)) {
|
|
83
|
-
return new URL(input);
|
|
84
|
-
}
|
|
85
|
-
const host = headers.host;
|
|
86
|
-
const base = host ? `http://${host}` : "http://localhost";
|
|
87
|
-
return new URL(input, base);
|
|
88
|
-
}
|
|
89
35
|
function concatChunks(chunks) {
|
|
90
36
|
if (chunks.length === 1) {
|
|
91
37
|
return chunks[0] ?? new Uint8Array();
|
|
@@ -173,6 +119,50 @@ async function resolveBody(body, contentType, stream) {
|
|
|
173
119
|
rawBody: rawText
|
|
174
120
|
};
|
|
175
121
|
}
|
|
122
|
+
|
|
123
|
+
function normalizeQuery(params) {
|
|
124
|
+
const query = {};
|
|
125
|
+
for (const [key, value] of params.entries()) {
|
|
126
|
+
const current = query[key];
|
|
127
|
+
if (typeof current === "undefined") {
|
|
128
|
+
query[key] = value;
|
|
129
|
+
} else if (Array.isArray(current)) {
|
|
130
|
+
current.push(value);
|
|
131
|
+
} else {
|
|
132
|
+
query[key] = [current, value];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return query;
|
|
136
|
+
}
|
|
137
|
+
function normalizeHeaders(headers) {
|
|
138
|
+
const record = {};
|
|
139
|
+
headers.forEach((value, key) => {
|
|
140
|
+
record[key.toLowerCase()] = value;
|
|
141
|
+
});
|
|
142
|
+
return record;
|
|
143
|
+
}
|
|
144
|
+
function normalizeNodeHeaders(headers) {
|
|
145
|
+
if (!headers) {
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
const record = {};
|
|
149
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
150
|
+
if (typeof value === "undefined") {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
record[key.toLowerCase()] = Array.isArray(value) ? value.join(",") : String(value);
|
|
154
|
+
}
|
|
155
|
+
return record;
|
|
156
|
+
}
|
|
157
|
+
function resolveUrl(input, headers) {
|
|
158
|
+
if (/^https?:\/\//.test(input)) {
|
|
159
|
+
return new URL(input);
|
|
160
|
+
}
|
|
161
|
+
const host = headers.host;
|
|
162
|
+
const base = host ? `http://${host}` : "http://localhost";
|
|
163
|
+
return new URL(input, base);
|
|
164
|
+
}
|
|
165
|
+
|
|
176
166
|
function buildRuntimeRequest(url, method, headers, body, rawBody) {
|
|
177
167
|
const request = {
|
|
178
168
|
method,
|
|
@@ -217,6 +207,19 @@ async function toRuntimeRequestFromNode(req, bodyOverride) {
|
|
|
217
207
|
resolvedBody.rawBody
|
|
218
208
|
);
|
|
219
209
|
}
|
|
210
|
+
|
|
211
|
+
function toRuntimeOptions(options) {
|
|
212
|
+
const runtimeOptions = {
|
|
213
|
+
manifest: options.manifest
|
|
214
|
+
};
|
|
215
|
+
if (typeof options.moduleBase !== "undefined") {
|
|
216
|
+
runtimeOptions.moduleBase = options.moduleBase;
|
|
217
|
+
}
|
|
218
|
+
if (typeof options.moduleMap !== "undefined") {
|
|
219
|
+
runtimeOptions.moduleMap = options.moduleMap;
|
|
220
|
+
}
|
|
221
|
+
return runtimeOptions;
|
|
222
|
+
}
|
|
220
223
|
function applyRuntimeResultToNode(res, result) {
|
|
221
224
|
res.statusCode = result.status;
|
|
222
225
|
for (const [key, value] of Object.entries(result.headers)) {
|
|
@@ -2,52 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const textDecoder = new TextDecoder();
|
|
4
4
|
const textEncoder = new TextEncoder();
|
|
5
|
-
function toRuntimeOptions(options) {
|
|
6
|
-
const runtimeOptions = {
|
|
7
|
-
manifest: options.manifest
|
|
8
|
-
};
|
|
9
|
-
if (typeof options.moduleBase !== "undefined") {
|
|
10
|
-
runtimeOptions.moduleBase = options.moduleBase;
|
|
11
|
-
}
|
|
12
|
-
if (typeof options.moduleMap !== "undefined") {
|
|
13
|
-
runtimeOptions.moduleMap = options.moduleMap;
|
|
14
|
-
}
|
|
15
|
-
return runtimeOptions;
|
|
16
|
-
}
|
|
17
|
-
function normalizeQuery(params) {
|
|
18
|
-
const query = {};
|
|
19
|
-
for (const [key, value] of params.entries()) {
|
|
20
|
-
const current = query[key];
|
|
21
|
-
if (typeof current === "undefined") {
|
|
22
|
-
query[key] = value;
|
|
23
|
-
} else if (Array.isArray(current)) {
|
|
24
|
-
current.push(value);
|
|
25
|
-
} else {
|
|
26
|
-
query[key] = [current, value];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return query;
|
|
30
|
-
}
|
|
31
|
-
function normalizeHeaders(headers) {
|
|
32
|
-
const record = {};
|
|
33
|
-
headers.forEach((value, key) => {
|
|
34
|
-
record[key.toLowerCase()] = value;
|
|
35
|
-
});
|
|
36
|
-
return record;
|
|
37
|
-
}
|
|
38
|
-
function normalizeNodeHeaders(headers) {
|
|
39
|
-
if (!headers) {
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
|
-
const record = {};
|
|
43
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
44
|
-
if (typeof value === "undefined") {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
record[key.toLowerCase()] = Array.isArray(value) ? value.join(",") : String(value);
|
|
48
|
-
}
|
|
49
|
-
return record;
|
|
50
|
-
}
|
|
51
5
|
function parseBody(rawText, contentType) {
|
|
52
6
|
if (!rawText) {
|
|
53
7
|
return void 0;
|
|
@@ -80,14 +34,6 @@ function toArrayBuffer(body) {
|
|
|
80
34
|
copy.set(body);
|
|
81
35
|
return copy.buffer;
|
|
82
36
|
}
|
|
83
|
-
function resolveUrl(input, headers) {
|
|
84
|
-
if (/^https?:\/\//.test(input)) {
|
|
85
|
-
return new URL(input);
|
|
86
|
-
}
|
|
87
|
-
const host = headers.host;
|
|
88
|
-
const base = host ? `http://${host}` : "http://localhost";
|
|
89
|
-
return new URL(input, base);
|
|
90
|
-
}
|
|
91
37
|
function concatChunks(chunks) {
|
|
92
38
|
if (chunks.length === 1) {
|
|
93
39
|
return chunks[0] ?? new Uint8Array();
|
|
@@ -175,6 +121,50 @@ async function resolveBody(body, contentType, stream) {
|
|
|
175
121
|
rawBody: rawText
|
|
176
122
|
};
|
|
177
123
|
}
|
|
124
|
+
|
|
125
|
+
function normalizeQuery(params) {
|
|
126
|
+
const query = {};
|
|
127
|
+
for (const [key, value] of params.entries()) {
|
|
128
|
+
const current = query[key];
|
|
129
|
+
if (typeof current === "undefined") {
|
|
130
|
+
query[key] = value;
|
|
131
|
+
} else if (Array.isArray(current)) {
|
|
132
|
+
current.push(value);
|
|
133
|
+
} else {
|
|
134
|
+
query[key] = [current, value];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return query;
|
|
138
|
+
}
|
|
139
|
+
function normalizeHeaders(headers) {
|
|
140
|
+
const record = {};
|
|
141
|
+
headers.forEach((value, key) => {
|
|
142
|
+
record[key.toLowerCase()] = value;
|
|
143
|
+
});
|
|
144
|
+
return record;
|
|
145
|
+
}
|
|
146
|
+
function normalizeNodeHeaders(headers) {
|
|
147
|
+
if (!headers) {
|
|
148
|
+
return {};
|
|
149
|
+
}
|
|
150
|
+
const record = {};
|
|
151
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
152
|
+
if (typeof value === "undefined") {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
record[key.toLowerCase()] = Array.isArray(value) ? value.join(",") : String(value);
|
|
156
|
+
}
|
|
157
|
+
return record;
|
|
158
|
+
}
|
|
159
|
+
function resolveUrl(input, headers) {
|
|
160
|
+
if (/^https?:\/\//.test(input)) {
|
|
161
|
+
return new URL(input);
|
|
162
|
+
}
|
|
163
|
+
const host = headers.host;
|
|
164
|
+
const base = host ? `http://${host}` : "http://localhost";
|
|
165
|
+
return new URL(input, base);
|
|
166
|
+
}
|
|
167
|
+
|
|
178
168
|
function buildRuntimeRequest(url, method, headers, body, rawBody) {
|
|
179
169
|
const request = {
|
|
180
170
|
method,
|
|
@@ -219,6 +209,19 @@ async function toRuntimeRequestFromNode(req, bodyOverride) {
|
|
|
219
209
|
resolvedBody.rawBody
|
|
220
210
|
);
|
|
221
211
|
}
|
|
212
|
+
|
|
213
|
+
function toRuntimeOptions(options) {
|
|
214
|
+
const runtimeOptions = {
|
|
215
|
+
manifest: options.manifest
|
|
216
|
+
};
|
|
217
|
+
if (typeof options.moduleBase !== "undefined") {
|
|
218
|
+
runtimeOptions.moduleBase = options.moduleBase;
|
|
219
|
+
}
|
|
220
|
+
if (typeof options.moduleMap !== "undefined") {
|
|
221
|
+
runtimeOptions.moduleMap = options.moduleMap;
|
|
222
|
+
}
|
|
223
|
+
return runtimeOptions;
|
|
224
|
+
}
|
|
222
225
|
function applyRuntimeResultToNode(res, result) {
|
|
223
226
|
res.statusCode = result.status;
|
|
224
227
|
for (const [key, value] of Object.entries(result.headers)) {
|
package/dist/worker-node.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fetch = require('./fetch.cjs');
|
|
4
4
|
require('@mokup/runtime');
|
|
5
|
-
require('./shared/server.
|
|
5
|
+
require('./shared/server.aaygIV2Q.cjs');
|
|
6
6
|
|
|
7
7
|
function isManifest(value) {
|
|
8
8
|
return typeof value === "object" && value !== null && !Array.isArray(value) && "version" in value && "routes" in value;
|
package/dist/worker-node.d.cts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import { a as WorkerInput } from './shared/server.
|
|
1
|
+
import { a as WorkerInput } from './shared/server.DkerfsA-.cjs';
|
|
2
2
|
import '@mokup/runtime';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Minimal Worker-style fetch interface for Node helpers.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import type { FetchWorker } from '@mokup/server/node'
|
|
9
|
+
*
|
|
10
|
+
* const worker: FetchWorker = { fetch: async () => new Response('ok') }
|
|
11
|
+
*/
|
|
4
12
|
interface FetchWorker {
|
|
13
|
+
/** Fetch handler for the Worker runtime. */
|
|
5
14
|
fetch: (request: Request) => Promise<Response>;
|
|
6
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Input accepted by the Node worker helper.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import type { NodeWorkerInput } from '@mokup/server/node'
|
|
21
|
+
*
|
|
22
|
+
* const input: NodeWorkerInput = '.mokup'
|
|
23
|
+
*/
|
|
7
24
|
type NodeWorkerInput = string | WorkerInput;
|
|
25
|
+
/**
|
|
26
|
+
* Create a Worker-compatible fetch handler for Node.
|
|
27
|
+
*
|
|
28
|
+
* @param input - Directory path, manifest, or bundle.
|
|
29
|
+
* @returns Worker handler or a promise when input is a directory.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { createMokupWorker } from '@mokup/server/node'
|
|
33
|
+
*
|
|
34
|
+
* const worker = await createMokupWorker('.mokup')
|
|
35
|
+
*/
|
|
8
36
|
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
9
37
|
declare function createMokupWorker(input: WorkerInput): FetchWorker;
|
|
10
38
|
|
package/dist/worker-node.d.mts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import { a as WorkerInput } from './shared/server.
|
|
1
|
+
import { a as WorkerInput } from './shared/server.DkerfsA-.mjs';
|
|
2
2
|
import '@mokup/runtime';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Minimal Worker-style fetch interface for Node helpers.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import type { FetchWorker } from '@mokup/server/node'
|
|
9
|
+
*
|
|
10
|
+
* const worker: FetchWorker = { fetch: async () => new Response('ok') }
|
|
11
|
+
*/
|
|
4
12
|
interface FetchWorker {
|
|
13
|
+
/** Fetch handler for the Worker runtime. */
|
|
5
14
|
fetch: (request: Request) => Promise<Response>;
|
|
6
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Input accepted by the Node worker helper.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import type { NodeWorkerInput } from '@mokup/server/node'
|
|
21
|
+
*
|
|
22
|
+
* const input: NodeWorkerInput = '.mokup'
|
|
23
|
+
*/
|
|
7
24
|
type NodeWorkerInput = string | WorkerInput;
|
|
25
|
+
/**
|
|
26
|
+
* Create a Worker-compatible fetch handler for Node.
|
|
27
|
+
*
|
|
28
|
+
* @param input - Directory path, manifest, or bundle.
|
|
29
|
+
* @returns Worker handler or a promise when input is a directory.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { createMokupWorker } from '@mokup/server/node'
|
|
33
|
+
*
|
|
34
|
+
* const worker = await createMokupWorker('.mokup')
|
|
35
|
+
*/
|
|
8
36
|
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
9
37
|
declare function createMokupWorker(input: WorkerInput): FetchWorker;
|
|
10
38
|
|