From 17cb510a8078ebd70bcc77c0334d74726f8ef98c Mon Sep 17 00:00:00 2001 From: ynqa Date: Mon, 30 Mar 2026 22:01:46 +0900 Subject: [PATCH 1/2] chore: use jaq=3.0.0 --- Cargo.lock | 296 +++++++++++++++++++++------------------------------- Cargo.toml | 6 +- src/json.rs | 35 +++++-- 3 files changed, 146 insertions(+), 191 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae940c6..26e7867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,15 +17,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - [[package]] name = "anstream" version = "1.0.0" @@ -125,10 +116,15 @@ dependencies = [ ] [[package]] -name = "bumpalo" -version = "3.20.2" +name = "bstr" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] [[package]] name = "bytemuck" @@ -164,17 +160,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" -[[package]] -name = "chrono" -version = "0.4.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" -dependencies = [ - "iana-time-zone", - "num-traits", - "windows-link", -] - [[package]] name = "clap" version = "4.6.0" @@ -239,12 +224,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "crc32fast" version = "1.5.0" @@ -647,33 +626,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hifijson" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a7763b98ba8a24f59e698bf9ab197e7676c640d6455d1580b4ce7dc560f0f0d" - -[[package]] -name = "iana-time-zone" -version = "0.1.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] +checksum = "242402749acf71e6f32f5857598b7002c4058a4e3c3b22b4c7d51cab9aea754e" [[package]] name = "image" @@ -713,9 +668,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "jaq-core" -version = "2.2.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77526a72eb79412c29fd141767a6549bbfcb1cb40e00556fe16532d5e878e098" +checksum = "dca0f164c8e9c55fc5aefe60b371df735c719b09930dac185878f2f8c7ab6b68" dependencies = [ "dyn-clone", "once_cell", @@ -724,34 +679,81 @@ dependencies = [ [[package]] name = "jaq-json" -version = "1.1.3" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01dbdbd07b076e8403abac68ce7744d93e2ecd953bbc44bf77bf00e1e81172bc" +checksum = "f5c5baabe63d1d72cde60ec7548a098036773e3541dbc65c6a44fb38e9cfb272" dependencies = [ + "bstr", + "bytes", "foldhash", "hifijson", "indexmap", "jaq-core", "jaq-std", - "serde_json", + "num-bigint", + "num-traits", + "ryu", + "self_cell", ] [[package]] name = "jaq-std" -version = "2.1.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c264fe397c981705976c71f1bfe020382b9eda52ae950e57fe885e147bdd67d" +checksum = "2a11bb307027b20b3dc7b212ad687e7e410cbc43933eec5d498672ab2bc60666" dependencies = [ "aho-corasick", "base64", - "chrono", + "bstr", "jaq-core", + "jiff", "libm", "log", - "regex-lite", + "regex-bites", "urlencoding", ] +[[package]] +name = "jiff" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359" +dependencies = [ + "jiff-static", + "jiff-tzdb-platform", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", + "windows-sys 0.61.2", +] + +[[package]] +name = "jiff-static" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "jiff-tzdb" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c900ef84826f1338a557697dc8fc601df9ca9af4ac137c7fb61d4c6f2dfd3076" + +[[package]] +name = "jiff-tzdb-platform" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" +dependencies = [ + "jiff-tzdb", +] + [[package]] name = "jnv" version = "0.7.1" @@ -773,16 +775,6 @@ dependencies = [ "toml", ] -[[package]] -name = "js-sys" -version = "0.3.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - [[package]] name = "libc" version = "0.2.183" @@ -878,6 +870,25 @@ dependencies = [ "memchr", ] +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1053,6 +1064,21 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "portable-atomic-util" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" +dependencies = [ + "portable-atomic", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -1161,10 +1187,16 @@ dependencies = [ ] [[package]] -name = "regex-lite" -version = "0.1.9" +name = "regex-automata" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" + +[[package]] +name = "regex-bites" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a15a2fa0bfda9361941c45550896ae87b15cc6c8c939ea350079670332e211" [[package]] name = "rustc_version" @@ -1189,10 +1221,10 @@ dependencies = [ ] [[package]] -name = "rustversion" -version = "1.0.22" +name = "ryu" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] name = "scopeguard" @@ -1200,6 +1232,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "self_cell" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b12e76d157a900eb52e81bc6e9f3069344290341720e9178cde2407113ac8d89" + [[package]] name = "semver" version = "1.0.27" @@ -1526,51 +1564,6 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" -[[package]] -name = "wasm-bindgen" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" -dependencies = [ - "bumpalo", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" -dependencies = [ - "unicode-ident", -] - [[package]] name = "wayland-backend" version = "0.3.14" @@ -1669,65 +1662,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.60.2" diff --git a/Cargo.toml b/Cargo.toml index 7d5489e..e330c03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ tokio = { version = "1.50.0", features = ["full"] } toml = "1.1.0" # jaq dependencies -jaq-core = "2.2.1" -jaq-json = { version = "1.1.3", features = ["serde_json"] } -jaq-std = "2.1.2" +jaq-core = "3.0.0" +jaq-json = "2.0.0" +jaq-std = "3.0.0" [dependencies.promkit-widgets] version = "0.5.0" diff --git a/src/json.rs b/src/json.rs index f12a377..9036aa8 100644 --- a/src/json.rs +++ b/src/json.rs @@ -1,8 +1,9 @@ use jaq_core::{ + data, load::{Arena, File, Loader}, - Compiler, Ctx, RcIter, + unwrap_valr, Compiler, Ctx, Vars, }; -use jaq_json::Val; +use jaq_json::{read, Val}; use promkit_widgets::{ jsonstream::jsonz, @@ -40,7 +41,8 @@ pub fn run_jaq( json_stream: &[serde_json::Value], ) -> anyhow::Result> { let arena = Arena::default(); - let loader = Loader::new(jaq_std::defs().chain(jaq_json::defs())); + let defs = jaq_core::defs().chain(jaq_std::defs()).chain(jaq_json::defs()); + let loader = Loader::new(defs); let modules = loader .load( &arena, @@ -50,21 +52,34 @@ pub fn run_jaq( }, ) .map_err(|errs| anyhow::anyhow!("jq filter parsing failed: {errs:?}"))?; + let funs = jaq_core::funs::>() + .chain(jaq_std::funs::>()) + .chain(jaq_json::funs::>()); let filter = Compiler::default() - .with_funs(jaq_std::funs().chain(jaq_json::funs())) + .with_funs(funs) .compile(modules) .map_err(|errs| anyhow::anyhow!("jq filter compilation failed: {errs:?}"))?; let mut ret = Vec::::new(); for input in json_stream { - let inputs = RcIter::new(core::iter::empty()); - let out = filter.run((Ctx::new([], &inputs), Val::from(input.clone()))); + let input = serde_json::to_vec(input) + .map_err(|e| anyhow::anyhow!("failed to serialize input JSON: {e}"))?; + let input = read::parse_single(&input) + .map_err(|e| anyhow::anyhow!("failed to parse input into jaq value: {e}"))?; + + let ctx = Ctx::>::new(&filter.lut, Vars::new([])); + let out = filter.id.run((ctx, input)).map(unwrap_valr); + for item in out { - match item { - Ok(val) => ret.push(val.into()), - Err(err) => return Err(anyhow::anyhow!("jq filter execution failed: {err}")), - } + let val = item.map_err(|err| anyhow::anyhow!("jq filter execution failed: {err}"))?; + let text = val.to_string(); + let json = serde_json::from_str(&text).map_err(|e| { + anyhow::anyhow!( + "failed to convert jaq output to JSON value (possibly non-JSON output): {e}" + ) + })?; + ret.push(json); } } From f9d995e0e794aa8d63688aa466a1a8f901b30d96 Mon Sep 17 00:00:00 2001 From: ynqa Date: Mon, 30 Mar 2026 22:46:30 +0900 Subject: [PATCH 2/2] cargo-fmt --- src/json.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/json.rs b/src/json.rs index 9036aa8..9c6a90d 100644 --- a/src/json.rs +++ b/src/json.rs @@ -41,7 +41,9 @@ pub fn run_jaq( json_stream: &[serde_json::Value], ) -> anyhow::Result> { let arena = Arena::default(); - let defs = jaq_core::defs().chain(jaq_std::defs()).chain(jaq_json::defs()); + let defs = jaq_core::defs() + .chain(jaq_std::defs()) + .chain(jaq_json::defs()); let loader = Loader::new(defs); let modules = loader .load(