From 2cd3ebb69d2cb625a17c36a489fe01d787aca214 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 4 Nov 2024 12:26:51 +0200 Subject: [PATCH] Offline writes --- Cargo.lock | 762 +++++++++++++++++++++++++-- Cargo.toml | 2 +- examples/offline-writes/example.js | 35 ++ examples/offline-writes/package.json | 17 + index.js | 5 +- package-lock.json | 4 +- promise.js | 5 +- src/database.rs | 27 +- src/lib.rs | 2 +- types/promise.d.ts.map | 2 +- 10 files changed, 796 insertions(+), 65 deletions(-) create mode 100644 examples/offline-writes/example.js create mode 100644 examples/offline-writes/package.json diff --git a/Cargo.lock b/Cargo.lock index a81bf4c..8f5b987 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,9 +111,9 @@ dependencies = [ "bitflags 1.3.2", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", "itoa", "matchit", "memchr", @@ -122,7 +122,7 @@ dependencies = [ "pin-project-lite", "rustversion", "serde", - "sync_wrapper", + "sync_wrapper 0.1.2", "tower", "tower-layer", "tower-service", @@ -137,8 +137,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "mime", "rustversion", "tower-layer", @@ -198,7 +198,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn", "which", @@ -225,6 +225,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.5.0" @@ -273,6 +279,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "cipher" version = "0.4.4" @@ -329,6 +341,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "either" version = "1.13.0" @@ -375,6 +398,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures" version = "0.3.30" @@ -508,7 +540,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", "indexmap 2.5.0", "slab", "tokio", @@ -567,6 +599,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -574,7 +617,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", "pin-project-lite", ] @@ -607,8 +673,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -620,6 +686,25 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" version = "0.25.0" @@ -627,14 +712,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "399c78f9338483cb7e630c8474b07268983c6bd5acee012e4211f9f7bb21b070" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.30", "log", - "rustls", + "rustls 0.22.4", "rustls-native-certs", "rustls-pki-types", "tokio", - "tokio-rustls", + "tokio-rustls 0.25.0", + "webpki-roots", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper 1.5.0", + "hyper-util", + "rustls 0.23.13", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", "webpki-roots", ] @@ -644,12 +747,170 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.30", "pin-project-lite", "tokio", "tokio-io-timeout", ] +[[package]] +name = "hyper-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.5.0", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -680,6 +941,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "ipnet" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + [[package]] name = "itertools" version = "0.12.1" @@ -695,6 +962,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -725,8 +1001,8 @@ dependencies = [ [[package]] name = "libsql" -version = "0.5.1" -source = "git+https://github.com/tursodatabase/libsql/?rev=20147731c4a9d6e942b159f183215e9399fda2c3#20147731c4a9d6e942b159f183215e9399fda2c3" +version = "0.6.0" +source = "git+https://github.com/tursodatabase/libsql/?rev=18f444290d9f2542d6da14e559d2b3e31f8f157d#18f444290d9f2542d6da14e559d2b3e31f8f157d" dependencies = [ "anyhow", "async-stream", @@ -737,14 +1013,15 @@ dependencies = [ "bytes", "fallible-iterator 0.3.0", "futures", - "http", - "hyper", - "hyper-rustls", + "http 0.2.12", + "hyper 0.14.30", + "hyper-rustls 0.25.0", "libsql-hrana", "libsql-sqlite3-parser", "libsql-sys", "libsql_replication", "parking_lot", + "reqwest", "serde", "serde_json", "thiserror", @@ -762,8 +1039,8 @@ dependencies = [ [[package]] name = "libsql-ffi" -version = "0.4.1" -source = "git+https://github.com/tursodatabase/libsql/?rev=20147731c4a9d6e942b159f183215e9399fda2c3#20147731c4a9d6e942b159f183215e9399fda2c3" +version = "0.5.0" +source = "git+https://github.com/tursodatabase/libsql/?rev=18f444290d9f2542d6da14e559d2b3e31f8f157d#18f444290d9f2542d6da14e559d2b3e31f8f157d" dependencies = [ "bindgen", "cc", @@ -772,7 +1049,7 @@ dependencies = [ [[package]] name = "libsql-hrana" version = "0.2.0" -source = "git+https://github.com/tursodatabase/libsql/?rev=20147731c4a9d6e942b159f183215e9399fda2c3#20147731c4a9d6e942b159f183215e9399fda2c3" +source = "git+https://github.com/tursodatabase/libsql/?rev=18f444290d9f2542d6da14e559d2b3e31f8f157d#18f444290d9f2542d6da14e559d2b3e31f8f157d" dependencies = [ "base64 0.21.7", "bytes", @@ -794,8 +1071,8 @@ dependencies = [ [[package]] name = "libsql-rusqlite" -version = "0.32.0" -source = "git+https://github.com/tursodatabase/libsql/?rev=20147731c4a9d6e942b159f183215e9399fda2c3#20147731c4a9d6e942b159f183215e9399fda2c3" +version = "0.33.0" +source = "git+https://github.com/tursodatabase/libsql/?rev=18f444290d9f2542d6da14e559d2b3e31f8f157d#18f444290d9f2542d6da14e559d2b3e31f8f157d" dependencies = [ "bitflags 2.6.0", "fallible-iterator 0.2.0", @@ -808,7 +1085,7 @@ dependencies = [ [[package]] name = "libsql-sqlite3-parser" version = "0.13.0" -source = "git+https://github.com/tursodatabase/libsql/?rev=20147731c4a9d6e942b159f183215e9399fda2c3#20147731c4a9d6e942b159f183215e9399fda2c3" +source = "git+https://github.com/tursodatabase/libsql/?rev=18f444290d9f2542d6da14e559d2b3e31f8f157d#18f444290d9f2542d6da14e559d2b3e31f8f157d" dependencies = [ "bitflags 2.6.0", "cc", @@ -824,8 +1101,8 @@ dependencies = [ [[package]] name = "libsql-sys" -version = "0.7.0" -source = "git+https://github.com/tursodatabase/libsql/?rev=20147731c4a9d6e942b159f183215e9399fda2c3#20147731c4a9d6e942b159f183215e9399fda2c3" +version = "0.8.0" +source = "git+https://github.com/tursodatabase/libsql/?rev=18f444290d9f2542d6da14e559d2b3e31f8f157d#18f444290d9f2542d6da14e559d2b3e31f8f157d" dependencies = [ "bytes", "libsql-ffi", @@ -837,8 +1114,8 @@ dependencies = [ [[package]] name = "libsql_replication" -version = "0.5.0" -source = "git+https://github.com/tursodatabase/libsql/?rev=20147731c4a9d6e942b159f183215e9399fda2c3#20147731c4a9d6e942b159f183215e9399fda2c3" +version = "0.6.0" +source = "git+https://github.com/tursodatabase/libsql/?rev=18f444290d9f2542d6da14e559d2b3e31f8f157d#18f444290d9f2542d6da14e559d2b3e31f8f157d" dependencies = [ "aes", "async-stream", @@ -866,6 +1143,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" version = "0.4.12" @@ -1165,6 +1448,55 @@ dependencies = [ "syn", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash 2.0.0", + "rustls 0.23.13", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash 2.0.0", + "rustls 0.23.13", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e346e016eacfff12233c243718197ca12f148c84e1e84268a896699b41c71780" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.37" @@ -1257,6 +1589,48 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "reqwest" +version = "0.12.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-core", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.5.0", + "hyper-rustls 0.27.3", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls 0.23.13", + "rustls-pemfile", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "windows-registry", +] + [[package]] name = "ring" version = "0.17.8" @@ -1284,6 +1658,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustix" version = "0.38.36" @@ -1311,6 +1691,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + [[package]] name = "rustls-native-certs" version = "0.7.3" @@ -1445,6 +1839,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1506,6 +1912,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "subtle" version = "2.6.1" @@ -1540,6 +1952,26 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thiserror" version = "1.0.63" @@ -1570,6 +2002,31 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.40.0" @@ -1615,7 +2072,18 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ - "rustls", + "rustls 0.22.4", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls 0.23.13", "rustls-pki-types", "tokio", ] @@ -1656,24 +2124,19 @@ dependencies = [ "base64 0.21.7", "bytes", "h2", - "http", - "http-body", - "hyper", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", "hyper-timeout", "percent-encoding", "pin-project", "prost", - "rustls-native-certs", - "rustls-pemfile", - "rustls-pki-types", "tokio", - "tokio-rustls", "tokio-stream", "tower", "tower-layer", "tower-service", "tracing", - "webpki-roots", ] [[package]] @@ -1684,9 +2147,9 @@ checksum = "dc3b0e1cedbf19fdfb78ef3d672cb9928e0a91a9cb4629cc0c916e8cff8aaaa1" dependencies = [ "base64 0.21.7", "bytes", - "http", - "http-body", - "hyper", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", "pin-project", "tokio-stream", "tonic", @@ -1726,8 +2189,8 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "http-range-header", "pin-project-lite", "tower", @@ -1843,6 +2306,29 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "url" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "1.10.0" @@ -1880,6 +2366,83 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + +[[package]] +name = "web-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki-roots" version = "0.26.5" @@ -1923,6 +2486,36 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -2005,6 +2598,42 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -2026,8 +2655,51 @@ dependencies = [ "syn", ] +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 8f779da..ba54efe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] [dependencies] tracing-subscriber = { version = "0.3", features = ["env-filter"] } -libsql = { git = "https://github.com/tursodatabase/libsql/", rev = "20147731c4a9d6e942b159f183215e9399fda2c3", features = ["encryption"] } +libsql = { git = "https://github.com/tursodatabase/libsql/", rev = "18f444290d9f2542d6da14e559d2b3e31f8f157d", features = ["encryption"] } tracing = "0.1" once_cell = "1.18.0" tokio = { version = "1.29.1", features = [ "rt-multi-thread" ] } diff --git a/examples/offline-writes/example.js b/examples/offline-writes/example.js new file mode 100644 index 0000000..051f2af --- /dev/null +++ b/examples/offline-writes/example.js @@ -0,0 +1,35 @@ +import Database from "libsql"; +import reader from "readline-sync"; + +const dbPath = process.env.LIBSQL_DB_PATH; +if (!dbPath) { + throw new Error("Environment variable LIBSQL_DB_PATH is not set."); +} +const syncUrl = process.env.LIBSQL_SYNC_URL; +if (!syncUrl) { + throw new Error("Environment variable LIBSQL_SYNC_URL is not set."); +} +const authToken = process.env.LIBSQL_AUTH_TOKEN; + +const options = { syncUrl: syncUrl, authToken: authToken, offline: true }; +const db = new Database(dbPath, options); + +db.exec("CREATE TABLE IF NOT EXISTS guest_book_entries (text TEXT)"); + +const comment = reader.question("Enter your comment: "); + +console.log(comment); + +const stmt = db.prepare("INSERT INTO guest_book_entries (text) VALUES (?)"); +stmt.run(comment); +console.log("max write replication index: " + db.maxWriteReplicationIndex()); + +const replicated = db.sync(); +console.log("frames synced: " + replicated.frames_synced); +console.log("frame no: " + replicated.frame_no); + +console.log("Guest book entries:"); +const rows = db.prepare("SELECT * FROM guest_book_entries").all(); +for (const row of rows) { + console.log(" - " + row.text); +} diff --git a/examples/offline-writes/package.json b/examples/offline-writes/package.json new file mode 100644 index 0000000..1cef708 --- /dev/null +++ b/examples/offline-writes/package.json @@ -0,0 +1,17 @@ +{ + "name": "libsql-example", + "version": "1.0.0", + "description": "", + "type": "module", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "libsql": "../..", + "readline-sync": "^1.4.10" + } +} diff --git a/index.js b/index.js index 4e84234..4f8ae73 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ function requireNative() { const { databaseOpen, - databaseOpenWithRpcSync, + databaseOpenWithSync, databaseInTransaction, databaseClose, databaseSyncSync, @@ -76,7 +76,8 @@ class Database { const encryptionKey = opts?.encryptionKey ?? ""; const syncPeriod = opts?.syncPeriod ?? 0.0; const readYourWrites = opts?.readYourWrites ?? true; - this.db = databaseOpenWithRpcSync(path, opts.syncUrl, authToken, encryptionCipher, encryptionKey, syncPeriod, readYourWrites); + const offline = opts?.offline ?? false; + this.db = databaseOpenWithSync(path, opts.syncUrl, authToken, encryptionCipher, encryptionKey, syncPeriod, readYourWrites, offline); } else { const authToken = opts?.authToken ?? ""; const encryptionKey = opts?.encryptionKey ?? ""; diff --git a/package-lock.json b/package-lock.json index 167a241..018bf50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "libsql", - "version": "0.4.5", + "version": "0.4.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "libsql", - "version": "0.4.5", + "version": "0.4.6", "cpu": [ "x64", "arm64", diff --git a/promise.js b/promise.js index cc7313d..86251b3 100644 --- a/promise.js +++ b/promise.js @@ -38,7 +38,7 @@ function requireNative() { const { databaseOpen, - databaseOpenWithRpcSync, + databaseOpenWithSync, databaseInTransaction, databaseClose, databaseSyncAsync, @@ -79,7 +79,8 @@ class Database { } const encryptionKey = opts?.encryptionKey ?? ""; const syncPeriod = opts?.syncPeriod ?? 0.0; - this.db = databaseOpenWithRpcSync(path, opts.syncUrl, authToken, encryptionCipher, encryptionKey, syncPeriod); + const offline = opts?.offline ?? false; + this.db = databaseOpenWithSync(path, opts.syncUrl, authToken, encryptionCipher, encryptionKey, syncPeriod, offline); } else { const authToken = opts?.authToken ?? ""; const encryptionKey = opts?.encryptionKey ?? ""; diff --git a/src/database.rs b/src/database.rs index e63435e..cc6c6e4 100644 --- a/src/database.rs +++ b/src/database.rs @@ -61,7 +61,7 @@ impl Database { Ok(cx.boxed(db)) } - pub fn js_open_with_rpc_sync(mut cx: FunctionContext) -> JsResult> { + pub fn js_open_with_sync(mut cx: FunctionContext) -> JsResult> { let db_path = cx.argument::(0)?.value(&mut cx); let sync_url = cx.argument::(1)?.value(&mut cx); let sync_auth = cx.argument::(2)?.value(&mut cx); @@ -69,6 +69,7 @@ impl Database { let encryption_key = cx.argument::(4)?.value(&mut cx); let sync_period = cx.argument::(5)?.value(&mut cx); let read_your_writes = cx.argument::(6)?.value(&mut cx); + let offline = cx.argument::(7)?.value(&mut cx); let cipher = libsql::Cipher::from_str(&encryption_cipher).or_else(|err| { throw_libsql_error( @@ -95,16 +96,20 @@ impl Database { sync_url ); let rt = runtime(&mut cx)?; - let fut = libsql::Database::open_with_remote_sync_internal( - db_path, - sync_url, - sync_auth, - Some(version), - read_your_writes, - encryption_config, - sync_period, - ); - let result = rt.block_on(fut); + let result = if offline { + rt.block_on(libsql::Builder::new_synced_database(db_path, sync_url, sync_auth).build()) + } else { + rt.block_on(async { + let mut builder = libsql::Builder::new_remote_replica(db_path, sync_url, sync_auth); + if let Some(encryption_config) = encryption_config { + builder = builder.encryption_config(encryption_config); + } + if let Some(sync_period) = sync_period { + builder = builder.sync_interval(sync_period); + } + builder.build().await + }) + }; let db = result.or_else(|err| cx.throw_error(err.to_string()))?; let conn = db .connect() diff --git a/src/lib.rs b/src/lib.rs index 20cd362..cf4048c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> { ) .try_init(); cx.export_function("databaseOpen", Database::js_open)?; - cx.export_function("databaseOpenWithRpcSync", Database::js_open_with_rpc_sync)?; + cx.export_function("databaseOpenWithSync", Database::js_open_with_sync)?; cx.export_function("databaseInTransaction", Database::js_in_transaction)?; cx.export_function("databaseClose", Database::js_close)?; cx.export_function("databaseSyncSync", Database::js_sync_sync)?; diff --git a/types/promise.d.ts.map b/types/promise.d.ts.map index 9af29f2..21e4249 100644 --- a/types/promise.d.ts.map +++ b/types/promise.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.js"],"names":[],"mappings":";AA2DA;;GAEG;AACH;IACE;;;;;OAKG;IACH,kBAFW,MAAM,aAkChB;IApBG,QAA6G;IAO/G,gBAAiC;IACjC,kBAAqB;IACrB,aAAc;IACd,cAAgB;IAYlB,YAEC;IAED,sCAEC;IAED;;;;OAIG;IACH,aAFW,MAAM,OAQhB;IAED;;;;OAIG;IACH,sEA8BC;IAED,uCAQC;IAED,0CAEC;IAED,8BAEC;IAED,iDAqBC;IAED,yCAYC;IAED,qCAUC;IAED,oCAEC;IAED,gCAEC;IAED;;;;OAIG;IACH,UAFW,MAAM,OAMhB;IAED;;OAEG;IACH,cAEC;IAED;;OAEG;IACH,uCAGC;IAED,iCAEC;CACF"} \ No newline at end of file +{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.js"],"names":[],"mappings":";AA2DA;;GAEG;AACH;IACE;;;;;OAKG;IACH,kBAFW,MAAM,aAmChB;IApBG,QAAmH;IAOrH,gBAAiC;IACjC,kBAAqB;IACrB,aAAc;IACd,cAAgB;IAYlB,YAEC;IAED,sCAEC;IAED;;;;OAIG;IACH,aAFW,MAAM,OAQhB;IAED;;;;OAIG;IACH,sEA8BC;IAED,uCAQC;IAED,0CAEC;IAED,8BAEC;IAED,iDAqBC;IAED,yCAYC;IAED,qCAUC;IAED,oCAEC;IAED,gCAEC;IAED;;;;OAIG;IACH,UAFW,MAAM,OAMhB;IAED;;OAEG;IACH,cAEC;IAED;;OAEG;IACH,uCAGC;IAED,iCAEC;CACF"} \ No newline at end of file