diff --git a/Cargo.lock b/Cargo.lock index 70dbbcec79..12a409df2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,139 +3,927 @@ version = 3 [[package]] -name = "Inflector" -version = "0.11.4" +name = "aho-corasick" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "azle_generate_rearchitecture" +version = "0.0.0" +dependencies = [ + "anyhow", + "candid 0.9.7", + "canister_methods", + "ic-cdk 0.10.0", + "ic-cdk-macros 0.7.1", + "ic-cdk-timers", + "ic-stable-structures 0.6.0-beta.1", + "ic-wasi-polyfill", + "quickjs-wasm-rs", + "slotmap", +] + +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + +[[package]] +name = "bindgen" +version = "0.64.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 1.0.109", + "which", +] + +[[package]] +name = "binread" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16598dfc8e6578e9b597d9910ba2e73618385dc9f4b1d43dd92c349d6be6418f" +dependencies = [ + "binread_derive", + "lazy_static", + "rustversion", +] + +[[package]] +name = "binread_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" +dependencies = [ + "either", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "candid" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "244005a1917bb7614cd775ca8a5d59efeb5ac74397bb14ba29a19347ebd78591" +dependencies = [ + "anyhow", + "binread", + "byteorder", + "candid_derive 0.5.0", + "codespan-reporting", + "crc32fast", + "data-encoding", + "hex", + "lalrpop 0.19.12", + "lalrpop-util 0.19.12", + "leb128", + "logos 0.12.1", + "num-bigint", + "num-traits", + "num_enum 0.5.11", + "paste", + "pretty 0.10.0", + "serde", + "serde_bytes", + "sha2", + "thiserror", +] + +[[package]] +name = "candid" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f391a0d11d997af68e1a06b5e2ab354079cecb82b6eefb26addb38adf66d351d" +dependencies = [ + "anyhow", + "binread", + "byteorder", + "candid_derive 0.6.3", + "codespan-reporting", + "convert_case", + "crc32fast", + "data-encoding", + "hex", + "lalrpop 0.20.0", + "lalrpop-util 0.20.0", + "leb128", + "logos 0.13.0", + "num-bigint", + "num-traits", + "num_enum 0.6.1", + "paste", + "pretty 0.12.3", + "serde", + "serde_bytes", + "sha2", + "stacker", + "thiserror", +] + +[[package]] +name = "candid_derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f1f4db7c7d04b87b70b3a35c5dc5c2c9dd73cef8bdf6760e2f18a0d45350dd" +dependencies = [ + "lazy_static", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "candid_derive" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "158403ea38fab5904ae47a5d67eb7047650a91681407f5ccbcbcabc4f4ffb489" +dependencies = [ + "lazy_static", + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "canister_methods" +version = "0.0.0" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.37", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ciborium" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" + +[[package]] +name = "ciborium-ll" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clang-sys" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "cpufeatures" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "ena" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1" +dependencies = [ + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "function_name" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1ab577a896d09940b5fe12ec5ae71f9d8211fff62c919c03a3750a9901e98a7" +dependencies = [ + "function_name-proc-macro", +] + +[[package]] +name = "function_name-proc-macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673464e1e314dd67a0fd9544abc99e8eb28d0c7e3b69b033bcff9b2d00b87333" + +[[package]] +name = "futures" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" + +[[package]] +name = "futures-executor" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" + +[[package]] +name = "futures-util" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "951dfc2e32ac02d67c90c0d65bd27009a635dc9b381a2cc7d284ab01e3a0150d" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92445bc9cc14bfa0a3ce56817dc3b5bcc227a168781a356b702410789cec0d10" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75264b2003a3913f118d35c586e535293b3e22e41f074930762929d071e092" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", + "tracing", + "want", +] + +[[package]] +name = "ic-cdk" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +checksum = "1faa7b42964694fb38d7f62172e0d8261381e39ce85b4d6b519929f7cad9b4fb" dependencies = [ - "lazy_static", - "regex", + "candid 0.8.4", + "ic-cdk-macros 0.6.10", + "ic0", + "serde", + "serde_bytes", ] [[package]] -name = "aho-corasick" -version = "1.0.5" +name = "ic-cdk" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "08d4c0b932bf454d5d60e61e13c3c944972fcfd74dc82b9ed5c8b0a75979cf50" dependencies = [ - "memchr", + "candid 0.9.7", + "ic-cdk-macros 0.7.1", + "ic0", + "serde", + "serde_bytes", ] [[package]] -name = "ast_node" -version = "0.9.5" +name = "ic-cdk-macros" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c09c69dffe06d222d072c878c3afe86eee2179806f20503faec97250268b4c24" +checksum = "ebf50458685a0fc6b0e414cdba487610aeb199ac94db52d9fd76270565debee7" dependencies = [ - "pmutil", + "candid 0.8.4", "proc-macro2", "quote", - "swc_macros_common", - "syn 2.0.29", + "serde", + "serde_tokenstream", + "syn 1.0.109", ] [[package]] -name = "autocfg" -version = "1.1.0" +name = "ic-cdk-macros" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "azle-vm-value-derive" -version = "0.0.0" +checksum = "411c0dd4c149132b68e679274d397053332ee29996c6a541075895881916333b" dependencies = [ + "candid 0.9.7", "proc-macro2", "quote", + "serde", + "serde_tokenstream", "syn 1.0.109", ] [[package]] -name = "azle_generate_rearchitecture" -version = "0.0.0" +name = "ic-cdk-timers" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "198e55e4d9e069903fbea1dceae6fd28f7e0b38d5a4e1026ed2c772e1d55f5e0" dependencies = [ - "prettyplease", - "proc-macro2", - "quote", + "futures", + "ic-cdk 0.10.0", + "ic0", "serde", - "serde_json", - "swc_common", - "syn 2.0.29", + "serde_bytes", + "slotmap", ] [[package]] -name = "better_scoped_tls" -version = "0.1.1" +name = "ic-stable-structures" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95dce29e3ceb0e6da3e78b305d95365530f2efd2146ca18590c0ef3aa6038568" + +[[package]] +name = "ic-stable-structures" +version = "0.6.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794edcc9b3fb07bb4aecaa11f093fd45663b4feadb782d68303a2268bc2701de" +checksum = "2fc18a65191884de50fc7f25d550aa55f4f608e9e3b17fbaec9bf290483eb2b8" + +[[package]] +name = "ic-wasi-polyfill" +version = "0.3.10" +source = "git+https://github.com/demergent-labs/ic-wasi-polyfill?rev=f3812b879c096faf930331e76441fadf2ebe6586#f3812b879c096faf930331e76441fadf2ebe6586" dependencies = [ - "scoped-tls", + "function_name", + "ic-cdk 0.8.1", + "ic-stable-structures 0.5.6", + "rand", + "stable-fs", ] [[package]] -name = "bitflags" -version = "1.3.2" +name = "ic0" +version = "0.18.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "16efdbe5d9b0ea368da50aedbf7640a054139569236f1a5249deb5fd9af5a5d5" [[package]] -name = "cfg-if" -version = "1.0.0" +name = "indexmap" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown", +] [[package]] -name = "either" -version = "1.9.0" +name = "is-terminal" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys 0.48.0", +] [[package]] -name = "form_urlencoded" -version = "1.2.0" +name = "itertools" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ - "percent-encoding", + "either", ] [[package]] -name = "from_variant" -version = "0.1.6" +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "lalrpop" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ec5dc38ee19078d84a692b1c41181ff9f94331c76cee66ff0208c770b5e54f" +checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" dependencies = [ - "pmutil", - "proc-macro2", - "swc_macros_common", - "syn 2.0.29", + "ascii-canvas", + "bit-set", + "diff", + "ena", + "is-terminal", + "itertools", + "lalrpop-util 0.19.12", + "petgraph", + "regex", + "regex-syntax 0.6.29", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", ] [[package]] -name = "getrandom" -version = "0.2.10" +name = "lalrpop" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "da4081d44f4611b66c6dd725e6de3169f9f63905421e8626fcb86b6a898998b8" dependencies = [ - "cfg-if", - "libc", - "wasi", + "ascii-canvas", + "bit-set", + "diff", + "ena", + "is-terminal", + "itertools", + "lalrpop-util 0.20.0", + "petgraph", + "pico-args", + "regex", + "regex-syntax 0.7.5", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", ] [[package]] -name = "idna" -version = "0.4.0" +name = "lalrpop-util" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "regex", ] [[package]] -name = "itoa" -version = "1.0.9" +name = "lalrpop-util" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "3f35c735096c0293d313e8f2a641627472b83d01b937177fe76e5e2708d31e0d" +dependencies = [ + "regex", +] [[package]] name = "lazy_static" @@ -143,12 +931,40 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + [[package]] name = "libc" version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" + [[package]] name = "lock_api" version = "0.4.10" @@ -159,18 +975,125 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "logos" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" +dependencies = [ + "logos-derive 0.12.1", +] + +[[package]] +name = "logos" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1" +dependencies = [ + "logos-derive 0.13.0", +] + +[[package]] +name = "logos-codegen" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68" +dependencies = [ + "beef", + "fnv", + "proc-macro2", + "quote", + "regex-syntax 0.6.29", + "syn 2.0.37", +] + +[[package]] +name = "logos-derive" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" +dependencies = [ + "beef", + "fnv", + "proc-macro2", + "quote", + "regex-syntax 0.6.29", + "syn 1.0.109", +] + +[[package]] +name = "logos-derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e" +dependencies = [ + "logos-codegen", +] + [[package]] name = "memchr" version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.45.0", +] + +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "new_debug_unreachable" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -180,6 +1103,7 @@ dependencies = [ "autocfg", "num-integer", "num-traits", + "serde", ] [[package]] @@ -201,12 +1125,98 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" +dependencies = [ + "num_enum_derive 0.5.11", +] + +[[package]] +name = "num_enum" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +dependencies = [ + "num_enum_derive 0.6.1", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "num_enum_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.37", +] + [[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "openssl" +version = "0.10.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" +dependencies = [ + "bitflags 2.4.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -225,25 +1235,31 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.3.5", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] -name = "percent-encoding" -version = "2.3.0" +name = "paste" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] -name = "phf_generator" -version = "0.10.0" +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "petgraph" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ - "phf_shared", - "rand", + "fixedbitset", + "indexmap", ] [[package]] @@ -255,6 +1271,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pico-args" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -262,15 +1284,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] -name = "pmutil" -version = "0.6.1" +name = "pin-utils" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "ppv-lite86" @@ -285,24 +1308,88 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] -name = "prettyplease" -version = "0.2.12" +name = "pretty" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c64d9ba0963cdcea2e1b2230fbae2bab30eb25a174be395c41e764bfb65dd62" +checksum = "ad9940b913ee56ddd94aec2d3cd179dd47068236f42a1a6415ccf9d880ce2a61" dependencies = [ - "proc-macro2", - "syn 2.0.29", + "arrayvec", + "typed-arena", +] + +[[package]] +name = "pretty" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55c4d17d994b637e2f4daf6e5dc5d660d209d5642377d675d7a1c3ab69fa579" +dependencies = [ + "arrayvec", + "typed-arena", + "unicode-width", +] + +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", ] [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + +[[package]] +name = "quickjs-wasm-rs" +version = "1.0.0" +source = "git+https://github.com/ulan/javy.git?branch=ulan/local-changes#5377d60e279e69aa4596bc63b9495805bfaf9258" +dependencies = [ + "anyhow", + "once_cell", + "quickjs-wasm-sys", + "serde", +] + +[[package]] +name = "quickjs-wasm-sys" +version = "1.0.0" +source = "git+https://github.com/ulan/javy.git?branch=ulan/local-changes#5377d60e279e69aa4596bc63b9495805bfaf9258" +dependencies = [ + "anyhow", + "bindgen", + "bytes", + "cc", + "futures-core", + "futures-task", + "futures-util", + "http-body-util", + "hyper", + "mio", + "native-tls", + "openssl-macros", + "tokio", + "tokio-macros", + "tokio-native-tls", + "walkdir", +] + [[package]] name = "quote" version = "1.0.33" @@ -342,13 +1429,33 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall 0.2.16", + "thiserror", ] [[package]] @@ -360,7 +1467,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax", + "regex-syntax 0.7.5", ] [[package]] @@ -371,9 +1478,15 @@ checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.7.5", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.5" @@ -386,6 +1499,25 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "0.38.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.15" @@ -393,10 +1525,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] -name = "scoped-tls" -version = "1.0.1" +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys 0.48.0", +] [[package]] name = "scopeguard" @@ -404,54 +1548,162 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] +[[package]] +name = "serde_bytes" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", ] [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", "serde", ] +[[package]] +name = "serde_tokenstream" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "797ba1d80299b264f3aac68ab5d12e5825a561749db4df7cd7c8083900c5d4e9" +dependencies = [ + "proc-macro2", + "serde", + "syn 1.0.109", +] + +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" + [[package]] name = "siphasher" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "slotmap" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] + [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] -name = "stable_deref_trait" -version = "1.2.0" +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "stable-fs" +version = "0.1.9" +source = "git+https://github.com/wasm-forge/stable-fs?rev=98a42fa9a32e999d5c2eb7ea2852bb1c62cff402#98a42fa9a32e999d5c2eb7ea2852bb1c62cff402" +dependencies = [ + "bitflags 2.4.0", + "ciborium", + "ic-cdk 0.8.1", + "ic-stable-structures 0.5.6", + "serde", + "serde_bytes", +] + +[[package]] +name = "stacker" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" +dependencies = [ + "cc", + "cfg-if", + "libc", + "psm", + "winapi", +] [[package]] name = "string_cache" @@ -464,145 +1716,144 @@ dependencies = [ "parking_lot", "phf_shared", "precomputed-hash", - "serde", ] [[package]] -name = "string_cache_codegen" -version = "0.5.2" +name = "syn" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "phf_generator", - "phf_shared", "proc-macro2", "quote", + "unicode-ident", ] [[package]] -name = "swc_atoms" -version = "0.5.9" +name = "syn" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f54563d7dcba626d4acfe14ed12def7ecc28e004debe3ecd2c3ee07cc47e449" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ - "once_cell", - "rustc-hash", - "serde", - "string_cache", - "string_cache_codegen", - "triomphe", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "swc_common" -version = "0.31.22" +name = "tempfile" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d00f960c667c59c133f30492f4d07f26242fcf988a066d3871e6d3d838d528" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "ast_node", - "better_scoped_tls", "cfg-if", - "either", - "from_variant", - "new_debug_unreachable", - "num-bigint", - "once_cell", - "rustc-hash", - "serde", - "siphasher", - "string_cache", - "swc_atoms", - "swc_eq_ignore_macros", - "swc_visit", - "tracing", - "unicode-width", - "url", + "fastrand", + "redox_syscall 0.3.5", + "rustix", + "windows-sys 0.48.0", ] [[package]] -name = "swc_eq_ignore_macros" -version = "0.1.2" +name = "term" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05a95d367e228d52484c53336991fdcf47b6b553ef835d9159db4ba40efb0ee8" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" dependencies = [ - "pmutil", - "proc-macro2", - "quote", - "syn 2.0.29", + "dirs-next", + "rustversion", + "winapi", ] [[package]] -name = "swc_macros_common" -version = "0.3.8" +name = "termcolor" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a273205ccb09b51fabe88c49f3b34c5a4631c4c00a16ae20e03111d6a42e832" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ - "pmutil", - "proc-macro2", - "quote", - "syn 2.0.29", + "winapi-util", ] [[package]] -name = "swc_visit" -version = "0.5.7" +name = "thiserror" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87c337fbb2d191bf371173dea6a957f01899adb8f189c6c31b122a6cfc98fc3" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" dependencies = [ - "either", - "swc_visit_macros", + "thiserror-impl", ] [[package]] -name = "swc_visit_macros" -version = "0.5.8" +name = "thiserror-impl" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f322730fb82f3930a450ac24de8c98523af7d34ab8cb2f46bcb405839891a99" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ - "Inflector", - "pmutil", "proc-macro2", "quote", - "swc_macros_common", - "syn 2.0.29", + "syn 2.0.37", ] [[package]] -name = "syn" -version = "1.0.109" +name = "tiny-keccak" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "crunchy", ] [[package]] -name = "syn" -version = "2.0.29" +name = "tokio" +version = "1.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +dependencies = [ + "autocfg", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.45.0", +] + +[[package]] +name = "tokio-macros" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ "proc-macro2", "quote", - "unicode-ident", + "syn 1.0.109", ] [[package]] -name = "tinyvec" -version = "1.6.0" +name = "tokio-native-tls" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ - "tinyvec_macros", + "native-tls", + "tokio", ] [[package]] -name = "tinyvec_macros" -version = "0.1.1" +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" + +[[package]] +name = "toml_edit" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] [[package]] name = "tracing" @@ -612,21 +1863,9 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] - [[package]] name = "tracing-core" version = "0.1.31" @@ -637,20 +1876,22 @@ dependencies = [ ] [[package]] -name = "triomphe" -version = "0.1.9" +name = "try-lock" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee8098afad3fb0c54a9007aab6804558410503ad676d4633f9c2559a00ac0f" -dependencies = [ - "serde", - "stable_deref_trait", -] +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + +[[package]] +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" [[package]] -name = "unicode-bidi" -version = "0.3.13" +name = "typenum" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" @@ -659,13 +1900,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] -name = "unicode-normalization" -version = "0.1.22" +name = "unicode-segmentation" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" @@ -674,14 +1912,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] -name = "url" -version = "2.4.1" +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", + "try-lock", ] [[package]] @@ -690,59 +1954,186 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 06944e3776..45506db323 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,6 @@ members = [ # "src/compiler/typescript_to_rust/azle_generate", "src/compiler/typescript_to_rust/azle_generate_rearchitecture", - "src/compiler/typescript_to_rust/azle_vm_value_derive" + "src/compiler/typescript_to_rust/canister_methods" + # "src/compiler/typescript_to_rust/azle_vm_value_derive" ] diff --git a/examples/query/Cargo.lock b/examples/query/Cargo.lock deleted file mode 100644 index 666a952a04..0000000000 --- a/examples/query/Cargo.lock +++ /dev/null @@ -1,950 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - -[[package]] -name = "anyhow" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "ascii-canvas" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" -dependencies = [ - "term", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "base32" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" - -[[package]] -name = "beef" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" - -[[package]] -name = "binread" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16598dfc8e6578e9b597d9910ba2e73618385dc9f4b1d43dd92c349d6be6418f" -dependencies = [ - "binread_derive", - "lazy_static", - "rustversion", -] - -[[package]] -name = "binread_derive" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" -dependencies = [ - "either", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "bit-set" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "candid" -version = "0.7.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba9e536514a3c655568e23e36e68cbef20ee6595f641719ade03a849a13ed0ac" -dependencies = [ - "anyhow", - "binread", - "byteorder", - "candid_derive", - "codespan-reporting", - "hex", - "ic-types", - "lalrpop", - "lalrpop-util", - "leb128", - "logos", - "num-bigint", - "num-traits", - "num_enum", - "paste", - "pretty", - "serde", - "serde_bytes", - "thiserror", -] - -[[package]] -name = "candid_derive" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e02c03c4d547674a3f3f3109538fb49871fbe636216daa019f06a62faca9061" -dependencies = [ - "lazy_static", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - -[[package]] -name = "cpufeatures" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "either" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" - -[[package]] -name = "ena" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" -dependencies = [ - "log", -] - -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "generic-array" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "ic-cdk" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e471fa2e2464d4f9d676b81d33ae0d1cd190981166c53bbe4d536f13da281fc6" -dependencies = [ - "candid", - "cfg-if", - "serde", -] - -[[package]] -name = "ic-cdk-macros" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb6d2c14db28f427154a52088077419edf1848e2bbd0f527dee3150e592a0863" -dependencies = [ - "candid", - "ic-cdk", - "proc-macro2", - "quote", - "serde", - "serde_tokenstream", - "syn", -] - -[[package]] -name = "ic-types" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e78ec6f58886cdc252d6f912dc794211bd6bbc39ddc9dcda434b2dc16c335b3" -dependencies = [ - "base32", - "crc32fast", - "hex", - "serde", - "serde_bytes", - "sha2", - "thiserror", -] - -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "lalrpop" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" -dependencies = [ - "ascii-canvas", - "atty", - "bit-set", - "diff", - "ena", - "itertools", - "lalrpop-util", - "petgraph", - "pico-args", - "regex", - "regex-syntax", - "string_cache", - "term", - "tiny-keccak", - "unicode-xid", -] - -[[package]] -name = "lalrpop-util" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" -dependencies = [ - "regex", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "libc" -version = "0.2.126" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" - -[[package]] -name = "lock_api" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "logos" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" -dependencies = [ - "logos-derive", -] - -[[package]] -name = "logos-derive" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" -dependencies = [ - "beef", - "fnv", - "proc-macro2", - "quote", - "regex-syntax", - "syn", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "new_debug_unreachable" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" - -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_enum" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "once_cell" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" - -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys", -] - -[[package]] -name = "paste" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" - -[[package]] -name = "petgraph" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" -dependencies = [ - "fixedbitset", - "indexmap", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pico-args" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - -[[package]] -name = "pretty" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9940b913ee56ddd94aec2d3cd179dd47068236f42a1a6415ccf9d880ce2a61" -dependencies = [ - "arrayvec", - "typed-arena", -] - -[[package]] -name = "proc-macro-crate" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" -dependencies = [ - "thiserror", - "toml", -] - -[[package]] -name = "proc-macro2" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - -[[package]] -name = "regex" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" - -[[package]] -name = "rust" -version = "0.0.0" -dependencies = [ - "ic-cdk", - "ic-cdk-macros", -] - -[[package]] -name = "rustversion" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0a5f7c728f5d284929a1cccb5bc19884422bfe6ef4d6c409da2c41838983fcf" - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "serde" -version = "1.0.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_bytes" -version = "0.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_tokenstream" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6deb15c3a535e81438110111d90168d91721652f502abb147f31cde129f683d" -dependencies = [ - "proc-macro2", - "serde", - "syn", -] - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer", - "cfg-if", - "cpufeatures", - "digest", - "opaque-debug", -] - -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - -[[package]] -name = "smallvec" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" - -[[package]] -name = "string_cache" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" -dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared", - "precomputed-hash", -] - -[[package]] -name = "syn" -version = "1.0.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "thiserror" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "typed-arena" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" - -[[package]] -name = "typenum" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" - -[[package]] -name = "unicode-ident" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" - -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] -name = "unicode-xid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" diff --git a/examples/query/Cargo.toml b/examples/query/Cargo.toml deleted file mode 100644 index 4513438de5..0000000000 --- a/examples/query/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[workspace] -members = [ - "canisters/rust", -] - -[profile.release] -lto = true -opt-level = 'z' -codegen-units = 1 diff --git a/examples/query/dfx.json b/examples/query/dfx.json index c10b7eb79d..25b41e31d5 100644 --- a/examples/query/dfx.json +++ b/examples/query/dfx.json @@ -6,7 +6,8 @@ "root": "src", "ts": "src/index.ts", "candid": "src/index.did", - "wasm": ".azle/query/query.wasm.gz", + "wasm": ".azle/query/query.wasm", + "gzip": true, "declarations": { "output": "test/dfx_generated/query", "node_compatibility": true diff --git a/src/compiler/compile_rust_code.ts b/src/compiler/compile_rust_code.ts index a503f85607..7c3b36b8a2 100644 --- a/src/compiler/compile_rust_code.ts +++ b/src/compiler/compile_rust_code.ts @@ -14,7 +14,7 @@ export async function compileRustCode( ) { await time(`[2/2] 🚧 Building Wasm binary...`, 'inline', async () => { execSync( - `cd ${canisterPath} && ${GLOBAL_AZLE_RUST_BIN_DIR}/cargo build --target wasm32-wasi --package ${canisterName} --release`, + `cd ${canisterPath} && ${GLOBAL_AZLE_RUST_BIN_DIR}/cargo build --target wasm32-wasi --package azle_generate_rearchitecture --release`, { stdio, env: { @@ -28,12 +28,12 @@ export async function compileRustCode( } ); - const wasmTargetFilePath = `${GLOBAL_AZLE_TARGET_DIR}/wasm32-wasi/release/${canisterName}.wasm`; + const wasmTargetFilePath = `${GLOBAL_AZLE_TARGET_DIR}/wasm32-wasi/release/azle_generate_rearchitecture.wasm`; execSync(`cp ${wasmTargetFilePath} ${canisterPath}`); execSync( - `cd ${canisterPath} && ${GLOBAL_AZLE_RUST_BIN_DIR}/wasi2ic ${canisterName}.wasm ${canisterName}.wasm`, + `cd ${canisterPath} && ${GLOBAL_AZLE_RUST_BIN_DIR}/wasi2ic azle_generate_rearchitecture.wasm ${canisterName}.wasm`, { stdio, env: { diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/Cargo.toml b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/Cargo.toml index 74ad67264b..38b621612c 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/Cargo.toml +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/Cargo.toml @@ -3,11 +3,20 @@ name = "azle_generate_rearchitecture" version = "0.0.0" edition = "2018" +[lib] +crate-type = ["cdylib"] + [dependencies] -prettyplease = "0.2.12" -proc-macro2 = "1.0.66" -quote = "1.0.33" -serde = "1.0.183" -serde_json = "1.0.105" -swc_common = "0.31.21" # TODO why can't we get rid of this? -syn = "2.0.29" +anyhow = "1.0.75" +candid = { version = "0.9.1", features = ["parser"] } +ic-cdk-timers = "0.4.0" +ic-stable-structures = "0.6.0-beta.1" +canister_methods = { path = "../canister_methods" } +quickjs-wasm-rs = { git = "https://github.com/ulan/javy.git", branch = "ulan/local-changes" } +slotmap = "=1.0.6" +ic-cdk = "0.10.0" +ic-cdk-macros = "0.7.0" +# TODO for now we must turn on the transient feature (no stable storage file system) or we can't generate the Candid file +ic-wasi-polyfill = { git = "https://github.com/demergent-labs/ic-wasi-polyfill", rev = "f3812b879c096faf930331e76441fadf2ebe6586", features = [ + "transient", +] } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/accept_message.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/accept_message.rs index bfa9ab4336..0742df03ed 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/accept_message.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/accept_message.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn accept_message<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - ic_cdk::api::call::accept_message(); - context.undefined_value() - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + ic_cdk::api::call::accept_message(); + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw.rs index be74ca1f96..dbcb09e046 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn arg_data_raw<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let arg_data_raw_js_value: JSValue = ic_cdk::api::call::arg_data_raw().into(); - to_qjs_value(&context, &arg_data_raw_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let arg_data_raw_js_value: JSValue = ic_cdk::api::call::arg_data_raw().into(); + to_qjs_value(&context, &arg_data_raw_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw_size.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw_size.rs index ef4bcf960e..17dd77ff57 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw_size.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/arg_data_raw_size.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn arg_data_raw_size<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let arg_data_raw_size_js_value: JSValue = ic_cdk::api::call::arg_data_raw_size().into(); - to_qjs_value(&context, &arg_data_raw_size_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let arg_data_raw_size_js_value: JSValue = ic_cdk::api::call::arg_data_raw_size().into(); + to_qjs_value(&context, &arg_data_raw_size_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw.rs index 83aa6a7b35..125dc37941 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw.rs @@ -1,64 +1,87 @@ // TODO basically copied into call_raw128 +use std::convert::TryInto; -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn call_raw<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let promise_id: String = args.get(0).expect("call_raw promise_id argument is undefined").to_js_value()?.try_into()?; - let canister_id_bytes: Vec = args.get(1).expect("call_raw canister_id_bytes is undefined").to_js_value()?.try_into()?; - let canister_id = candid::Principal::from_slice(&canister_id_bytes); - let method: String = args.get(2).expect("call_raw method argument is undefined").to_js_value()?.try_into()?; - let args_raw: Vec = args.get(3).expect("call_raw args_raw argument is undefined").to_js_value()?.try_into()?; - let payment_candid_bytes: Vec = args.get(4).expect("call_raw payment_candid_bytes argument is undefined").to_js_value()?.try_into()?; - let payment: u64 = candid::decode_one(&payment_candid_bytes)?; +use crate::CONTEXT; - ic_cdk::spawn(async move { - let call_result = ic_cdk::api::call::call_raw(canister_id, &method, &args_raw, payment).await; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let promise_id: String = args + .get(0) + .expect("call_raw promise_id argument is undefined") + .to_js_value()? + .try_into()?; + let canister_id_bytes: Vec = args + .get(1) + .expect("call_raw canister_id_bytes is undefined") + .to_js_value()? + .try_into()?; + let canister_id = candid::Principal::from_slice(&canister_id_bytes); + let method: String = args + .get(2) + .expect("call_raw method argument is undefined") + .to_js_value()? + .try_into()?; + let args_raw: Vec = args + .get(3) + .expect("call_raw args_raw argument is undefined") + .to_js_value()? + .try_into()?; + let payment_candid_bytes: Vec = args + .get(4) + .expect("call_raw payment_candid_bytes argument is undefined") + .to_js_value()? + .try_into()?; + let payment: u64 = candid::decode_one(&payment_candid_bytes)?; - let (should_resolve, js_value) = match call_result { - Ok(candid_bytes) => { - let candid_bytes_js_value: JSValue = candid_bytes.into(); - (true, candid_bytes_js_value) - }, - Err(err) => { - let err_js_value: JSValue = format!( - "Rejection code {rejection_code}, {error_message}", - rejection_code = (err.0 as i32).to_string(), - error_message = err.1 - ).into(); + ic_cdk::spawn(async move { + let call_result = + ic_cdk::api::call::call_raw(canister_id, &method, &args_raw, payment).await; - (false, err_js_value) - } - }; + let (should_resolve, js_value) = match call_result { + Ok(candid_bytes) => { + let candid_bytes_js_value: JSValue = candid_bytes.into(); + (true, candid_bytes_js_value) + } + Err(err) => { + let err_js_value: JSValue = format!( + "Rejection code {rejection_code}, {error_message}", + rejection_code = (err.0 as i32).to_string(), + error_message = err.1 + ) + .into(); - CONTEXT.with(|context| { - let mut context = context.borrow_mut(); - let context = context.as_mut().unwrap(); + (false, err_js_value) + } + }; - let global = context.global_object().unwrap(); + CONTEXT.with(|context| { + let mut context = context.borrow_mut(); + let context = context.as_mut().unwrap(); - let js_value_ref = to_qjs_value(&context, &js_value).unwrap(); + let global = context.global_object().unwrap(); - if should_resolve { - let resolve = global.get_property(format!("_resolve_{promise_id}").as_str()).unwrap(); - resolve.call(&resolve, &[js_value_ref]).unwrap(); - } - else { - let reject = global.get_property(format!("_reject_{promise_id}").as_str()).unwrap(); - reject.call(&reject, &[js_value_ref]).unwrap(); - } + let js_value_ref = to_qjs_value(&context, &js_value).unwrap(); - context.execute_pending().unwrap(); - }); - }); + if should_resolve { + let resolve = global + .get_property(format!("_resolve_{promise_id}").as_str()) + .unwrap(); + resolve.call(&resolve, &[js_value_ref]).unwrap(); + } else { + let reject = global + .get_property(format!("_reject_{promise_id}").as_str()) + .unwrap(); + reject.call(&reject, &[js_value_ref]).unwrap(); + } - context.undefined_value() - } - } + context.execute_pending().unwrap(); + }); + }); + + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw128.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw128.rs index b98cbe4f55..adaf3b7e7b 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw128.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/call_raw128.rs @@ -1,64 +1,87 @@ // TODO basically copied from call_raw +use std::convert::TryInto; -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn call_raw128<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let promise_id: String = args.get(0).expect("call_raw promise_id argument is undefined").to_js_value()?.try_into()?; - let canister_id_bytes: Vec = args.get(1).expect("call_raw canister_id_bytes is undefined").to_js_value()?.try_into()?; - let canister_id = candid::Principal::from_slice(&canister_id_bytes); - let method: String = args.get(2).expect("call_raw method argument is undefined").to_js_value()?.try_into()?; - let args_raw: Vec = args.get(3).expect("call_raw args_raw argument is undefined").to_js_value()?.try_into()?; - let payment_candid_bytes: Vec = args.get(4).expect("call_raw payment_candid_bytes argument is undefined").to_js_value()?.try_into()?; - let payment: u128 = candid::decode_one(&payment_candid_bytes)?; +use crate::CONTEXT; - ic_cdk::spawn(async move { - let call_result = ic_cdk::api::call::call_raw128(canister_id, &method, &args_raw, payment).await; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let promise_id: String = args + .get(0) + .expect("call_raw promise_id argument is undefined") + .to_js_value()? + .try_into()?; + let canister_id_bytes: Vec = args + .get(1) + .expect("call_raw canister_id_bytes is undefined") + .to_js_value()? + .try_into()?; + let canister_id = candid::Principal::from_slice(&canister_id_bytes); + let method: String = args + .get(2) + .expect("call_raw method argument is undefined") + .to_js_value()? + .try_into()?; + let args_raw: Vec = args + .get(3) + .expect("call_raw args_raw argument is undefined") + .to_js_value()? + .try_into()?; + let payment_candid_bytes: Vec = args + .get(4) + .expect("call_raw payment_candid_bytes argument is undefined") + .to_js_value()? + .try_into()?; + let payment: u128 = candid::decode_one(&payment_candid_bytes)?; - let (should_resolve, js_value) = match call_result { - Ok(candid_bytes) => { - let candid_bytes_js_value: JSValue = candid_bytes.into(); - (true, candid_bytes_js_value) - }, - Err(err) => { - let err_js_value: JSValue = format!( - "Rejection code {rejection_code}, {error_message}", - rejection_code = (err.0 as i32).to_string(), - error_message = err.1 - ).into(); + ic_cdk::spawn(async move { + let call_result = + ic_cdk::api::call::call_raw128(canister_id, &method, &args_raw, payment).await; - (false, err_js_value) - } - }; + let (should_resolve, js_value) = match call_result { + Ok(candid_bytes) => { + let candid_bytes_js_value: JSValue = candid_bytes.into(); + (true, candid_bytes_js_value) + } + Err(err) => { + let err_js_value: JSValue = format!( + "Rejection code {rejection_code}, {error_message}", + rejection_code = (err.0 as i32).to_string(), + error_message = err.1 + ) + .into(); - CONTEXT.with(|context| { - let mut context = context.borrow_mut(); - let context = context.as_mut().unwrap(); + (false, err_js_value) + } + }; - let global = context.global_object().unwrap(); + CONTEXT.with(|context| { + let mut context = context.borrow_mut(); + let context = context.as_mut().unwrap(); - let js_value_ref = to_qjs_value(&context, &js_value).unwrap(); + let global = context.global_object().unwrap(); - if should_resolve { - let resolve = global.get_property(format!("_resolve_{promise_id}").as_str()).unwrap(); - resolve.call(&resolve, &[js_value_ref]).unwrap(); - } - else { - let reject = global.get_property(format!("_reject_{promise_id}").as_str()).unwrap(); - reject.call(&reject, &[js_value_ref]).unwrap(); - } + let js_value_ref = to_qjs_value(&context, &js_value).unwrap(); - context.execute_pending().unwrap(); - }); - }); + if should_resolve { + let resolve = global + .get_property(format!("_resolve_{promise_id}").as_str()) + .unwrap(); + resolve.call(&resolve, &[js_value_ref]).unwrap(); + } else { + let reject = global + .get_property(format!("_reject_{promise_id}").as_str()) + .unwrap(); + reject.call(&reject, &[js_value_ref]).unwrap(); + } - context.undefined_value() - } - } + context.execute_pending().unwrap(); + }); + }); + + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/caller.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/caller.rs index 02aef07f3f..f94d56ff34 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/caller.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/caller.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn caller<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let caller_js_value = ic_cdk::api::caller().as_slice().into(); - to_qjs_value(&context, &caller_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let caller_js_value = ic_cdk::api::caller().as_slice().into(); + to_qjs_value(&context, &caller_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_decode.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_decode.rs index b2fd76af98..bbc1cf7d04 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_decode.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_decode.rs @@ -1,20 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn candid_decode<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let candid_encoded: Vec = _args.get(0).expect("candidDecode must have at least one argument").to_js_value()?.try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let candid_args: candid::IDLArgs = candid::IDLArgs::from_bytes(&candid_encoded)?; - let candid_string = candid_args.to_string(); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let candid_encoded: Vec = _args + .get(0) + .expect("candidDecode must have at least one argument") + .to_js_value()? + .try_into()?; - let candid_string_js_value: JSValue = candid_string.into(); - to_qjs_value(&context, &candid_string_js_value) - } - } + let candid_args: candid::IDLArgs = candid::IDLArgs::from_bytes(&candid_encoded)?; + let candid_string = candid_args.to_string(); + + let candid_string_js_value: JSValue = candid_string.into(); + to_qjs_value(&context, &candid_string_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_encode.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_encode.rs index d8bf709dcd..868569f7ef 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_encode.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/candid_encode.rs @@ -1,20 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn candid_encode<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let candid_string: String = _args.get(0).expect("candidEncode must have at least one argument").to_js_value()?.try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let candid_args: candid::IDLArgs = candid_string.parse()?; - let candid_encoded: Vec = candid_args.to_bytes()?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let candid_string: String = _args + .get(0) + .expect("candidEncode must have at least one argument") + .to_js_value()? + .try_into()?; - let candid_encoded_js_value: JSValue = candid_encoded.into(); - to_qjs_value(&context, &candid_encoded_js_value) - } - } + let candid_args: candid::IDLArgs = candid_string.parse()?; + let candid_encoded: Vec = candid_args.to_bytes()?; + + let candid_encoded_js_value: JSValue = candid_encoded.into(); + to_qjs_value(&context, &candid_encoded_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance.rs index 66a309a380..7c41017d55 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance.rs @@ -1,15 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn canister_balance<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let canister_balance_js_value: JSValue = candid::encode_one(ic_cdk::api::canister_balance())?.into(); - to_qjs_value(&context, &canister_balance_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let canister_balance_js_value: JSValue = + candid::encode_one(ic_cdk::api::canister_balance())?.into(); + to_qjs_value(&context, &canister_balance_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance128.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance128.rs index e4a1d1d3e9..0531fbaa29 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance128.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_balance128.rs @@ -1,15 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn canister_balance128<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let canister_balance128_js_value: JSValue = candid::encode_one(ic_cdk::api::canister_balance128())?.into(); - to_qjs_value(&context, &canister_balance128_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let canister_balance128_js_value: JSValue = + candid::encode_one(ic_cdk::api::canister_balance128())?.into(); + to_qjs_value(&context, &canister_balance128_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_version.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_version.rs index 3e010c98c9..1c2817b15e 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_version.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/canister_version.rs @@ -1,15 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn canister_version<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let canister_version_js_value: JSValue = candid::encode_one(ic_cdk::api::canister_version())?.into(); - to_qjs_value(&context, &canister_version_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let canister_version_js_value: JSValue = + candid::encode_one(ic_cdk::api::canister_version())?.into(); + to_qjs_value(&context, &canister_version_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/clear_timer.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/clear_timer.rs index f87a89bb6d..46ef273e64 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/clear_timer.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/clear_timer.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn clear_timer<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let timer_id_vec_u8: Vec = args - .get(0) - .expect("clearTimer must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - let timer_id_u64: u64 = candid::decode_one(&timer_id_vec_u8)?; - let timer_id = ic_cdk_timers::TimerId::from(slotmap::KeyData::from_ffi(timer_id_u64)); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let timer_id_vec_u8: Vec = args + .get(0) + .expect("clearTimer must have one argument") + .to_js_value()? + .try_into()?; - ic_cdk_timers::clear_timer(timer_id); - context.undefined_value() - } - } + let timer_id_u64: u64 = candid::decode_one(&timer_id_vec_u8)?; + let timer_id = ic_cdk_timers::TimerId::from(slotmap::KeyData::from_ffi(timer_id_u64)); + + ic_cdk_timers::clear_timer(timer_id); + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/data_certificate.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/data_certificate.rs index 323b9c1809..40ead5b248 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/data_certificate.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/data_certificate.rs @@ -1,22 +1,15 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn data_certificate<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - match ic_cdk::api::data_certificate() { - Some(data_certificate_vec_u8) => { - let data_certificate_js_value: JSValue = data_certificate_vec_u8.into(); - to_qjs_value(&context, &data_certificate_js_value) - }, - None => { - context.undefined_value() - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + match ic_cdk::api::data_certificate() { + Some(data_certificate_vec_u8) => { + let data_certificate_js_value: JSValue = data_certificate_vec_u8.into(); + to_qjs_value(&context, &data_certificate_js_value) } + None => context.undefined_value(), } } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/id.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/id.rs index ccf25deaaa..9740c8ad96 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/id.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/id.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn id<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let canister_id = ic_cdk::id().to_text(); - context.value_from_str(&canister_id) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let canister_id = ic_cdk::id().to_text(); + context.value_from_str(&canister_id) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/instruction_counter.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/instruction_counter.rs index c1df4a3b49..d7f862c93a 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/instruction_counter.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/instruction_counter.rs @@ -1,15 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn instruction_counter<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let instruction_counter_js_value: JSValue = candid::encode_one(ic_cdk::api::instruction_counter())?.into(); - to_qjs_value(&context, &instruction_counter_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let instruction_counter_js_value: JSValue = + candid::encode_one(ic_cdk::api::instruction_counter())?.into(); + to_qjs_value(&context, &instruction_counter_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/is_controller.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/is_controller.rs index 6e9ee07e98..1519d863c5 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/is_controller.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/is_controller.rs @@ -1,23 +1,20 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn is_controller<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let principal_bytes: Vec = args - .get(0) - .expect("isController must have at least one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let principal = candid::Principal::from_slice(&principal_bytes); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let principal_bytes: Vec = args + .get(0) + .expect("isController must have at least one argument") + .to_js_value()? + .try_into()?; - let is_controller_js_value: JSValue = ic_cdk::api::is_controller(&principal).into(); - to_qjs_value(&context, &is_controller_js_value) - } - } + let principal = candid::Principal::from_slice(&principal_bytes); + + let is_controller_js_value: JSValue = ic_cdk::api::is_controller(&principal).into(); + to_qjs_value(&context, &is_controller_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/method_name.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/method_name.rs index 7caa4e0f70..50a55c321e 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/method_name.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/method_name.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn method_name<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let method_name_js_value: JSValue = ic_cdk::api::call::method_name().into(); - to_qjs_value(&context, &method_name_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let method_name_js_value: JSValue = ic_cdk::api::call::method_name().into(); + to_qjs_value(&context, &method_name_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/mod.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/mod.rs index bd311084fe..7ea91051fd 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/mod.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/mod.rs @@ -1,6 +1,3 @@ -use proc_macro2::TokenStream; -use quote::quote; - mod accept_message; mod arg_data_raw; mod arg_data_raw_size; @@ -56,176 +53,368 @@ mod stable_write; mod time; mod trap; -pub fn generate() -> TokenStream { - let accept_message = accept_message::generate(); - let arg_data_raw_size = arg_data_raw_size::generate(); - let arg_data_raw = arg_data_raw::generate(); - let call_raw = call_raw::generate(); - let call_raw128 = call_raw128::generate(); - let caller = caller::generate(); - let candid_decode = candid_decode::generate(); - let candid_encode = candid_encode::generate(); - let canister_balance = canister_balance::generate(); - let canister_balance128 = canister_balance128::generate(); - let canister_version = canister_version::generate(); - let clear_timer = clear_timer::generate(); - let data_certificate = data_certificate::generate(); - let id = id::generate(); - let instruction_counter = instruction_counter::generate(); - let is_controller = is_controller::generate(); - let method_name = method_name::generate(); - let msg_cycles_accept = msg_cycles_accept::generate(); - let msg_cycles_accept128 = msg_cycles_accept128::generate(); - let msg_cycles_available = msg_cycles_available::generate(); - let msg_cycles_available128 = msg_cycles_available128::generate(); - let msg_cycles_refunded = msg_cycles_refunded::generate(); - let msg_cycles_refunded128 = msg_cycles_refunded128::generate(); - let notify_raw = notify_raw::generate(); - let performance_counter = performance_counter::generate(); - let print = print::generate(); - let reject = reject::generate(); - let reject_code = reject_code::generate(); - let reject_message = reject_message::generate(); - let reply_raw = reply_raw::generate(); - let set_certified_data = set_certified_data::generate(); - let set_timer = set_timer::generate(); - let set_timer_interval = set_timer_interval::generate(); - let stable_bytes = stable_bytes::generate(); - let stable_grow = stable_grow::generate(); - let stable_read = stable_read::generate(); - let stable_size = stable_size::generate(); - let stable_write = stable_write::generate(); - let stable64_grow = stable64_grow::generate(); - let stable64_read = stable64_read::generate(); - let stable64_size = stable64_size::generate(); - let stable64_write = stable64_write::generate(); - let stable_b_tree_map_contains_key = stable_b_tree_map_contains_key::generate(); - let stable_b_tree_map_get = stable_b_tree_map_get::generate(); - let stable_b_tree_map_init = stable_b_tree_map_init::generate(); - let stable_b_tree_map_insert = stable_b_tree_map_insert::generate(); - let stable_b_tree_map_is_empty = stable_b_tree_map_is_empty::generate(); - let stable_b_tree_map_items = stable_b_tree_map_items::generate(); - let stable_b_tree_map_keys = stable_b_tree_map_keys::generate(); - let stable_b_tree_map_len = stable_b_tree_map_len::generate(); - let stable_b_tree_map_remove = stable_b_tree_map_remove::generate(); - let stable_b_tree_map_values = stable_b_tree_map_values::generate(); - let time = time::generate(); - let trap = trap::generate(); - - quote! { - #accept_message - #arg_data_raw_size - #arg_data_raw - #call_raw - #call_raw128 - #caller - #candid_decode - #candid_encode - #canister_balance - #canister_balance128 - #canister_version - #clear_timer - #data_certificate - #id - #instruction_counter - #is_controller - #method_name - #msg_cycles_accept - #msg_cycles_accept128 - #msg_cycles_available - #msg_cycles_available128 - #msg_cycles_refunded - #msg_cycles_refunded128 - #notify_raw - #performance_counter - #print - #reject - #reject_code - #reject_message - #reply_raw - #set_certified_data - #set_timer - #set_timer_interval - #stable_bytes - #stable_grow - #stable_read - #stable_size - #stable_write - #stable64_grow - #stable64_read - #stable64_size - #stable64_write - #stable_b_tree_map_contains_key - #stable_b_tree_map_get - #stable_b_tree_map_init - #stable_b_tree_map_insert - #stable_b_tree_map_is_empty - #stable_b_tree_map_items - #stable_b_tree_map_keys - #stable_b_tree_map_len - #stable_b_tree_map_remove - #stable_b_tree_map_values - #time - #trap +use quickjs_wasm_rs::JSContextRef; - let ic = context.object_value().unwrap(); +#[allow(unused)] +pub fn register(context: &JSContextRef) { + let ic = context.object_value().unwrap(); - ic.set_property("acceptMessage", context.wrap_callback2(accept_message).unwrap()).unwrap(); - ic.set_property("argDataRawSize", context.wrap_callback2(arg_data_raw_size).unwrap()).unwrap(); - ic.set_property("argDataRaw", context.wrap_callback2(arg_data_raw).unwrap()).unwrap(); - ic.set_property("callRaw", context.wrap_callback2(call_raw).unwrap()).unwrap(); - ic.set_property("callRaw128", context.wrap_callback2(call_raw128).unwrap()).unwrap(); - ic.set_property("caller", context.wrap_callback2(caller).unwrap()).unwrap(); - ic.set_property("candidDecode", context.wrap_callback2(candid_decode).unwrap()).unwrap(); - ic.set_property("candidEncode", context.wrap_callback2(candid_encode).unwrap()).unwrap(); - ic.set_property("canisterBalance", context.wrap_callback2(canister_balance).unwrap()).unwrap(); - ic.set_property("canisterBalance128", context.wrap_callback2(canister_balance128).unwrap()).unwrap(); - ic.set_property("canisterVersion", context.wrap_callback2(canister_version).unwrap()).unwrap(); - ic.set_property("clearTimer", context.wrap_callback2(clear_timer).unwrap()).unwrap(); - ic.set_property("dataCertificate", context.wrap_callback2(data_certificate).unwrap()).unwrap(); - ic.set_property("id", context.wrap_callback2(id).unwrap()).unwrap(); - ic.set_property("instructionCounter", context.wrap_callback2(instruction_counter).unwrap()).unwrap(); - ic.set_property("isController", context.wrap_callback2(is_controller).unwrap()).unwrap(); - ic.set_property("methodName", context.wrap_callback2(method_name).unwrap()).unwrap(); - ic.set_property("msgCyclesAccept", context.wrap_callback2(msg_cycles_accept).unwrap()).unwrap(); - ic.set_property("msgCyclesAccept128", context.wrap_callback2(msg_cycles_accept128).unwrap()).unwrap(); - ic.set_property("msgCyclesAvailable", context.wrap_callback2(msg_cycles_available).unwrap()).unwrap(); - ic.set_property("msgCyclesAvailable128", context.wrap_callback2(msg_cycles_available128).unwrap()).unwrap(); - ic.set_property("msgCyclesRefunded", context.wrap_callback2(msg_cycles_refunded).unwrap()).unwrap(); - ic.set_property("msgCyclesRefunded128", context.wrap_callback2(msg_cycles_refunded128).unwrap()).unwrap(); - ic.set_property("notifyRaw", context.wrap_callback2(notify_raw).unwrap()).unwrap(); - ic.set_property("performanceCounter", context.wrap_callback2(performance_counter).unwrap()).unwrap(); - ic.set_property("print", context.wrap_callback2(print).unwrap()).unwrap(); - ic.set_property("reject", context.wrap_callback2(reject).unwrap()).unwrap(); - ic.set_property("rejectCode", context.wrap_callback2(reject_code).unwrap()).unwrap(); - ic.set_property("rejectMessage", context.wrap_callback2(reject_message).unwrap()).unwrap(); - ic.set_property("replyRaw", context.wrap_callback2(reply_raw).unwrap()).unwrap(); - ic.set_property("setCertifiedData", context.wrap_callback2(set_certified_data).unwrap()).unwrap(); - ic.set_property("setTimer", context.wrap_callback2(set_timer).unwrap()).unwrap(); - ic.set_property("setTimerInterval", context.wrap_callback2(set_timer_interval).unwrap()).unwrap(); - ic.set_property("stable64Grow", context.wrap_callback2(stable64_grow).unwrap()).unwrap(); - ic.set_property("stable64Read", context.wrap_callback2(stable64_read).unwrap()).unwrap(); - ic.set_property("stable64Size", context.wrap_callback2(stable64_size).unwrap()).unwrap(); - ic.set_property("stable64Write", context.wrap_callback2(stable64_write).unwrap()).unwrap(); - ic.set_property("stableBytes", context.wrap_callback2(stable_bytes).unwrap()).unwrap(); - ic.set_property("stableGrow", context.wrap_callback2(stable_grow).unwrap()).unwrap(); - ic.set_property("stableRead", context.wrap_callback2(stable_read).unwrap()).unwrap(); - ic.set_property("stableSize", context.wrap_callback2(stable_size).unwrap()).unwrap(); - ic.set_property("stableWrite", context.wrap_callback2(stable_write).unwrap()).unwrap(); - ic.set_property("stableBTreeMapContainsKey", context.wrap_callback2(stable_b_tree_map_contains_key).unwrap()).unwrap(); - ic.set_property("stableBTreeMapGet", context.wrap_callback2(stable_b_tree_map_get).unwrap()).unwrap(); - ic.set_property("stableBTreeMapInit", context.wrap_callback2(stable_b_tree_map_init).unwrap()).unwrap(); - ic.set_property("stableBTreeMapInsert", context.wrap_callback2(stable_b_tree_map_insert).unwrap()).unwrap(); - ic.set_property("stableBTreeMapIsEmpty", context.wrap_callback2(stable_b_tree_map_is_empty).unwrap()).unwrap(); - ic.set_property("stableBTreeMapItems", context.wrap_callback2(stable_b_tree_map_items).unwrap()).unwrap(); - ic.set_property("stableBTreeMapKeys", context.wrap_callback2(stable_b_tree_map_keys).unwrap()).unwrap(); - ic.set_property("stableBTreeMapLen", context.wrap_callback2(stable_b_tree_map_len).unwrap()).unwrap(); - ic.set_property("stableBTreeMapRemove", context.wrap_callback2(stable_b_tree_map_remove).unwrap()).unwrap(); - ic.set_property("stableBTreeMapValues", context.wrap_callback2(stable_b_tree_map_values).unwrap()).unwrap(); - ic.set_property("time", context.wrap_callback2(time).unwrap()).unwrap(); - ic.set_property("trap", context.wrap_callback2(trap).unwrap()).unwrap(); + ic.set_property( + "acceptMessage", + context + .wrap_callback2(accept_message::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "argDataRawSize", + context + .wrap_callback2(arg_data_raw_size::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "argDataRaw", + context + .wrap_callback2(arg_data_raw::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "callRaw", + context.wrap_callback2(call_raw::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "callRaw128", + context + .wrap_callback2(call_raw128::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "caller", + context.wrap_callback2(caller::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "candidDecode", + context + .wrap_callback2(candid_decode::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "candidEncode", + context + .wrap_callback2(candid_encode::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "canisterBalance", + context + .wrap_callback2(canister_balance::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "canisterBalance128", + context + .wrap_callback2(canister_balance128::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "canisterVersion", + context + .wrap_callback2(canister_version::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "clearTimer", + context + .wrap_callback2(clear_timer::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "dataCertificate", + context + .wrap_callback2(data_certificate::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property("id", context.wrap_callback2(id::native_function).unwrap()) + .unwrap(); + ic.set_property( + "instructionCounter", + context + .wrap_callback2(instruction_counter::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "isController", + context + .wrap_callback2(is_controller::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "methodName", + context + .wrap_callback2(method_name::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "msgCyclesAccept", + context + .wrap_callback2(msg_cycles_accept::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "msgCyclesAccept128", + context + .wrap_callback2(msg_cycles_accept128::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "msgCyclesAvailable", + context + .wrap_callback2(msg_cycles_available::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "msgCyclesAvailable128", + context + .wrap_callback2(msg_cycles_available128::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "msgCyclesRefunded", + context + .wrap_callback2(msg_cycles_refunded::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "msgCyclesRefunded128", + context + .wrap_callback2(msg_cycles_refunded128::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "notifyRaw", + context.wrap_callback2(notify_raw::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "performanceCounter", + context + .wrap_callback2(performance_counter::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "print", + context.wrap_callback2(print::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "reject", + context.wrap_callback2(reject::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "rejectCode", + context + .wrap_callback2(reject_code::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "rejectMessage", + context + .wrap_callback2(reject_message::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "replyRaw", + context.wrap_callback2(reply_raw::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "setCertifiedData", + context + .wrap_callback2(set_certified_data::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "setTimer", + context.wrap_callback2(set_timer::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "setTimerInterval", + context + .wrap_callback2(set_timer_interval::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stable64Grow", + context + .wrap_callback2(stable64_grow::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stable64Read", + context + .wrap_callback2(stable64_read::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stable64Size", + context + .wrap_callback2(stable64_size::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stable64Write", + context + .wrap_callback2(stable64_write::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBytes", + context + .wrap_callback2(stable_bytes::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableGrow", + context + .wrap_callback2(stable_grow::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableRead", + context + .wrap_callback2(stable_read::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableSize", + context + .wrap_callback2(stable_size::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableWrite", + context + .wrap_callback2(stable_write::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapContainsKey", + context + .wrap_callback2(stable_b_tree_map_contains_key::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapGet", + context + .wrap_callback2(stable_b_tree_map_get::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapInit", + context + .wrap_callback2(stable_b_tree_map_init::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapInsert", + context + .wrap_callback2(stable_b_tree_map_insert::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapIsEmpty", + context + .wrap_callback2(stable_b_tree_map_is_empty::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapItems", + context + .wrap_callback2(stable_b_tree_map_items::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapKeys", + context + .wrap_callback2(stable_b_tree_map_keys::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapLen", + context + .wrap_callback2(stable_b_tree_map_len::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapRemove", + context + .wrap_callback2(stable_b_tree_map_remove::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "stableBTreeMapValues", + context + .wrap_callback2(stable_b_tree_map_values::native_function) + .unwrap(), + ) + .unwrap(); + ic.set_property( + "time", + context.wrap_callback2(time::native_function).unwrap(), + ) + .unwrap(); + ic.set_property( + "trap", + context.wrap_callback2(trap::native_function).unwrap(), + ) + .unwrap(); - let global = context.global_object().unwrap(); - global.set_property("_azleIc", ic).unwrap(); - } + let global = context.global_object().unwrap(); + global.set_property("_azleIc", ic).unwrap(); } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept.rs index 7a255a1664..d06fd7b3b6 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn msg_cycles_accept<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let max_amount_vec_u8: Vec = args - .get(0) - .expect("msgCyclesAccept must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let max_amount: u64 = candid::decode_one(&max_amount_vec_u8)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let max_amount_vec_u8: Vec = args + .get(0) + .expect("msgCyclesAccept must have one argument") + .to_js_value()? + .try_into()?; - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::msg_cycles_accept(max_amount))?.into(); - to_qjs_value(&context, &return_js_value) - } - } + let max_amount: u64 = candid::decode_one(&max_amount_vec_u8)?; + + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::call::msg_cycles_accept(max_amount))?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept128.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept128.rs index 21820632be..9726060586 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept128.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_accept128.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn msg_cycles_accept128<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let max_amount_vec_u8: Vec = args - .get(0) - .expect("msgCyclesAccept128 must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let max_amount: u128 = candid::decode_one(&max_amount_vec_u8)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let max_amount_vec_u8: Vec = args + .get(0) + .expect("msgCyclesAccept128 must have one argument") + .to_js_value()? + .try_into()?; - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::msg_cycles_accept128(max_amount))?.into(); - to_qjs_value(&context, &return_js_value) - } - } + let max_amount: u128 = candid::decode_one(&max_amount_vec_u8)?; + + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::call::msg_cycles_accept128(max_amount))?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available.rs index 307baf6386..201ac279b9 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available.rs @@ -1,16 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn msg_cycles_available<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::msg_cycles_available())?.into(); - to_qjs_value(&context, &return_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::call::msg_cycles_available())?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available128.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available128.rs index 508379419d..5257edabd8 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available128.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_available128.rs @@ -1,16 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn msg_cycles_available128<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::msg_cycles_available128())?.into(); - to_qjs_value(&context, &return_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::call::msg_cycles_available128())?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded.rs index ba3900e5d8..1c778163b6 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded.rs @@ -1,16 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn msg_cycles_refunded<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::msg_cycles_refunded())?.into(); - to_qjs_value(&context, &return_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::call::msg_cycles_refunded())?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded128.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded128.rs index fe64a254dc..a1ccf5cf9e 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded128.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/msg_cycles_refunded128.rs @@ -1,16 +1,11 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn msg_cycles_refunded128<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::msg_cycles_refunded128())?.into(); - to_qjs_value(&context, &return_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::call::msg_cycles_refunded128())?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/notify_raw.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/notify_raw.rs index 8b4f90597e..9e26f57492 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/notify_raw.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/notify_raw.rs @@ -1,39 +1,49 @@ -// TODO basically copied from call_raw128 +use std::convert::TryInto; -use proc_macro2::TokenStream; -use quote::quote; +// TODO basically copied from call_raw128 +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn notify_raw<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let canister_id_bytes: Vec = args.get(0).expect("notify_raw canister_id_bytes is undefined").to_js_value()?.try_into()?; - let canister_id = candid::Principal::from_slice(&canister_id_bytes); - let method: String = args.get(1).expect("notify_raw method argument is undefined").to_js_value()?.try_into()?; - let args_raw: Vec = args.get(2).expect("notify_raw args_raw argument is undefined").to_js_value()?.try_into()?; - let payment_candid_bytes: Vec = args.get(3).expect("notify_raw payment_candid_bytes argument is undefined").to_js_value()?.try_into()?; - let payment: u128 = candid::decode_one(&payment_candid_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let canister_id_bytes: Vec = args + .get(0) + .expect("notify_raw canister_id_bytes is undefined") + .to_js_value()? + .try_into()?; + let canister_id = candid::Principal::from_slice(&canister_id_bytes); + let method: String = args + .get(1) + .expect("notify_raw method argument is undefined") + .to_js_value()? + .try_into()?; + let args_raw: Vec = args + .get(2) + .expect("notify_raw args_raw argument is undefined") + .to_js_value()? + .try_into()?; + let payment_candid_bytes: Vec = args + .get(3) + .expect("notify_raw payment_candid_bytes argument is undefined") + .to_js_value()? + .try_into()?; + let payment: u128 = candid::decode_one(&payment_candid_bytes)?; - let notify_result = ic_cdk::api::call::notify_raw(canister_id, &method, &args_raw, payment); + let notify_result = ic_cdk::api::call::notify_raw(canister_id, &method, &args_raw, payment); - match notify_result { - Ok(_) => { - context.undefined_value() - }, - Err(err) => { - // TODO it might be nice to convert the rejection code to a string as well if possible - // TODO to give the user an actual error message (like the enum variants converted to string) - let err_string = format!( - "Rejection code {rejection_code}", - rejection_code = (err as i32).to_string() - ); + match notify_result { + Ok(_) => context.undefined_value(), + Err(err) => { + // TODO it might be nice to convert the rejection code to a string as well if possible + // TODO to give the user an actual error message (like the enum variants converted to string) + let err_string = format!( + "Rejection code {rejection_code}", + rejection_code = (err as i32).to_string() + ); - Err(anyhow::anyhow!(err_string)) - } - } + Err(anyhow::anyhow!(err_string)) } } } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/performance_counter.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/performance_counter.rs index b797e7b219..d7d0b796c5 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/performance_counter.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/performance_counter.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn performance_counter<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let counter_type_vec_u8: Vec = args - .get(0) - .expect("performanceCounter must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let counter_type: u32 = candid::decode_one(&counter_type_vec_u8)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let counter_type_vec_u8: Vec = args + .get(0) + .expect("performanceCounter must have one argument") + .to_js_value()? + .try_into()?; - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::call::performance_counter(counter_type))?.into(); - to_qjs_value(&context, &return_js_value) - } - } + let counter_type: u32 = candid::decode_one(&counter_type_vec_u8)?; + + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::call::performance_counter(counter_type))?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/print.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/print.rs index 2ae66637d4..80afab0124 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/print.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/print.rs @@ -1,18 +1,13 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn print<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - for arg in args { - let value = arg.to_js_value()?; - ic_cdk::println!("{:?} ", value); - } - context.undefined_value() - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + for arg in args { + let value = arg.to_js_value()?; + ic_cdk::println!("{:?} ", value); } + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject.rs index 692ae37a8e..dfb6490695 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject.rs @@ -1,21 +1,18 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn reject<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let message: String = args - .get(0) - .expect("reject must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - ic_cdk::api::call::reject(&message); - context.undefined_value() - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let message: String = args + .get(0) + .expect("reject must have one argument") + .to_js_value()? + .try_into()?; + + ic_cdk::api::call::reject(&message); + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_code.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_code.rs index f439dd8b1c..20b513ba04 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_code.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_code.rs @@ -1,28 +1,23 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn reject_code<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let reject_code = ic_cdk::api::call::reject_code(); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let reject_code = ic_cdk::api::call::reject_code(); - let reject_code_as_u8 = match reject_code { - ic_cdk::api::call::RejectionCode::NoError => 0, - ic_cdk::api::call::RejectionCode::SysFatal => 1, - ic_cdk::api::call::RejectionCode::SysTransient => 2, - ic_cdk::api::call::RejectionCode::DestinationInvalid => 3, - ic_cdk::api::call::RejectionCode::CanisterReject => 4, - ic_cdk::api::call::RejectionCode::CanisterError => 5, - ic_cdk::api::call::RejectionCode::Unknown => 6, - }; + let reject_code_as_u8 = match reject_code { + ic_cdk::api::call::RejectionCode::NoError => 0, + ic_cdk::api::call::RejectionCode::SysFatal => 1, + ic_cdk::api::call::RejectionCode::SysTransient => 2, + ic_cdk::api::call::RejectionCode::DestinationInvalid => 3, + ic_cdk::api::call::RejectionCode::CanisterReject => 4, + ic_cdk::api::call::RejectionCode::CanisterError => 5, + ic_cdk::api::call::RejectionCode::Unknown => 6, + }; - let reject_code_as_js_value: JSValue = reject_code_as_u8.into(); + let reject_code_as_js_value: JSValue = reject_code_as_u8.into(); - to_qjs_value(&context, &reject_code_as_js_value) - } - } + to_qjs_value(&context, &reject_code_as_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_message.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_message.rs index 9fb3e7b5ca..ad5c54a1cd 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_message.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reject_message.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn reject_message<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let return_js_value: JSValue = ic_cdk::api::call::reject_message().into(); - to_qjs_value(&context, &return_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let return_js_value: JSValue = ic_cdk::api::call::reject_message().into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reply_raw.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reply_raw.rs index 1288bd5039..dc59ae96fe 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reply_raw.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/reply_raw.rs @@ -1,21 +1,18 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn reply_raw<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let buf: Vec = args - .get(0) - .expect("replyRaw must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - ic_cdk::api::call::reply_raw(&buf); - context.undefined_value() - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let buf: Vec = args + .get(0) + .expect("replyRaw must have one argument") + .to_js_value()? + .try_into()?; + + ic_cdk::api::call::reply_raw(&buf); + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_certified_data.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_certified_data.rs index 71293db37e..2674e4294e 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_certified_data.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_certified_data.rs @@ -1,23 +1,20 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn set_certified_data<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let certified_data_bytes: Vec = args - .get(0) - .expect("setCertifiedData must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - let certified_data: Vec = candid::decode_one(&certified_data_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let certified_data_bytes: Vec = args + .get(0) + .expect("setCertifiedData must have one argument") + .to_js_value()? + .try_into()?; - ic_cdk::api::set_certified_data(&certified_data); - context.undefined_value() - } - } + let certified_data: Vec = candid::decode_one(&certified_data_bytes)?; + + ic_cdk::api::set_certified_data(&certified_data); + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer.rs index 91b033a3e7..8c42e3f1bb 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer.rs @@ -1,61 +1,61 @@ -use proc_macro2::TokenStream; -use quote::quote; - -pub fn generate() -> TokenStream { - quote! { - fn set_timer<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let candid_encoded_array_buffer: Vec = args - .get(0) - .expect("performanceCounter must have one argument") - .to_js_value()? - .try_into()?; - - let delay_as_u64: u64 = candid::decode_one(&candid_encoded_array_buffer)?; - - let delay = core::time::Duration::new(delay_as_u64, 0); - - let callback_id: String = args - .get(1) - .expect("An argument for 'callback' was not provided") - .to_js_value()? - .try_into()?; - - let closure = move || { - CONTEXT.with(|context| { - let mut context = context.borrow_mut(); - let context = context.as_mut().unwrap(); - - let global = context.global_object().unwrap(); - - let timer_callback = global - .get_property(callback_id.as_str()) - .unwrap_or_else(|e| ic_cdk::api::trap(e.to_string().as_str())); - - // TODO I am not sure what the first parameter to call is supposed to be - let callback_result = timer_callback.call(&timer_callback, &[]); - - if let Err(e) = callback_result { - ic_cdk::api::trap(e.to_string().as_str()) - } - }); - }; - - let timer_id: ic_cdk_timers::TimerId = ic_cdk_timers::set_timer(delay, closure); - let timer_id_as_u64: u64 = timer_id.data().as_ffi(); - let timer_id_candid_encoded_bytes: JSValue = candid::encode_one(timer_id_as_u64) - .unwrap_or_else(|e| { - // If something goes wrong we need to clear the timer before - // throwing to the JS above. - ic_cdk_timers::clear_timer(timer_id); - ic_cdk::api::trap(e.to_string().as_str()); - }) - .into(); - - to_qjs_value(&context, &timer_id_candid_encoded_bytes) - } - } +use std::convert::TryInto; + +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; +use slotmap::Key; + +use crate::CONTEXT; + +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let candid_encoded_array_buffer: Vec = args + .get(0) + .expect("performanceCounter must have one argument") + .to_js_value()? + .try_into()?; + + let delay_as_u64: u64 = candid::decode_one(&candid_encoded_array_buffer)?; + + let delay = core::time::Duration::new(delay_as_u64, 0); + + let callback_id: String = args + .get(1) + .expect("An argument for 'callback' was not provided") + .to_js_value()? + .try_into()?; + + let closure = move || { + CONTEXT.with(|context| { + let mut context = context.borrow_mut(); + let context = context.as_mut().unwrap(); + + let global = context.global_object().unwrap(); + + let timer_callback = global + .get_property(callback_id.as_str()) + .unwrap_or_else(|e| ic_cdk::api::trap(e.to_string().as_str())); + + // TODO I am not sure what the first parameter to call is supposed to be + let callback_result = timer_callback.call(&timer_callback, &[]); + + if let Err(e) = callback_result { + ic_cdk::api::trap(e.to_string().as_str()) + } + }); + }; + + let timer_id: ic_cdk_timers::TimerId = ic_cdk_timers::set_timer(delay, closure); + let timer_id_as_u64: u64 = timer_id.data().as_ffi(); + let timer_id_candid_encoded_bytes: JSValue = candid::encode_one(timer_id_as_u64) + .unwrap_or_else(|e| { + // If something goes wrong we need to clear the timer before + // throwing to the JS above. + ic_cdk_timers::clear_timer(timer_id); + ic_cdk::api::trap(e.to_string().as_str()); + }) + .into(); + + to_qjs_value(&context, &timer_id_candid_encoded_bytes) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer_interval.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer_interval.rs index d9e4d06e9d..856000629f 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer_interval.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/set_timer_interval.rs @@ -1,62 +1,61 @@ -use proc_macro2::TokenStream; -use quote::quote; - -pub fn generate() -> TokenStream { - quote! { - fn set_timer_interval<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let candid_encoded_array_buffer: Vec = args - .get(0) - .expect("performanceCounter must have one argument") - .to_js_value()? - .try_into()?; - - let interval_as_u64: u64 = candid::decode_one(&candid_encoded_array_buffer)?; - - let interval = core::time::Duration::new(interval_as_u64, 0); - - let callback_id: String = args - .get(1) - .expect("An argument for 'callback' was not provided") - .to_js_value()? - .try_into()?; - - let closure = move || { - CONTEXT.with(|context| { - let mut context = context.borrow_mut(); - let context = context.as_mut().unwrap(); - - let global = context.global_object().unwrap(); - - let timer_callback = global - .get_property(callback_id.as_str()) - .unwrap_or_else(|e| ic_cdk::api::trap(e.to_string().as_str())); - - // TODO I am not sure what the first parameter to call is supposed to be - let callback_result = timer_callback.call(&timer_callback, &[]); - - if let Err(e) = callback_result { - ic_cdk::api::trap(e.to_string().as_str()) - } - }); - }; - - let timer_id: ic_cdk_timers::TimerId = - ic_cdk_timers::set_timer_interval(interval, closure); - let timer_id_as_u64: u64 = timer_id.data().as_ffi(); - let timer_id_candid_encoded_bytes: JSValue = candid::encode_one(timer_id_as_u64) - .unwrap_or_else(|e| { - // If something goes wrong we need to clear the timer before - // throwing to the JS above. - ic_cdk_timers::clear_timer(timer_id); - ic_cdk::api::trap(e.to_string().as_str()); - }) - .into(); - - to_qjs_value(&context, &timer_id_candid_encoded_bytes) - } - } +use std::convert::TryInto; + +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; +use slotmap::Key; + +use crate::CONTEXT; + +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let candid_encoded_array_buffer: Vec = args + .get(0) + .expect("performanceCounter must have one argument") + .to_js_value()? + .try_into()?; + + let interval_as_u64: u64 = candid::decode_one(&candid_encoded_array_buffer)?; + + let interval = core::time::Duration::new(interval_as_u64, 0); + + let callback_id: String = args + .get(1) + .expect("An argument for 'callback' was not provided") + .to_js_value()? + .try_into()?; + + let closure = move || { + CONTEXT.with(|context| { + let mut context = context.borrow_mut(); + let context = context.as_mut().unwrap(); + + let global = context.global_object().unwrap(); + + let timer_callback = global + .get_property(callback_id.as_str()) + .unwrap_or_else(|e| ic_cdk::api::trap(e.to_string().as_str())); + + // TODO I am not sure what the first parameter to call is supposed to be + let callback_result = timer_callback.call(&timer_callback, &[]); + + if let Err(e) = callback_result { + ic_cdk::api::trap(e.to_string().as_str()) + } + }); + }; + + let timer_id: ic_cdk_timers::TimerId = ic_cdk_timers::set_timer_interval(interval, closure); + let timer_id_as_u64: u64 = timer_id.data().as_ffi(); + let timer_id_candid_encoded_bytes: JSValue = candid::encode_one(timer_id_as_u64) + .unwrap_or_else(|e| { + // If something goes wrong we need to clear the timer before + // throwing to the JS above. + ic_cdk_timers::clear_timer(timer_id); + ic_cdk::api::trap(e.to_string().as_str()); + }) + .into(); + + to_qjs_value(&context, &timer_id_candid_encoded_bytes) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_grow.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_grow.rs index 2c3891cd3b..348f35b9d6 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_grow.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_grow.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable64_grow<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let new_pages_bytes: Vec = args - .get(0) - .expect("stable64Grow must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let new_pages: u64 = candid::decode_one(&new_pages_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let new_pages_bytes: Vec = args + .get(0) + .expect("stable64Grow must have one argument") + .to_js_value()? + .try_into()?; - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::stable::stable64_grow(new_pages)?)?.into(); - to_qjs_value(&context, &return_js_value) - } - } + let new_pages: u64 = candid::decode_one(&new_pages_bytes)?; + + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::stable::stable64_grow(new_pages)?)?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_read.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_read.rs index cd00b184fa..e7173248ab 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_read.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_read.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable64_read<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let params_bytes: Vec = args - .get(0) - .expect("stable64Read must have two arguments") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValueRef}; - let (offset, length): (u64, u64) = candid::decode_args(¶ms_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let params_bytes: Vec = args + .get(0) + .expect("stable64Read must have two arguments") + .to_js_value()? + .try_into()?; - let mut buf: Vec = vec![0; length as usize]; - ic_cdk::api::stable::stable64_read(offset, &mut buf); - to_qjs_value(&context, &buf.into()) - } - } + let (offset, length): (u64, u64) = candid::decode_args(¶ms_bytes)?; + + let mut buf: Vec = vec![0; length as usize]; + ic_cdk::api::stable::stable64_read(offset, &mut buf); + to_qjs_value(&context, &buf.into()) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_size.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_size.rs index 52a608c5b5..171f412d47 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_size.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_size.rs @@ -1,16 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn stable64_size<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::stable::stable64_size())?.into(); - to_qjs_value(&context, &return_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let return_js_value: JSValue = candid::encode_one(ic_cdk::api::stable::stable64_size())?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_write.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_write.rs index 9490d429eb..8901b0a73b 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_write.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable64_write.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable64_write<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let params_bytes: Vec = args - .get(0) - .expect("stable64Write must have two arguments") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - let (offset, buf): (u64, Vec) = candid::decode_args(¶ms_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let params_bytes: Vec = args + .get(0) + .expect("stable64Write must have two arguments") + .to_js_value()? + .try_into()?; - ic_cdk::api::stable::stable64_write(offset, &buf); + let (offset, buf): (u64, Vec) = candid::decode_args(¶ms_bytes)?; - context.undefined_value() - } - } + ic_cdk::api::stable::stable64_write(offset, &buf); + + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_contains_key.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_contains_key.rs index b5ced532e2..1ddbc82095 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_contains_key.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_contains_key.rs @@ -1,27 +1,35 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_contains_key<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let key: Vec = args.get(1).expect("stable_b_tree_map_get argument 1 is undefined").to_js_value()?.try_into()?; +use crate::{AzleStableBTreeMapKey, STABLE_B_TREE_MAPS}; - let result_js_value: JSValue = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let stable_b_tree_maps = stable_b_tree_maps.borrow(); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - stable_b_tree_maps[&memory_id].contains_key(&AzleStableBTreeMapKey { - candid_bytes: key - }) - }).into(); + let key: Vec = args + .get(1) + .expect("stable_b_tree_map_get argument 1 is undefined") + .to_js_value()? + .try_into()?; - to_qjs_value(&context, &result_js_value) - } - } + let result_js_value: JSValue = STABLE_B_TREE_MAPS + .with(|stable_b_tree_maps| { + let stable_b_tree_maps = stable_b_tree_maps.borrow(); + + stable_b_tree_maps[&memory_id] + .contains_key(&AzleStableBTreeMapKey { candid_bytes: key }) + }) + .into(); + + to_qjs_value(&context, &result_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_get.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_get.rs index 1d34562811..e4d888ae72 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_get.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_get.rs @@ -1,37 +1,40 @@ -use proc_macro2::TokenStream; -use quote::quote; - -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_get<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - - let key: Vec = args.get(1).expect("stable_b_tree_map_get argument 1 is undefined").to_js_value()?.try_into()?; - - let value_option = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let stable_b_tree_maps = stable_b_tree_maps.borrow(); - - stable_b_tree_maps[&memory_id].get(&AzleStableBTreeMapKey { - candid_bytes: key - }) - }); - - // TODO could we somehow encode the entire option here more easily - match value_option { - Some(value) => { - let candid_bytes_js_value: JSValue = value.candid_bytes.into(); - - to_qjs_value(&context, &candid_bytes_js_value) - }, - None => { - context.undefined_value() - } - } +use std::convert::TryInto; + +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; + +use crate::{AzleStableBTreeMapKey, STABLE_B_TREE_MAPS}; + +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; + + let key: Vec = args + .get(1) + .expect("stable_b_tree_map_get argument 1 is undefined") + .to_js_value()? + .try_into()?; + + let value_option = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let stable_b_tree_maps = stable_b_tree_maps.borrow(); + + stable_b_tree_maps[&memory_id].get(&AzleStableBTreeMapKey { candid_bytes: key }) + }); + + // TODO could we somehow encode the entire option here more easily + match value_option { + Some(value) => { + let candid_bytes_js_value: JSValue = value.candid_bytes.into(); + + to_qjs_value(&context, &candid_bytes_js_value) } + None => context.undefined_value(), } } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_init.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_init.rs index f920b10665..6f0dbaeaba 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_init.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_init.rs @@ -1,25 +1,31 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_init<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; +use ic_stable_structures::{memory_manager::MemoryId, StableBTreeMap}; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let mut stable_b_tree_maps = stable_b_tree_maps.borrow_mut(); - stable_b_tree_maps.insert( - memory_id, - StableBTreeMap::init(MEMORY_MANAGER_REF_CELL.with(|m| m.borrow().get(MemoryId::new(memory_id))),) - ); - }); +use crate::{MEMORY_MANAGER_REF_CELL, STABLE_B_TREE_MAPS}; - context.undefined_value() - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; + + STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let mut stable_b_tree_maps = stable_b_tree_maps.borrow_mut(); + stable_b_tree_maps.insert( + memory_id, + StableBTreeMap::init( + MEMORY_MANAGER_REF_CELL.with(|m| m.borrow().get(MemoryId::new(memory_id))), + ), + ); + }); + + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_insert.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_insert.rs index b46d0e181b..9981dbd689 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_insert.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_insert.rs @@ -1,42 +1,52 @@ -use proc_macro2::TokenStream; -use quote::quote; - -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_insert<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_insert argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - - let key: Vec = args.get(1).expect("stable_b_tree_map_insert argument 1 is undefined").to_js_value()?.try_into()?; - let value: Vec = args.get(2).expect("stable_b_tree_map_insert argument 2 is undefined").to_js_value()?.try_into()?; - - let value_option = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let mut stable_b_tree_maps = stable_b_tree_maps.borrow_mut(); - - let result = stable_b_tree_maps.get_mut(&memory_id).unwrap().insert(AzleStableBTreeMapKey { - candid_bytes: key - }, AzleStableBTreeMapValue { - candid_bytes: value - }); - - result - }); - - // TODO could we somehow encode the entire option here more easily - match value_option { - Some(value) => { - let candid_bytes_js_value: JSValue = value.candid_bytes.into(); - - to_qjs_value(&context, &candid_bytes_js_value) - }, - None => { - context.undefined_value() - } - } +use std::convert::TryInto; + +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; + +use crate::{AzleStableBTreeMapKey, AzleStableBTreeMapValue, STABLE_B_TREE_MAPS}; + +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_insert argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; + + let key: Vec = args + .get(1) + .expect("stable_b_tree_map_insert argument 1 is undefined") + .to_js_value()? + .try_into()?; + let value: Vec = args + .get(2) + .expect("stable_b_tree_map_insert argument 2 is undefined") + .to_js_value()? + .try_into()?; + + let value_option = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let mut stable_b_tree_maps = stable_b_tree_maps.borrow_mut(); + + let result = stable_b_tree_maps.get_mut(&memory_id).unwrap().insert( + AzleStableBTreeMapKey { candid_bytes: key }, + AzleStableBTreeMapValue { + candid_bytes: value, + }, + ); + + result + }); + + // TODO could we somehow encode the entire option here more easily + match value_option { + Some(value) => { + let candid_bytes_js_value: JSValue = value.candid_bytes.into(); + + to_qjs_value(&context, &candid_bytes_js_value) } + None => context.undefined_value(), } } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_is_empty.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_is_empty.rs index d94f127940..9ad99ed2de 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_is_empty.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_is_empty.rs @@ -1,23 +1,28 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_is_empty<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let result_js_value: JSValue = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let stable_b_tree_maps = stable_b_tree_maps.borrow(); +use crate::STABLE_B_TREE_MAPS; - stable_b_tree_maps[&memory_id].is_empty() - }).into(); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - to_qjs_value(&context, &result_js_value) - } - } + let result_js_value: JSValue = STABLE_B_TREE_MAPS + .with(|stable_b_tree_maps| { + let stable_b_tree_maps = stable_b_tree_maps.borrow(); + + stable_b_tree_maps[&memory_id].is_empty() + }) + .into(); + + to_qjs_value(&context, &result_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_items.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_items.rs index 3b84ab034c..04d2d6da1b 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_items.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_items.rs @@ -1,33 +1,42 @@ -use proc_macro2::TokenStream; -use quote::quote; - -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_items<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - - let items: Vec>> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let stable_b_tree_maps = stable_b_tree_maps.borrow(); - - stable_b_tree_maps[&memory_id].iter().map(|(key, value)| vec![key.candid_bytes, value.candid_bytes]).collect() - }); - - let js_values: Vec> = items.into_iter().map(|items| { - let keys = items[0].clone(); - let values = items[1].clone(); - - vec![keys.into(), values.into()] - }).collect(); - let js_values: Vec = js_values.into_iter().map(|items| items.into()).collect(); - - let js_value: JSValue = js_values.into(); - - to_qjs_value(&context, &js_value) - } - } +use std::convert::TryInto; + +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; + +use crate::STABLE_B_TREE_MAPS; + +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; + + let items: Vec>> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let stable_b_tree_maps = stable_b_tree_maps.borrow(); + + stable_b_tree_maps[&memory_id] + .iter() + .map(|(key, value)| vec![key.candid_bytes, value.candid_bytes]) + .collect() + }); + + let js_values: Vec> = items + .into_iter() + .map(|items| { + let keys = items[0].clone(); + let values = items[1].clone(); + + vec![keys.into(), values.into()] + }) + .collect(); + let js_values: Vec = js_values.into_iter().map(|items| items.into()).collect(); + + let js_value: JSValue = js_values.into(); + + to_qjs_value(&context, &js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_keys.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_keys.rs index eca41ccffc..c5e647e25e 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_keys.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_keys.rs @@ -1,27 +1,33 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_keys<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let keys: Vec> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let stable_b_tree_maps = stable_b_tree_maps.borrow(); +use crate::STABLE_B_TREE_MAPS; - stable_b_tree_maps[&memory_id].iter().map(|(key, _)| key.candid_bytes).collect() - }); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - let js_values: Vec = keys.into_iter().map(|key| key.into()).collect(); + let keys: Vec> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let stable_b_tree_maps = stable_b_tree_maps.borrow(); - let js_value: JSValue = js_values.into(); + stable_b_tree_maps[&memory_id] + .iter() + .map(|(key, _)| key.candid_bytes) + .collect() + }); - to_qjs_value(&context, &js_value) - } - } + let js_values: Vec = keys.into_iter().map(|key| key.into()).collect(); + + let js_value: JSValue = js_values.into(); + + to_qjs_value(&context, &js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_len.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_len.rs index fdff6f7957..12ee920126 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_len.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_len.rs @@ -1,24 +1,27 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_len<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let len = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let stable_b_tree_maps = stable_b_tree_maps.borrow(); +use crate::STABLE_B_TREE_MAPS; - stable_b_tree_maps[&memory_id].len() - }); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - let len_js_value: JSValue = candid::encode_one(len)?.into(); - to_qjs_value(&context, &len_js_value) - } - } + let len = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let stable_b_tree_maps = stable_b_tree_maps.borrow(); + + stable_b_tree_maps[&memory_id].len() + }); + + let len_js_value: JSValue = candid::encode_one(len)?.into(); + to_qjs_value(&context, &len_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_remove.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_remove.rs index 64a469a0f0..d695a04c8e 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_remove.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_remove.rs @@ -1,37 +1,43 @@ -use proc_macro2::TokenStream; -use quote::quote; - -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_remove<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - - let key: Vec = args.get(1).expect("stable_b_tree_map_get argument 1 is undefined").to_js_value()?.try_into()?; - - let value_option = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let mut stable_b_tree_maps = stable_b_tree_maps.borrow_mut(); - - stable_b_tree_maps.get_mut(&memory_id).unwrap().remove(&AzleStableBTreeMapKey { - candid_bytes: key - }) - }); - - // TODO could we somehow encode the entire option here more easily - match value_option { - Some(value) => { - let candid_bytes_js_value: JSValue = value.candid_bytes.into(); - - to_qjs_value(&context, &candid_bytes_js_value) - }, - None => { - context.undefined_value() - } - } +use std::convert::TryInto; + +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; + +use crate::{AzleStableBTreeMapKey, STABLE_B_TREE_MAPS}; + +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; + + let key: Vec = args + .get(1) + .expect("stable_b_tree_map_get argument 1 is undefined") + .to_js_value()? + .try_into()?; + + let value_option = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let mut stable_b_tree_maps = stable_b_tree_maps.borrow_mut(); + + stable_b_tree_maps + .get_mut(&memory_id) + .unwrap() + .remove(&AzleStableBTreeMapKey { candid_bytes: key }) + }); + + // TODO could we somehow encode the entire option here more easily + match value_option { + Some(value) => { + let candid_bytes_js_value: JSValue = value.candid_bytes.into(); + + to_qjs_value(&context, &candid_bytes_js_value) } + None => context.undefined_value(), } } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_values.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_values.rs index b0e31d5865..54161a4952 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_values.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_b_tree_map_values.rs @@ -1,27 +1,33 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_b_tree_map_values<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let memory_id_candid_bytes: Vec = args.get(0).expect("stable_b_tree_map_get argument 0 is undefined").to_js_value()?.try_into()?; - let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let values: Vec> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { - let stable_b_tree_maps = stable_b_tree_maps.borrow(); +use crate::STABLE_B_TREE_MAPS; - stable_b_tree_maps[&memory_id].iter().map(|(_, value)| value.candid_bytes).collect() - }); +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let memory_id_candid_bytes: Vec = args + .get(0) + .expect("stable_b_tree_map_get argument 0 is undefined") + .to_js_value()? + .try_into()?; + let memory_id: u8 = candid::decode_one(&memory_id_candid_bytes)?; - let js_values: Vec = values.into_iter().map(|value| value.into()).collect(); + let values: Vec> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| { + let stable_b_tree_maps = stable_b_tree_maps.borrow(); - let js_value: JSValue = js_values.into(); + stable_b_tree_maps[&memory_id] + .iter() + .map(|(_, value)| value.candid_bytes) + .collect() + }); - to_qjs_value(&context, &js_value) - } - } + let js_values: Vec = values.into_iter().map(|value| value.into()).collect(); + + let js_value: JSValue = js_values.into(); + + to_qjs_value(&context, &js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_bytes.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_bytes.rs index 7d916f43cd..441efdc0ef 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_bytes.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_bytes.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn stable_bytes<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let stable_bytes_js_value: JSValue = ic_cdk::api::stable::stable_bytes().into(); - to_qjs_value(&context, &stable_bytes_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let stable_bytes_js_value: JSValue = ic_cdk::api::stable::stable_bytes().into(); + to_qjs_value(&context, &stable_bytes_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_grow.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_grow.rs index 6aa6d564e3..2229cd2d3c 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_grow.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_grow.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_grow<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let new_pages_bytes: Vec = args - .get(0) - .expect("stableGrow must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; - let new_pages: u32 = candid::decode_one(&new_pages_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let new_pages_bytes: Vec = args + .get(0) + .expect("stableGrow must have one argument") + .to_js_value()? + .try_into()?; - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::stable::stable_grow(new_pages)?)?.into(); - to_qjs_value(&context, &return_js_value) - } - } + let new_pages: u32 = candid::decode_one(&new_pages_bytes)?; + + let return_js_value: JSValue = + candid::encode_one(ic_cdk::api::stable::stable_grow(new_pages)?)?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_read.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_read.rs index 33781c018e..0f9a8beae9 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_read.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_read.rs @@ -1,25 +1,22 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_read<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let params_bytes: Vec = args - .get(0) - .expect("stableRead must have two arguments") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValueRef}; - let (offset, length): (u32, u32) = candid::decode_args(¶ms_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let params_bytes: Vec = args + .get(0) + .expect("stableRead must have two arguments") + .to_js_value()? + .try_into()?; - let mut buf: Vec = vec![0; length as usize]; - ic_cdk::api::stable::stable_read(offset, &mut buf); + let (offset, length): (u32, u32) = candid::decode_args(¶ms_bytes)?; - to_qjs_value(&context, &buf.into()) - } - } + let mut buf: Vec = vec![0; length as usize]; + ic_cdk::api::stable::stable_read(offset, &mut buf); + + to_qjs_value(&context, &buf.into()) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_size.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_size.rs index b3742d72ce..449dc359c3 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_size.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_size.rs @@ -1,16 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn stable_size<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let return_js_value: JSValue = - candid::encode_one(ic_cdk::api::stable::stable_size())?.into(); - to_qjs_value(&context, &return_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let return_js_value: JSValue = candid::encode_one(ic_cdk::api::stable::stable_size())?.into(); + to_qjs_value(&context, &return_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_write.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_write.rs index 169c20328c..5d93c4cb19 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_write.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/stable_write.rs @@ -1,24 +1,21 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn stable_write<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let params_bytes: Vec = args - .get(0) - .expect("stableWrite must have two arguments") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - let (offset, buf): (u32, Vec) = candid::decode_args(¶ms_bytes)?; +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let params_bytes: Vec = args + .get(0) + .expect("stableWrite must have two arguments") + .to_js_value()? + .try_into()?; - ic_cdk::api::stable::stable_write(offset, &buf); + let (offset, buf): (u32, Vec) = candid::decode_args(¶ms_bytes)?; - context.undefined_value() - } - } + ic_cdk::api::stable::stable_write(offset, &buf); + + context.undefined_value() } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/time.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/time.rs index 1d14f3dae9..522e30f1d1 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/time.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/time.rs @@ -1,15 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; +use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; -pub fn generate() -> TokenStream { - quote! { - fn time<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - _args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let time_js_value: JSValue = candid::encode_one(ic_cdk::api::time())?.into(); - to_qjs_value(&context, &time_js_value) - } - } +pub fn native_function<'a>( + context: &'a JSContextRef, + _this: &CallbackArg, + _args: &[CallbackArg], +) -> Result, anyhow::Error> { + let time_js_value: JSValue = candid::encode_one(ic_cdk::api::time())?.into(); + to_qjs_value(&context, &time_js_value) } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/trap.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/trap.rs index e4978fc054..12c2867d42 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/trap.rs +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/ic/trap.rs @@ -1,20 +1,17 @@ -use proc_macro2::TokenStream; -use quote::quote; +use std::convert::TryInto; -pub fn generate() -> TokenStream { - quote! { - fn trap<'a>( - context: &'a JSContextRef, - _this: &CallbackArg, - args: &[CallbackArg], - ) -> Result, anyhow::Error> { - let message: String = args - .get(0) - .expect("trap must have one argument") - .to_js_value()? - .try_into()?; +use quickjs_wasm_rs::{CallbackArg, JSContextRef, JSValueRef}; - ic_cdk::api::trap(&message); - } - } +pub fn native_function<'a>( + _context: &'a JSContextRef, + _this: &CallbackArg, + args: &[CallbackArg], +) -> Result, anyhow::Error> { + let message: String = args + .get(0) + .expect("trap must have one argument") + .to_js_value()? + .try_into()?; + + ic_cdk::api::trap(&message); } diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/lib.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/lib.rs new file mode 100644 index 0000000000..6d8f6fdb92 --- /dev/null +++ b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/lib.rs @@ -0,0 +1,100 @@ +#[allow(unused)] +use canister_methods::canister_methods; +use ic_stable_structures::{ + memory_manager::{MemoryManager, VirtualMemory}, + storable::Bound, + DefaultMemoryImpl, StableBTreeMap, Storable, +}; +use quickjs_wasm_rs::{to_qjs_value, JSContextRef, JSValue}; +use std::cell::RefCell; +use std::collections::BTreeMap; + +mod ic; + +#[cfg(all(target_arch = "wasm32", target_os = "wasi"))] +const MAIN_JS: &[u8] = include_bytes!("main.js"); + +#[allow(unused)] +type Memory = VirtualMemory; +#[allow(unused)] +type AzleStableBTreeMap = StableBTreeMap; + +#[derive(Ord, PartialOrd, Eq, PartialEq, Clone)] +struct AzleStableBTreeMapKey { + candid_bytes: Vec, +} + +impl Storable for AzleStableBTreeMapKey { + fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + std::borrow::Cow::Borrowed(&self.candid_bytes) + } + + fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { + AzleStableBTreeMapKey { + candid_bytes: bytes.to_vec(), + } + } + + const BOUND: Bound = Bound::Unbounded; +} + +#[derive(Ord, PartialOrd, Eq, PartialEq, Clone)] +struct AzleStableBTreeMapValue { + candid_bytes: Vec, +} + +impl Storable for AzleStableBTreeMapValue { + fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + std::borrow::Cow::Borrowed(&self.candid_bytes) + } + + fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { + AzleStableBTreeMapValue { + candid_bytes: bytes.to_vec(), + } + } + + const BOUND: Bound = Bound::Unbounded; +} + +thread_local! { + static CONTEXT: RefCell> = RefCell::new(None); + + static MEMORY_MANAGER_REF_CELL: RefCell> = RefCell::new(MemoryManager::init(DefaultMemoryImpl::default())); + + static STABLE_B_TREE_MAPS: RefCell> = RefCell::new(BTreeMap::new()); +} + +#[cfg(all(target_arch = "wasm32", target_os = "wasi"))] +canister_methods!(); + +#[allow(unused)] +fn execute_js(function_name: &str, pass_arg_data: bool) { + CONTEXT.with(|context| { + let mut context = context.borrow_mut(); + let context = context.as_mut().unwrap(); + + let global = context.global_object().unwrap(); + let exports = global.get_property("exports").unwrap(); + let canister_methods = exports.get_property("canisterMethods").unwrap(); + let callbacks = canister_methods.get_property("callbacks").unwrap(); + let method_callbacks = callbacks.get_property(function_name).unwrap(); + let canister_method_callback = method_callbacks.get_property("canisterCallback").unwrap(); + + let candid_args = if pass_arg_data { + ic_cdk::api::call::arg_data_raw() + } else { + vec![] + }; + + let candid_args_js_value: JSValue = candid_args.into(); + let candid_args_js_value_ref = to_qjs_value(&context, &candid_args_js_value).unwrap(); + + // TODO I am not sure what the first parameter to call is supposed to be + canister_method_callback + .call(&canister_method_callback, &[candid_args_js_value_ref]) + .unwrap(); + + context.execute_pending().unwrap(); + }); +} diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/traits/mod.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/traits/mod.rs deleted file mode 100644 index 8bc928b593..0000000000 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/traits/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub use to_ident::ToIdent; - -pub mod to_ident; diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/traits/to_ident.rs b/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/traits/to_ident.rs deleted file mode 100644 index 72da578d0b..0000000000 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/traits/to_ident.rs +++ /dev/null @@ -1,12 +0,0 @@ -use proc_macro2::Ident; -use quote::format_ident; - -pub trait ToIdent { - fn to_ident(&self) -> Ident; -} - -impl ToIdent for String { - fn to_ident(&self) -> Ident { - format_ident!("{}", self) - } -} diff --git a/src/compiler/typescript_to_rust/canister_methods/Cargo.toml b/src/compiler/typescript_to_rust/canister_methods/Cargo.toml new file mode 100644 index 0000000000..fd62233b27 --- /dev/null +++ b/src/compiler/typescript_to_rust/canister_methods/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "canister_methods" +version = "0.0.0" +edition = "2018" + +[lib] +proc-macro = true + +[dependencies] +proc-macro2 = "1.0.67" +quote = "1.0.33" +syn = "2.0.37" +serde = "1.0.188" +serde_json = "1.0.107" diff --git a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/main.rs b/src/compiler/typescript_to_rust/canister_methods/src/lib.rs similarity index 60% rename from src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/main.rs rename to src/compiler/typescript_to_rust/canister_methods/src/lib.rs index bc7ec6105c..67f6184cc0 100644 --- a/src/compiler/typescript_to_rust/azle_generate_rearchitecture/src/main.rs +++ b/src/compiler/typescript_to_rust/canister_methods/src/lib.rs @@ -1,17 +1,22 @@ -// TODO So I'm going to create a macro for the dynamic portion of the code here -// TODO Then I'm going to integrate rquickjs +// TODO we need an easy way to see the expanded file now +// TODO perhaps we should automatically do this and store it in the filesystem for easy retrieval? -use crate::traits::to_ident::ToIdent; -use quote::quote; +use std::fs; + +use proc_macro::TokenStream; +use proc_macro2::Ident; +use quote::{format_ident, quote}; use serde::{Deserialize, Serialize}; -use std::{ - env, - fs::{self, File}, - io::Write, -}; -mod ic; -mod traits; +trait ToIdent { + fn to_ident(&self) -> Ident; +} + +impl ToIdent for String { + fn to_ident(&self) -> Ident { + format_ident!("{}", self) + } +} #[derive(Debug, Serialize, Deserialize)] struct CompilerInfo { @@ -38,20 +43,9 @@ struct CanisterMethod { guard_name: Option, } -fn main() -> Result<(), String> { - let args: Vec = env::args().collect(); - - if args.len() < 2 { - let executable_name = &args[0]; - - return Err(format!( - "Usage: {executable_name} [env_vars_csv]" - )); - } - - let compiler_info = get_compiler_info(&args[1])?; - - let ic = ic::generate(); +#[proc_macro] +pub fn canister_methods(_: TokenStream) -> TokenStream { + let compiler_info = get_compiler_info("compiler_info.json").unwrap(); let init_method_call = compiler_info.canister_methods.init.map(|init_method| { let js_function_name = &init_method.name; @@ -59,7 +53,28 @@ fn main() -> Result<(), String> { quote!(execute_js(#js_function_name, true);) }); - let post_upgrade_method_call = + let init_method = quote! { + #[ic_cdk_macros::init] + fn init() { + unsafe { ic_wasi_polyfill::init(&[], &[]); } + + let context = JSContextRef::default(); + + ic::register(&context); + + context.eval_global("exports.js", "globalThis.exports = {};").unwrap(); + context.eval_global("main.js", std::str::from_utf8(MAIN_JS).unwrap()).unwrap(); + + CONTEXT.with(|ctx| { + let mut ctx = ctx.borrow_mut(); + *ctx = Some(context); + }); + + #init_method_call + } + }; + + let post_update_method_call = compiler_info .canister_methods .post_upgrade @@ -69,6 +84,27 @@ fn main() -> Result<(), String> { quote!(execute_js(#js_function_name, true);) }); + let post_update_method = quote! { + #[ic_cdk_macros::post_upgrade] + fn post_upgrade() { + unsafe { ic_wasi_polyfill::init(&[], &[]); } + + let context = JSContextRef::default(); + + ic::register(&context); + + context.eval_global("exports.js", "globalThis.exports = {}").unwrap(); + context.eval_global("main.js", std::str::from_utf8(MAIN_JS).unwrap()).unwrap(); + + CONTEXT.with(|ctx| { + let mut ctx = ctx.borrow_mut(); + *ctx = Some(context); + }); + + #post_update_method_call + } + }; + let pre_upgrade_method = compiler_info .canister_methods .pre_upgrade @@ -166,148 +202,22 @@ fn main() -> Result<(), String> { } }); - let lib_file = quote! { - #![allow(non_snake_case)] - use quickjs_wasm_rs::{JSContextRef, JSValueRef, JSValue, from_qjs_value, to_qjs_value, CallbackArg}; - use slotmap::Key; - use std::cell::RefCell; - use std::convert::TryInto; - use std::collections::BTreeMap; - use ic_stable_structures::{ DefaultMemoryImpl, memory_manager::{ MemoryId, MemoryManager, VirtualMemory }, StableBTreeMap, storable::Bound, Storable }; - - const MAIN_JS: &[u8] = include_bytes!("main.js"); - - type Memory = VirtualMemory; - type AzleStableBTreeMap = StableBTreeMap; - - #[derive(Ord, PartialOrd, Eq, PartialEq, Clone)] - struct AzleStableBTreeMapKey { - candid_bytes: Vec - } - - impl Storable for AzleStableBTreeMapKey { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { - std::borrow::Cow::Borrowed(&self.candid_bytes) - } - - fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { - AzleStableBTreeMapKey { - candid_bytes: bytes.to_vec() - } - } - - const BOUND: Bound = Bound::Unbounded; - } - - #[derive(Ord, PartialOrd, Eq, PartialEq, Clone)] - struct AzleStableBTreeMapValue { - candid_bytes: Vec - } - - impl Storable for AzleStableBTreeMapValue { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { - std::borrow::Cow::Borrowed(&self.candid_bytes) - } - - fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { - AzleStableBTreeMapValue { - candid_bytes: bytes.to_vec() - } - } - - const BOUND: Bound = Bound::Unbounded; - } - - thread_local! { - static CONTEXT: RefCell> = RefCell::new(None); - - static MEMORY_MANAGER_REF_CELL: RefCell> = RefCell::new(MemoryManager::init(DefaultMemoryImpl::default())); - - static STABLE_B_TREE_MAPS: RefCell> = RefCell::new(BTreeMap::new()); - } - - #[ic_cdk_macros::init] - fn init() { - unsafe { ic_wasi_polyfill::init(&[], &[]); } - - let context = JSContextRef::default(); - - #ic + quote! { + #init_method - context.eval_global("exports.js", "globalThis.exports = {};").unwrap(); - context.eval_global("main.js", std::str::from_utf8(MAIN_JS).unwrap()).unwrap(); - - CONTEXT.with(|ctx| { - let mut ctx = ctx.borrow_mut(); - *ctx = Some(context); - }); - - #init_method_call - } - - #[ic_cdk_macros::post_upgrade] - fn post_upgrade() { - unsafe { ic_wasi_polyfill::init(&[], &[]); } - - let context = JSContextRef::default(); - - #ic - - context.eval_global("exports.js", "globalThis.exports = {}").unwrap(); - context.eval_global("main.js", std::str::from_utf8(MAIN_JS).unwrap()).unwrap(); - - CONTEXT.with(|ctx| { - let mut ctx = ctx.borrow_mut(); - *ctx = Some(context); - }); - - #post_upgrade_method_call - } + #post_update_method #pre_upgrade_method - #heartbeat_method - #inspect_message_method + #heartbeat_method + #(#query_methods)* #(#update_methods)* - - fn execute_js(function_name: &str, pass_arg_data: bool) { - CONTEXT.with(|context| { - let mut context = context.borrow_mut(); - let context = context.as_mut().unwrap(); - - let global = context.global_object().unwrap(); - let exports = global.get_property("exports").unwrap(); - let canister_methods = exports.get_property("canisterMethods").unwrap(); - let callbacks = canister_methods.get_property("callbacks").unwrap(); - let methodCallbacks = callbacks.get_property(function_name).unwrap(); - let canisterMethodCallback = methodCallbacks.get_property("canisterCallback").unwrap(); - - let candid_args = if pass_arg_data { ic_cdk::api::call::arg_data_raw() } else { vec![] }; - - let candid_args_js_value: JSValue = candid_args.into(); - let candid_args_js_value_ref = to_qjs_value(&context, &candid_args_js_value).unwrap(); - - // TODO I am not sure what the first parameter to call is supposed to be - canisterMethodCallback.call(&canisterMethodCallback, &[candid_args_js_value_ref]).unwrap(); - - context.execute_pending().unwrap(); - }); - } } - .to_string(); - - let syntax_tree = syn::parse_file(&lib_file).map_err(|err| err.to_string())?; - let formatted = prettyplease::unparse(&syntax_tree); - - let mut f = File::create("../src/lib.rs").map_err(|err| err.to_string())?; - f.write_all(formatted.as_bytes()) - .map_err(|err| err.to_string())?; - - Ok(()) + .into() } fn get_compiler_info(compiler_info_path: &str) -> Result { diff --git a/src/compiler/typescript_to_rust/generate_rust_canister.ts b/src/compiler/typescript_to_rust/generate_rust_canister.ts index 1e26babf60..73f97d8335 100644 --- a/src/compiler/typescript_to_rust/generate_rust_canister.ts +++ b/src/compiler/typescript_to_rust/generate_rust_canister.ts @@ -43,17 +43,12 @@ export function generateRustCanister( } // TODO we should probably just grab the props out that we need }; - const compilerInfoPath = join( - canisterPath, - canisterConfig.root, - 'azle_generate_rearchitecture', - 'compiler_info.json' - ); + const compilerInfoPath = join(canisterPath, 'compiler_info.json'); // TODO why not just write the dfx.json file here as well? writeFileSync(compilerInfoPath, JSON.stringify(compilerInfo)); - return runAzleGenerate('compiler_info.json', canisterPath, canisterConfig); + return Result.Ok(null); } function runAzleGenerate( diff --git a/src/compiler/typescript_to_rust/write_code_to_file_system.ts b/src/compiler/typescript_to_rust/write_code_to_file_system.ts index 9c4723b50d..a13912027b 100644 --- a/src/compiler/typescript_to_rust/write_code_to_file_system.ts +++ b/src/compiler/typescript_to_rust/write_code_to_file_system.ts @@ -50,8 +50,6 @@ export function writeCodeToFileSystem( `${canisterPath}/${rootPath}/azle_generate` ); - writeFileSync(`${canisterPath}/${rootPath}/src/main.js`, mainJs); - if ( !existsSync(`${canisterPath}/${rootPath}/azle_generate_rearchitecture`) ) { @@ -63,5 +61,19 @@ export function writeCodeToFileSystem( `${canisterPath}/${rootPath}/azle_generate_rearchitecture` ); + if (!existsSync(`${canisterPath}/${rootPath}/canister_methods`)) { + mkdirSync(`${canisterPath}/${rootPath}/canister_methods`); + } + + copySync( + `${__dirname}/canister_methods`, + `${canisterPath}/${rootPath}/canister_methods` + ); + + writeFileSync( + `${canisterPath}/${rootPath}/azle_generate_rearchitecture/src/main.js`, + mainJs + ); + writeFileSync(candidPath, candid); }