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
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectConfiguredWorkerFamilies
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-2yv7w548.js";
|
|
4
4
|
import {
|
|
5
5
|
asOptionalString,
|
|
6
6
|
resolveCloudflareAccountId,
|
|
7
7
|
resolveNamedSelection
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-0cc05hzv.js";
|
|
9
9
|
import {
|
|
10
10
|
account
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-phcrvs6d.js";
|
|
12
12
|
import"./index-atwc3csp.js";
|
|
13
|
-
import"./index-
|
|
13
|
+
import"./index-hvtd936d.js";
|
|
14
14
|
import {
|
|
15
15
|
getDependencies
|
|
16
16
|
} from "./index-z9gy8w6b.js";
|
|
@@ -28,19 +28,16 @@ import {
|
|
|
28
28
|
yellow
|
|
29
29
|
} from "./index-maw0jjnn.js";
|
|
30
30
|
import"./index-3t6rypgc.js";
|
|
31
|
-
import"./index-x0wpeb3x.js";
|
|
32
31
|
import {
|
|
33
32
|
findFiles
|
|
34
33
|
} from "./index-5dkjffqz.js";
|
|
35
|
-
import"./index-
|
|
34
|
+
import"./index-mek9msfv.js";
|
|
36
35
|
import {
|
|
37
36
|
ConfigNotFoundError,
|
|
38
37
|
loadConfig
|
|
39
|
-
} from "./index-
|
|
38
|
+
} from "./index-x8s9rwfh.js";
|
|
40
39
|
import"./index-h7r11y4a.js";
|
|
41
40
|
import"./index-04wh9bxx.js";
|
|
42
|
-
import"./index-wxdcrzcp.js";
|
|
43
|
-
import"./index-34dejneh.js";
|
|
44
41
|
import"./index-37x76zdn.js";
|
|
45
42
|
|
|
46
43
|
// src/cli/commands/productions.ts
|
|
@@ -6,13 +6,108 @@ import {
|
|
|
6
6
|
RESET,
|
|
7
7
|
YELLOW
|
|
8
8
|
} from "./index-3t6rypgc.js";
|
|
9
|
-
import {
|
|
10
|
-
disableRemoteMode,
|
|
11
|
-
enableRemoteMode,
|
|
12
|
-
getEffectiveRemoteModeStatus
|
|
13
|
-
} from "./index-4xmtkg9g.js";
|
|
14
9
|
import"./index-37x76zdn.js";
|
|
15
10
|
|
|
11
|
+
// src/cloudflare/remote-config.ts
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
13
|
+
import { homedir } from "os";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
var MIN_MINUTES = 1;
|
|
16
|
+
var MAX_MINUTES = 1440;
|
|
17
|
+
function getConfigDir() {
|
|
18
|
+
return join(homedir(), ".devflare");
|
|
19
|
+
}
|
|
20
|
+
function getConfigPath() {
|
|
21
|
+
return join(getConfigDir(), "remote.json");
|
|
22
|
+
}
|
|
23
|
+
function readConfig() {
|
|
24
|
+
const path = getConfigPath();
|
|
25
|
+
if (!existsSync(path))
|
|
26
|
+
return null;
|
|
27
|
+
try {
|
|
28
|
+
const content = readFileSync(path, "utf-8");
|
|
29
|
+
return JSON.parse(content);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function writeConfig(config) {
|
|
35
|
+
const dir = getConfigDir();
|
|
36
|
+
if (!existsSync(dir)) {
|
|
37
|
+
mkdirSync(dir, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
writeFileSync(getConfigPath(), JSON.stringify(config, null, "\t"));
|
|
40
|
+
}
|
|
41
|
+
function deleteConfig() {
|
|
42
|
+
const path = getConfigPath();
|
|
43
|
+
if (existsSync(path)) {
|
|
44
|
+
try {
|
|
45
|
+
unlinkSync(path);
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function enableRemoteMode(minutes = 30) {
|
|
50
|
+
const validMinutes = Math.max(MIN_MINUTES, Math.min(MAX_MINUTES, Math.floor(minutes) || 30));
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
writeConfig({
|
|
53
|
+
enabledAt: now,
|
|
54
|
+
expiresAt: now + validMinutes * 60 * 1000,
|
|
55
|
+
durationMinutes: validMinutes
|
|
56
|
+
});
|
|
57
|
+
return validMinutes;
|
|
58
|
+
}
|
|
59
|
+
function disableRemoteMode() {
|
|
60
|
+
deleteConfig();
|
|
61
|
+
}
|
|
62
|
+
function getRemoteModeStatus() {
|
|
63
|
+
const config = readConfig();
|
|
64
|
+
if (!config) {
|
|
65
|
+
return { isEnabled: false, remainingMinutes: 0, expiresAt: null };
|
|
66
|
+
}
|
|
67
|
+
const now = Date.now();
|
|
68
|
+
if (now >= config.expiresAt) {
|
|
69
|
+
deleteConfig();
|
|
70
|
+
return { isEnabled: false, remainingMinutes: 0, expiresAt: null };
|
|
71
|
+
}
|
|
72
|
+
const remainingMs = config.expiresAt - now;
|
|
73
|
+
const remainingMinutes = Math.ceil(remainingMs / 60000);
|
|
74
|
+
return {
|
|
75
|
+
isEnabled: true,
|
|
76
|
+
remainingMinutes,
|
|
77
|
+
expiresAt: new Date(config.expiresAt)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function getEffectiveRemoteModeStatus() {
|
|
81
|
+
const envValue = process.env.DEVFLARE_REMOTE ?? "";
|
|
82
|
+
const envVarSet = ["1", "true", "yes"].includes(envValue.toLowerCase());
|
|
83
|
+
if (envVarSet) {
|
|
84
|
+
return {
|
|
85
|
+
isActive: true,
|
|
86
|
+
source: "env",
|
|
87
|
+
remainingMinutes: Number.POSITIVE_INFINITY,
|
|
88
|
+
expiresAt: null,
|
|
89
|
+
envVarSet: true
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const status = getRemoteModeStatus();
|
|
93
|
+
if (status.isEnabled) {
|
|
94
|
+
return {
|
|
95
|
+
isActive: true,
|
|
96
|
+
source: "config",
|
|
97
|
+
remainingMinutes: status.remainingMinutes,
|
|
98
|
+
expiresAt: status.expiresAt,
|
|
99
|
+
envVarSet: false
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
isActive: false,
|
|
104
|
+
source: "none",
|
|
105
|
+
remainingMinutes: 0,
|
|
106
|
+
expiresAt: null,
|
|
107
|
+
envVarSet: false
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
16
111
|
// src/cli/commands/remote.ts
|
|
17
112
|
function log(message = "") {
|
|
18
113
|
console.log(message);
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,66 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertExplicitQueueHandlerStyle,
|
|
3
|
-
assertExplicitScheduledHandlerStyle,
|
|
4
|
-
createResolveFetch,
|
|
5
|
-
createRouteResolve,
|
|
6
|
-
ctx,
|
|
7
|
-
defineFetchHandler,
|
|
8
|
-
defineQueueHandler,
|
|
9
|
-
defineScheduledHandler,
|
|
10
|
-
env,
|
|
11
|
-
event,
|
|
12
|
-
invokeFetchHandler,
|
|
13
|
-
invokeFetchModule,
|
|
14
|
-
invokeRouteModules,
|
|
15
|
-
locals,
|
|
16
|
-
markResolveStyle,
|
|
17
|
-
markWorkerStyle,
|
|
18
|
-
matchFetchRoute,
|
|
19
|
-
resolveFetchHandler,
|
|
20
|
-
sequence,
|
|
21
|
-
vars
|
|
22
|
-
} from "../index-97rfy7n2.js";
|
|
23
|
-
import"../index-t23wq5js.js";
|
|
24
|
-
import {
|
|
25
|
-
durableObject,
|
|
26
|
-
getDurableObjectOptions
|
|
27
|
-
} from "../index-y7w3x9p1.js";
|
|
28
|
-
import {
|
|
29
|
-
ContextAccessError,
|
|
30
|
-
createContextProxy,
|
|
31
|
-
createDurableObjectAlarmEvent,
|
|
32
|
-
createDurableObjectFetchEvent,
|
|
33
|
-
createDurableObjectWebSocketCloseEvent,
|
|
34
|
-
createDurableObjectWebSocketErrorEvent,
|
|
35
|
-
createDurableObjectWebSocketMessageEvent,
|
|
36
|
-
createEmailEvent,
|
|
37
|
-
createFetchEvent,
|
|
38
|
-
createQueueEvent,
|
|
39
|
-
createScheduledEvent,
|
|
40
|
-
createTailEvent,
|
|
41
|
-
getContext,
|
|
42
|
-
getContextOrNull,
|
|
43
|
-
getDurableObjectAlarmEvent,
|
|
44
|
-
getDurableObjectEvent,
|
|
45
|
-
getDurableObjectFetchEvent,
|
|
46
|
-
getDurableObjectWebSocketCloseEvent,
|
|
47
|
-
getDurableObjectWebSocketErrorEvent,
|
|
48
|
-
getDurableObjectWebSocketMessageEvent,
|
|
49
|
-
getEmailEvent,
|
|
50
|
-
getEventContext,
|
|
51
|
-
getEventContextOrNull,
|
|
52
|
-
getFetchEvent,
|
|
53
|
-
getQueueEvent,
|
|
54
|
-
getScheduledEvent,
|
|
55
|
-
getTailEvent,
|
|
56
|
-
hasContext,
|
|
57
|
-
runWithContext,
|
|
58
|
-
runWithEventContext
|
|
59
|
-
} from "../index-1trss579.js";
|
|
60
|
-
import {
|
|
61
|
-
clearLocalSendEmailBindings,
|
|
62
|
-
setLocalSendEmailBindings
|
|
63
|
-
} from "../index-n4xkaymm.js";
|
|
64
1
|
import"../index-37x76zdn.js";
|
|
65
2
|
export {
|
|
66
3
|
vars,
|
|
@@ -2,13 +2,11 @@ import {
|
|
|
2
2
|
deleteLocalSecret,
|
|
3
3
|
listLocalSecrets,
|
|
4
4
|
writeLocalSecret
|
|
5
|
-
} from "./index-
|
|
6
|
-
import"./index-
|
|
7
|
-
import"./index-
|
|
5
|
+
} from "./index-kcp7y951.js";
|
|
6
|
+
import"./index-mek9msfv.js";
|
|
7
|
+
import"./index-x8s9rwfh.js";
|
|
8
8
|
import"./index-h7r11y4a.js";
|
|
9
9
|
import"./index-04wh9bxx.js";
|
|
10
|
-
import"./index-wxdcrzcp.js";
|
|
11
|
-
import"./index-34dejneh.js";
|
|
12
10
|
import"./index-37x76zdn.js";
|
|
13
11
|
|
|
14
12
|
// src/cli/commands/secrets.ts
|
package/dist/sveltekit/index.js
CHANGED
|
@@ -1,267 +1,4 @@
|
|
|
1
|
-
import"../index-za0r01bx.js";
|
|
2
|
-
import {
|
|
3
|
-
createLocalHyperdrive,
|
|
4
|
-
createLocalWorkerLoaderBinding,
|
|
5
|
-
extractBindingHints
|
|
6
|
-
} from "../index-c4zd39tc.js";
|
|
7
|
-
import {
|
|
8
|
-
createLocalImagesBinding,
|
|
9
|
-
createLocalMediaBinding
|
|
10
|
-
} from "../index-dm9q84c7.js";
|
|
11
|
-
import {
|
|
12
|
-
buildLocalSecretNodeBindings
|
|
13
|
-
} from "../index-13sfensw.js";
|
|
14
|
-
import {
|
|
15
|
-
createEnvProxy,
|
|
16
|
-
createFetchEvent,
|
|
17
|
-
getClient,
|
|
18
|
-
runWithEventContext,
|
|
19
|
-
setBindingHints
|
|
20
|
-
} from "../index-1trss579.js";
|
|
21
|
-
import {
|
|
22
|
-
createLocalSendEmailBinding
|
|
23
|
-
} from "../index-n4xkaymm.js";
|
|
24
|
-
import"../index-w8c8tjc5.js";
|
|
25
|
-
import {
|
|
26
|
-
loadConfig,
|
|
27
|
-
normalizeHyperdriveBinding
|
|
28
|
-
} from "../index-pd97hk2j.js";
|
|
29
|
-
import"../index-h7r11y4a.js";
|
|
30
|
-
import"../index-04wh9bxx.js";
|
|
31
|
-
import"../index-wxdcrzcp.js";
|
|
32
|
-
import"../index-34dejneh.js";
|
|
33
1
|
import"../index-37x76zdn.js";
|
|
34
|
-
// src/sveltekit/local-bindings.ts
|
|
35
|
-
function buildLocalHyperdriveBindings(config) {
|
|
36
|
-
const bindings = {};
|
|
37
|
-
for (const [name, binding] of Object.entries(config.bindings?.hyperdrive ?? {})) {
|
|
38
|
-
const normalized = normalizeHyperdriveBinding(binding);
|
|
39
|
-
if (normalized.localConnectionString) {
|
|
40
|
-
bindings[name] = createLocalHyperdrive(normalized.localConnectionString);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return bindings;
|
|
44
|
-
}
|
|
45
|
-
function buildSvelteKitLocalBindings(config, cwd) {
|
|
46
|
-
const bindings = {
|
|
47
|
-
...config.vars ?? {},
|
|
48
|
-
...buildLocalHyperdriveBindings(config),
|
|
49
|
-
...buildLocalSecretNodeBindings(config, cwd)
|
|
50
|
-
};
|
|
51
|
-
for (const [name, binding] of Object.entries(config.bindings?.sendEmail ?? {})) {
|
|
52
|
-
bindings[name] = createLocalSendEmailBinding(binding);
|
|
53
|
-
}
|
|
54
|
-
for (const name of Object.keys(config.bindings?.workerLoaders ?? {})) {
|
|
55
|
-
bindings[name] = createLocalWorkerLoaderBinding();
|
|
56
|
-
}
|
|
57
|
-
for (const name of Object.keys(config.bindings?.images ?? {})) {
|
|
58
|
-
bindings[name] = createLocalImagesBinding();
|
|
59
|
-
}
|
|
60
|
-
for (const name of Object.keys(config.bindings?.media ?? {})) {
|
|
61
|
-
bindings[name] = createLocalMediaBinding();
|
|
62
|
-
}
|
|
63
|
-
return bindings;
|
|
64
|
-
}
|
|
65
|
-
function overlayLocalBindings(baseEnv, localBindings) {
|
|
66
|
-
if (Object.keys(localBindings).length === 0) {
|
|
67
|
-
return baseEnv;
|
|
68
|
-
}
|
|
69
|
-
return new Proxy(baseEnv, {
|
|
70
|
-
get(target, prop, receiver) {
|
|
71
|
-
if (typeof prop === "string" && prop in localBindings) {
|
|
72
|
-
return localBindings[prop];
|
|
73
|
-
}
|
|
74
|
-
return Reflect.get(target, prop, receiver);
|
|
75
|
-
},
|
|
76
|
-
has(target, prop) {
|
|
77
|
-
return typeof prop === "string" && prop in localBindings || Reflect.has(target, prop);
|
|
78
|
-
},
|
|
79
|
-
ownKeys(target) {
|
|
80
|
-
return Array.from(new Set([...Reflect.ownKeys(target), ...Reflect.ownKeys(localBindings)]));
|
|
81
|
-
},
|
|
82
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
83
|
-
if (typeof prop === "string" && prop in localBindings) {
|
|
84
|
-
return {
|
|
85
|
-
configurable: true,
|
|
86
|
-
enumerable: true,
|
|
87
|
-
writable: false,
|
|
88
|
-
value: localBindings[prop]
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/sveltekit/platform.ts
|
|
97
|
-
var platformCache = null;
|
|
98
|
-
function fingerprintHints(hints) {
|
|
99
|
-
const entries = Object.keys(hints).sort().map((name) => [name, hints[name]]);
|
|
100
|
-
return JSON.stringify(entries);
|
|
101
|
-
}
|
|
102
|
-
function getPlatformCacheKey(bridgeUrl, hints) {
|
|
103
|
-
return `${bridgeUrl}\x00${fingerprintHints(hints)}`;
|
|
104
|
-
}
|
|
105
|
-
function shouldUseCachedPlatform(localBindings) {
|
|
106
|
-
return Object.keys(localBindings).length === 0;
|
|
107
|
-
}
|
|
108
|
-
function createDevExecutionContext(pendingErrors) {
|
|
109
|
-
return {
|
|
110
|
-
waitUntil: (promise) => {
|
|
111
|
-
promise.catch((err) => {
|
|
112
|
-
console.error("[devflare] waitUntil error:", err);
|
|
113
|
-
pendingErrors.push(err);
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
passThroughOnException: () => {}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async function createDevflarePlatform(options = {}) {
|
|
120
|
-
const {
|
|
121
|
-
bridgeUrl = `ws://localhost:${process.env.DEVFLARE_BRIDGE_PORT ?? 8787}`,
|
|
122
|
-
hints = {},
|
|
123
|
-
localBindings = {}
|
|
124
|
-
} = options;
|
|
125
|
-
const cacheKey = getPlatformCacheKey(bridgeUrl, hints);
|
|
126
|
-
if (shouldUseCachedPlatform(localBindings) && platformCache?.key === cacheKey) {
|
|
127
|
-
return platformCache.platform;
|
|
128
|
-
}
|
|
129
|
-
const client = getClient({ url: bridgeUrl });
|
|
130
|
-
await client.connect();
|
|
131
|
-
const env = overlayLocalBindings(createEnvProxy({ client, hints, strict: true }), localBindings);
|
|
132
|
-
const pendingErrors = [];
|
|
133
|
-
const context = createDevExecutionContext(pendingErrors);
|
|
134
|
-
const caches = {
|
|
135
|
-
default: createMockCache(),
|
|
136
|
-
open: async (cacheName) => createMockCache()
|
|
137
|
-
};
|
|
138
|
-
const cf = {
|
|
139
|
-
colo: "DEV",
|
|
140
|
-
country: "XX",
|
|
141
|
-
city: "Development",
|
|
142
|
-
continent: "XX",
|
|
143
|
-
latitude: "0",
|
|
144
|
-
longitude: "0",
|
|
145
|
-
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
146
|
-
region: "Development",
|
|
147
|
-
regionCode: "DEV",
|
|
148
|
-
asn: 0,
|
|
149
|
-
asOrganization: "Devflare Dev"
|
|
150
|
-
};
|
|
151
|
-
const platform = { env, context, caches, cf, pendingErrors };
|
|
152
|
-
if (shouldUseCachedPlatform(localBindings)) {
|
|
153
|
-
platformCache = { key: cacheKey, platform };
|
|
154
|
-
}
|
|
155
|
-
return platform;
|
|
156
|
-
}
|
|
157
|
-
function createMockCache() {
|
|
158
|
-
const store = new Map;
|
|
159
|
-
return {
|
|
160
|
-
async match(request) {
|
|
161
|
-
const key = typeof request === "string" ? request : request instanceof URL ? request.href : request.url;
|
|
162
|
-
return store.get(key)?.clone();
|
|
163
|
-
},
|
|
164
|
-
async put(request, response) {
|
|
165
|
-
const key = typeof request === "string" ? request : request instanceof URL ? request.href : request.url;
|
|
166
|
-
store.set(key, response.clone());
|
|
167
|
-
},
|
|
168
|
-
async delete(request) {
|
|
169
|
-
const key = typeof request === "string" ? request : request instanceof URL ? request.href : request.url;
|
|
170
|
-
return store.delete(key);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function resetPlatform() {
|
|
175
|
-
platformCache = null;
|
|
176
|
-
}
|
|
177
|
-
function resetConfigCache() {
|
|
178
|
-
configCache = null;
|
|
179
|
-
}
|
|
180
|
-
function isDevflareDev() {
|
|
181
|
-
return process.env.DEVFLARE_DEV === "true";
|
|
182
|
-
}
|
|
183
|
-
function getBridgePort() {
|
|
184
|
-
return Number.parseInt(process.env.DEVFLARE_BRIDGE_PORT ?? "8787", 10);
|
|
185
|
-
}
|
|
186
|
-
var configCache = null;
|
|
187
|
-
function getConfigFileFromEnv() {
|
|
188
|
-
return process.env.DEVFLARE_CONFIG_PATH;
|
|
189
|
-
}
|
|
190
|
-
async function loadConfigFromCurrentCwd() {
|
|
191
|
-
const cwd = process.cwd();
|
|
192
|
-
const configFile = getConfigFileFromEnv();
|
|
193
|
-
if (configCache?.cwd === cwd && configCache.configFile === configFile) {
|
|
194
|
-
return configCache.promise;
|
|
195
|
-
}
|
|
196
|
-
const promise = loadConfig({ cwd, configFile }).catch((err) => {
|
|
197
|
-
if (process.env.DEVFLARE_DEBUG) {
|
|
198
|
-
console.warn("[devflare] Failed to load config for hints:", err.message);
|
|
199
|
-
}
|
|
200
|
-
return null;
|
|
201
|
-
});
|
|
202
|
-
configCache = { cwd, configFile, promise };
|
|
203
|
-
return promise;
|
|
204
|
-
}
|
|
205
|
-
async function loadPlatformOptionsFromConfig() {
|
|
206
|
-
const cwd = process.cwd();
|
|
207
|
-
const config = await loadConfigFromCurrentCwd();
|
|
208
|
-
if (!config) {
|
|
209
|
-
return { hints: {}, localBindings: {} };
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
hints: extractBindingHints(config),
|
|
213
|
-
localBindings: buildSvelteKitLocalBindings(config, cwd)
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
function resolveWithPlatformContext(event, resolve, platform) {
|
|
217
|
-
if (!(event.request instanceof Request)) {
|
|
218
|
-
return resolve(event);
|
|
219
|
-
}
|
|
220
|
-
const fetchEvent = createFetchEvent(event.request, platform.env, platform.context);
|
|
221
|
-
return runWithEventContext(fetchEvent, () => resolve(event));
|
|
222
|
-
}
|
|
223
|
-
async function createPlatformWithRequestContext(event, resolve, options) {
|
|
224
|
-
const platform = await createDevflarePlatform(options);
|
|
225
|
-
event.platform = platform;
|
|
226
|
-
return resolveWithPlatformContext(event, resolve, platform);
|
|
227
|
-
}
|
|
228
|
-
async function getAutoPlatformOptions() {
|
|
229
|
-
const options = await loadPlatformOptionsFromConfig();
|
|
230
|
-
setBindingHints(options.hints ?? {});
|
|
231
|
-
return options;
|
|
232
|
-
}
|
|
233
|
-
async function getCustomPlatformOptions(options) {
|
|
234
|
-
if (options.hints) {
|
|
235
|
-
setBindingHints(options.hints);
|
|
236
|
-
}
|
|
237
|
-
return options;
|
|
238
|
-
}
|
|
239
|
-
function createHandle(options = {}) {
|
|
240
|
-
const { shouldEnable, ...platformOptions } = options;
|
|
241
|
-
return async ({ event, resolve }) => {
|
|
242
|
-
const enabled = shouldEnable ? shouldEnable() : process.env.DEVFLARE_DEV === "true";
|
|
243
|
-
if (enabled) {
|
|
244
|
-
try {
|
|
245
|
-
return await createPlatformWithRequestContext(event, resolve, await getCustomPlatformOptions(platformOptions));
|
|
246
|
-
} catch (error) {
|
|
247
|
-
console.error("[devflare] Failed to create platform:", error);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return resolve(event);
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
var handle = async (input) => {
|
|
254
|
-
const { event, resolve } = input;
|
|
255
|
-
const enabled = process.env.DEVFLARE_DEV === "true";
|
|
256
|
-
if (enabled) {
|
|
257
|
-
try {
|
|
258
|
-
return await createPlatformWithRequestContext(event, resolve, await getAutoPlatformOptions());
|
|
259
|
-
} catch (error) {
|
|
260
|
-
console.error("[devflare] Failed to create platform:", error);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return resolve(event);
|
|
264
|
-
};
|
|
265
2
|
export {
|
|
266
3
|
resetPlatform,
|
|
267
4
|
resetConfigCache,
|