Skip to content

Commit

Permalink
Ensure routers can be run in any order
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Jan 3, 2025
1 parent 81a595a commit 7db868c
Show file tree
Hide file tree
Showing 86 changed files with 5,295 additions and 6,736 deletions.
35 changes: 27 additions & 8 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ wayfind-authority = { path = "crates/authority" }
wayfind-path = { path = "crates/path" }
wayfind-method = { path = "crates/method" }

# FIXME
wayfind-tree = { path = "crates/tree" }

# Decoding
wayfind-percent = { path = "crates/percent" }
wayfind-punycode = { path = "crates/punycode" }
Expand Down Expand Up @@ -131,7 +134,7 @@ codspeed-criterion-compat = "=2.7.2"

# Routers
actix-router = "=0.5.3"
matchit = "=0.8.5"
matchit = "=0.8.6"
ntex-router = "=0.5.3"
path-tree = "=0.8.1"
route-recognizer = "=0.3.1"
Expand Down
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ fn main() -> Result<(), Box<dyn Error>> {
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 1);
assert_eq!(search.path.route, "/users/{id}");
assert_eq!(search.path.route, "/users/{id}".into());
assert_eq!(search.path.parameters[0], ("id", "123"));

let request = RequestBuilder::new()
.path("/users/123/files/my.document.pdf")
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 2);
assert_eq!(search.path.route, "/users/{id}/files/{filename}.{extension}");
assert_eq!(search.path.route, "/users/{id}/files/{filename}.{extension}".into());
assert_eq!(search.path.parameters[0], ("id", "123"));
assert_eq!(search.path.parameters[1], ("filename", "my.document"));
assert_eq!(search.path.parameters[2], ("extension", "pdf"));
Expand Down Expand Up @@ -114,15 +114,15 @@ fn main() -> Result<(), Box<dyn Error>> {
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 1);
assert_eq!(search.path.route, "/files/{*slug}/delete");
assert_eq!(search.path.route, "/files/{*slug}/delete".into());
assert_eq!(search.path.parameters[0], ("slug", "documents/reports/annual.pdf"));

let request = RequestBuilder::new()
.path("/any/other/path")
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 2);
assert_eq!(search.path.route, "/{*catch_all}");
assert_eq!(search.path.route, "/{*catch_all}".into());
assert_eq!(search.path.parameters[0], ("catch_all", "any/other/path"));

Ok(())
Expand Down Expand Up @@ -171,25 +171,25 @@ fn main() -> Result<(), Box<dyn Error>> {
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 1);
assert_eq!(search.path.route, "/users(/{id})");
assert_eq!(search.path.expanded, Some("/users"));
assert_eq!(search.path.route, "/users(/{id})".into());
assert_eq!(search.path.expanded, Some("/users".into()));

let request = RequestBuilder::new()
.path("/users/123")
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 1);
assert_eq!(search.path.route, "/users(/{id})");
assert_eq!(search.path.expanded, Some("/users/{id}"));
assert_eq!(search.path.route, "/users(/{id})".into());
assert_eq!(search.path.expanded, Some("/users/{id}".into()));
assert_eq!(search.path.parameters[0], ("id", "123"));

let request = RequestBuilder::new()
.path("/files/documents/folder/report.pdf")
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 2);
assert_eq!(search.path.route, "/files/{*slug}/{file}(.{extension})");
assert_eq!(search.path.expanded, Some("/files/{*slug}/{file}.{extension}"));
assert_eq!(search.path.route, "/files/{*slug}/{file}(.{extension})".into());
assert_eq!(search.path.expanded, Some("/files/{*slug}/{file}.{extension}".into()));
assert_eq!(search.path.parameters[0], ("slug", "documents/folder"));
assert_eq!(search.path.parameters[1], ("file", "report"));
assert_eq!(search.path.parameters[2], ("extension", "pdf"));
Expand All @@ -199,8 +199,8 @@ fn main() -> Result<(), Box<dyn Error>> {
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 2);
assert_eq!(search.path.route, "/files/{*slug}/{file}(.{extension})");
assert_eq!(search.path.expanded, Some("/files/{*slug}/{file}"));
assert_eq!(search.path.route, "/files/{*slug}/{file}(.{extension})".into());
assert_eq!(search.path.expanded, Some("/files/{*slug}/{file}".into()));
assert_eq!(search.path.parameters[0], ("slug", "documents/folder"));
assert_eq!(search.path.parameters[1], ("file", "readme"));

