diff --git a/Cargo.toml b/Cargo.toml index 229ac82..bb0a0c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ js-sys = "0.3.50" serde = { version = "1.0.125", features = ["derive"] } serde_json = "1.0.64" thiserror = "1.0.29" -wasm-bindgen = "0.2.73" +wasm-bindgen = "0.2.84" wasm-bindgen-futures = "0.4.23" gloo-utils = { version = "0.1.5", features = ["serde"] } diff --git a/tests/worker_kv_test/Cargo.toml b/tests/worker_kv_test/Cargo.toml index a4043dd..ae93303 100644 --- a/tests/worker_kv_test/Cargo.toml +++ b/tests/worker_kv_test/Cargo.toml @@ -12,7 +12,7 @@ default = ["console_error_panic_hook"] [dependencies] cfg-if = "0.1.2" -worker = "0.0.4" +worker = "0.0.13" worker-kv = { path = "../../" } serde_json = "1.0.67" diff --git a/tests/worker_kv_test/src/lib.rs b/tests/worker_kv_test/src/lib.rs index d4f749a..8567fc4 100644 --- a/tests/worker_kv_test/src/lib.rs +++ b/tests/worker_kv_test/src/lib.rs @@ -20,14 +20,14 @@ macro_rules! kv_assert_eq { } #[event(fetch)] -pub async fn main(req: Request, env: Env) -> Result { +pub async fn main(req: Request, env: Env, _ctx: Context) -> Result { // Optionally, get more helpful error messages written to the console in the case of a panic. utils::set_panic_hook(); // Create the KV store directly from `worker_kv` as the rust worker sdk uses a published version. let store = KvStore::from_this(&env, "test").expect("test kv store not bound"); - Router::new(store) + Router::with_data(store) .get_async("/get", |req, ctx| wrap(req, ctx, get)) .get_async("/get-not-found", |req, ctx| wrap(req, ctx, get_not_found)) .get_async("/list-keys", |req, ctx| wrap(req, ctx, list_keys)) @@ -39,7 +39,7 @@ pub async fn main(req: Request, env: Env) -> Result { } async fn get(_: Request, ctx: RouteContext) -> TestResult { - let store = ctx.data().unwrap(); + let store = ctx.data; store .get("simple") .text() @@ -52,7 +52,7 @@ async fn get(_: Request, ctx: RouteContext) -> TestResult { } async fn get_not_found(_: Request, ctx: RouteContext) -> TestResult { - let store = ctx.data().unwrap(); + let store = ctx.data; let value = store.get("not_found").text().await; value.map_err(TestError::from).and_then(|v| match v { @@ -62,7 +62,7 @@ async fn get_not_found(_: Request, ctx: RouteContext) -> TestResult { } async fn list_keys(_: Request, ctx: RouteContext) -> TestResult { - let store = ctx.data().unwrap(); + let store = ctx.data; let list_res = store.list().execute().await?; // TODO: Test cursor and things. @@ -72,7 +72,7 @@ async fn list_keys(_: Request, ctx: RouteContext) -> TestResult { } async fn put_simple(_: Request, ctx: RouteContext) -> TestResult { - let store = ctx.data().unwrap(); + let store = ctx.data; store.put("put_a", "test")?.execute().await?; let val = store.get("put_a").text().await?.unwrap(); @@ -82,13 +82,10 @@ async fn put_simple(_: Request, ctx: RouteContext) -> TestResult { } async fn put_metadata(_: Request, ctx: RouteContext) -> TestResult { - let store = ctx.data().unwrap(); + let store = ctx.data; store.put("put_b", "test")?.metadata(100)?.execute().await?; - let (val, meta) = store - .get("put_b") - .text_with_metadata::() - .await?; + let (val, meta) = store.get("put_b").text_with_metadata::().await?; kv_assert_eq!(val.unwrap(), "test")?; kv_assert_eq!(meta.unwrap(), 100)?; @@ -97,7 +94,7 @@ async fn put_metadata(_: Request, ctx: RouteContext) -> TestResult { async fn put_expiration(_: Request, ctx: RouteContext) -> TestResult { const EXPIRATION: u64 = 2000000000; - let store = ctx.data().unwrap(); + let store = ctx.data; store .put("put_c", "test")? .expiration(EXPIRATION)