Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d10423b
kv: built-in KV namespaces
ry Nov 3, 2026
cf4d6e2
wrangler: kv_namespaces as kvNamespaceId bindings
ry Nov 2, 2026
ccee498
kv: write byte sizes as multiples of 1024
ry Nov 3, 2026
3ae12db
kv: address review: README, bulk text, cache TTL
ry Nov 3, 2026
5f53e01
kv: no entry cache outside a cluster
ry Nov 3, 2026
fdaca0e
kv: errors as production gives them
ry Nov 3, 2026
1b86078
kv: reach a namespace chosen at runtime through workerd:kv
ry Nov 3, 2026
caa5255
kv: an expiration clock tests can advance
ry Nov 3, 2026
5e353c7
kv: enable the test clock only with WORKERD_KV_TEST_CLOCK
ry Nov 3, 2026
8890202
wrangler: no verbatim paths on Windows; split load
ry Nov 3, 2026
5d461e5
bindings: kvNamespaceId in its own function
ry Nov 3, 2026
5ec5389
kv: give kv-test the large size
ry Nov 3, 2026
ba67e0e
Merge remote-tracking branch 'origin/main' into ry/kv-builtin
ry Nov 3, 2026
a58e76c
kv: address review; cut the tests' waiting
ry Nov 3, 2026
ad86004
kv: plain services instead of a built-in rewrite
ry Nov 5, 2026
fabc816
kv: the built-in module /workerd/kv.js
ry Nov 6, 2026
1b67d07
Merge remote-tracking branch 'origin/main' into ry/kv-builtin
ry Nov 6, 2026
24773af
kv: built-in modules by name in a map
ry Nov 6, 2026
a6d6c24
kv: Worker.Module.bundled, not builtin
ry Nov 6, 2026
b186da6
Merge remote-tracking branch 'origin/main' into ry/kv-builtin
ry Nov 6, 2026
b7e9b3e
kv: bundled modules need --experimental
ry Nov 6, 2026
4f36767
kv: a malformed key escape or a non-object bulk body is a 400
ry Nov 6, 2026
39f695c
AGENTS.md: how wrangler's kv_namespaces become the KV Worker
ry Nov 6, 2026
e04050a
kv: read the schema version in the migrating transaction
ry Nov 6, 2026
5a99723
kv: don't rewrite the schema row when no migration runs
ry Nov 6, 2026
a544729
Merge remote-tracking branch 'origin/main' into ry/kv-builtin
ry Nov 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ bazel build --config=thin-lto //src/workerd/server:workerd
For simple projects, `workerd serve wrangler.jsonc` also accepts a Wrangler
config. `main` is bundled with esbuild, as Wrangler does. The supported fields
are `name`, `main`, `compatibility_date`, `compatibility_flags`, `vars`,
`durable_objects`, `exports`, `migrations`, `no_bundle` and `$schema`; any
other field is an error.
`durable_objects`, `exports`, `migrations`, `no_bundle`, `$schema` and, with
`--experimental`, `kv_namespaces`; any other field is an error. Each KV
namespace is one Durable Object, so its throughput is that of one object.

A simple "Hello World!" config file might look like:

