Skip to content

Commit e119963

Browse files
Merge remote-tracking branch 'origin/Travis-Gilbert/rustyred-Geo-space-plugin'
2 parents 12f1636 + cf33004 commit e119963

16 files changed

Lines changed: 2901 additions & 50 deletions

File tree

Cargo.lock

Lines changed: 220 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustyred-core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ tantivy = ["dep:tantivy"]
1818
# §P8-A pa8.1+pa8.2: S2 cells as alternative spatial backend behind
1919
# RUSTY_RED_SPATIAL_BACKEND=s2. Default builds keep H3.
2020
s2 = ["dep:s2"]
21+
geometry = ["dep:geo", "dep:geo-types", "dep:geozero"]
2122

2223
[dependencies]
2324
fs2 = "0.4"
25+
geo = { version = "0.32.0", optional = true }
26+
geo-types = { version = "0.7.19", optional = true }
27+
geozero = { version = "0.15.1", default-features = false, features = ["with-geo", "with-wkb", "with-wkt"], optional = true }
2428
h3o = "0.7"
2529
instant-distance = "0.6.1"
2630
redis = { version = "0.27", optional = true }

crates/rustyred-core/src/executor.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,13 @@ impl RustyredExecutor for InMemoryRustyredExecutor {
523523

524524
fn execute_request(&mut self, request: RustyredRequest) -> RustyredResponse {
525525
let command_name = request.command.clone();
526+
if let Some(operation) = crate::plugin::builtin_plugin_registry().operation(&command_name) {
527+
let context = crate::plugin::PluginOperationContext {
528+
command: operation.command,
529+
state_hash: self.state_hash(),
530+
};
531+
return (operation.handler)(context, request.args);
532+
}
526533
match RustyredCommand::from_name(&request.command) {
527534
Ok(command) => self.execute(command, request.args).unwrap_or_else(|error| {
528535
RustyredResponse::err(command_name, error, self.state_hash())
@@ -551,6 +558,17 @@ impl<S: RustyredStore> RustyredExecutor for StoreBackedRustyredExecutor<S> {
551558

552559
fn execute_request(&mut self, request: RustyredRequest) -> RustyredResponse {
553560
let command_name = request.command.clone();
561+
if let Some(operation) = crate::plugin::builtin_plugin_registry().operation(&command_name) {
562+
let context = crate::plugin::PluginOperationContext {
563+
command: operation.command,
564+
state_hash: self.state_hash(),
565+
};
566+
let response = (operation.handler)(context, request.args);
567+
if response.ok {
568+
self.persist();
569+
}
570+
return response;
571+
}
554572
match RustyredCommand::from_name(&request.command) {
555573
Ok(command) => self.execute(command, request.args).unwrap_or_else(|error| {
556574
RustyredResponse::err(command_name, error, self.state_hash())
@@ -907,4 +925,17 @@ mod tests {
907925
Some("missing_graph_endpoint")
908926
);
909927
}
928+
929+
#[test]
930+
fn plugin_operation_round_trips_through_json_executor() {
931+
let mut executor = InMemoryRustyredExecutor::new();
932+
let raw = executor.execute_json(
933+
r#"{"command":"RUSTYRED.PLUGIN.ECHO","args":{"message":"hello plugin"}}"#,
934+
);
935+
let parsed: serde_json::Value = serde_json::from_str(&raw).unwrap();
936+
937+
assert_eq!(parsed["ok"], true);
938+
assert_eq!(parsed["command"], "RUSTYRED.PLUGIN.ECHO");
939+
assert_eq!(parsed["payload"]["args"]["message"], "hello plugin");
940+
}
910941
}

0 commit comments

Comments
 (0)