streamdal-detective

Crates.iostreamdal-detective
lib.rsstreamdal-detective
version0.0.28
sourcesrc
created_at2023-10-19 20:27:29.135825
updated_at2023-10-20 23:59:09.112206
descriptionData matcher library used by Streamdal WASM functions
homepage
repositoryhttps://github.com/streamdal/streamdal-detective
max_upload_size
id1008313
size89,300
Daniel Selans (dselans)

documentation

README

wasm-detective

Release Test

Rust helper lib for performing value matching in streamdal/wasm Wasm functions.

For available matchers, look at the enums listed in protos.

Install

cargo add streamdal-protos
cargo add streamdal-wasm-detective

Usage

fn main() {
    let det = detective::Detective::new();

    let sample_json = r#"{
        "field1": {
            "field2": "2"
        }
    }"#;

    let request = Request {
        match_type: DetectiveType::DETECTIVE_TYPE_HAS_FIELD,
        data: &sample_json.as_bytes().to_vec(),
        path: "field1".to_string(),
        args: vec!["1".to_string()],
        negate: false,
    };

    match det.matches(&request) {
        Ok(value) => println!("Result: {:#?}", value),
        Err(err) => println!("Error: {:#?}", err),
    }
}

Note on regex

Regex-based matchers are currently slow because we have to compile the pattern on every call.

This will improve when we implement K/V functionality in SDK's.

The idea is that WASM funcs will be given the ability to GET/PUT items in cache, so detective would be wired up to accept a param that is a trait that allows working with the cache funcs.

If K/V trait is provided to detective - before compiling a regex pattern, it would first check if the cache already contains it. If yes, it'll use that, if not, it'll compile and put it in the cache.

~DS 06-29-2023

Development

The library must be tested using Rust nightly (because we use #![feature(test)] to enable the ability to bench).

To install nightly: rustup install nightly

To run tests using nightly: cargo +nightly test

To run benches using nightly: cargo +nightly bench

You can also set nightly as default using rustup default nightly.

Commit count: 0

cargo fmt