Expand Down
113 changes: 57 additions & 56 deletions src/workerd/server/AGENTS.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/workerd/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ wd_cc_library(
"//src/workerd/io",
"//src/workerd/io:worker-modules",
"//src/workerd/jsg",
"//src/workerd/server/kv:kv-js",
"//src/workerd/util:perfetto",
"@capnp-cpp//src/kj/compat:kj-gzip",
] + select({
Expand Down
31 changes: 24 additions & 7 deletions src/workerd/server/cli/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ fn run_command(args: args::Main, executable: Option<Executable>) -> workerd_serv
let watcher = watcher::<T>(&serve_or_test, executable.as_ref());
let (options, inherited_sockets) = serve_options::<T>(serve, &serve_or_test);
let process = Process::new(executable, watcher, inherited_sockets);
let config = load_config::<T>(config, const_name.const_name, &process);
let config = load_config::<T>(
config,
const_name.const_name,
&process,
serve_or_test.experimental,
);
let (config, options) = with_deployments(config, &serve_or_test, options, &process);
entry::serve(
verbose,
Expand Down Expand Up @@ -156,7 +161,7 @@ fn run_command(args: args::Main, executable: Option<Executable>) -> workerd_serv
check_serve_or_test::<T>(&serve_or_test);
let watcher = watcher::<T>(&serve_or_test, executable.as_ref());
let process = Process::new(executable, watcher, Vec::new());
let config = load_config::<T>(config, None, &process);
let config = load_config::<T>(config, None, &process, serve_or_test.experimental);
entry::test(
verbose,
config.into_words(),
Expand All @@ -176,7 +181,12 @@ fn run_command(args: args::Main, executable: Option<Executable>) -> workerd_serv
let filter = test.filter.take().unwrap_or_default();
let watcher = watcher::<T>(&serve_or_test, executable.as_ref());
let process = Process::new(executable, watcher, Vec::new());
let config = load_config::<T>(config, filter.const_name.clone(), &process);
let config = load_config::<T>(
config,
filter.const_name.clone(),
&process,
serve_or_test.experimental,
);
entry::test(
verbose,
config.into_words(),
Expand Down Expand Up @@ -257,7 +267,7 @@ fn run_deploy(
binary: args.binary,
config_file,
};
(name, load_config::<T>(config, const_name, &process))
(name, load_config::<T>(config, const_name, &process, true))
}
Err(error) => usage_error::<T>(error),
};
Expand Down Expand Up @@ -301,7 +311,8 @@ fn run_compile(
);
}
let process = Process::new(executable, None, Vec::new());
let config = load_config::<T>(config, const_name, &process);
// The binary checks `--experimental` when it runs (the server, for bundled modules).
let config = load_config::<T>(config, const_name, &process, true);
let written = if config_only {
config.write_to_stdout()
} else {
Expand All @@ -324,7 +335,12 @@ fn run_bench(
let filter = bench.filter.take().unwrap_or_default();
let watcher = watcher::<T>(serve_or_test, executable.as_ref());
let process = Process::new(executable, watcher, Vec::new());
let config = load_config::<T>(config, filter.test.const_name.clone(), &process);
let config = load_config::<T>(
config,
filter.test.const_name.clone(),
&process,
serve_or_test.experimental,
);
entry::bench(
verbose,
config.into_words(),
Expand Down Expand Up @@ -408,6 +424,7 @@ fn load_config<T: CommandFactory>(
config: args::ConfigFileArgs,
const_name: Option<String>,
process: &Process,
experimental: bool,
) -> Config {
let args::ConfigFileArgs {
import_paths,
Expand Down Expand Up @@ -443,7 +460,7 @@ fn load_config<T: CommandFactory>(
if !std::path::Path::new(&config_file).is_file() {
usage_error::<T>(format!("{config_file}: No such file."));
}
return wrangler::load(&config_file, process)
return wrangler::load(&config_file, process, experimental)
.unwrap_or_else(|error| config_errors(&[format!("{config_file}: {error}")], process));
}

Expand Down
97 changes: 96 additions & 1 deletion src/workerd/server/cli/wrangler-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// https://opensource.org/licenses/Apache-2.0

use workerd_capnp::service;
use workerd_capnp::service_designator;
use workerd_capnp::worker;

use super::*;
Expand Down Expand Up @@ -32,6 +33,7 @@ fn load_project(files: &[(&str, &str)]) -> Result<Config, String> {
load(
dir.join("wrangler.jsonc").to_str().unwrap(),
&Process::new(None, None, Vec::new()),
true,
)
}

Expand Down Expand Up @@ -352,15 +354,108 @@ fn unsupported_field_is_an_error() {
(
"wrangler.jsonc",
r#"{ "main": "index.js", "compatibility_date": "2026-01-01",
"kv_namespaces": [{ "binding": "KV", "id": "x" }] }"#,
"kv_namespaces": [{ "binding": "KV", "bogus": "y" }] }"#,
),
("index.js", ""),
])
.err()
.unwrap();
assert!(error.contains("bogus"), "{error}");
}

#[test]
fn kv_namespaces_require_experimental() {
let dir = project(&[
(
"wrangler.jsonc",
Comment thread
ry marked this conversation as resolved.
Resolved
r#"{ "main": "index.js", "compatibility_date": "2026-01-01",
"kv_namespaces": [{ "binding": "KV", "id": "x" }] }"#,
),
("index.js", ""),
]);
let process = Process::new(None, None, Vec::new());
let path = dir.join("wrangler.jsonc");
let error = load(path.to_str().unwrap(), &process, false).err().unwrap();
assert!(error.contains("kv_namespaces"), "{error}");
assert!(error.contains("--experimental"), "{error}");
let error = load_deployment(path.to_str().unwrap(), Some("app"), &process)
.err()
.unwrap();
assert!(error.contains("kv_namespaces"), "{error}");
}

#[test]
fn kv_namespaces_bind_the_kv_worker() {
let dir = project(&[
(
"wrangler.jsonc",
r#"{ "name": "app", "main": "index.js", "compatibility_date": "2026-01-01",
"no_bundle": true,
"kv_namespaces": [{ "binding": "A", "id": "a", "preview_id": "p" },
{ "binding": "B", "remote": true }] }"#,
),
("index.js", ""),
]);
let config = load(
dir.join("wrangler.jsonc").to_str().unwrap(),
&Process::new(None, None, Vec::new()),
true,
)
.unwrap();
let message = read(config);
let conf = message.get_root::<config::Reader>().unwrap();
let services = conf.get_services().unwrap();
let names: Vec<_> = services
.iter()
.map(|s| s.get_name().unwrap().to_str().unwrap().to_owned())
.collect();
assert_eq!(names, ["app", "app-kv", "app-kv-storage", "app-kv-blobs"]);
let service::Which::Disk(disk) = services.get(3).which().unwrap() else {
panic!("not a disk");
};
let disk = disk.unwrap();
assert!(disk.get_writable());
let blobs = dir.join(".wrangler/state/workerd/kv/blobs");
assert!(blobs.is_dir());
assert_eq!(
fs::canonicalize(disk.get_path().unwrap().to_str().unwrap()).unwrap(),
fs::canonicalize(blobs).unwrap()
);
let service::Which::Worker(w) = services.get(0).which().unwrap() else {
panic!("not a worker");
};
let bound: Vec<_> = w
.unwrap()
.get_bindings()
.unwrap()
.iter()
.map(|b| {
let worker::binding::Which::KvNamespace(d) = b.which().unwrap() else {
panic!("not a kvNamespace");
};
let d = d.unwrap();
let service_designator::props::Which::Json(props) = d.get_props().which().unwrap()
else {
panic!("no JSON props");
};
let text = |t: capnp::text::Reader<'_>| t.to_str().unwrap().to_owned();
(
text(b.get_name().unwrap()),
text(d.get_name().unwrap()),
text(props.unwrap()),
)
})
.collect();
let kv = |b: &str, id: &str| {
(
b.into(),
"app-kv".into(),
format!(r#"{{"namespace":"{id}"}}"#),
)
};
assert_eq!(bound, [kv("A", "a"), kv("B", "B")]);
}

#[test]
fn unbundled_typescript_main_is_an_error() {
let error = load_project(&[
Expand Down
Loading
Loading