diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..971644e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# All files +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.rust] +indent_size = 4 \ No newline at end of file diff --git a/.gitignore b/.gitignore index da61cc3..6c05438 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target .deno_plugins -.DS_STORE \ No newline at end of file +.DS_STORE +.vscode \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 93458a8..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "deno.enable": true, - "deno.unstable": true, - "editor.tabSize": 2, - "editor.formatOnSave": true, - "[typescript]": { - "editor.defaultFormatter": "denoland.vscode-deno" - }, - "[rust]": { - "editor.tabSize": 4 - }, - "deno.suggest.imports.hosts": { - "https://deno.land": true - } -} diff --git a/Cargo.lock b/Cargo.lock index a3dd590..73ed375 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.44" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" +checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7" [[package]] name = "arrayref" @@ -22,12 +22,11 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "async-io" -version = "1.4.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bbfd5cf2794b1e908ea8457e6c45f8f8f1f6ec5f74617bf4662623f47503c3b" +checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" dependencies = [ "concurrent-queue", - "fastrand", "futures-lite", "libc", "log", @@ -54,9 +53,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "blake2b_simd" @@ -89,9 +88,9 @@ checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "cc" -version = "1.0.68" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" [[package]] name = "cfg-if" @@ -127,12 +126,6 @@ dependencies = [ "cache-padded", ] -[[package]] -name = "const-sha1" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d" - [[package]] name = "constant_time_eq" version = "0.1.5" @@ -151,27 +144,28 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.104.0" +version = "0.107.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2962206e59360848dfd9ffb09b48b65a3aa2b88c3b9e46c4a3d61abee3df5737" +checksum = "bc0ec633bafdcb727bf24f28dc4aa4fc5449ffb650d8624c9abea926bbf46e29" dependencies = [ "anyhow", "futures", "indexmap", "lazy_static", + "libc", "log", "parking_lot", "pin-project", - "rusty_v8", "serde", "serde_json", "serde_v8", "url", + "v8", ] [[package]] name = "deno_notify" -version = "1.0.1" +version = "1.1.0" dependencies = [ "deno_core", "futures", @@ -230,9 +224,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b705829d1e87f762c2df6da140b26af5839e1033aa84aa5f56bb688e4e1bdb" +checksum = "b394ed3d285a429378d3b384b9eb1285267e7df4b166df24b7a6939a04dc392e" dependencies = [ "instant", ] @@ -249,9 +243,9 @@ dependencies = [ [[package]] name = "fslock" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b14c83e47c73f7d62d907ae24a1a98e9132df3c33eb6c54fcf4bce0dbc41d5af" +checksum = "57eafdd0c16f57161105ae1b98a1238f97645f2f588438b2949c99a2af9616bf" dependencies = [ "libc", "winapi", @@ -415,18 +409,18 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.9" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "itoa" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "lazy_static" @@ -436,9 +430,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.102" +version = "0.2.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" +checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" [[package]] name = "lock_api" @@ -481,15 +475,15 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "memchr" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "nb-connect" @@ -516,9 +510,9 @@ dependencies = [ [[package]] name = "notify-rust" -version = "4.5.4" +version = "4.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "825e9c9efdcb4d14920f72e2ef329b4dae0219791834c000c42c1475dad341f8" +checksum = "ca6ebab865e67efdd7182a88d76cadbdd2a8d02d1c7a4e16bb7c234016a12cac" dependencies = [ "mac-notification-sys", "serde", @@ -578,9 +572,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "parking" @@ -621,18 +615,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" +checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" +checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" dependencies = [ "proc-macro2", "quote", @@ -641,9 +635,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -653,14 +647,14 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "polling" -version = "2.0.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc12d774e799ee9ebae13f4076ca003b40d18a11ac0f3641e6f899618580b7b" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" dependencies = [ "cfg-if 1.0.0", "libc", "log", - "wepoll-sys", + "wepoll-ffi", "winapi", ] @@ -673,6 +667,16 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-crate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +dependencies = [ + "thiserror", + "toml", +] + [[package]] name = "proc-macro-hack" version = "0.5.19" @@ -687,18 +691,18 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ "proc-macro2", ] @@ -741,19 +745,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "rusty_v8" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b311db3661f6b7631f94ad431133ff0f299c423e6bcc35b748ad0d57d6e604" -dependencies = [ - "bitflags", - "fslock", - "lazy_static", - "libc", - "which", -] - [[package]] name = "ryu" version = "1.0.5" @@ -781,6 +772,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_bytes" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.130" @@ -794,9 +794,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "e277c495ac6cd1a01a58d0a0c574568b4d1ddf14f59965c6a58b8d96400b54f3" dependencies = [ "indexmap", "itoa", @@ -817,50 +817,57 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.15.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b431c505c5ece0caf45ffa6d089d6da7c675303aa82f8cccb76135bb1bc6a2b0" +checksum = "4cc3e270d6d3caf1c311458ca26cae66d36b912bfa9ebf268a5ebcdba3be1f97" dependencies = [ - "rusty_v8", "serde", + "serde_bytes", + "v8", ] [[package]] name = "slab" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smallvec" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "socket2" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" dependencies = [ "libc", "winapi", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strum" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" +checksum = "f7ac893c7d471c8a21f31cfe213ec4f6d9afeed25537c772e08ef3f005f8729e" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.21.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" +checksum = "339f799d8b549e3744c7ac7feb216383e4005d94bdb22561b3ab8f3b808ae9fb" dependencies = [ "heck", "proc-macro2", @@ -870,15 +877,35 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.72" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "time" version = "0.1.44" @@ -892,9 +919,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.2.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" dependencies = [ "tinyvec_macros", ] @@ -916,12 +943,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -dependencies = [ - "matches", -] +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" @@ -957,6 +981,19 @@ dependencies = [ "serde", ] +[[package]] +name = "v8" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "102e1d6d3654edf9624ad2b05458bb2e91c05c9275ec92b2a282b18cc840620b" +dependencies = [ + "bitflags", + "fslock", + "lazy_static", + "libc", + "which", +] + [[package]] name = "void" version = "1.0.2" @@ -982,21 +1019,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] -name = "wepoll-sys" -version = "3.0.1" +name = "wepoll-ffi" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" dependencies = [ "cc", ] [[package]] name = "which" -version = "4.1.0" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe" +checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9" dependencies = [ "either", + "lazy_static", "libc", ] @@ -1024,55 +1062,45 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.21.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f5f8d2ea79bf690bbee453fd4a1516ae426e5d5c7215d96cc0c3dc134fc4a0" +checksum = "a9f39345ae0c8ab072c0ac7fe8a8b411636aa34f89be19ddd0d9226544f13944" dependencies = [ - "const-sha1", - "windows_gen", - "windows_macros", - "windows_reader", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", ] [[package]] -name = "windows_gen" -version = "0.21.1" +name = "windows_i686_gnu" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6994f42f8481387778cc608407d6703410672d57f32a66009419d7a18aa912" -dependencies = [ - "windows_quote", - "windows_reader", -] +checksum = "c0866510a3eca9aed73a077490bbbf03e5eaac4e1fd70849d89539e5830501fd" [[package]] -name = "windows_macros" -version = "0.21.1" +name = "windows_i686_msvc" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cc2357b1b03c19f056cb0e6d06011f80f54beadb4e36aee2ca98493c7cfc3c" -dependencies = [ - "syn", - "windows_gen", - "windows_quote", - "windows_reader", -] +checksum = "bf0ffed56b7e9369a29078d2ab3aaeceea48eb58999d2cff3aa2494a275b95c6" [[package]] -name = "windows_quote" -version = "0.21.1" +name = "windows_x86_64_gnu" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cf987b5288c15e1997226848f78f3ed3ef8b78dcfd71a201c8c8684163a7e4d" +checksum = "384a173630588044205a2993b6864a2f56e5a8c1e7668c07b93ec18cf4888dc4" [[package]] -name = "windows_reader" -version = "0.21.1" +name = "windows_x86_64_msvc" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237b53e8b40766ea7db5da0d8c6c1442d21d0429f0ee7500d7b5688967bd9d7b" +checksum = "9bd8f062d8ca5446358159d79a90be12c543b3a965c847c8f3eedf14b321d399" [[package]] name = "winrt-notification" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0cc832b8c66c42b3ee6b625c124fe2d0b3ff7fb2cec18b28926e9c4bfdb72da" +checksum = "eda101fb8e034a25f3d50a0714d7ca4f234a4fc7bc57427f6d81040db0ccbe6a" dependencies = [ "strum", "windows", @@ -1114,7 +1142,7 @@ version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a482c56029e48681b89b92b5db3c446db0915e8dd1052c0328a574eda38d5f93" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 0.1.5", "proc-macro2", "quote", "syn", @@ -1122,23 +1150,25 @@ dependencies = [ [[package]] name = "zvariant" -version = "2.6.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678e7262502a135f49b1ece65010526649be7ee68acb80e1fc5377fc71fef878" +checksum = "e1a9373dead84d640ccf5798f2928917e6aa1ab3f130751406bb13e0a9dd9913" dependencies = [ "byteorder", "enumflags2", + "libc", "serde", + "static_assertions", "zvariant_derive", ] [[package]] name = "zvariant_derive" -version = "2.6.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27d7c34325a35020b94343389cc9391e0f8ac245cca9155429c4022d93141241" +checksum = "46ee71e0e88747ec582d290dbe98ff7907ff28770c7a35f16da41e5e6f1f4fa3" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.0", "proc-macro2", "quote", "syn", diff --git a/Cargo.toml b/Cargo.toml index f60f79e..65d38fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "deno_notify" -version = "1.0.1" +version = "1.1.0" authors = ["Pandawan "] edition = "2018" publish = false @@ -12,6 +12,6 @@ crate-type = ["cdylib"] [dependencies] futures = "0.3.17" -deno_core = "0.104.0" -notify-rust = "4.5.4" +deno_core = "0.107.0" +notify-rust = "4.5.5" serde = "1.0.130" \ No newline at end of file diff --git a/README.md b/README.md index 5ade14e..d32e181 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ _You will need to run using the `--unstable` and `--allow-all` permissions to allow for automatic plugin loading and caching._ ```ts -import { Notification } from "https://deno.land/x/deno_notify@1.0.1/ts/mod.ts"; +import { Notification } from "https://deno.land/x/deno_notify@1.1.0/ts/mod.ts"; // Create a new notification const notif = new Notification(); diff --git a/src/lib.rs b/src/lib.rs index dc5190e..1469a2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,24 @@ use deno_core::serde::Deserialize; use deno_core::serde_json; -use notify_rust::{error::Error as NotifyRustError, Notification}; +use notify_rust::{self, error::Error as NotifyRustError, Notification}; + +#[derive(Debug, Deserialize)] +#[serde(tag = "type")] +enum NotificationTimeout { + /// Do not expire, user will have to close this manually. + Never, + /// Expire after n milliseconds. + Milliseconds(u32), +} + +impl Into for NotificationTimeout { + fn into(self) -> notify_rust::Timeout { + match self { + NotificationTimeout::Never => notify_rust::Timeout::Never, + NotificationTimeout::Milliseconds(t) => notify_rust::Timeout::Milliseconds(t), + } + } +} #[derive(Debug, Deserialize)] struct NotificationOptions { @@ -18,34 +36,37 @@ struct NotificationOptions { #[serde(rename = "_soundName")] sound_name: Option, + + #[serde(rename = "_timeout")] + timeout: Option, } fn send_notification(options: NotificationOptions) -> Result<(), NotifyRustError> { let mut notification = Notification::new(); - // Notification title + // Set Notification options notification.summary(&options.title); - // Notification subtitle if let Some(subtitle) = &options.subtitle { notification.subtitle(subtitle); } - // Notification body if let Some(body) = &options.body { notification.body(body); } - // Add an icon if let Some(icon) = &options.icon { notification.icon(icon); } - // Add a sound if let Some(sound_name) = &options.sound_name { notification.sound_name(sound_name); } + if let Some(timeout) = options.timeout { + notification.timeout(timeout); + } + // Display it match notification.show() { Ok(_) => Ok(()), @@ -58,6 +79,7 @@ fn send_notification(options: NotificationOptions) -> Result<(), NotifyRustError pub extern "C" fn notify_send(ptr: *const u8, len: usize) -> u8 { let buf = unsafe { std::slice::from_raw_parts(ptr, len) }; + // Try parsing JSON into NotificationOptions object let options: NotificationOptions = match serde_json::from_slice(buf) { Ok(opt) => opt, Err(error) => { @@ -66,10 +88,11 @@ pub extern "C" fn notify_send(ptr: *const u8, len: usize) -> u8 { } }; + // Try sending the notification match send_notification(options) { Ok(_) => 0, Err(error) => { - println!("Error reading input data as JSON: {}", error); + println!("Error sending notification: {}", error); 1 } } diff --git a/tests/basic.test.ts b/tests/basic.test.ts index d69e9ba..55752e4 100644 --- a/tests/basic.test.ts +++ b/tests/basic.test.ts @@ -3,7 +3,7 @@ import { assert, assertNotStrictEquals, assertThrows, -} from "https://deno.land/std@0.112.0/testing/asserts.ts"; +} from "https://deno.land/std@0.114.0/testing/asserts.ts"; Deno.test("Creating a notification", () => { new Notification(); diff --git a/tests/options.test.ts b/tests/options.test.ts index eca94ae..cfa01a9 100644 --- a/tests/options.test.ts +++ b/tests/options.test.ts @@ -1,5 +1,8 @@ import { Notification } from "../ts/notification.ts"; -import { assertStrictEquals } from "https://deno.land/std@0.112.0/testing/asserts.ts"; +import { + assertStrictEquals, + assertThrows, +} from "https://deno.land/std@0.114.0/testing/asserts.ts"; Deno.test("Set title", () => { const title = "Example title"; @@ -9,10 +12,12 @@ Deno.test("Set title", () => { Deno.test({ name: "Set subtitle", - ignore: Deno.build.os !== "darwin", + ignore: Deno.build.os !== "darwin" && Deno.build.os !== "windows", fn() { const subtitle = "Example subtitle"; - const notif = new Notification({ macos: true }).subtitle(subtitle); + const notif = new Notification({ macos: true, windows: true }).subtitle( + subtitle, + ); assertStrictEquals((notif as any)._subtitle, subtitle); }, }); @@ -25,10 +30,10 @@ Deno.test("Set body", () => { Deno.test({ name: "Set icon", - ignore: Deno.build.os !== "windows" && Deno.build.os !== "linux", + ignore: Deno.build.os !== "linux", fn() { const icon = "/path/to/icon"; - const notif = new Notification({ linux: true, windows: true }).icon(icon); + const notif = new Notification({ linux: true }).icon(icon); assertStrictEquals((notif as any)._icon, icon); }, }); @@ -38,3 +43,30 @@ Deno.test("Set soundName", () => { const notif = new Notification().soundName(soundName); assertStrictEquals((notif as any)._soundName, soundName); }); + +Deno.test({ + name: "Set timeout", + ignore: Deno.build.os !== "windows" && Deno.build.os !== "linux", + fn() { + const notif = new Notification({ linux: true, windows: true }).timeout( + "never", + ); + assertStrictEquals((notif as any)._timeout, "never"); + + notif.timeout(10); + assertStrictEquals((notif as any)._timeout, 10); + }, +}); + +Deno.test({ + name: "Error on negative timeout", + ignore: Deno.build.os !== "windows" && Deno.build.os !== "linux", + fn() { + const notif = new Notification({ linux: true, windows: true }); + assertThrows( + () => notif.timeout(-5), + Error, + `Notification timeout must be a number greater than 0 (or 'never').`, + ); + }, +}); diff --git a/tests/platforms.test.ts b/tests/platforms.test.ts index 1645c9e..7cd94b9 100644 --- a/tests/platforms.test.ts +++ b/tests/platforms.test.ts @@ -1,5 +1,5 @@ import { Notification } from "../ts/notification.ts"; -import { assertThrows } from "https://deno.land/std@0.112.0/testing/asserts.ts"; +import { assertThrows } from "https://deno.land/std@0.114.0/testing/asserts.ts"; Deno.test("Attempt unsupported platform feature (strict)", () => { const notif = new Notification(); @@ -24,7 +24,7 @@ Deno.test({ ignore: Deno.build.os !== "windows", fn() { const notif = new Notification({ windows: true }); - (notif as any).icon("/path/to/icon"); + (notif as any).subtitle("Example subtitle"); }, }); @@ -41,7 +41,7 @@ Deno.test({ name: "Attempt supported platform feature on invalid os (strict, macos)", ignore: Deno.build.os !== "darwin", fn() { - const notif = new Notification({ linux: true, windows: true }); + const notif = new Notification({ linux: true }); assertThrows( () => (notif as any).icon("/path/to/icon"), Error, @@ -51,15 +51,27 @@ Deno.test({ }); Deno.test({ - name: - "Attempt supported platform feature on invalid os (strict, windows & linux)", - ignore: Deno.build.os !== "windows" && Deno.build.os !== "linux", + name: "Attempt supported platform feature on invalid os (strict, windows)", + ignore: Deno.build.os !== "windows", fn() { - const notif = new Notification({ macos: true }); + const notif = new Notification({ linux: true }); + assertThrows( + () => (notif as any).icon("/path/to/icon"), + Error, + `Current operating system (windows) does not support icon.`, + ); + }, +}); + +Deno.test({ + name: "Attempt supported platform feature on invalid os (strict, linux)", + ignore: Deno.build.os !== "linux", + fn() { + const notif = new Notification({ macos: true, windows: true }); assertThrows( () => (notif as any).subtitle("Example subtitle"), Error, - `Current operating system (${Deno.build.os}) does not support subtitle.`, + `Current operating system (linux) does not support subtitle.`, ); }, }); @@ -79,6 +91,7 @@ Deno.test({ ignore: Deno.build.os === "darwin", fn() { const notif = new Notification({ macos: true }, false); + // Show not throw on windows/linux (notif as any).subtitle("Example subtitle"); }, }); @@ -89,15 +102,15 @@ Deno.test({ fn() { const notif = new Notification({ windows: true }, false); // Should not throw on linux/macos - (notif as any).icon("/path/to/icon"); + (notif as any).subtitle("Example subtitle"); }, }); Deno.test({ - name: "Attempt supported multi-platform feature (strict, windows and linux)", - ignore: Deno.build.os !== "windows" && Deno.build.os !== "linux", + name: "Attempt supported multi-platform feature (strict, windows and macos)", + ignore: Deno.build.os !== "windows" && Deno.build.os !== "darwin", fn() { - const notif = new Notification({ windows: true, linux: true }); - (notif as any).icon("/path/to/icon"); + const notif = new Notification({ windows: true, macos: true }); + (notif as any).subtitle("Example subtitle"); }, }); diff --git a/ts/deps.ts b/ts/deps.ts deleted file mode 100644 index 0be07b6..0000000 --- a/ts/deps.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "https://deno.land/x/plug@0.4.0/mod.ts"; diff --git a/ts/notification.ts b/ts/notification.ts index bb352f4..1903fd9 100644 --- a/ts/notification.ts +++ b/ts/notification.ts @@ -42,6 +42,7 @@ export class Notification< private _body: string | null = null; private _icon: string | null = null; private _soundName: string | null = null; + private _timeout: "never" | number | null = null; /** * Create a Notification. @@ -96,17 +97,19 @@ export class Notification< /** * Set the `subtitle`. - * Available on macOS. + * Available on macOS and Windows. * * For more elaborate content, use the `body` field. * * @param subtitle */ public subtitle = ((subtitle: string) => { - if (this.#verifyPlatform(["macos"], "subtitle") === false) return; + if (this.#verifyPlatform(["macos", "windows"], "subtitle") === false) { + return; + } this._subtitle = subtitle; return this; - }) as PlatformFeature this>; + }) as PlatformFeature this>; /** * Set the `body`. @@ -124,24 +127,24 @@ export class Notification< /** * Set the `icon`. - * Available on Windows and Linux. + * Available on Linux. * - * Can either be a file URL, + * Can either be a file:// URI, * or a common icon name, usually those in `/usr/share/icons` * can all be used (or freedesktop.org names). * * @param icon */ public icon = ((icon: string) => { - if (this.#verifyPlatform(["linux", "windows"], "icon") === false) return; + if (this.#verifyPlatform(["linux"], "icon") === false) return; this._icon = icon; return this; - }) as PlatformFeature this>; + }) as PlatformFeature this>; /** * Set the `soundName` to play with the notification. * - * With macOS support, a list of default sounds is provided. + * With macOS support, a list of default sound names is provided. * * @param soundName */ @@ -152,6 +155,31 @@ export class Notification< return this; }; + /** + * Set the `timeout`. + * Available on Windows and Linux. + * + * This sets the time (in milliseconds) from the time the notification is displayed + * until it is closed again by the Notification Server. + * + * Setting this to `'never'` will cause the notification to never expire. + * + * @param timeout + */ + public timeout = ((timeout: "never" | number) => { + if (this.#verifyPlatform(["windows", "linux"], "timeout") === false) return; + + // TODO: Once TypeScript 4.5 comes out, add compile-time check for numbers greater than 0 (see https://stackoverflow.com/a/69090186/4588880) + if (typeof timeout === "number" && timeout <= 0) { + throw new Error( + "Notification timeout must be a number greater than 0 (or 'never').", + ); + } + + this._timeout = timeout; + return this; + }) as PlatformFeature this>; + /** * Display the notification to the user. */ diff --git a/ts/plugin.ts b/ts/plugin.ts index 76fd28a..b862d22 100644 --- a/ts/plugin.ts +++ b/ts/plugin.ts @@ -1,6 +1,6 @@ -import { Plug } from "./deps.ts"; +import { Plug } from "https://deno.land/x/plug@0.4.1/mod.ts"; -const VERSION = "1.0.1"; +const VERSION = "1.1.0"; const POLICY = Deno.env.get("NOTIFY_PLUGIN_URL") === undefined ? Plug.CachePolicy.STORE : Plug.CachePolicy.NONE;