@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.
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/dist/connect.cjs +25 -0
- package/dist/connect.d.cts +19 -0
- package/dist/connect.d.mts +19 -0
- package/dist/connect.d.ts +19 -0
- package/dist/connect.mjs +23 -0
- package/dist/express.cjs +11 -0
- package/dist/express.d.cts +18 -0
- package/dist/express.d.mts +18 -0
- package/dist/express.d.ts +18 -0
- package/dist/express.mjs +9 -0
- package/dist/fastify.cjs +39 -0
- package/dist/fastify.d.cts +29 -0
- package/dist/fastify.d.mts +29 -0
- package/dist/fastify.d.ts +29 -0
- package/dist/fastify.mjs +37 -0
- package/dist/fetch-server.cjs +1659 -0
- package/dist/fetch-server.d.cts +108 -0
- package/dist/fetch-server.d.mts +108 -0
- package/dist/fetch-server.d.ts +108 -0
- package/dist/fetch-server.mjs +1652 -0
- package/dist/fetch.cjs +26 -0
- package/dist/fetch.d.cts +17 -0
- package/dist/fetch.d.mts +17 -0
- package/dist/fetch.d.ts +17 -0
- package/dist/fetch.mjs +24 -0
- package/dist/hono.cjs +27 -0
- package/dist/hono.d.cts +32 -0
- package/dist/hono.d.mts +32 -0
- package/dist/hono.d.ts +32 -0
- package/dist/hono.mjs +25 -0
- package/dist/index.cjs +29 -1677
- package/dist/index.d.cts +42 -136
- package/dist/index.d.mts +42 -136
- package/dist/index.d.ts +42 -136
- package/dist/index.mjs +28 -1666
- package/dist/koa.cjs +38 -0
- package/dist/koa.d.cts +29 -0
- package/dist/koa.d.mts +29 -0
- package/dist/koa.d.ts +29 -0
- package/dist/koa.mjs +36 -0
- package/dist/node.cjs +26 -0
- package/dist/node.d.cts +13 -0
- package/dist/node.d.mts +13 -0
- package/dist/node.d.ts +13 -0
- package/dist/node.mjs +19 -0
- 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.Dje1y79O.mjs → server.LbftO9Jh.mjs} +58 -77
- package/dist/shared/{server.BdTl0qJd.cjs → server.aaygIV2Q.cjs} +59 -77
- package/dist/worker-node.cjs +74 -0
- package/dist/worker-node.d.cts +40 -0
- package/dist/worker-node.d.mts +40 -0
- package/dist/worker-node.d.ts +40 -0
- package/dist/worker-node.mjs +72 -0
- package/dist/worker.cjs +6 -2
- package/dist/worker.d.cts +24 -2
- package/dist/worker.d.mts +24 -2
- package/dist/worker.d.ts +24 -2
- package/dist/worker.mjs +6 -2
- package/package.json +44 -4
- package/dist/shared/server.DNITwCtQ.d.cts +0 -15
- package/dist/shared/server.DNITwCtQ.d.mts +0 -15
- package/dist/shared/server.DNITwCtQ.d.ts +0 -15
|
@@ -1,53 +1,5 @@
|
|
|
1
|
-
import { createRuntime } from '@mokup/runtime';
|
|
2
|
-
|
|
3
1
|
const textDecoder = new TextDecoder();
|
|
4
2
|
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
3
|
function parseBody(rawText, contentType) {
|
|
52
4
|
if (!rawText) {
|
|
53
5
|
return void 0;
|
|
@@ -80,14 +32,6 @@ function toArrayBuffer(body) {
|
|
|
80
32
|
copy.set(body);
|
|
81
33
|
return copy.buffer;
|
|
82
34
|
}
|
|
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
35
|
function concatChunks(chunks) {
|
|
92
36
|
if (chunks.length === 1) {
|
|
93
37
|
return chunks[0] ?? new Uint8Array();
|
|
@@ -175,6 +119,50 @@ async function resolveBody(body, contentType, stream) {
|
|
|
175
119
|
rawBody: rawText
|
|
176
120
|
};
|
|
177
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
|
+
|
|
178
166
|
function buildRuntimeRequest(url, method, headers, body, rawBody) {
|
|
179
167
|
const request = {
|
|
180
168
|
method,
|
|
@@ -219,6 +207,19 @@ async function toRuntimeRequestFromNode(req, bodyOverride) {
|
|
|
219
207
|
resolvedBody.rawBody
|
|
220
208
|
);
|
|
221
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
|
+
}
|
|
222
223
|
function applyRuntimeResultToNode(res, result) {
|
|
223
224
|
res.statusCode = result.status;
|
|
224
225
|
for (const [key, value] of Object.entries(result.headers)) {
|
|
@@ -235,24 +236,4 @@ function applyRuntimeResultToNode(res, result) {
|
|
|
235
236
|
res.end(toBinaryBody(result.body));
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
|
|
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 };
|
|
239
|
+
export { toRuntimeRequestFromNode as a, applyRuntimeResultToNode as b, toBinaryBody as c, toRuntimeRequestFromFetch as d, toArrayBuffer as e, toRuntimeOptions as t };
|
|
@@ -1,55 +1,7 @@
|
|
|
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
|
-
function toRuntimeOptions(options) {
|
|
8
|
-
const runtimeOptions = {
|
|
9
|
-
manifest: options.manifest
|
|
10
|
-
};
|
|
11
|
-
if (typeof options.moduleBase !== "undefined") {
|
|
12
|
-
runtimeOptions.moduleBase = options.moduleBase;
|
|
13
|
-
}
|
|
14
|
-
if (typeof options.moduleMap !== "undefined") {
|
|
15
|
-
runtimeOptions.moduleMap = options.moduleMap;
|
|
16
|
-
}
|
|
17
|
-
return runtimeOptions;
|
|
18
|
-
}
|
|
19
|
-
function normalizeQuery(params) {
|
|
20
|
-
const query = {};
|
|
21
|
-
for (const [key, value] of params.entries()) {
|
|
22
|
-
const current = query[key];
|
|
23
|
-
if (typeof current === "undefined") {
|
|
24
|
-
query[key] = value;
|
|
25
|
-
} else if (Array.isArray(current)) {
|
|
26
|
-
current.push(value);
|
|
27
|
-
} else {
|
|
28
|
-
query[key] = [current, value];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return query;
|
|
32
|
-
}
|
|
33
|
-
function normalizeHeaders(headers) {
|
|
34
|
-
const record = {};
|
|
35
|
-
headers.forEach((value, key) => {
|
|
36
|
-
record[key.toLowerCase()] = value;
|
|
37
|
-
});
|
|
38
|
-
return record;
|
|
39
|
-
}
|
|
40
|
-
function normalizeNodeHeaders(headers) {
|
|
41
|
-
if (!headers) {
|
|
42
|
-
return {};
|
|
43
|
-
}
|
|
44
|
-
const record = {};
|
|
45
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
46
|
-
if (typeof value === "undefined") {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
record[key.toLowerCase()] = Array.isArray(value) ? value.join(",") : String(value);
|
|
50
|
-
}
|
|
51
|
-
return record;
|
|
52
|
-
}
|
|
53
5
|
function parseBody(rawText, contentType) {
|
|
54
6
|
if (!rawText) {
|
|
55
7
|
return void 0;
|
|
@@ -82,14 +34,6 @@ function toArrayBuffer(body) {
|
|
|
82
34
|
copy.set(body);
|
|
83
35
|
return copy.buffer;
|
|
84
36
|
}
|
|
85
|
-
function resolveUrl(input, headers) {
|
|
86
|
-
if (/^https?:\/\//.test(input)) {
|
|
87
|
-
return new URL(input);
|
|
88
|
-
}
|
|
89
|
-
const host = headers.host;
|
|
90
|
-
const base = host ? `http://${host}` : "http://localhost";
|
|
91
|
-
return new URL(input, base);
|
|
92
|
-
}
|
|
93
37
|
function concatChunks(chunks) {
|
|
94
38
|
if (chunks.length === 1) {
|
|
95
39
|
return chunks[0] ?? new Uint8Array();
|
|
@@ -177,6 +121,50 @@ async function resolveBody(body, contentType, stream) {
|
|
|
177
121
|
rawBody: rawText
|
|
178
122
|
};
|
|
179
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
|
+
|
|
180
168
|
function buildRuntimeRequest(url, method, headers, body, rawBody) {
|
|
181
169
|
const request = {
|
|
182
170
|
method,
|
|
@@ -221,6 +209,19 @@ async function toRuntimeRequestFromNode(req, bodyOverride) {
|
|
|
221
209
|
resolvedBody.rawBody
|
|
222
210
|
);
|
|
223
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
|
+
}
|
|
224
225
|
function applyRuntimeResultToNode(res, result) {
|
|
225
226
|
res.statusCode = result.status;
|
|
226
227
|
for (const [key, value] of Object.entries(result.headers)) {
|
|
@@ -237,28 +238,9 @@ function applyRuntimeResultToNode(res, result) {
|
|
|
237
238
|
res.end(toBinaryBody(result.body));
|
|
238
239
|
}
|
|
239
240
|
|
|
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
241
|
exports.applyRuntimeResultToNode = applyRuntimeResultToNode;
|
|
261
|
-
exports.
|
|
242
|
+
exports.toArrayBuffer = toArrayBuffer;
|
|
262
243
|
exports.toBinaryBody = toBinaryBody;
|
|
263
244
|
exports.toRuntimeOptions = toRuntimeOptions;
|
|
245
|
+
exports.toRuntimeRequestFromFetch = toRuntimeRequestFromFetch;
|
|
264
246
|
exports.toRuntimeRequestFromNode = toRuntimeRequestFromNode;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fetch = require('./fetch.cjs');
|
|
4
|
+
require('@mokup/runtime');
|
|
5
|
+
require('./shared/server.aaygIV2Q.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,40 @@
|
|
|
1
|
+
import { a as WorkerInput } from './shared/server.DkerfsA-.cjs';
|
|
2
|
+
import '@mokup/runtime';
|
|
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
|
+
*/
|
|
12
|
+
interface FetchWorker {
|
|
13
|
+
/** Fetch handler for the Worker runtime. */
|
|
14
|
+
fetch: (request: Request) => Promise<Response>;
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
36
|
+
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
37
|
+
declare function createMokupWorker(input: WorkerInput): FetchWorker;
|
|
38
|
+
|
|
39
|
+
export { createMokupWorker };
|
|
40
|
+
export type { FetchWorker, NodeWorkerInput };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { a as WorkerInput } from './shared/server.DkerfsA-.mjs';
|
|
2
|
+
import '@mokup/runtime';
|
|
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
|
+
*/
|
|
12
|
+
interface FetchWorker {
|
|
13
|
+
/** Fetch handler for the Worker runtime. */
|
|
14
|
+
fetch: (request: Request) => Promise<Response>;
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
36
|
+
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
37
|
+
declare function createMokupWorker(input: WorkerInput): FetchWorker;
|
|
38
|
+
|
|
39
|
+
export { createMokupWorker };
|
|
40
|
+
export type { FetchWorker, NodeWorkerInput };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { a as WorkerInput } from './shared/server.DkerfsA-.js';
|
|
2
|
+
import '@mokup/runtime';
|
|
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
|
+
*/
|
|
12
|
+
interface FetchWorker {
|
|
13
|
+
/** Fetch handler for the Worker runtime. */
|
|
14
|
+
fetch: (request: Request) => Promise<Response>;
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
36
|
+
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
37
|
+
declare function createMokupWorker(input: WorkerInput): FetchWorker;
|
|
38
|
+
|
|
39
|
+
export { createMokupWorker };
|
|
40
|
+
export type { FetchWorker, NodeWorkerInput };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createFetchHandler } from './fetch.mjs';
|
|
2
|
+
import '@mokup/runtime';
|
|
3
|
+
import './shared/server.LbftO9Jh.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('./
|
|
3
|
+
const fetch = require('./fetch.cjs');
|
|
4
4
|
require('@mokup/runtime');
|
|
5
|
+
require('./shared/server.aaygIV2Q.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 (
|
|
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,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as WorkerInput } from './shared/server.DkerfsA-.cjs';
|
|
2
2
|
import '@mokup/runtime';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Minimal Worker-style fetch interface.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import type { FetchWorker } from '@mokup/server/worker'
|
|
9
|
+
*
|
|
10
|
+
* const worker: FetchWorker = {
|
|
11
|
+
* fetch: async () => new Response('ok'),
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
4
14
|
interface FetchWorker {
|
|
15
|
+
/** Fetch handler for the Worker runtime. */
|
|
5
16
|
fetch: (request: Request) => Promise<Response>;
|
|
6
17
|
}
|
|
7
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Create a Worker-compatible fetch handler from a manifest or bundle.
|
|
20
|
+
*
|
|
21
|
+
* @param input - Manifest or bundle input.
|
|
22
|
+
* @returns Worker fetch handler.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* import { createMokupWorker } from '@mokup/server/worker'
|
|
26
|
+
*
|
|
27
|
+
* const worker = createMokupWorker({ version: 1, routes: [] })
|
|
28
|
+
*/
|
|
29
|
+
declare function createMokupWorker(input: WorkerInput): FetchWorker;
|
|
8
30
|
|
|
9
31
|
export { createMokupWorker };
|
|
10
32
|
export type { FetchWorker };
|
package/dist/worker.d.mts
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as WorkerInput } from './shared/server.DkerfsA-.mjs';
|
|
2
2
|
import '@mokup/runtime';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Minimal Worker-style fetch interface.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import type { FetchWorker } from '@mokup/server/worker'
|
|
9
|
+
*
|
|
10
|
+
* const worker: FetchWorker = {
|
|
11
|
+
* fetch: async () => new Response('ok'),
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
4
14
|
interface FetchWorker {
|
|
15
|
+
/** Fetch handler for the Worker runtime. */
|
|
5
16
|
fetch: (request: Request) => Promise<Response>;
|
|
6
17
|
}
|
|
7
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Create a Worker-compatible fetch handler from a manifest or bundle.
|
|
20
|
+
*
|
|
21
|
+
* @param input - Manifest or bundle input.
|
|
22
|
+
* @returns Worker fetch handler.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* import { createMokupWorker } from '@mokup/server/worker'
|
|
26
|
+
*
|
|
27
|
+
* const worker = createMokupWorker({ version: 1, routes: [] })
|
|
28
|
+
*/
|
|
29
|
+
declare function createMokupWorker(input: WorkerInput): FetchWorker;
|
|
8
30
|
|
|
9
31
|
export { createMokupWorker };
|
|
10
32
|
export type { FetchWorker };
|