devflare 1.0.0-next.34 → 1.0.0-next.35
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/LICENSE +21 -0
- package/bin/devflare.js +1 -1
- package/dist/{account-p9eywryw.js → account-4tgh03a8.js} +4 -6
- package/dist/browser.js +2340 -19
- package/dist/{build-8bn7frg8.js → build-rh7ghrgw.js} +7 -10
- package/dist/cli/index.js +1377 -6
- package/dist/cloudflare/index.js +2 -3
- package/dist/config-entry.js +1 -9
- package/dist/{config-gphd6wx7.js → config-ghk2bxj3.js} +3 -6
- package/dist/{deploy-vpcp41fw.js → deploy-6hzv76sh.js} +13 -17
- package/dist/{dev-9scy9gap.js → dev-mkhjdwh7.js} +971 -73
- package/dist/{doctor-swfeeqny.js → doctor-0ng5qrr1.js} +2 -3
- package/dist/{index-e7xn30bh.js → index-0cc05hzv.js} +1 -1
- package/dist/{index-t0r7evpw.js → index-293aqfy4.js} +7 -9
- package/dist/{index-3t0e51a0.js → index-2yv7w548.js} +1 -1
- package/dist/{index-ksqth51q.js → index-a8pnvg3r.js} +1 -1
- package/dist/{index-bhxj7ff6.js → index-e251zhns.js} +943 -117
- package/dist/{index-2xz4etye.js → index-hvtd936d.js} +3 -0
- package/dist/{index-13sfensw.js → index-kcp7y951.js} +2 -13
- package/dist/{index-w8c8tjc5.js → index-mek9msfv.js} +1 -4
- package/dist/{index-dem45895.js → index-mjvybn39.js} +1 -1
- package/dist/{index-x0wpeb3x.js → index-phcrvs6d.js} +112 -2
- package/dist/{index-b20xx2vk.js → index-se4kw8tm.js} +4 -6
- package/dist/{index-pd97hk2j.js → index-x8s9rwfh.js} +466 -19
- package/dist/index.js +1 -42
- package/dist/{login-7vyzeqy4.js → login-4h1sfsed.js} +4 -6
- package/dist/{previews-jfbectpc.js → previews-qr7c5j8h.js} +10 -14
- package/dist/{productions-49ct4kjm.js → productions-xpmd6bw8.js} +6 -9
- package/dist/{remote-6876k6mz.js → remote-kqcvhnfx.js} +100 -5
- package/dist/runtime/index.js +0 -63
- package/dist/{secrets-9ne7armr.js → secrets-6wbdsdek.js} +3 -5
- package/dist/sveltekit/index.js +0 -263
- package/dist/test/index.js +2 -4626
- package/dist/{types-zekmbebk.js → types-ahnnpphq.js} +6 -8
- package/dist/vite/index.js +7 -9
- package/dist/{worker-706g8qeh.js → worker-1yg72jxg.js} +6 -9
- package/package.json +5 -3
- package/dist/index-1trss579.js +0 -2299
- package/dist/index-34dejneh.js +0 -214
- package/dist/index-3z20d3kd.js +0 -1380
- package/dist/index-4xmtkg9g.js +0 -109
- package/dist/index-62b3gt2g.js +0 -12
- package/dist/index-97rfy7n2.js +0 -413
- package/dist/index-c4zd39tc.js +0 -155
- package/dist/index-dgx495pv.js +0 -1036
- package/dist/index-dm9q84c7.js +0 -360
- package/dist/index-pmnb7eke.js +0 -109
- package/dist/index-t23wq5js.js +0 -111
- package/dist/index-wxdcrzcp.js +0 -475
- package/dist/index-x2fd1361.js +0 -133
- package/dist/index-za0r01bx.js +0 -588
package/dist/index-4xmtkg9g.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// src/cloudflare/remote-config.ts
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
3
|
-
import { homedir } from "os";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
var MIN_MINUTES = 1;
|
|
6
|
-
var MAX_MINUTES = 1440;
|
|
7
|
-
function getConfigDir() {
|
|
8
|
-
return join(homedir(), ".devflare");
|
|
9
|
-
}
|
|
10
|
-
function getConfigPath() {
|
|
11
|
-
return join(getConfigDir(), "remote.json");
|
|
12
|
-
}
|
|
13
|
-
function readConfig() {
|
|
14
|
-
const path = getConfigPath();
|
|
15
|
-
if (!existsSync(path))
|
|
16
|
-
return null;
|
|
17
|
-
try {
|
|
18
|
-
const content = readFileSync(path, "utf-8");
|
|
19
|
-
return JSON.parse(content);
|
|
20
|
-
} catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function writeConfig(config) {
|
|
25
|
-
const dir = getConfigDir();
|
|
26
|
-
if (!existsSync(dir)) {
|
|
27
|
-
mkdirSync(dir, { recursive: true });
|
|
28
|
-
}
|
|
29
|
-
writeFileSync(getConfigPath(), JSON.stringify(config, null, "\t"));
|
|
30
|
-
}
|
|
31
|
-
function deleteConfig() {
|
|
32
|
-
const path = getConfigPath();
|
|
33
|
-
if (existsSync(path)) {
|
|
34
|
-
try {
|
|
35
|
-
unlinkSync(path);
|
|
36
|
-
} catch {}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function enableRemoteMode(minutes = 30) {
|
|
40
|
-
const validMinutes = Math.max(MIN_MINUTES, Math.min(MAX_MINUTES, Math.floor(minutes) || 30));
|
|
41
|
-
const now = Date.now();
|
|
42
|
-
writeConfig({
|
|
43
|
-
enabledAt: now,
|
|
44
|
-
expiresAt: now + validMinutes * 60 * 1000,
|
|
45
|
-
durationMinutes: validMinutes
|
|
46
|
-
});
|
|
47
|
-
return validMinutes;
|
|
48
|
-
}
|
|
49
|
-
function disableRemoteMode() {
|
|
50
|
-
deleteConfig();
|
|
51
|
-
}
|
|
52
|
-
function getRemoteModeStatus() {
|
|
53
|
-
const config = readConfig();
|
|
54
|
-
if (!config) {
|
|
55
|
-
return { isEnabled: false, remainingMinutes: 0, expiresAt: null };
|
|
56
|
-
}
|
|
57
|
-
const now = Date.now();
|
|
58
|
-
if (now >= config.expiresAt) {
|
|
59
|
-
deleteConfig();
|
|
60
|
-
return { isEnabled: false, remainingMinutes: 0, expiresAt: null };
|
|
61
|
-
}
|
|
62
|
-
const remainingMs = config.expiresAt - now;
|
|
63
|
-
const remainingMinutes = Math.ceil(remainingMs / 60000);
|
|
64
|
-
return {
|
|
65
|
-
isEnabled: true,
|
|
66
|
-
remainingMinutes,
|
|
67
|
-
expiresAt: new Date(config.expiresAt)
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function getEffectiveRemoteModeStatus() {
|
|
71
|
-
const envValue = process.env.DEVFLARE_REMOTE ?? "";
|
|
72
|
-
const envVarSet = ["1", "true", "yes"].includes(envValue.toLowerCase());
|
|
73
|
-
if (envVarSet) {
|
|
74
|
-
return {
|
|
75
|
-
isActive: true,
|
|
76
|
-
source: "env",
|
|
77
|
-
remainingMinutes: Number.POSITIVE_INFINITY,
|
|
78
|
-
expiresAt: null,
|
|
79
|
-
envVarSet: true
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
const status = getRemoteModeStatus();
|
|
83
|
-
if (status.isEnabled) {
|
|
84
|
-
return {
|
|
85
|
-
isActive: true,
|
|
86
|
-
source: "config",
|
|
87
|
-
remainingMinutes: status.remainingMinutes,
|
|
88
|
-
expiresAt: status.expiresAt,
|
|
89
|
-
envVarSet: false
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
isActive: false,
|
|
94
|
-
source: "none",
|
|
95
|
-
remainingMinutes: 0,
|
|
96
|
-
expiresAt: null,
|
|
97
|
-
envVarSet: false
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function isRemoteModeActive() {
|
|
101
|
-
const envValue = process.env.DEVFLARE_REMOTE ?? "";
|
|
102
|
-
if (["1", "true", "yes"].includes(envValue.toLowerCase())) {
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
const status = getRemoteModeStatus();
|
|
106
|
-
return status.isEnabled;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export { enableRemoteMode, disableRemoteMode, getRemoteModeStatus, getEffectiveRemoteModeStatus, isRemoteModeActive };
|
package/dist/index-62b3gt2g.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/workerName.ts
|
|
2
|
-
var workerName = (() => {
|
|
3
|
-
if (typeof __DEVFLARE_WORKER_NAME__ !== "undefined") {
|
|
4
|
-
return __DEVFLARE_WORKER_NAME__;
|
|
5
|
-
}
|
|
6
|
-
if (typeof process !== "undefined" && process.env?.DEVFLARE_WORKER_NAME) {
|
|
7
|
-
return process.env.DEVFLARE_WORKER_NAME;
|
|
8
|
-
}
|
|
9
|
-
return "unknown";
|
|
10
|
-
})();
|
|
11
|
-
|
|
12
|
-
export { workerName };
|
package/dist/index-97rfy7n2.js
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContextProxy,
|
|
3
|
-
createFetchEvent,
|
|
4
|
-
getContextOrNull,
|
|
5
|
-
runWithEventContext
|
|
6
|
-
} from "./index-1trss579.js";
|
|
7
|
-
|
|
8
|
-
// src/runtime/exports.ts
|
|
9
|
-
function createReadonlyProxy(getter, name) {
|
|
10
|
-
return createContextProxy(getter, name, { mutable: false });
|
|
11
|
-
}
|
|
12
|
-
var env = createReadonlyProxy(() => getContextOrNull()?.env, "env");
|
|
13
|
-
var vars = createReadonlyProxy(() => getContextOrNull()?.env, "vars");
|
|
14
|
-
var ctx = createReadonlyProxy(() => getContextOrNull()?.ctx, "ctx");
|
|
15
|
-
var event = createReadonlyProxy(() => getContextOrNull()?.event, "event");
|
|
16
|
-
var locals = createContextProxy(() => getContextOrNull()?.locals, "locals");
|
|
17
|
-
// src/runtime/middleware.ts
|
|
18
|
-
var FETCH_SEQUENCE_SYMBOL = Symbol.for("devflare.fetch-sequence");
|
|
19
|
-
var FETCH_RESOLVE_STYLE_SYMBOL = Symbol.for("devflare.fetch-resolve-style");
|
|
20
|
-
var FETCH_WORKER_STYLE_SYMBOL = Symbol.for("devflare.fetch-worker-style");
|
|
21
|
-
var QUEUE_WORKER_STYLE_SYMBOL = Symbol.for("devflare.queue-worker-style");
|
|
22
|
-
var SCHEDULED_WORKER_STYLE_SYMBOL = Symbol.for("devflare.scheduled-worker-style");
|
|
23
|
-
function createNotFoundResponse() {
|
|
24
|
-
return new Response("Not Found", { status: 404 });
|
|
25
|
-
}
|
|
26
|
-
function isFunction(value) {
|
|
27
|
-
return typeof value === "function";
|
|
28
|
-
}
|
|
29
|
-
function markResolveStyle(handler) {
|
|
30
|
-
Object.defineProperty(handler, FETCH_RESOLVE_STYLE_SYMBOL, {
|
|
31
|
-
value: true,
|
|
32
|
-
enumerable: false,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: false
|
|
35
|
-
});
|
|
36
|
-
return handler;
|
|
37
|
-
}
|
|
38
|
-
function markWorkerStyle(handler) {
|
|
39
|
-
Object.defineProperty(handler, FETCH_WORKER_STYLE_SYMBOL, {
|
|
40
|
-
value: true,
|
|
41
|
-
enumerable: false,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: false
|
|
44
|
-
});
|
|
45
|
-
return handler;
|
|
46
|
-
}
|
|
47
|
-
function defineFetchHandler(handler, options) {
|
|
48
|
-
if (options?.style === "resolve") {
|
|
49
|
-
return markResolveStyle(handler);
|
|
50
|
-
}
|
|
51
|
-
if (options?.style === "worker") {
|
|
52
|
-
return markWorkerStyle(handler);
|
|
53
|
-
}
|
|
54
|
-
return handler;
|
|
55
|
-
}
|
|
56
|
-
function hasResolveStyleMarker(handler) {
|
|
57
|
-
const record = handler;
|
|
58
|
-
return Boolean(record[FETCH_RESOLVE_STYLE_SYMBOL] || record[FETCH_SEQUENCE_SYMBOL]);
|
|
59
|
-
}
|
|
60
|
-
function hasWorkerStyleMarker(handler) {
|
|
61
|
-
const record = handler;
|
|
62
|
-
return Boolean(record[FETCH_WORKER_STYLE_SYMBOL]);
|
|
63
|
-
}
|
|
64
|
-
function isResolveStyleFunction(handler) {
|
|
65
|
-
return hasResolveStyleMarker(handler);
|
|
66
|
-
}
|
|
67
|
-
function assertExplicit2ArgStyle(handler) {
|
|
68
|
-
if (handler.length !== 2) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (hasResolveStyleMarker(handler) || hasWorkerStyleMarker(handler)) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
throw new Error("[devflare] Ambiguous 2-argument fetch handler. The calling convention must be declared explicitly via " + "`defineFetchHandler(fn, { style: 'resolve' })` (for `(event, resolve) => Response`) or " + "`defineFetchHandler(fn, { style: 'worker' })` (for `(request, env) => Response`). " + "Single-arg `(event) => Response` and 3-arg worker-style `(request, env, ctx) => Response` " + "handlers do not require wrapping.");
|
|
75
|
-
}
|
|
76
|
-
function defineQueueHandler(handler) {
|
|
77
|
-
Object.defineProperty(handler, QUEUE_WORKER_STYLE_SYMBOL, {
|
|
78
|
-
value: true,
|
|
79
|
-
enumerable: false,
|
|
80
|
-
configurable: true,
|
|
81
|
-
writable: false
|
|
82
|
-
});
|
|
83
|
-
return handler;
|
|
84
|
-
}
|
|
85
|
-
function defineScheduledHandler(handler) {
|
|
86
|
-
Object.defineProperty(handler, SCHEDULED_WORKER_STYLE_SYMBOL, {
|
|
87
|
-
value: true,
|
|
88
|
-
enumerable: false,
|
|
89
|
-
configurable: true,
|
|
90
|
-
writable: false
|
|
91
|
-
});
|
|
92
|
-
return handler;
|
|
93
|
-
}
|
|
94
|
-
function hasQueueWorkerStyleMarker(handler) {
|
|
95
|
-
const record = handler;
|
|
96
|
-
return Boolean(record[QUEUE_WORKER_STYLE_SYMBOL]);
|
|
97
|
-
}
|
|
98
|
-
function hasScheduledWorkerStyleMarker(handler) {
|
|
99
|
-
const record = handler;
|
|
100
|
-
return Boolean(record[SCHEDULED_WORKER_STYLE_SYMBOL]);
|
|
101
|
-
}
|
|
102
|
-
function assertExplicitQueueHandlerStyle(handler) {
|
|
103
|
-
if (handler.length !== 2) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (hasQueueWorkerStyleMarker(handler)) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
throw new Error("[devflare] Ambiguous 2-argument queue handler. The calling convention must be declared explicitly via " + "`defineQueueHandler(fn)` for `(batch, env) => void` worker-style handlers. " + "Single-arg `(event) => void` and 3-arg `(batch, env, ctx) => void` handlers do not require wrapping.");
|
|
110
|
-
}
|
|
111
|
-
function assertExplicitScheduledHandlerStyle(handler) {
|
|
112
|
-
if (handler.length !== 2) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (hasScheduledWorkerStyleMarker(handler)) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
throw new Error("[devflare] Ambiguous 2-argument scheduled handler. The calling convention must be declared explicitly via " + "`defineScheduledHandler(fn)` for `(controller, env) => void` worker-style handlers. " + "Single-arg `(event) => void` and 3-arg `(controller, env, ctx) => void` handlers do not require wrapping.");
|
|
119
|
-
}
|
|
120
|
-
function isWorkerStyleFetchFunction(handler) {
|
|
121
|
-
if (isResolveStyleFunction(handler)) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if (handler.length >= 3) {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
return hasWorkerStyleMarker(handler);
|
|
128
|
-
}
|
|
129
|
-
function invokeWorkerStyleFetchFunction(handler, event2) {
|
|
130
|
-
return handler(event2.request, event2.env, event2.ctx);
|
|
131
|
-
}
|
|
132
|
-
function bindMethod(target, key) {
|
|
133
|
-
if (!target || typeof target !== "object") {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
const value = target[key];
|
|
137
|
-
if (!isFunction(value)) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const boundHandler = value.bind(target);
|
|
141
|
-
if (isResolveStyleFunction(value)) {
|
|
142
|
-
markResolveStyle(boundHandler);
|
|
143
|
-
}
|
|
144
|
-
if (hasWorkerStyleMarker(value)) {
|
|
145
|
-
markWorkerStyle(boundHandler);
|
|
146
|
-
}
|
|
147
|
-
return boundHandler;
|
|
148
|
-
}
|
|
149
|
-
function createFetchSequence(middlewares) {
|
|
150
|
-
return async (event2, resolve = async () => createNotFoundResponse()) => {
|
|
151
|
-
const executeMiddleware = async (index, activeEvent) => {
|
|
152
|
-
if (index >= middlewares.length) {
|
|
153
|
-
return resolve(activeEvent);
|
|
154
|
-
}
|
|
155
|
-
const middleware = middlewares[index];
|
|
156
|
-
return middleware(activeEvent, async (nextEvent = activeEvent) => {
|
|
157
|
-
return executeMiddleware(index + 1, nextEvent);
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
return executeMiddleware(0, event2);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function sequence(...middlewares) {
|
|
164
|
-
const composed = createFetchSequence(middlewares);
|
|
165
|
-
Object.defineProperty(composed, FETCH_SEQUENCE_SYMBOL, {
|
|
166
|
-
value: true,
|
|
167
|
-
enumerable: false,
|
|
168
|
-
configurable: false,
|
|
169
|
-
writable: false
|
|
170
|
-
});
|
|
171
|
-
return markResolveStyle(composed);
|
|
172
|
-
}
|
|
173
|
-
function getDefaultHandleHandler(module) {
|
|
174
|
-
return bindMethod(module.default, "handle");
|
|
175
|
-
}
|
|
176
|
-
function getDefaultFetchHandler(module) {
|
|
177
|
-
const defaultExport = module.default;
|
|
178
|
-
if (isFunction(defaultExport)) {
|
|
179
|
-
return defaultExport;
|
|
180
|
-
}
|
|
181
|
-
return bindMethod(defaultExport, "fetch");
|
|
182
|
-
}
|
|
183
|
-
function getPrimaryFetchEntryCandidates(module) {
|
|
184
|
-
const candidates = [];
|
|
185
|
-
const namedHandle = isFunction(module.handle) ? module.handle : null;
|
|
186
|
-
if (namedHandle) {
|
|
187
|
-
candidates.push({
|
|
188
|
-
name: "handle",
|
|
189
|
-
handler: namedHandle
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
const namedFetch = isFunction(module.fetch) ? module.fetch : null;
|
|
193
|
-
if (namedFetch) {
|
|
194
|
-
candidates.push({
|
|
195
|
-
name: "fetch",
|
|
196
|
-
handler: namedFetch
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
const defaultHandle = getDefaultHandleHandler(module);
|
|
200
|
-
if (defaultHandle) {
|
|
201
|
-
candidates.push({
|
|
202
|
-
name: "default.handle",
|
|
203
|
-
handler: defaultHandle
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const defaultFetch = getDefaultFetchHandler(module);
|
|
207
|
-
if (defaultFetch) {
|
|
208
|
-
candidates.push({
|
|
209
|
-
name: isFunction(module.default) ? "default" : "default.fetch",
|
|
210
|
-
handler: defaultFetch
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
return candidates;
|
|
214
|
-
}
|
|
215
|
-
function assertSinglePrimaryFetchEntry(candidates) {
|
|
216
|
-
if (candidates.length <= 1) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const foundEntries = candidates.map(({ name }) => `"${name}"`).join(", ");
|
|
220
|
-
throw new Error(`Ambiguous fetch entry module. Export exactly one primary fetch entry per module. ` + `Use either "fetch" or "handle" (or one default equivalent), not both. ` + `Found: ${foundEntries}`);
|
|
221
|
-
}
|
|
222
|
-
function resolveMethodHandler(module, method) {
|
|
223
|
-
const normalizedMethod = method.toUpperCase();
|
|
224
|
-
const directHandler = isFunction(module[normalizedMethod]) ? module[normalizedMethod] : bindMethod(module.default, normalizedMethod);
|
|
225
|
-
if (directHandler) {
|
|
226
|
-
return {
|
|
227
|
-
handler: directHandler,
|
|
228
|
-
stripBody: false
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
if (normalizedMethod === "HEAD") {
|
|
232
|
-
const getHandler = isFunction(module.GET) ? module.GET : bindMethod(module.default, "GET");
|
|
233
|
-
if (getHandler) {
|
|
234
|
-
return {
|
|
235
|
-
handler: getHandler,
|
|
236
|
-
stripBody: true
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const allHandler = isFunction(module.ALL) ? module.ALL : bindMethod(module.default, "ALL");
|
|
241
|
-
if (allHandler) {
|
|
242
|
-
return {
|
|
243
|
-
handler: allHandler,
|
|
244
|
-
stripBody: false
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
async function invokeResolvedFetchHandler(handler, event2) {
|
|
250
|
-
if (isResolveStyleFunction(handler)) {
|
|
251
|
-
return handler(event2, async () => createNotFoundResponse());
|
|
252
|
-
}
|
|
253
|
-
if (isWorkerStyleFetchFunction(handler)) {
|
|
254
|
-
return invokeWorkerStyleFetchFunction(handler, event2);
|
|
255
|
-
}
|
|
256
|
-
assertExplicit2ArgStyle(handler);
|
|
257
|
-
return handler(event2);
|
|
258
|
-
}
|
|
259
|
-
function resolveFetchHandler(module) {
|
|
260
|
-
const candidates = getPrimaryFetchEntryCandidates(module);
|
|
261
|
-
assertSinglePrimaryFetchEntry(candidates);
|
|
262
|
-
return candidates[0]?.handler ?? null;
|
|
263
|
-
}
|
|
264
|
-
async function invokeFetchHandler(handler, event2, resolve = async () => createNotFoundResponse()) {
|
|
265
|
-
if (!isFunction(handler)) {
|
|
266
|
-
return resolve(event2);
|
|
267
|
-
}
|
|
268
|
-
if (isResolveStyleFunction(handler)) {
|
|
269
|
-
const response2 = await handler(event2, resolve);
|
|
270
|
-
return response2 ?? createNotFoundResponse();
|
|
271
|
-
}
|
|
272
|
-
if (isWorkerStyleFetchFunction(handler)) {
|
|
273
|
-
const response2 = await invokeWorkerStyleFetchFunction(handler, event2);
|
|
274
|
-
return response2 ?? createNotFoundResponse();
|
|
275
|
-
}
|
|
276
|
-
assertExplicit2ArgStyle(handler);
|
|
277
|
-
const response = await handler(event2);
|
|
278
|
-
return response ?? createNotFoundResponse();
|
|
279
|
-
}
|
|
280
|
-
function createResolveFetch(module, _currentEntry, initialEvent, options = {}) {
|
|
281
|
-
return async (nextEvent = initialEvent) => {
|
|
282
|
-
return runWithEventContext(nextEvent, async () => {
|
|
283
|
-
const methodResolution = resolveMethodHandler(module, nextEvent.request.method);
|
|
284
|
-
if (methodResolution) {
|
|
285
|
-
const response = await invokeResolvedFetchHandler(methodResolution.handler, nextEvent);
|
|
286
|
-
const finalResponse = response ?? createNotFoundResponse();
|
|
287
|
-
if (methodResolution.stripBody) {
|
|
288
|
-
return new Response(null, finalResponse);
|
|
289
|
-
}
|
|
290
|
-
return finalResponse;
|
|
291
|
-
}
|
|
292
|
-
if (options.fallbackResolve) {
|
|
293
|
-
return options.fallbackResolve(nextEvent);
|
|
294
|
-
}
|
|
295
|
-
return createNotFoundResponse();
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
async function invokeFetchModule(module, event2, fallbackResolve) {
|
|
300
|
-
const handler = resolveFetchHandler(module);
|
|
301
|
-
if (!handler) {
|
|
302
|
-
return createResolveFetch(module, null, event2, { fallbackResolve })(event2);
|
|
303
|
-
}
|
|
304
|
-
return invokeFetchHandler(handler, event2, createResolveFetch(module, handler, event2, { fallbackResolve }));
|
|
305
|
-
}
|
|
306
|
-
// src/runtime/router/index.ts
|
|
307
|
-
function normalizePathname(pathname) {
|
|
308
|
-
if (!pathname || pathname === "/") {
|
|
309
|
-
return "/";
|
|
310
|
-
}
|
|
311
|
-
const normalized = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
312
|
-
const trimmed = normalized.replace(/\/+$|\/+$/g, "");
|
|
313
|
-
return trimmed === "" ? "/" : trimmed;
|
|
314
|
-
}
|
|
315
|
-
function decodePathSegment(segment) {
|
|
316
|
-
try {
|
|
317
|
-
return decodeURIComponent(segment);
|
|
318
|
-
} catch {
|
|
319
|
-
return segment;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function getPathSegments(pathname) {
|
|
323
|
-
const normalizedPathname = normalizePathname(pathname);
|
|
324
|
-
if (normalizedPathname === "/") {
|
|
325
|
-
return [];
|
|
326
|
-
}
|
|
327
|
-
return normalizedPathname.slice(1).split("/").filter(Boolean).map(decodePathSegment);
|
|
328
|
-
}
|
|
329
|
-
function getMatchPathname(input) {
|
|
330
|
-
if (input instanceof Request) {
|
|
331
|
-
return new URL(input.url).pathname;
|
|
332
|
-
}
|
|
333
|
-
if (input instanceof URL) {
|
|
334
|
-
return input.pathname;
|
|
335
|
-
}
|
|
336
|
-
if (input.includes("://")) {
|
|
337
|
-
return new URL(input).pathname;
|
|
338
|
-
}
|
|
339
|
-
return input;
|
|
340
|
-
}
|
|
341
|
-
function matchRouteSegments(routeSegments, pathnameSegments) {
|
|
342
|
-
if (routeSegments.length === 0) {
|
|
343
|
-
return pathnameSegments.length === 0 ? {} : null;
|
|
344
|
-
}
|
|
345
|
-
const params = {};
|
|
346
|
-
let routeIndex = 0;
|
|
347
|
-
let pathIndex = 0;
|
|
348
|
-
while (routeIndex < routeSegments.length) {
|
|
349
|
-
const routeSegment = routeSegments[routeIndex];
|
|
350
|
-
if (routeSegment.type === "optional-rest") {
|
|
351
|
-
params[routeSegment.name] = pathnameSegments.slice(pathIndex).join("/");
|
|
352
|
-
pathIndex = pathnameSegments.length;
|
|
353
|
-
routeIndex += 1;
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
if (routeSegment.type === "rest") {
|
|
357
|
-
if (pathIndex >= pathnameSegments.length) {
|
|
358
|
-
return null;
|
|
359
|
-
}
|
|
360
|
-
params[routeSegment.name] = pathnameSegments.slice(pathIndex).join("/");
|
|
361
|
-
pathIndex = pathnameSegments.length;
|
|
362
|
-
routeIndex += 1;
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
const pathnameSegment = pathnameSegments[pathIndex];
|
|
366
|
-
if (pathnameSegment === undefined) {
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
if (routeSegment.type === "static") {
|
|
370
|
-
if (pathnameSegment !== routeSegment.value) {
|
|
371
|
-
return null;
|
|
372
|
-
}
|
|
373
|
-
} else {
|
|
374
|
-
params[routeSegment.name] = pathnameSegment;
|
|
375
|
-
}
|
|
376
|
-
pathIndex += 1;
|
|
377
|
-
routeIndex += 1;
|
|
378
|
-
}
|
|
379
|
-
if (pathIndex !== pathnameSegments.length) {
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
return params;
|
|
383
|
-
}
|
|
384
|
-
function matchFetchRoute(routes, input) {
|
|
385
|
-
const pathnameSegments = getPathSegments(getMatchPathname(input));
|
|
386
|
-
for (const route of routes) {
|
|
387
|
-
const params = matchRouteSegments(route.segments, pathnameSegments);
|
|
388
|
-
if (params) {
|
|
389
|
-
return {
|
|
390
|
-
route,
|
|
391
|
-
params
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return null;
|
|
396
|
-
}
|
|
397
|
-
async function invokeRouteModules(routes, event2) {
|
|
398
|
-
const match = matchFetchRoute(routes, event2.request);
|
|
399
|
-
if (!match) {
|
|
400
|
-
return new Response("Not Found", { status: 404 });
|
|
401
|
-
}
|
|
402
|
-
const routeEvent = createFetchEvent(event2.request, event2.env, event2.ctx, {
|
|
403
|
-
params: match.params,
|
|
404
|
-
locals: event2.locals
|
|
405
|
-
});
|
|
406
|
-
return runWithEventContext(routeEvent, () => invokeFetchModule(match.route.module, routeEvent));
|
|
407
|
-
}
|
|
408
|
-
function createRouteResolve(routes, initialEvent) {
|
|
409
|
-
return async (nextEvent = initialEvent) => {
|
|
410
|
-
return invokeRouteModules(routes, nextEvent);
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
export { env, vars, ctx, event, locals, markResolveStyle, markWorkerStyle, defineFetchHandler, defineQueueHandler, defineScheduledHandler, assertExplicitQueueHandlerStyle, assertExplicitScheduledHandlerStyle, sequence, resolveFetchHandler, invokeFetchHandler, createResolveFetch, invokeFetchModule, matchFetchRoute, invokeRouteModules, createRouteResolve };
|
package/dist/index-c4zd39tc.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./index-37x76zdn.js";
|
|
4
|
-
|
|
5
|
-
// src/test/binding-hints.ts
|
|
6
|
-
function extractBindingHints(config) {
|
|
7
|
-
const hints = {};
|
|
8
|
-
if (config.bindings?.kv) {
|
|
9
|
-
for (const name of Object.keys(config.bindings.kv)) {
|
|
10
|
-
hints[name] = "kv";
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if (config.bindings?.r2) {
|
|
14
|
-
for (const name of Object.keys(config.bindings.r2)) {
|
|
15
|
-
hints[name] = "r2";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (config.bindings?.d1) {
|
|
19
|
-
for (const name of Object.keys(config.bindings.d1)) {
|
|
20
|
-
hints[name] = "d1";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (config.bindings?.durableObjects) {
|
|
24
|
-
for (const name of Object.keys(config.bindings.durableObjects)) {
|
|
25
|
-
hints[name] = "do";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (config.bindings?.services) {
|
|
29
|
-
for (const name of Object.keys(config.bindings.services)) {
|
|
30
|
-
hints[name] = "service";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (config.bindings?.queues?.consumers) {
|
|
34
|
-
for (const consumer of config.bindings.queues.consumers) {
|
|
35
|
-
hints[consumer.queue] = "queue";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (config.bindings?.queues?.producers) {
|
|
39
|
-
for (const name of Object.keys(config.bindings.queues.producers)) {
|
|
40
|
-
hints[name] = "queue";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (config.bindings?.ai) {
|
|
44
|
-
hints[config.bindings.ai.binding] = "ai";
|
|
45
|
-
}
|
|
46
|
-
if (config.bindings?.sendEmail) {
|
|
47
|
-
for (const name of Object.keys(config.bindings.sendEmail)) {
|
|
48
|
-
hints[name] = "sendEmail";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (config.bindings?.workflows) {
|
|
52
|
-
for (const name of Object.keys(config.bindings.workflows)) {
|
|
53
|
-
hints[name] = "workflow";
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return hints;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/shims/local-hyperdrive.ts
|
|
60
|
-
var HYPERDRIVE_CONNECT_MESSAGE = "Local Hyperdrive does not implement the raw socket connect(). " + "Use the populated connection fields (connectionString, or host/port/user/password/database) " + "with your Node database driver, or run a createTestContext()/Miniflare-backed test " + "(Miniflare establishes real Hyperdrive socket connections) for socket-level behavior.";
|
|
61
|
-
function defaultPortForDatabaseUrl(url) {
|
|
62
|
-
if (url.port) {
|
|
63
|
-
return Number(url.port);
|
|
64
|
-
}
|
|
65
|
-
return url.protocol === "mysql:" ? 3306 : 5432;
|
|
66
|
-
}
|
|
67
|
-
function createLocalHyperdrive(connectionString) {
|
|
68
|
-
const url = new URL(connectionString);
|
|
69
|
-
return {
|
|
70
|
-
connectionString,
|
|
71
|
-
host: url.hostname,
|
|
72
|
-
port: defaultPortForDatabaseUrl(url),
|
|
73
|
-
user: decodeURIComponent(url.username),
|
|
74
|
-
password: decodeURIComponent(url.password),
|
|
75
|
-
database: decodeURIComponent(url.pathname.replace(/^\//, "")),
|
|
76
|
-
connect() {
|
|
77
|
-
throw new Error(HYPERDRIVE_CONNECT_MESSAGE);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/shims/local-worker-loader.ts
|
|
83
|
-
var activeWorkerLoaderRuntimes = new Set;
|
|
84
|
-
function getModuleSource(module, mainModule) {
|
|
85
|
-
if (typeof module === "string") {
|
|
86
|
-
return module;
|
|
87
|
-
}
|
|
88
|
-
if (module && typeof module === "object" && typeof module.js === "string") {
|
|
89
|
-
return module.js;
|
|
90
|
-
}
|
|
91
|
-
throw new Error(`Worker Loader local shim only supports JavaScript main modules. Could not load "${mainModule}".`);
|
|
92
|
-
}
|
|
93
|
-
function createRequestInit(request) {
|
|
94
|
-
return {
|
|
95
|
-
method: request.method,
|
|
96
|
-
headers: request.headers,
|
|
97
|
-
body: request.body
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
async function createRuntime(code) {
|
|
101
|
-
const { Miniflare } = await import("miniflare");
|
|
102
|
-
const mainModule = code.mainModule;
|
|
103
|
-
const script = getModuleSource(code.modules[mainModule], mainModule);
|
|
104
|
-
const miniflare = new Miniflare({
|
|
105
|
-
modules: true,
|
|
106
|
-
compatibilityDate: code.compatibilityDate,
|
|
107
|
-
...code.compatibilityFlags && { compatibilityFlags: code.compatibilityFlags },
|
|
108
|
-
...code.env && { bindings: code.env },
|
|
109
|
-
script
|
|
110
|
-
});
|
|
111
|
-
await miniflare.ready;
|
|
112
|
-
activeWorkerLoaderRuntimes.add(miniflare);
|
|
113
|
-
return miniflare;
|
|
114
|
-
}
|
|
115
|
-
function createLocalWorkerStub(codeProvider) {
|
|
116
|
-
let runtimePromise = null;
|
|
117
|
-
const getRuntime = () => {
|
|
118
|
-
runtimePromise ??= Promise.resolve(codeProvider()).then(createRuntime);
|
|
119
|
-
return runtimePromise;
|
|
120
|
-
};
|
|
121
|
-
const fetcher = {
|
|
122
|
-
async fetch(input, init) {
|
|
123
|
-
const request = input instanceof Request ? input : new Request(input, init);
|
|
124
|
-
const runtime = await getRuntime();
|
|
125
|
-
return runtime.dispatchFetch(request.url, createRequestInit(request));
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
return {
|
|
129
|
-
getEntrypoint() {
|
|
130
|
-
return fetcher;
|
|
131
|
-
},
|
|
132
|
-
getDurableObjectClass() {
|
|
133
|
-
throw new Error("Worker Loader local shim cannot materialise a dynamic Durable Object class. getDurableObjectClass() returns an opaque facet-spawning reference that workerd only exposes inside the runtime. Use createTestContext() (a real Miniflare worker) for Durable Object behavior, or createMockWorkerLoader({ stub }) to inject a stub.");
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
function createLocalWorkerLoaderBinding() {
|
|
138
|
-
return {
|
|
139
|
-
get(_name, getCode) {
|
|
140
|
-
return createLocalWorkerStub(getCode);
|
|
141
|
-
},
|
|
142
|
-
load(code) {
|
|
143
|
-
return createLocalWorkerStub(() => code);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
async function disposeLocalWorkerLoaderBindings() {
|
|
148
|
-
const runtimes = Array.from(activeWorkerLoaderRuntimes);
|
|
149
|
-
activeWorkerLoaderRuntimes.clear();
|
|
150
|
-
await Promise.all(runtimes.map(async (runtime) => {
|
|
151
|
-
await runtime.dispose();
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { extractBindingHints, createLocalWorkerLoaderBinding, disposeLocalWorkerLoaderBindings, createLocalHyperdrive };
|