Skip to content

Commit

Permalink
H-2444: Add Turbine from BP incubator (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilkinsons authored Apr 17, 2024
1 parent 8d51bb5 commit b80a5db
Show file tree
Hide file tree
Showing 112 changed files with 18,415 additions and 1 deletion.
99 changes: 99 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[target.'cfg(all())']
rustflags = [
"-Wclippy::all",
"-Wclippy::as_underscore",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
"-Wclippy::checked_conversions",
"-Wclippy::clone_on_ref_ptr",
"-Wclippy::create_dir",
"-Wclippy::dbg_macro",
"-Wclippy::debug_assert_with_mut_call",
"-Wclippy::default_union_representation",
"-Wclippy::deref_by_slicing",
"-Wclippy::doc_markdown",
"-Wclippy::empty_enum",
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::enum_glob_use",
"-Wclippy::exit",
"-Wclippy::expl_impl_clone_on_copy",
"-Wclippy::explicit_deref_methods",
"-Wclippy::explicit_into_iter_loop",
"-Wclippy::fallible_impl_from",
"-Wclippy::filetype_is_file",
"-Wclippy::filter_map_next",
"-Wclippy::flat_map_option",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_params_excessive_bools",
"-Wclippy::from_iter_instead_of_collect",
"-Wclippy::get_unwrap",
"-Wclippy::if_let_mutex",
"-Wclippy::if_then_some_else_none",
"-Wclippy::implicit_clone",
"-Wclippy::imprecise_flops",
"-Wclippy::inefficient_to_string",
"-Wclippy::invalid_upcast_comparisons",
"-Wclippy::large_digit_groups",
"-Wclippy::large_stack_arrays",
"-Wclippy::large_types_passed_by_value",
"-Wclippy::let_unit_value",
"-Wclippy::linkedlist",
"-Wclippy::lossy_float_literal",
"-Wclippy::macro_use_imports",
"-Wclippy::manual_ok_or",
"-Wclippy::map_err_ignore",
"-Wclippy::map_flatten",
"-Wclippy::map_unwrap_or",
"-Wclippy::match_on_vec_items",
"-Wclippy::match_same_arms",
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mod_module_files",
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
"-Wclippy::needless_borrow",
"-Wclippy::needless_continue",
"-Wclippy::needless_for_each",
"-Wclippy::nursery",
"-Wclippy::option_option",
"-Wclippy::path_buf_push_overwrite",
"-Wclippy::pedantic",
"-Wclippy::print_stderr",
"-Wclippy::print_stdout",
"-Wclippy::ptr_as_ptr",
"-Wclippy::rc_buffer",
"-Wclippy::rc_mutex",
"-Wclippy::ref_option_ref",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::same_name_method",
"-Wclippy::semicolon_if_nothing_returned",
"-Wclippy::single_match_else",
"-Wclippy::str_to_string",
"-Wclippy::string_add",
"-Wclippy::string_add_assign",
"-Wclippy::string_lit_as_bytes",
"-Wclippy::string_slice",
"-Wclippy::string_to_string",
"-Wclippy::todo",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::try_err",
"-Wclippy::undocumented_unsafe_blocks",
"-Wclippy::unnecessary_self_imports",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unused_self",
"-Wclippy::unwrap_used",
"-Wclippy::use_debug",
"-Wclippy::useless_transmute",
"-Wclippy::verbose_file_reads",
"-Wclippy::zero_sized_map_values",
"-Wfuture_incompatible",
"-Wnonstandard_style",
"-Wunreachable_pub",
"-Aclippy::module_name_repetitions",
"-Aclippy::redundant_pub_crate",
"-Amissing_docs",
]
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,20 @@
.config/**/*.log
dist/
node_modules/
target/
test_artifacts/

### Rust template
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ The [HASH] app seeks to enable its users to make better decisions by utilizing a
- [`sim-core-plugins`](apps/sim-core-plugins) contains an example external plugin developed for hCore, which provides a visual interface for process modeling
- [`sim-engine`](apps/sim-engine) contains [HASH Engine], a versatile agent-based simulation engine written in Rust (with support for TypeScript & Python sims)

## Libs

### Block Protocol Libraries

- [`turbine`](libs/turbine)
- [`turbine-transformer`](libs/turbine-transformer)

## POCs

The `pocs` folder contains **proof of concepts** and other one-off experiments.
Expand Down
Binary file added libs/turbine-transformer/.DS_Store
Binary file not shown.
99 changes: 99 additions & 0 deletions libs/turbine-transformer/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[target.'cfg(all())']
rustflags = [
"-Wclippy::all",
"-Wclippy::as_underscore",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
"-Wclippy::checked_conversions",
"-Wclippy::clone_on_ref_ptr",
"-Wclippy::create_dir",
"-Wclippy::dbg_macro",
"-Wclippy::debug_assert_with_mut_call",
"-Wclippy::default_union_representation",
"-Wclippy::deref_by_slicing",
"-Wclippy::doc_markdown",
"-Wclippy::empty_enum",
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::enum_glob_use",
"-Wclippy::exit",
"-Wclippy::expl_impl_clone_on_copy",
"-Wclippy::explicit_deref_methods",
"-Wclippy::explicit_into_iter_loop",
"-Wclippy::fallible_impl_from",
"-Wclippy::filetype_is_file",
"-Wclippy::filter_map_next",
"-Wclippy::flat_map_option",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_params_excessive_bools",
"-Wclippy::from_iter_instead_of_collect",
"-Wclippy::get_unwrap",
"-Wclippy::if_let_mutex",
"-Wclippy::if_then_some_else_none",
"-Wclippy::implicit_clone",
"-Wclippy::imprecise_flops",
"-Wclippy::inefficient_to_string",
"-Wclippy::invalid_upcast_comparisons",
"-Wclippy::large_digit_groups",
"-Wclippy::large_stack_arrays",
"-Wclippy::large_types_passed_by_value",
"-Wclippy::let_unit_value",
"-Wclippy::linkedlist",
"-Wclippy::lossy_float_literal",
"-Wclippy::macro_use_imports",
"-Wclippy::manual_ok_or",
"-Wclippy::map_err_ignore",
"-Wclippy::map_flatten",
"-Wclippy::map_unwrap_or",
"-Wclippy::match_on_vec_items",
"-Wclippy::match_same_arms",
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mod_module_files",
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
"-Wclippy::needless_borrow",
"-Wclippy::needless_continue",
"-Wclippy::needless_for_each",
"-Wclippy::nursery",
"-Wclippy::option_option",
"-Wclippy::path_buf_push_overwrite",
"-Wclippy::pedantic",
"-Wclippy::print_stderr",
"-Wclippy::print_stdout",
"-Wclippy::ptr_as_ptr",
"-Wclippy::rc_buffer",
"-Wclippy::rc_mutex",
"-Wclippy::ref_option_ref",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::same_name_method",
"-Wclippy::semicolon_if_nothing_returned",
"-Wclippy::single_match_else",
"-Wclippy::str_to_string",
"-Wclippy::string_add",
"-Wclippy::string_add_assign",
"-Wclippy::string_lit_as_bytes",
"-Wclippy::string_slice",
"-Wclippy::string_to_string",
"-Wclippy::todo",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::try_err",
"-Wclippy::undocumented_unsafe_blocks",
"-Wclippy::unnecessary_self_imports",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unused_self",
"-Wclippy::unwrap_used",
"-Wclippy::use_debug",
"-Wclippy::useless_transmute",
"-Wclippy::verbose_file_reads",
"-Wclippy::zero_sized_map_values",
"-Wfuture_incompatible",
"-Wnonstandard_style",
"-Wunreachable_pub",
"-Aclippy::module_name_repetitions",
"-Aclippy::redundant_pub_crate",
"-Amissing_docs",
]
17 changes: 17 additions & 0 deletions libs/turbine-transformer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "turbine-transformer"
version = "0.1.0"
edition = "2021"

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

[dependencies]
petgraph = "0.6.3"
error-stack = { version = "0.4.1", default-features = false }
funty = "3.0.0-rc2"
serde_json = "1.0.96"
ordered-float = "3.7.0"
paste = "1.0.12"
hashbrown = "0.13.2"

turbine = { path = "../turbine/lib/turbine" }
79 changes: 79 additions & 0 deletions libs/turbine-transformer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# `turbine-transformer`

> Origin of the name: A wind turbine uses wind to generate electricity through rotation. The transformer is used to
> transform the voltage. This project aims to take the input from the turbine and transform it, by applying a set of
> instructions.

The goal of the project is to supplement the HASH REST-APIs query abilities with a more powerful query language. This
has some trade-offs, you will still need to load in all entities from HASH, but you can then filter them down to the
ones you want.

This is _very_ early in development, and is not ready for production use. Tests are missing, and the API is not stable.
Especially the names of the different types are likely to change. Do not expect this to be usable in production, over
the next weeks and months I will be working on this project to make it more stable and usable.

## Examples

```rust
use turbine_transformer::View;

fn main() {
let view = View::new(&mut subgraph.entities);
let always_include = /* entity id */;

view.select(vec![
Statement::type_()
.or_id(always_include)
.or_type::<User>()
.or_type::<Post>()
.or_inherits_from::<Person>()
.and(
PropertyMatch::equals(
JsonPath::new().then::<Name>(),
"John Doe"
)
)
.with_links()
.with_left(
TypeMatch::new()
.or_type::<User>()
.or_type::<Post>()
)
.with_right(
TypeMatch::new()
.or_type::<User>()
.or_type::<Post>()
)
]);

// You can also update selected entities
view.select_properties(vec![
Select::new(TypeMatch::new().or_type::<User>(), Action::Exclude)
.do_(StaticAction::new::<Name>())
.do_(StaticAction::new::<Email>())
.do_(StaticAction::new::<Password>())
]);

// ... or change the value of specific properties
view.update_properties(vec![
Update::new(TypeMatch::new().or_type::<User>())
.do_(StaticUpdate::new::<Name>("John Doe"))
]);

// or remap a specific user name to a different value
view.update_properties(vec![
Update::new(TypeMatch::new().or_type::<User>().or(
PropertyMatch::equals(
JsonPath::new().then::<Name>(),
"John Doe"
)
))
.do_(StaticUpdate::new::<Name>("Doe John"))
]);
}
```

## Credit

Developed by [Bilal Mahmoud](https://github.com/indietyp).
3 changes: 3 additions & 0 deletions libs/turbine-transformer/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly-2023-08-28"
components = ["cargo", "clippy", "rustfmt", "rust-std", "rust-src"]
30 changes: 30 additions & 0 deletions libs/turbine-transformer/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# General
edition = "2021" # Default: "2015"
unstable_features = true # Default: false
version = "Two" # Default: "One"

# Settings
condense_wildcard_suffixes = true # Default: false
overflow_delimited_expr = true # Default: false
reorder_impl_items = true # Default: false
use_field_init_shorthand = true # Default: false
use_try_shorthand = true # Default: false
wrap_comments = true # Default: false

# Parameters
comment_width = 100 # Default: 80
hex_literal_case = "Upper" # Default: "Preserve"

# Areas
format_code_in_doc_comments = true # Default: false
format_generated_files = true # Default: false
format_macro_matchers = true # Default: false
format_macro_bodies = true # Default: false
format_strings = true # Default: false

# Imports
imports_granularity = "Crate" # Default: "Preserve"
group_imports = "StdExternalCrate" # Default: "Preserve"

# Diagnostics
error_on_unformatted = true # Default: false
Binary file added libs/turbine-transformer/src/.DS_Store
Binary file not shown.
Loading

0 comments on commit b80a5db

Please sign in to comment.