Skip to content

Commit 2ebaef9

Browse files
committed
Add binding ID map for Local Explorer namespace resolution
Pass a JSON binding map to the Local Explorer worker that maps binding names to actual namespace IDs, allowing correct ID resolution when binding name differs from namespace ID.
1 parent f54442d commit 2ebaef9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/miniflare/src/plugins/core/index.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,27 @@ export function getGlobalServices({
10771077
];
10781078

10791079
if (sharedOptions.unsafeLocalExplorer) {
1080+
// Build binding ID map from proxyBindings
1081+
// Maps binding names to their actual namespace/bucket IDs
1082+
const bindingIdMap: { kv: Record<string, string> } = { kv: {} };
1083+
1084+
for (const binding of proxyBindings) {
1085+
// KV bindings: name = "MINIFLARE_PROXY:kv:worker:BINDING", kvNamespace.name = "kv:ns:ID"
1086+
if (
1087+
binding.name?.startsWith(
1088+
`${CoreBindings.DURABLE_OBJECT_NAMESPACE_PROXY}:kv:`
1089+
) &&
1090+
"kvNamespace" in binding &&
1091+
binding.kvNamespace?.name
1092+
) {
1093+
const parts = binding.name.split(":");
1094+
const bindingName = parts[parts.length - 1];
1095+
// Extract ID from service name "kv:ns:ID"
1096+
const namespaceId = binding.kvNamespace.name.replace("kv:ns:", "");
1097+
bindingIdMap.kv[bindingName] = namespaceId;
1098+
}
1099+
}
1100+
10801101
services.push({
10811102
name: SERVICE_LOCAL_EXPLORER,
10821103
worker: {
@@ -1088,7 +1109,13 @@ export function getGlobalServices({
10881109
esModule: SCRIPT_LOCAL_EXPLORER_API(),
10891110
},
10901111
],
1091-
bindings: [...proxyBindings],
1112+
bindings: [
1113+
...proxyBindings,
1114+
{
1115+
name: CoreBindings.JSON_LOCAL_EXPLORER_BINDING_MAP,
1116+
json: JSON.stringify(bindingIdMap),
1117+
},
1118+
],
10921119
},
10931120
});
10941121
}

packages/miniflare/src/workers/core/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const CoreBindings = {
4545
TRIGGER_HANDLERS: "TRIGGER_HANDLERS",
4646
LOG_REQUESTS: "LOG_REQUESTS",
4747
STRIP_DISABLE_PRETTY_ERROR: "STRIP_DISABLE_PRETTY_ERROR",
48+
JSON_LOCAL_EXPLORER_BINDING_MAP: "LOCAL_EXPLORER_BINDING_MAP",
4849
} as const;
4950

5051
export const ProxyOps = {

0 commit comments

Comments
 (0)