Skip to content

Commit

Permalink
Fix issues with Request.clone in http types (#440)
Browse files Browse the repository at this point in the history
* Bump wasm-streams

* Use Body::into_readable_stream

* fmt

* clippy

* Remove unused js hack

* clippy

* Added remaining routes and fixed testes (#473)

* Added test script to package.json.

* Added worker-sandbox r2 routes.

* Added worker-build to the npm test script.

* Added worker-sandbox r2 routes - cleanup.

* Added worker-sandbox queue routes.

* Added worker-sandbox service-bindings routes - implied porting and adapting some improvements from the latest version.

* Added worker-sandbox service-bindings routes - implied porting and adapting some improvements from the latest version - fmt.

* Added worker-sandbox cache stream route - Implied porting some more recent stuff.

* Added worker-sandbox remaining cache routes.

* Added worker-sandbox init called route.

* Added worker-sandbox custom-response-body route.

* Added worker-sandbox now route.

* Added worker-sandbox redirect-307 route.

* Added worker-sandbox redirect-default route.

* Added worker-sandbox subrequests routes and fetch helpers that were requeried.

* Added worker-sandbox subrequests fetch-timeout to be shorter.

* Added worker-sandbox request catchall fixed test case.

* Added worker-sandbox request xor route.

* Added worker-sandbox request xor route.

* Added worker-sandbox websocket route.

* worker-sandbox queue routes clean up.

* worker unused dependencies clean up.

* worker-sandbox: Added missing d1 routes and improved d1 tests to use miniflare.

* worker-sandbox: Clippy.

* worker-sandbox: fmt.

---------

Co-authored-by: Alexandre Faria <[email protected]>
  • Loading branch information
kflansburg and spigaz authored Mar 11, 2024
1 parent 39b3701 commit 65454ee
Show file tree
Hide file tree
Showing 28 changed files with 947 additions and 194 deletions.
63 changes: 32 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ lto = true
[profile.release.package."*"]
codegen-units = 1
opt-level = "z"

[workspace.dependencies]
wasm-bindgen = "=0.2.87"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"vitest": "^0.32.0"
},
"scripts": {
"test": ""
"test": "cd worker-sandbox && worker-build --dev && vitest"
}
}
2 changes: 1 addition & 1 deletion worker-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ worker-sys = { path = "../worker-sys", version = "0.0.9" }
syn = "2.0.17"
proc-macro2 = "1.0.60"
quote = "1.0.28"
wasm-bindgen = "=0.2.86"
wasm-bindgen = {workspace=true}
wasm-bindgen-futures = "0.4.36"
wasm-bindgen-macro-support = "0.2.86"

Expand Down
9 changes: 6 additions & 3 deletions worker-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ default = ["console_error_panic_hook"]

[dependencies]
blake2 = "0.10.6"
bytes = "1.4.0"
chrono = { version = "0.4.26", default-features = false, features = [
"wasmbind",
"clock",
Expand All @@ -26,19 +27,21 @@ http = "0.2.9"
regex = "1.8.4"
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.96"
worker = { path = "../worker", version = "0.0.17", features= ["queue", "d1"] }
worker = { path = "../worker", version = "0.0.17", features = ["queue", "d1"] }
futures-channel = "0.3.28"
futures-util = { version = "0.3.28", default-features = false }
rand = "0.8.5"
uuid = {version = "1.3.3", features = ["v4", "serde"]}
uuid = { version = "1.3.3", features = ["v4", "serde"] }
serde-wasm-bindgen = "0.5.0"
md5 = "0.7.0"
router-service = { git = "https://github.com/zebp/router-service", version = "0.1.0" }
tower = "0.4.13"

[dev-dependencies]
futures-channel = { version = "0.3.28", features = ["sink"] }
futures-util = { version = "0.3.28", default-features = false, features = ["sink"] }
futures-util = { version = "0.3.28", default-features = false, features = [
"sink",
] }
reqwest = { version = "0.11.18", features = [
"blocking",
"json",
Expand Down
18 changes: 9 additions & 9 deletions worker-sandbox/src/d1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ struct Person {
age: u32,
}

pub async fn prepared_statement(
_req: http::Request<Body>,
env: Env,
) -> Result<http::Response<Body>> {
pub async fn prepared_statement(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let stmt = worker::query!(&db, "SELECT * FROM people WHERE name = ?", "Ryan Upton")?;

Expand Down Expand Up @@ -47,7 +44,7 @@ pub async fn prepared_statement(
Ok(http::Response::new("ok".into()))
}

pub async fn batch(_req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn batch(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let mut results = db
.batch(vec![
Expand All @@ -71,7 +68,7 @@ pub async fn batch(_req: http::Request<Body>, env: Env) -> Result<http::Response
Ok(http::Response::new("ok".into()))
}

pub async fn exec(req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn exec(req: http::Request<Body>, env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;

let result = db
Expand All @@ -84,21 +81,24 @@ pub async fn exec(req: http::Request<Body>, env: Env) -> Result<http::Response<B
))
}

pub async fn dump(_req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn dump(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let bytes = db.dump().await?;
Ok(http::Response::new(bytes.into()))
}

pub async fn error(_req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn error(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let error = db
.exec("THIS IS NOT VALID SQL")
.await
.expect_err("did not get error");

if let Error::D1(error) = error {
assert_eq!(error.cause(), "Error in line 1: THIS IS NOT VALID SQL: ERROR 9009: SQL prepare error: near \"THIS\": syntax error in THIS IS NOT VALID SQL at offset 0")
assert_eq!(
error.cause(),
"Error in line 1: THIS IS NOT VALID SQL: SqliteError: near \"THIS\": syntax error"
)
} else {
panic!("expected D1 error");
}
Expand Down
Loading

0 comments on commit 65454ee

Please sign in to comment.