From 30f85cb19f35638ecdc5bc129c933d7bc36e7e0f Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Mon, 11 May 2026 22:23:14 +0200 Subject: [PATCH] Add nats2.14 support. --- Cargo.lock | 390 +++++++++++++++++++---- Cargo.toml | 2 +- docker-compose.yaml | 4 +- python/natsrpy/_natsrpy_rs/__init__.pyi | 2 +- python/natsrpy/_natsrpy_rs/js/stream.pyi | 17 + src/js/stream.rs | 147 +++++---- src/nats_cls.rs | 2 +- 7 files changed, 437 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 191eb42..04685b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + [[package]] name = "arc-swap" version = "1.9.1" @@ -22,9 +28,9 @@ dependencies = [ [[package]] name = "async-nats" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07d6f157065c3461096d51aacde0c326fa49f3f6e0199e204c566842cdaa5299" +checksum = "31811585c7c5bc2f60f8b80d5a6b0f737115611dac47567d7f7d94562ebb180b" dependencies = [ "base64", "bytes", @@ -34,7 +40,7 @@ dependencies = [ "nuid", "pin-project", "portable-atomic", - "rand", + "rand 0.10.1", "regex", "ring", "rustls-native-certs", @@ -44,7 +50,7 @@ dependencies = [ "serde_json", "serde_nanos", "serde_repr", - "thiserror 1.0.69", + "thiserror", "time", "tokio", "tokio-rustls", @@ -70,9 +76,9 @@ checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" [[package]] name = "bitflags" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "block-buffer" @@ -94,9 +100,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.59" +version = "1.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7a4d3ec6524d28a329fc53654bbadc9bdd7b0431f5d65f1a56ffb28a1ee5283" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" dependencies = [ "find-msvc-tools", "shlex", @@ -108,6 +114,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -139,6 +156,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "crypto-common" version = "0.1.7" @@ -156,7 +182,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "curve25519-dalek-derive", "digest", "fiat-crypto", @@ -177,9 +203,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea" +checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" [[package]] name = "der" @@ -245,6 +271,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "errno" version = "0.3.14" @@ -267,6 +299,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -349,6 +387,35 @@ dependencies = [ "wasi", ] +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "rand_core 0.10.1", + "wasip2", + "wasip3", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + [[package]] name = "heck" version = "0.5.0" @@ -453,6 +520,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "idna" version = "1.1.0" @@ -466,25 +539,43 @@ dependencies = [ [[package]] name = "idna_adapter" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" dependencies = [ "icu_normalizer", "icu_properties", ] +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + [[package]] name = "itoa" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "libc" -version = "0.2.184" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "litemap" @@ -537,7 +628,7 @@ dependencies = [ "pyo3-log", "serde", "serde_json", - "thiserror 2.0.18", + "thiserror", "time", "tokio", ] @@ -551,9 +642,9 @@ dependencies = [ "data-encoding", "ed25519", "ed25519-dalek", - "getrandom", + "getrandom 0.2.17", "log", - "rand", + "rand 0.8.6", "signatory", ] @@ -563,7 +654,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc895af95856f929163a0aa20c26a78d26bfdc839f51b9d5aa7a5b79e52b7e83" dependencies = [ - "rand", + "rand 0.8.6", ] [[package]] @@ -624,18 +715,18 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pin-project" -version = "1.1.11" +version = "1.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" +checksum = "cbf0d9e68100b3a7989b4901972f265cd542e560a3a8a724e1e20322f4d06ce9" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.11" +version = "1.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" +checksum = "a990e22f43e84855daf260dded30524ef4a9021cc7541c26540500a50b624389" dependencies = [ "proc-macro2", "quote", @@ -688,6 +779,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -789,15 +890,32 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "rand" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" +dependencies = [ + "chacha20", + "getrandom 0.4.2", + "rand_core 0.10.1", ] [[package]] @@ -807,7 +925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -816,9 +934,15 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.17", ] +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "redox_syscall" version = "0.5.18" @@ -865,7 +989,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom", + "getrandom 0.2.17", "libc", "untrusted", "windows-sys 0.52.0", @@ -882,9 +1006,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.37" +version = "0.23.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" dependencies = [ "once_cell", "ring", @@ -908,18 +1032,18 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.14.0" +version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9" dependencies = [ "zeroize", ] [[package]] name = "rustls-webpki" -version = "0.103.10" +version = "0.103.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" dependencies = [ "ring", "rustls-pki-types", @@ -1046,7 +1170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] @@ -1073,7 +1197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1e303f8205714074f6068773f0e29527e0453937fe837c9717d066635b65f31" dependencies = [ "pkcs8", - "rand_core", + "rand_core 0.6.4", "signature", "zeroize", ] @@ -1085,7 +1209,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1160,33 +1284,13 @@ version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - [[package]] name = "thiserror" version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl 2.0.18", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "thiserror-impl", ] [[package]] @@ -1243,9 +1347,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.51.1" +version = "1.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f66bf9585cda4b724d3e78ab34b73fb2bbaba9011b9bfdf69dc836382ea13b8c" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" dependencies = [ "bytes", "libc", @@ -1315,7 +1419,7 @@ dependencies = [ "futures-sink", "http", "httparse", - "rand", + "rand 0.8.6", "ring", "rustls-pki-types", "tokio", @@ -1367,9 +1471,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" [[package]] name = "unicode-ident" @@ -1377,6 +1481,12 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" version = "0.9.0" @@ -1413,20 +1523,72 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "webpki-roots" version = "0.26.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" dependencies = [ - "webpki-roots 1.0.6", + "webpki-roots 1.0.7", ] [[package]] name = "webpki-roots" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +checksum = "52f5ee44c96cf55f1b349600768e3ece3a8f26010c05265ab73f945bb1a2eb9d" dependencies = [ "rustls-pki-types", ] @@ -1519,6 +1681,100 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + [[package]] name = "writeable" version = "0.6.3" diff --git a/Cargo.toml b/Cargo.toml index 64442de..aab1fbb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib"] name = "_natsrpy_rs" [dependencies] -async-nats = "0.47" +async-nats = "0.48" bytes = "1.11.1" futures-util = "0.3.32" log = "0.4.29" diff --git a/docker-compose.yaml b/docker-compose.yaml index 62c8076..87ce221 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ services: nats: - image: nats:2.12.5-alpine - command: -m 8222 --jetstream + image: nats:2.14-alpine + command: -m 8222 --jetstream -D healthcheck: test: - CMD diff --git a/python/natsrpy/_natsrpy_rs/__init__.pyi b/python/natsrpy/_natsrpy_rs/__init__.pyi index 1921378..5059c39 100644 --- a/python/natsrpy/_natsrpy_rs/__init__.pyi +++ b/python/natsrpy/_natsrpy_rs/__init__.pyi @@ -208,7 +208,7 @@ class Nats: def request( self, subject: str, - payload: bytes | str | bytearray | memoryview, + payload: bytes | str | bytearray | memoryview | None = None, *, headers: dict[str, Any] | None = None, inbox: str | None = None, diff --git a/python/natsrpy/_natsrpy_rs/js/stream.pyi b/python/natsrpy/_natsrpy_rs/js/stream.pyi index de0fbe1..556e158 100644 --- a/python/natsrpy/_natsrpy_rs/js/stream.pyi +++ b/python/natsrpy/_natsrpy_rs/js/stream.pyi @@ -132,6 +132,17 @@ class SubjectTransform: source: str destination: str +@final +class StreamConsumerSource: + """ + Configures a pre-created durable consumer. + + Used for stream mirroring. See ADR-60. + """ + + name: str + deliver_subject: str + @final class Source: """Configuration for a stream source or mirror origin. @@ -144,6 +155,7 @@ class Source: start_time: optional starting timestamp. domain: optional JetStream domain. subject_transforms: optional subject transformation rule. + consumer: pre-created durable consumer to use for sourcing. See ADR-60. """ name: str @@ -153,6 +165,7 @@ class Source: start_time: int | None = None domain: str | None = None subject_transforms: SubjectTransform | None = None + consumer: StreamConsumerSource | None = None def __new__( cls, @@ -163,6 +176,7 @@ class Source: start_time: int | None = None, domain: str | None = None, subject_transforms: SubjectTransform | None = None, + consumer: StreamConsumerSource | None = None, ) -> Self: ... @final @@ -247,6 +261,7 @@ class StreamConfig: allow_message_schedules: when True, enable scheduled message delivery. allow_message_counter: when True, enable message counter header. + allow_batch_publish: Allows fast-ingest batch publishing on the stream (ADR-50). """ name: str @@ -288,6 +303,7 @@ class StreamConfig: allow_atomic_publish: bool | None allow_message_schedules: bool | None allow_message_counter: bool | None + allow_batch_publish: bool def __new__( cls, @@ -330,6 +346,7 @@ class StreamConfig: allow_atomic_publish: bool | None = None, allow_message_schedules: bool | None = None, allow_message_counter: bool | None = None, + allow_batch_publish: bool | None = None, ) -> Self: ... @final diff --git a/src/js/stream.rs b/src/js/stream.rs index 66941db..9ce6ff8 100644 --- a/src/js/stream.rs +++ b/src/js/stream.rs @@ -289,6 +289,31 @@ impl From for SubjectTransform } } +#[pyo3::pyclass(from_py_object, get_all, set_all)] +#[derive(Debug, Clone)] +pub struct StreamConsumerSource { + pub name: String, + pub deliver_subject: String, +} + +impl From for async_nats::jetstream::stream::StreamConsumerSource { + fn from(value: StreamConsumerSource) -> Self { + Self { + name: value.name, + deliver_subject: value.deliver_subject, + } + } +} + +impl From for StreamConsumerSource { + fn from(value: async_nats::jetstream::stream::StreamConsumerSource) -> Self { + Self { + name: value.name.clone(), + deliver_subject: value.deliver_subject, + } + } +} + #[pyo3::pyclass(from_py_object, get_all, set_all)] #[derive(Debug, Clone)] pub struct Source { @@ -299,6 +324,7 @@ pub struct Source { pub start_time: Option, pub domain: Option, pub subject_transforms: Vec, + pub consumer: Option, } impl TryFrom for async_nats::jetstream::stream::Source { @@ -320,6 +346,7 @@ impl TryFrom for async_nats::jetstream::stream::Source { .into_iter() .map(std::convert::Into::into) .collect(), + consumer: value.consumer.map(Into::into), }) } } @@ -338,6 +365,7 @@ impl From for Source { .into_iter() .map(Into::into) .collect(), + consumer: value.consumer.map(Into::into), } } } @@ -352,7 +380,8 @@ impl Source { start_sequence = None, start_time=None, domain=None, - subject_transforms = None + subject_transforms = None, + consumer = None, ))] pub fn __new__( name: String, @@ -362,6 +391,7 @@ impl Source { start_time: Option, domain: Option, subject_transforms: Option>>, + consumer: Option, ) -> NatsrpyResult { Ok(Self { name, @@ -375,6 +405,7 @@ impl Source { .map(|val| val.borrow().deref().clone()) .collect(), external: external.map(|e| e.borrow().deref().clone()), + consumer, }) } } @@ -538,6 +569,7 @@ pub struct StreamConfig { pub allow_atomic_publish: bool, pub allow_message_schedules: bool, pub allow_message_counter: bool, + pub allow_batch_publish: bool, } #[pyo3::pymethods] @@ -583,6 +615,7 @@ impl StreamConfig { allow_atomic_publish=None, allow_message_schedules=None, allow_message_counter=None, + allow_batch_publish=None, ))] pub fn __new__( name: String, @@ -624,6 +657,7 @@ impl StreamConfig { allow_atomic_publish: Option, allow_message_schedules: Option, allow_message_counter: Option, + allow_batch_publish: Option, ) -> NatsrpyResult { let config = Self { name, @@ -666,6 +700,7 @@ impl StreamConfig { allow_atomic_publish: allow_atomic_publish.unwrap_or_default(), allow_message_schedules: allow_message_schedules.unwrap_or_default(), allow_message_counter: allow_message_counter.unwrap_or_default(), + allow_batch_publish: allow_batch_publish.unwrap_or_default(), }; Ok(config) @@ -718,6 +753,7 @@ impl TryFrom for StreamConfig { allow_atomic_publish: value.allow_atomic_publish, allow_message_schedules: value.allow_message_schedules, allow_message_counter: value.allow_message_counter, + allow_batch_publish: value.allow_batch_publish, }) } } @@ -726,65 +762,65 @@ impl TryFrom for async_nats::jetstream::stream::Config { type Error = NatsrpyError; fn try_from(value: StreamConfig) -> Result { - let mut conf = Self { + let conf = Self { name: value.name, subjects: value.subjects, description: value.description, first_sequence: value.first_sequence, subject_delete_marker_ttl: value.subject_delete_marker_ttl, - ..Default::default() - }; - // Optional values that have defaults. - // If the value is not present, we just use the one - // that nats' config defaults to. - conf.max_bytes = value.max_bytes; - conf.max_messages = value.max_messages; - conf.max_messages_per_subject = value.max_messages_per_subject; - conf.discard_new_per_subject = value.discard_new_per_subject; - conf.max_consumers = value.max_consumers; - conf.max_age = value.max_age; - conf.max_message_size = value.max_message_size; - conf.num_replicas = value.num_replicas; - conf.no_ack = value.no_ack; - conf.duplicate_window = value.duplicate_window; - conf.template_owner = value.template_owner; - conf.sealed = value.sealed; - conf.allow_rollup = value.allow_rollup; - conf.deny_delete = value.deny_delete; - conf.deny_purge = value.deny_purge; - conf.allow_direct = value.allow_direct; - conf.mirror_direct = value.mirror_direct; - conf.metadata = value.metadata; - conf.allow_message_ttl = value.allow_message_ttl; - conf.allow_atomic_publish = value.allow_atomic_publish; - conf.allow_message_schedules = value.allow_message_schedules; - conf.allow_message_counter = value.allow_message_counter; - - // Values that require conversion between python -> rust types. - conf.republish = value.republish.map(Into::into); - conf.storage = value.storage.into(); - conf.retention = value.retention.into(); - conf.discard = value.discard.into(); - conf.mirror = value.mirror.map(TryInto::try_into).transpose()?; - conf.sources = value - .sources - .map(|sources| { - sources - .into_iter() - .map(TryInto::try_into) - .collect::, _>>() - }) - .transpose()?; - conf.subject_transform = value.subject_transform.map(Into::into); - conf.compression = value.compression.map(Into::into); - conf.consumer_limits = value.consumer_limits.map(Into::into); - conf.placement = value.placement.map(Into::into); - conf.persist_mode = value.persist_mode.map(Into::into); - conf.pause_until = value - .pause_until - .map(time::OffsetDateTime::from_unix_timestamp) - .transpose()?; + // Optional values that have defaults. + // If the value is not present, we just use the one + // that nats' config defaults to. + max_bytes: value.max_bytes, + max_messages: value.max_messages, + max_messages_per_subject: value.max_messages_per_subject, + discard_new_per_subject: value.discard_new_per_subject, + max_consumers: value.max_consumers, + max_age: value.max_age, + max_message_size: value.max_message_size, + num_replicas: value.num_replicas, + no_ack: value.no_ack, + duplicate_window: value.duplicate_window, + template_owner: value.template_owner, + sealed: value.sealed, + allow_rollup: value.allow_rollup, + deny_delete: value.deny_delete, + deny_purge: value.deny_purge, + allow_direct: value.allow_direct, + mirror_direct: value.mirror_direct, + metadata: value.metadata, + allow_message_ttl: value.allow_message_ttl, + allow_atomic_publish: value.allow_atomic_publish, + allow_message_schedules: value.allow_message_schedules, + allow_message_counter: value.allow_message_counter, + allow_batch_publish: value.allow_batch_publish, + + // Values that require conversion between python -> rust types. + republish: value.republish.map(Into::into), + storage: value.storage.into(), + retention: value.retention.into(), + discard: value.discard.into(), + mirror: value.mirror.map(TryInto::try_into).transpose()?, + sources: value + .sources + .map(|sources| { + sources + .into_iter() + .map(TryInto::try_into) + .collect::, _>>() + }) + .transpose()?, + subject_transform: value.subject_transform.map(Into::into), + compression: value.compression.map(Into::into), + consumer_limits: value.consumer_limits.map(Into::into), + placement: value.placement.map(Into::into), + persist_mode: value.persist_mode.map(Into::into), + pause_until: value + .pause_until + .map(time::OffsetDateTime::from_unix_timestamp) + .transpose()?, + }; Ok(conf) } @@ -1109,6 +1145,7 @@ pub mod pymod { pub use super::{ ClusterInfo, Compression, ConsumerLimits, DiscardPolicy, External, PeerInfo, PersistenceMode, Placement, Republish, RetentionPolicy, Source, SourceInfo, StorageType, - Stream, StreamConfig, StreamInfo, StreamMessage, StreamState, SubjectTransform, + Stream, StreamConfig, StreamConsumerSource, StreamInfo, StreamMessage, StreamState, + SubjectTransform, }; } diff --git a/src/nats_cls.rs b/src/nats_cls.rs index 424f0e2..2e72176 100644 --- a/src/nats_cls.rs +++ b/src/nats_cls.rs @@ -175,7 +175,7 @@ impl NatsCls { }) } - #[pyo3(signature = (subject, payload, *, headers=None, inbox = None, timeout=None))] + #[pyo3(signature = (subject, payload = None, *, headers=None, inbox = None, timeout=None))] pub fn request<'py>( &self, py: Python<'py>,