Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
220 changes: 220 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/rustyred-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ tantivy = ["dep:tantivy"]
# §P8-A pa8.1+pa8.2: S2 cells as alternative spatial backend behind
# RUSTY_RED_SPATIAL_BACKEND=s2. Default builds keep H3.
s2 = ["dep:s2"]
geometry = ["dep:geo", "dep:geo-types", "dep:geozero"]

[dependencies]
fs2 = "0.4"
geo = { version = "0.32.0", optional = true }
geo-types = { version = "0.7.19", optional = true }
geozero = { version = "0.15.1", default-features = false, features = ["with-geo", "with-wkb", "with-wkt"], optional = true }
h3o = "0.7"
instant-distance = "0.6.1"
redis = { version = "0.27", optional = true }
Expand Down
31 changes: 31 additions & 0 deletions crates/rustyred-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ impl RustyredExecutor for InMemoryRustyredExecutor {

fn execute_request(&mut self, request: RustyredRequest) -> RustyredResponse {
let command_name = request.command.clone();
if let Some(operation) = crate::plugin::builtin_plugin_registry().operation(&command_name) {
let context = crate::plugin::PluginOperationContext {
command: operation.command,
state_hash: self.state_hash(),
};
return (operation.handler)(context, request.args);
}
match RustyredCommand::from_name(&request.command) {
Ok(command) => self.execute(command, request.args).unwrap_or_else(|error| {
RustyredResponse::err(command_name, error, self.state_hash())
Expand Down Expand Up @@ -551,6 +558,17 @@ impl<S: RustyredStore> RustyredExecutor for StoreBackedRustyredExecutor<S> {

fn execute_request(&mut self, request: RustyredRequest) -> RustyredResponse {
let command_name = request.command.clone();
if let Some(operation) = crate::plugin::builtin_plugin_registry().operation(&command_name) {
let context = crate::plugin::PluginOperationContext {
command: operation.command,
state_hash: self.state_hash(),
};
let response = (operation.handler)(context, request.args);
if response.ok {
self.persist();
}
return response;
}
match RustyredCommand::from_name(&request.command) {
Ok(command) => self.execute(command, request.args).unwrap_or_else(|error| {
RustyredResponse::err(command_name, error, self.state_hash())
Expand Down Expand Up @@ -907,4 +925,17 @@ mod tests {
Some("missing_graph_endpoint")
);
}

#[test]
fn plugin_operation_round_trips_through_json_executor() {
let mut executor = InMemoryRustyredExecutor::new();
let raw = executor.execute_json(
r#"{"command":"RUSTYRED.PLUGIN.ECHO","args":{"message":"hello plugin"}}"#,
);
let parsed: serde_json::Value = serde_json::from_str(&raw).unwrap();

assert_eq!(parsed["ok"], true);
assert_eq!(parsed["command"], "RUSTYRED.PLUGIN.ECHO");
assert_eq!(parsed["payload"]["args"]["message"], "hello plugin");
}
}
Loading
Loading