Expand Down Expand Up @@ -293,14 +293,14 @@ fn main() -> Result<(), Box<dyn Error>> {
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 1);
assert_eq!(search.path.route, "/v2");
assert_eq!(search.path.route, "/v2".into());

let request = RequestBuilder::new()
.path("/v2/my-org/my-repo/blobs/sha256:1234567890")
.build()?;
let search = router.search(&request)?.unwrap();
assert_eq!(*search.data, 2);
assert_eq!(search.path.route, "/v2/{*name:namespace}/blobs/{type}:{digest}");
assert_eq!(search.path.route, "/v2/{*name:namespace}/blobs/{type}:{digest}".into());
assert_eq!(search.path.parameters[0], ("name", "my-org/my-repo"));
assert_eq!(search.path.parameters[1], ("type", "sha256"));
assert_eq!(search.path.parameters[2], ("digest", "1234567890"));
Expand Down Expand Up @@ -348,7 +348,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let error = router.path.constraint::<ConstraintB>().unwrap_err();
insta::assert_snapshot!(error, @r"
duplicate constraint name
duplicate path constraint name
The constraint name 'my_constraint' is already in use:
- existing constraint type: 'rust_out::ConstraintA'
Expand Down Expand Up @@ -504,26 +504,26 @@ fn main() -> Result<(), Box<dyn Error>> {
Empty
=== Path
/
├─ user [9]
├─ user [*:9]
│ ╰─ /
│ ├─ createWithList [10]
│ ├─ createWithList [*:10]
│ ├─ log
│ │ ├─ out [12]
│ │ ╰─ in [11]
│ ╰─ {username} [13]
├─ pet [1]
│ │ ├─ out [*:12]
│ │ ╰─ in [*:11]
│ ╰─ {username} [*:13]
├─ pet [*:1]
│ ╰─ /
│ ├─ findBy
│ │ ├─ Status [2]
│ │ ╰─ Tags [3]
│ ╰─ {petId} [4]
│ ╰─ /uploadImage [5]
│ │ ├─ Status [*:2]
│ │ ╰─ Tags [*:3]
│ ╰─ {petId} [*:4]
│ ╰─ /uploadImage [*:5]
├─ store/
│ ├─ inventory [6]
│ ╰─ order [7]
│ ├─ inventory [*:6]
│ ╰─ order [*:7]
│ ╰─ /
│ ╰─ {orderId} [8]
╰─ {*catch_all} [14]
│ ╰─ {orderId} [*:8]
╰─ {*catch_all} [*:14]
=== Method
[1]
├─ POST [1]
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- [x] Authority router.
- [ ] Stop using the term 'route' to mean 'template'.
- [x] Split routers into seperate crates.
- [ ] Dedupe the 2 tree routers? (Auth vs Patha)
- [x] Dedupe the 2 tree routers? (Auth vs Patha)
- [ ] Consider removing expanded routes, and accepting routes as a vec? (complexity/performance issues) - would need to revamp gitlab logic too
- [ ] Improve our errors.
- [ ] Documentation refresh.
Expand Down
2 changes: 1 addition & 1 deletion benches/matchit_criterion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Benches sourced from `matchit` (MIT AND BSD-3-Clause)
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.5/benches/bench.rs>
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.6/benches/bench.rs>
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use matchit_routes::paths;
Expand Down
2 changes: 1 addition & 1 deletion benches/matchit_divan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Benches sourced from `matchit` (MIT AND BSD-3-Clause)
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.5/benches/bench.rs>
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.6/benches/bench.rs>
use divan::AllocProfiler;
use matchit_routes::paths;
Expand Down
2 changes: 2 additions & 0 deletions crates/authority/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ categories.workspace = true
workspace = true

[dependencies]
wayfind-tree = { path = "../tree" }
wayfind-storage = { path = "../storage" }
smallvec = { workspace = true }

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions crates/authority/src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ pub trait AuthorityConstraint: Send + Sync {

fn check(segment: &str) -> bool;
}

// TODO
Loading

0 comments on commit 7db868c

Please sign in to comment.