diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f8ad30..0d03e048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Changed + +- Normalized WASM interface to match Python API ([#120](https://github.com/developmentseed/cql2-rs/pull/120)) + - Renamed `CQL2` to `Expr` for consistency with Python + - Changed `Expr.matches()` and `Expr.reduce()` to accept JS objects instead of strings + - Changed `Expr.to_json()` to return JS objects instead of strings + ## [0.4.2] - 2025-11-12 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 84c8b6ac..e610e36a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -632,6 +632,8 @@ version = "0.4.2" dependencies = [ "cql2", "getrandom 0.3.4", + "js-sys", + "serde-wasm-bindgen", "serde_json", "wasm-bindgen", "wasm-bindgen-test", @@ -2306,6 +2308,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_core" version = "1.0.228" diff --git a/cli/src/lib.rs b/cli/src/lib.rs index decbb7b4..513044f9 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -92,8 +92,10 @@ impl Cli { pub fn run_inner(self) -> Result<()> { if let Some(filter_path) = self.filter.as_ref() { - use std::fs::File; - use std::io::{BufRead, BufReader}; + use std::{ + fs::File, + io::{BufRead, BufReader}, + }; // Use self.input as the CQL2 expression let expr_str = self.input.as_ref().ok_or_else(|| { anyhow!("CQL2 expression required as positional argument when using --filter") diff --git a/docs/index.md b/docs/index.md index 67e3ede3..e5af8499 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,6 +11,15 @@ {'op': '=', 'args': [{'property': 'landsat:scene_id'}, 'LC82030282019133LGN00']} ``` +## Javascript + +```js +> import { Expr } from 'cql2-wasm'; +> const expr = new Expr("landsat:scene_id = 'LC82030282019133LGN00'"); +> expr.to_json() +{'op': '=', 'args': [{'property': 'landsat:scene_id'}, 'LC82030282019133LGN00']} +``` + ## CLI ```shell diff --git a/docs/playground.md b/docs/playground.md index 59744322..db7c9415 100644 --- a/docs/playground.md +++ b/docs/playground.md @@ -69,7 +69,7 @@