Skip to content

Commit

Permalink
refactor: big changes
Browse files Browse the repository at this point in the history
  • Loading branch information
waynevanson committed Sep 10, 2023
1 parent 4c2bf4b commit b6fc542
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 701 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ['packages/uischema', 'packages/optics']
members = ['packages/uischema', 'packages/jmespath_optic']
resolver = '2'

[profile.release]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
name = "optics"
name = "jmespath_optic"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
jmespath = "0.3.0"
serde_json = "1.0.106"
33 changes: 33 additions & 0 deletions packages/jmespath_optic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use jmespath::ast::Ast;
use serde_json::Value;

pub trait JmesTraversal {
fn modify_json_value(&self, source: Value, target: Value) -> Value;
}

impl JmesTraversal for &Ast {
fn modify_json_value(&self, source: Value, target: Value) -> Value {
match self {
Ast::Identity { .. } => target,
Ast::And { lhs, rhs, .. } => target,
_ => todo!(),
}
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn identity() {
let expression = jmespath::compile("@").unwrap();
let ast = expression.as_ast();
assert_eq!(ast, &Ast::Identity { offset: 0 });

let source: Value = serde_json::from_str(r#"{ "hello": "world" }"#).unwrap();
let target = source.clone();
let result: Value = ast.modify_json_value(source, target.clone());
assert_eq!(result, target);
}
}
14 changes: 0 additions & 14 deletions packages/optics/src/getter.rs

This file was deleted.

218 changes: 0 additions & 218 deletions packages/optics/src/iso.rs

This file was deleted.

Loading

0 comments on commit b6fc542

Please sign in to comment.