diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 725c472..c164b09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,6 +8,8 @@ on: env: RUSTFLAGS: "-Dwarnings" + BUILD_ID: ${{ github.job }}-${{ github.run_id }} + ESLINT_USE_FLAT_CONFIG: false jobs: nodejs: @@ -18,7 +20,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 21.7.1 + node-version: 21.7.3 - name: Install run: npm install --omit=dev @@ -44,8 +46,8 @@ jobs: - name: Set Rust version run: | - rustup update 1.77.1 &&\ - rustup default 1.77.1 &&\ + rustup update 1.77.2 &&\ + rustup default 1.77.2 &&\ rustup component add clippy - name: Lint @@ -61,22 +63,24 @@ jobs: runs-on: self-hosted - env: - BUILD_ID: ${{ github.job }}-${{ github.run_id }} - steps: - uses: actions/checkout@v4 - name: Build CI run: | + docker \ + build \ + -t wiki-ci:build-$BUILD_ID \ + -f images/build.Dockerfile \ + . + docker \ run \ --rm \ -v ${{ github.workspace }}:${{ github.workspace }} \ -w ${{ github.workspace }} \ - -u 1000:1000 \ - rust:1.77.1 \ + wiki-ci:build-$BUILD_ID \ sh -c 'cargo build --bin ci' - name: Run CI - run: ./target/debug/ci --all + run: ./target/debug/ci --github-logger --all diff --git a/Cargo.lock b/Cargo.lock index 61993fb..7a4af93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,6 +74,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "async-trait" +version = "0.1.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.2.0" @@ -188,7 +199,7 @@ version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn", @@ -247,6 +258,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "digest" version = "0.10.7" @@ -255,6 +275,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -282,12 +303,24 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +[[package]] +name = "finl_unicode" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" + [[package]] name = "fnv" version = "1.0.7" @@ -334,6 +367,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.30" @@ -353,6 +397,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", + "futures-macro", "futures-sink", "futures-task", "pin-project-lite", @@ -436,6 +481,12 @@ dependencies = [ "http", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -448,6 +499,15 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "http" version = "0.2.12" @@ -608,6 +668,16 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.2" @@ -686,6 +756,12 @@ dependencies = [ "tempfile", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num_cpus" version = "1.16.0" @@ -833,7 +909,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ - "siphasher", + "siphasher 0.3.11", ] [[package]] @@ -874,6 +950,41 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "postgres-protocol" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b6c5ef183cd3ab4ba005f1ca64c21e8bd97ce4699cfea9e8d9a2c4958ca520" +dependencies = [ + "base64", + "byteorder", + "bytes", + "fallible-iterator", + "hmac", + "md-5", + "memchr", + "rand", + "sha2", + "stringprep", +] + +[[package]] +name = "postgres-types" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d2234cdee9408b523530a9b6d2d6b373d1db34f6a8e51dc03ded1828d7fb67c" +dependencies = [ + "bytes", + "fallible-iterator", + "postgres-protocol", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -937,6 +1048,51 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "refinery" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0904191f0566c3d3e0091d5cc8dec22e663d77def2d247b16e7a438b188bf75d" +dependencies = [ + "refinery-core", + "refinery-macros", +] + +[[package]] +name = "refinery-core" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bf253999e1899ae476c910b994959e341d84c4389ba9533d3dacbe06df04825" +dependencies = [ + "async-trait", + "cfg-if", + "log", + "regex", + "serde", + "siphasher 1.0.1", + "thiserror", + "time", + "tokio", + "tokio-postgres", + "toml", + "url", + "walkdir", +] + +[[package]] +name = "refinery-macros" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd81f69687fe8a1fa10995108b3ffc7cdbd63e682a4f8fbfd1020130780d7e17" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "refinery-core", + "regex", + "syn", +] + [[package]] name = "regex" version = "1.10.4" @@ -1081,6 +1237,15 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +[[package]] +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.23" @@ -1166,6 +1331,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1202,6 +1376,17 @@ dependencies = [ "digest", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -1217,6 +1402,12 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "slab" version = "0.4.9" @@ -1248,12 +1439,29 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "stringprep" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" +dependencies = [ + "finl_unicode", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + [[package]] name = "syn" version = "2.0.58" @@ -1324,6 +1532,37 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1379,6 +1618,32 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-postgres" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d340244b32d920260ae7448cb72b6e238bddc3d4f7603394e7dd46ed8e48f5b8" +dependencies = [ + "async-trait", + "byteorder", + "bytes", + "fallible-iterator", + "futures-channel", + "futures-util", + "log", + "parking_lot", + "percent-encoding", + "phf", + "pin-project-lite", + "postgres-protocol", + "postgres-types", + "rand", + "socket2", + "tokio", + "tokio-util", + "whoami", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -1426,6 +1691,40 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tools" version = "0.1.0" @@ -1571,6 +1870,16 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -1617,6 +1926,12 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -1699,18 +2014,64 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "whoami" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" +dependencies = [ + "redox_syscall", + "wasite", + "web-sys", +] + [[package]] name = "wiki" version = "0.1.0" dependencies = [ + "clap", "phf", "phf_codegen", + "rand", + "refinery", "regex", "serde_yaml", "tokio", + "tokio-postgres", "warp", ] +[[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.48.0" @@ -1843,6 +2204,15 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +[[package]] +name = "winnow" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" diff --git a/ci/README.md b/ci/README.md index 71c68f3..d423997 100644 --- a/ci/README.md +++ b/ci/README.md @@ -16,4 +16,5 @@ Wiki CI runs all steps required to accept code. ### End-to-end (e2e) tests -* ui dev server +* node dev server +* rust dev server diff --git a/ci/src/docker.rs b/ci/src/docker.rs index 8f661aa..fd5a93f 100644 --- a/ci/src/docker.rs +++ b/ci/src/docker.rs @@ -6,6 +6,42 @@ pub struct Docker { pub context: Rc, } +impl Docker { + fn build_docker_args(&self, background: bool, context: ExecutionContext, env: Vec<&str>, include_source: bool, cmd: Vec<&str>) -> Vec { + let mut args: Vec = vec![ + "run", + "--rm", + ].into_iter().map(|a| a.to_string()).collect(); + + if background { + args.push("-d".to_string()); + } + + if include_source { + args.append(&mut vec![ + "-v", + &format!("{}:{}", self.context.cwd, self.context.cwd), + "-w", + &self.context.cwd, + ].into_iter().map(|a| a.to_string()).collect()); + } + + for e in env { + args.push("-e".to_string()); + args.push(e.to_string()); + } + + match context { + ExecutionContext::Internal(i) => args.push(format!("{}:{}-{}", "wiki-ci", i, self.context.id)), + ExecutionContext::External(i) => args.push(i.to_string()), + } + + args.extend(cmd.into_iter().map(|a| a.to_string()).collect::>()); + + args + } +} + impl Builder for Docker { fn build(&self, tag: &str, dockerfile: &str, context: &str) -> Result<(), Error> { let cmd = Command::new("docker") @@ -43,20 +79,11 @@ impl Builder for Docker { } impl Runner for Docker { - fn run(&self, context: &str, script: &str) -> Result<(), Error> { + fn run(&self, context: ExecutionContext, env: Vec<&str>, include_source: bool, cmd: Vec<&str>) -> Result<(), Error> { + let args = self.build_docker_args(false, context, env, include_source, cmd); + let cmd = Command::new("docker") - .args([ - "run", - "--rm", - "-v", - &format!("{}:{}", self.context.cwd, self.context.cwd), - "-w", - &self.context.cwd, - &format!("{}:{}-{}", "wiki-ci", context, self.context.id), - "sh", - "-c", - script, - ]) + .args(args) .spawn(); match cmd { @@ -81,28 +108,18 @@ impl Runner for Docker { } } - fn run_background_server(&self, context: &str, script: &str) -> Result, Error> { + fn run_background(&self, context: ExecutionContext, env: Vec<&str>, include_source: bool, cmd: Vec<&str>) -> Result, Error> { + let args = self.build_docker_args(true, context, env, include_source, cmd); + let output = Command::new("docker") - .args([ - "run", - "--rm", - "-d", - "-v", - &format!("{}:{}", self.context.cwd, self.context.cwd), - "-w", - &self.context.cwd, - &format!("{}:{}-{}", "wiki-ci", context, self.context.id), - "sh", - "-c", - script, - ]) + .args(args) .output(); match output { Ok(o) => { let s = std::str::from_utf8(&o.stdout).unwrap().trim_end(); Ok(Box::new(DockerBackgroundServer{ id: s.to_string() })) - } + }, Err(e) => Err(Box::new(e)), } } diff --git a/ci/src/lib.rs b/ci/src/lib.rs index b017957..7a2ce2f 100644 --- a/ci/src/lib.rs +++ b/ci/src/lib.rs @@ -26,6 +26,10 @@ pub struct Cli { /// Print all stages in order #[arg(short, long)] list: bool, + + /// Enable GitHub-formatted logger + #[arg(short, long)] + github_logger: bool, } pub fn cmd(args: Cli) { @@ -57,15 +61,30 @@ pub fn cmd(args: Cli) { builder: docker.clone(), }; + let mut stages_run = 0; + let all_stages_len = all_stages.len(); for s in all_stages { - if args.all || args.stages.contains(&s.name()) { + if args.all || args.stages.iter().any(|stage| stage == s.name() ) { + if args.github_logger { + println!("::group::Stage: {}", s.name()); + } if let Err(e) = s.run(&context, &config) { panic!("Error: {:?}", e); } + if args.github_logger { + println!("::endgroup::"); + } + stages_run += 1; } } - println!("CI Passed!"); + if stages_run == 0 { + println!("No stages run"); + } else if stages_run < all_stages_len { + println!("{}/{} stages run, partial CI pass", stages_run, all_stages_len); + } else { + println!("{}/{} stages run, CI passed!", stages_run, all_stages_len); + } } pub type Error = Box; @@ -85,8 +104,13 @@ pub trait BackgroundServer { } pub trait Runner { - fn run(&self, context: &str, script: &str) -> Result<(), Error>; - fn run_background_server(&self, context: &str, script: &str) -> Result, Error>; + fn run(&self, context: ExecutionContext, env: Vec<&str>, include_source: bool, cmd: Vec<&str>) -> Result<(), Error>; + fn run_background(&self, context: ExecutionContext, env: Vec<&str>, include_source: bool, cmd: Vec<&str>) -> Result, Error>; +} + +pub enum ExecutionContext<'a> { + Internal(&'a str), + External(&'a str), } pub trait Builder { @@ -94,6 +118,6 @@ pub trait Builder { } pub trait Stage { - fn name(&self) -> String; + fn name(&self) -> &'static str; fn run(&self, context: &Context, config: &Config) -> Result<(), Error>; } diff --git a/ci/src/stages/build_images.rs b/ci/src/stages/build_images.rs index 06372ac..efb36c6 100644 --- a/ci/src/stages/build_images.rs +++ b/ci/src/stages/build_images.rs @@ -3,8 +3,8 @@ use crate::*; pub struct BuildImages {} impl Stage for BuildImages { - fn name(&self) -> String { - String::from("build_images") + fn name(&self) -> &'static str { + "Build_Images" } // run builds test and build images diff --git a/ci/src/stages/dev_e2e.rs b/ci/src/stages/dev_e2e.rs index 9911ea5..d2a9795 100644 --- a/ci/src/stages/dev_e2e.rs +++ b/ci/src/stages/dev_e2e.rs @@ -2,9 +2,14 @@ use crate::*; pub struct DevE2E {} +const BROWSERS: [&str; 2] = [ + "firefox", + "chrome", +]; + impl Stage for DevE2E { - fn name(&self) -> String { - String::from("dev_e2e") + fn name(&self) -> &'static str { + "Dev_E2E" } // run e2e tests against dev servers @@ -18,44 +23,92 @@ impl Stage for DevE2E { } fn node_dev_e2e(expiration: u32, config: &Config) -> Result<(), Error> { - let server = config.runner.run_background_server("build", &format!(r" - set -xe - ln -s /ci/node_modules ./ui/node_modules || true - cd ui - npm run dev -- --user-expiration {0} --api-expiration {0} - ", expiration))?; + let server = config.runner.run_background( + ExecutionContext::Internal("build"), + Vec::new(), + true, + vec![ + "sh", + "-c", + &format!(r" + set -xe + ln -s /ci/node_modules ./ui/node_modules || true + cd ui + npm run dev -- --user-expiration {0} --api-expiration {0} + ", expiration), + ] + )?; - config.runner.run("e2e", &format!(r" - set -xe - ln -s /ci/node_modules ./ui/node_modules || true - cd ui - node tools/configure.js --user-expiration {1} --api-expiration {1} - npx cypress run --browser firefox --config baseUrl=http://{0}:8080 - npx cypress run --browser chrome --config baseUrl=http://{0}:8080 - ", server.addr(), expiration)) + config.runner.run( + ExecutionContext::Internal("e2e"), + Vec::new(), + true, + vec![ + "sh", + "-c", + &format!(r" + set -xe + {} + ", make_cypress_script(expiration, &server.addr(), &BROWSERS)) + ] + ) } fn rust_dev_e2e(expiration: u32, config: &Config) -> Result<(), Error> { - config.runner.run("build", &format!(r" - set -xe - ln -s /ci/node_modules ./ui/node_modules || true - cd ui - npm run build -- --build dev --user-expiration {0} --api-expiration {0} - cd .. - cargo build --bin wiki - ", expiration))?; - - let server = config.runner.run_background_server("build", r" - set -xe - ./target/debug/wiki - ")?; - - config.runner.run("e2e", &format!(r" - set -xe + config.runner.run( + ExecutionContext::Internal("build"), + Vec::new(), + true, + vec![ + "sh", + "-c", + &format!(r" + set -xe + ln -s /ci/node_modules ./ui/node_modules || true + cd ui + npm run build -- --build dev --user-expiration {0} --api-expiration {0} + cd .. + cargo build --bin wiki + ", expiration), + ], + )?; + + let server = config.runner.run_background( + ExecutionContext::Internal("build"), + Vec::new(), + true, + vec![ + "sh", + "-c", + r" + set -xe + ./target/debug/wiki + ", + ], + )?; + + config.runner.run( + ExecutionContext::Internal("e2e"), + Vec::new(), + true, + vec![ + "sh", + "-c", + &format!(r" + set -xe + {} + ", make_cypress_script(expiration, &server.addr(), &BROWSERS)), + ], + ) +} + +fn make_cypress_script(expiration: u32, server_addr: &str, browsers: &[&str]) -> String { + format!(r" ln -s /ci/node_modules ./ui/node_modules || true cd ui - node tools/configure.js --user-expiration {1} --api-expiration {1} - npx cypress run --browser firefox --config baseUrl=http://{0}:8080 - npx cypress run --browser chrome --config baseUrl=http://{0}:8080 - ", server.addr(), expiration)) + node tools/configure.js --user-expiration {0} --api-expiration {0} + for b in {1}; do + npx cypress run --browser $b --config baseUrl=http://{2}:8080 + done + ", expiration, browsers.join(" "), server_addr) } diff --git a/ci/src/stages/nodejs_checks.rs b/ci/src/stages/nodejs_checks.rs index f7f08fb..664336c 100644 --- a/ci/src/stages/nodejs_checks.rs +++ b/ci/src/stages/nodejs_checks.rs @@ -3,18 +3,28 @@ use crate::*; pub struct NodeJSChecks {} impl Stage for NodeJSChecks { - fn name(&self) -> String { - String::from("nodejs_checks") + fn name(&self) -> &'static str { + "NodeJS_Checks" } // run runs unit tests and linters for Node.js source fn run(&self, _context: &Context, config: &Config) -> Result<(), Error> { - config.runner.run("build", r" - set -xe - ln -s /ci/node_modules ./ui/node_modules || true - cd ui - npm run lint - npm run test - ") + config.runner.run( + ExecutionContext::Internal("build"), + Vec::new(), + true, + vec![ + "sh", + "-c", + r" + set -xe + ln -s /ci/node_modules ./ui/node_modules || true + export ESLINT_USE_FLAT_CONFIG=false + cd ui + npm run lint + npm run test + ", + ], + ) } } diff --git a/ci/src/stages/rust_checks.rs b/ci/src/stages/rust_checks.rs index 1d0f12d..25964e5 100644 --- a/ci/src/stages/rust_checks.rs +++ b/ci/src/stages/rust_checks.rs @@ -3,16 +3,33 @@ use crate::*; pub struct RustChecks {} impl Stage for RustChecks { - fn name(&self) -> String { - String::from("rust_checks") + fn name(&self) -> &'static str { + "Rust_Checks" } // run runs unit tests and linters for Rust fn run(&self, _context: &Context, config: &Config) -> Result<(), Error> { - config.runner.run("build", r" - set -xe - RUSTFLAGS='-Dwarnings' cargo clippy --all-targets --all-features - cargo test --all-targets --all-features - ") + let db = config.runner.run_background( + ExecutionContext::External("postgres:16-alpine"), + vec!["POSTGRES_HOST_AUTH_METHOD=trust"], + false, + Vec::new(), + )?; + + config.runner.run( + ExecutionContext::Internal("build"), + Vec::new(), + true, + vec![ + "sh", + "-c", + &format!(r" + set -xe + RUSTFLAGS='-Dwarnings' cargo clippy --all-targets --all-features + export WIKI_CI_TEST_POSTGRES_HOST={} + cargo test --all-targets --all-features -- --include-ignored + ", &db.addr()), + ], + ) } } diff --git a/images/build.Dockerfile b/images/build.Dockerfile index faa074f..c003edd 100644 --- a/images/build.Dockerfile +++ b/images/build.Dockerfile @@ -1,18 +1,31 @@ -ARG NODE_VERSION="21.7.1" +ARG NODE_VERSION="21.7.3" FROM node:${NODE_VERSION} -ARG NPM_VERSION="10.5.1" -ARG RUST_VERSION="1.77.1" +USER root:root -RUN npm install --verbose -g npm@${NPM_VERSION} +ARG NPM_VERSION="10.5.2" +ARG RUST_VERSION="1.77.2" -USER 1000:1000 +RUN [ "$(npm --version)" = "${NPM_VERSION}" ] || npm install --verbose -g npm@${NPM_VERSION} -ENV PATH=$PATH:/home/node/.cargo/bin +ENV PATH=$PATH:/root/.cargo/bin RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_VERSION} WORKDIR /ci -COPY --chown=1000:1000 ./ui/package.json . -COPY --chown=1000:1000 ./ui/package-lock.json . +COPY ./ui/package.json . +COPY ./ui/package-lock.json . RUN npm install --verbose + +RUN mkdir wiki +RUN cd wiki &&\ + cargo new ci &&\ + cargo new tools &&\ + cargo new wiki +COPY ./Cargo.lock ./wiki/ +COPY ./Cargo.toml ./wiki/ +COPY ./ci/Cargo.toml ./wiki/ci/ +COPY ./tools/Cargo.toml ./wiki/tools/ +COPY ./wiki/Cargo.toml ./wiki/wiki/ +RUN cd wiki &&\ + cargo fetch -vv diff --git a/images/e2e.Dockerfile b/images/e2e.Dockerfile index 8434750..84b9fca 100644 --- a/images/e2e.Dockerfile +++ b/images/e2e.Dockerfile @@ -1,8 +1,8 @@ # Latest Node.js version: https://nodejs.org/en -ARG NODE_VERSION="21.7.2" +ARG NODE_VERSION="21.7.3" # Latest Chrome version: https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-stable -ARG CHROME_VERSION="123.0.6312.105-1" +ARG CHROME_VERSION="123.0.6312.122-1" # Latest Firefox version: https://www.mozilla.org/en-US/firefox/releases/ ARG FIREFOX_VERSION="124.0.2" @@ -12,11 +12,13 @@ ARG EDGE_VERSION= ARG YARN_VERSION= ARG CYPRESS_VERSION= -FROM cypress/factory:3.5.3 +FROM cypress/factory:3.5.4 -USER 1000:1000 +ARG NPM_VERSION="10.5.2" + +RUN [ "$(npm --version)" = "${NPM_VERSION}" ] || npm install --verbose -g npm@${NPM_VERSION} WORKDIR /ci -COPY --chown=1000:1000 ./ui/package.json . -COPY --chown=1000:1000 ./ui/package-lock.json . +COPY ./ui/package.json . +COPY ./ui/package-lock.json . RUN npm install --verbose diff --git a/ui/package-lock.json b/ui/package-lock.json index ed4ea9d..02b56f0 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -9,12 +9,12 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@testing-library/dom": "^9.3.4", + "@testing-library/dom": "^10.0.0", "ace-builds": "^1.32.9", "core-js": "^3.36.1", "esbuild": "^0.20.2", "esbuild-plugin-resolve": "^2.0.0", - "eslint": "^8.57.0", + "eslint": "^9.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", "jsdom": "^24.0.0", @@ -24,7 +24,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "cypress": "^13.7.2", + "cypress": "^13.7.3", "express": "^4.19.2", "nodemon": "^3.1.0" } @@ -635,14 +635,14 @@ } }, "node_modules/@eslint/eslintrc": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", - "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.0.2.tgz", + "integrity": "sha512-wV19ZEGEMAC1eHgrS7UQPqsdEiCIbTKTasEfcXAigzoXICcqZSjBZEHlZwNVvKg6UBCjSlos84XiLqsRJnIcIg==", "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.6.0", - "globals": "^13.19.0", + "espree": "^10.0.1", + "globals": "^14.0.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", @@ -650,26 +650,26 @@ "strip-json-comments": "^3.1.1" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.0.0.tgz", + "integrity": "sha512-RThY/MnKrhubF6+s1JflwUjPEsnCEmYCWwqa/aRISKWNXGZ9epUwft4bUMM35SdKF9xvBrLydAM1RDHd1Z//ZQ==", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.14", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", - "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", + "version": "0.12.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.12.3.tgz", + "integrity": "sha512-jsNnTBlMWuTpDkeE3on7+dWJi0D6fdDfeANj/w7MpS8ztROCoLvIO2nG0CcFj+E4k8j4QrSTh4Oryi3i2G669g==", "dependencies": { - "@humanwhocodes/object-schema": "^2.0.2", + "@humanwhocodes/object-schema": "^2.0.3", "debug": "^4.3.1", "minimatch": "^3.0.5" }, @@ -738,21 +738,21 @@ } }, "node_modules/@testing-library/dom": { - "version": "9.3.4", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.4.tgz", - "integrity": "sha512-FlS4ZWlp97iiNWig0Muq8p+3rVDjRiYE+YKGbAqXOu9nwJFFOdL00kFpz42M+4huzYi86vAK1sOOfyOG45muIQ==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.0.0.tgz", + "integrity": "sha512-PmJPnogldqoVFf+EwbHvbBJ98MmqASV8kLrBYgsDNxQcFMeIS7JFL48sfyXvuMtgmWO/wMhh25odr+8VhDmn4g==", "dependencies": { "@babel/code-frame": "^7.10.4", "@babel/runtime": "^7.12.5", "@types/aria-query": "^5.0.1", - "aria-query": "5.1.3", + "aria-query": "5.3.0", "chalk": "^4.1.0", "dom-accessibility-api": "^0.5.9", "lz-string": "^1.5.0", "pretty-format": "^27.0.2" }, "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/@types/aria-query": { @@ -792,11 +792,6 @@ "@types/node": "*" } }, - "node_modules/@ungap/structured-clone": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==" - }, "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -976,23 +971,11 @@ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" }, "node_modules/aria-query": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.1.3.tgz", - "integrity": "sha512-R5iJ5lkuHybztUfuOAznmboyjWq8O6sqNqtK7CLOqdydi54VNbORp49mb14KbWgG1QD3JFO9hJdZ+y4KutfdOQ==", - "dependencies": { - "deep-equal": "^2.0.5" - } - }, - "node_modules/array-buffer-byte-length": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.0.tgz", - "integrity": "sha512-LPuwb2P+NrQw3XhxGc36+XSvuBPopovXYTR9Ew++Du9Yb/bx5AzBfrIsBoj0EZUifjQU+sHL21sseZ3jerWO/A==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", + "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==", "dependencies": { - "call-bind": "^1.0.2", - "is-array-buffer": "^3.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "dequal": "^2.0.3" } }, "node_modules/array-flatten": { @@ -1048,17 +1031,6 @@ "node": ">= 4.0.0" } }, - "node_modules/available-typed-arrays": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", - "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/aws-sign2": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", @@ -1259,6 +1231,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", + "dev": true, "dependencies": { "function-bind": "^1.1.2", "get-intrinsic": "^1.2.1", @@ -1558,9 +1531,9 @@ } }, "node_modules/cypress": { - "version": "13.7.2", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.7.2.tgz", - "integrity": "sha512-FF5hFI5wlRIHY8urLZjJjj/YvfCBrRpglbZCLr/cYcL9MdDe0+5usa8kTIrDHthlEc9lwihbkb5dmwqBDNS2yw==", + "version": "13.7.3", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.7.3.tgz", + "integrity": "sha512-uoecY6FTCAuIEqLUYkTrxamDBjMHTYak/1O7jtgwboHiTnS1NaMOoR08KcTrbRZFCBvYOiS4tEkQRmsV+xcrag==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -1680,37 +1653,6 @@ "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==" }, - "node_modules/deep-equal": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.3.tgz", - "integrity": "sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==", - "dependencies": { - "array-buffer-byte-length": "^1.0.0", - "call-bind": "^1.0.5", - "es-get-iterator": "^1.1.3", - "get-intrinsic": "^1.2.2", - "is-arguments": "^1.1.1", - "is-array-buffer": "^3.0.2", - "is-date-object": "^1.0.5", - "is-regex": "^1.1.4", - "is-shared-array-buffer": "^1.0.2", - "isarray": "^2.0.5", - "object-is": "^1.1.5", - "object-keys": "^1.1.1", - "object.assign": "^4.1.4", - "regexp.prototype.flags": "^1.5.1", - "side-channel": "^1.0.4", - "which-boxed-primitive": "^1.0.2", - "which-collection": "^1.0.1", - "which-typed-array": "^1.1.13" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -1720,6 +1662,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "dev": true, "dependencies": { "get-intrinsic": "^1.2.1", "gopd": "^1.0.1", @@ -1729,22 +1672,6 @@ "node": ">= 0.4" } }, - "node_modules/define-properties": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", - "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", - "dependencies": { - "define-data-property": "^1.0.1", - "has-property-descriptors": "^1.0.0", - "object-keys": "^1.1.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -1762,6 +1689,14 @@ "node": ">= 0.8" } }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "engines": { + "node": ">=6" + } + }, "node_modules/destroy": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", @@ -1772,17 +1707,6 @@ "npm": "1.2.8000 || >= 1.4.16" } }, - "node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/dom-accessibility-api": { "version": "0.5.16", "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", @@ -1851,25 +1775,6 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, - "node_modules/es-get-iterator": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz", - "integrity": "sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==", - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.3", - "has-symbols": "^1.0.3", - "is-arguments": "^1.1.1", - "is-map": "^2.0.2", - "is-set": "^2.0.2", - "is-string": "^1.0.7", - "isarray": "^2.0.5", - "stop-iteration-iterator": "^1.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/esbuild": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz", @@ -1938,40 +1843,36 @@ } }, "node_modules/eslint": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", - "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.0.0.tgz", + "integrity": "sha512-IMryZ5SudxzQvuod6rUdIUz29qFItWx281VhtFVc2Psy/ZhlCeD/5DT6lBIJ4H3G+iamGJoTln1v+QSuPw0p7Q==", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.57.0", - "@humanwhocodes/config-array": "^0.11.14", + "@eslint/eslintrc": "^3.0.2", + "@eslint/js": "9.0.0", + "@humanwhocodes/config-array": "^0.12.3", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", - "@ungap/structured-clone": "^1.2.0", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.3.2", - "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.2.2", - "eslint-visitor-keys": "^3.4.3", - "espree": "^9.6.1", + "eslint-scope": "^8.0.1", + "eslint-visitor-keys": "^4.0.0", + "espree": "^10.0.1", "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", - "file-entry-cache": "^6.0.1", + "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", - "globals": "^13.19.0", "graphemer": "^1.4.0", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", - "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", @@ -1985,7 +1886,7 @@ "eslint": "bin/eslint.js" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -2032,15 +1933,15 @@ } }, "node_modules/eslint-scope": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", - "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.1.tgz", + "integrity": "sha512-pL8XjgP4ZOmmwfFE8mEhSxA7ZY4C+LWyqjQ3o4yWkkmD0qcMT9kkW3zWHOczhWcjTSgqycYAgwSlXvZltv65og==", "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -2057,17 +1958,39 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/eslint-visitor-keys": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", + "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.0.1.tgz", + "integrity": "sha512-MWkrWZbJsL2UwnjxTX3gG8FneachS/Mwg7tdGXce011sJd5b0JG54vat5KHnfSBODZ3Wvzd2WnjxyzsRoVv+ww==", "dependencies": { - "acorn": "^8.9.0", + "acorn": "^8.11.3", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" + "eslint-visitor-keys": "^4.0.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree/node_modules/eslint-visitor-keys": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", + "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -2330,14 +2253,14 @@ } }, "node_modules/file-entry-cache": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", - "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", "dependencies": { - "flat-cache": "^3.0.4" + "flat-cache": "^4.0.0" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=16.0.0" } }, "node_modules/fill-range": { @@ -2401,30 +2324,21 @@ } }, "node_modules/flat-cache": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", - "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", "dependencies": { "flatted": "^3.2.9", - "keyv": "^4.5.3", - "rimraf": "^3.0.2" + "keyv": "^4.5.4" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=16" } }, "node_modules/flatted": { - "version": "3.2.9", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz", - "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==" - }, - "node_modules/for-each": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", - "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", - "dependencies": { - "is-callable": "^1.1.3" - } + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", + "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==" }, "node_modules/forever-agent": { "version": "0.6.1", @@ -2485,7 +2399,8 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true }, "node_modules/fsevents": { "version": "2.3.3", @@ -2505,14 +2420,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/functions-have-names": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", - "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2529,6 +2437,7 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", + "dev": true, "dependencies": { "function-bind": "^1.1.2", "has-proto": "^1.0.1", @@ -2576,6 +2485,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -2618,14 +2528,11 @@ } }, "node_modules/globals": { - "version": "13.24.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", - "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", - "dependencies": { - "type-fest": "^0.20.2" - }, + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", "engines": { - "node": ">=8" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -2635,6 +2542,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -2653,14 +2561,6 @@ "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==" }, - "node_modules/has-bigints": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", - "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -2673,6 +2573,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", + "dev": true, "dependencies": { "get-intrinsic": "^1.2.2" }, @@ -2684,6 +2585,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2695,20 +2597,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-tostringtag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", - "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", - "dependencies": { - "has-symbols": "^1.0.2" - }, + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2720,6 +2609,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", + "dev": true, "dependencies": { "function-bind": "^1.1.2" }, @@ -2834,9 +2724,9 @@ ] }, "node_modules/ignore": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", - "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", + "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", "engines": { "node": ">= 4" } @@ -2883,6 +2773,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -2891,7 +2782,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "node_modules/ini": { "version": "2.0.0", @@ -2902,19 +2794,6 @@ "node": ">=10" } }, - "node_modules/internal-slot": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.6.tgz", - "integrity": "sha512-Xj6dv+PsbtwyPpEflsejS+oIZxmMlV44zAhG479uYu89MsjcYOhCFnNyKrkJrihbsiasQyY0afoCl/9BLR65bg==", - "dependencies": { - "get-intrinsic": "^1.2.2", - "hasown": "^2.0.0", - "side-channel": "^1.0.4" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -2924,45 +2803,6 @@ "node": ">= 0.10" } }, - "node_modules/is-arguments": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", - "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-array-buffer": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.2.tgz", - "integrity": "sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w==", - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.2.0", - "is-typed-array": "^1.1.10" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-bigint": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", - "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", - "dependencies": { - "has-bigints": "^1.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -2975,32 +2815,6 @@ "node": ">=8" } }, - "node_modules/is-boolean-object": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", - "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-callable": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", - "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-ci": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz", @@ -3013,20 +2827,6 @@ "is-ci": "bin.js" } }, - "node_modules/is-date-object": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", - "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", - "dependencies": { - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -3070,14 +2870,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-map": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.2.tgz", - "integrity": "sha512-cOZFQQozTha1f4MxLFzlgKYPTyj26picdZTx82hbc/Xf4K/tZOOXSCkMvU4pKioRXGDLJRn0GM7Upe7kR721yg==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -3087,20 +2879,6 @@ "node": ">=0.12.0" } }, - "node_modules/is-number-object": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", - "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", - "dependencies": { - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-path-inside": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", @@ -3114,40 +2892,6 @@ "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==" }, - "node_modules/is-regex": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", - "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-set": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.2.tgz", - "integrity": "sha512-+2cnTEZeY5z/iXGbLhPrOAaK/Mau5k5eXq9j14CpRTftq0pAJu2MwVRSZhyZWBzx3o6X795Lz6Bpb6R0GKf37g==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-shared-array-buffer": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz", - "integrity": "sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==", - "dependencies": { - "call-bind": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -3160,48 +2904,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-string": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", - "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", - "dependencies": { - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-symbol": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", - "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", - "dependencies": { - "has-symbols": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-typed-array": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.12.tgz", - "integrity": "sha512-Z14TF2JNG8Lss5/HMqt0//T9JeHXttXy5pH/DBU4vi98ozO2btxzq9MwYDZYnKwU8nRsz/+GVFVRDq3DkVuSPg==", - "dependencies": { - "which-typed-array": "^1.1.11" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -3220,31 +2922,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-weakmap": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.1.tgz", - "integrity": "sha512-NSBR4kH5oVj1Uwvv970ruUkCV7O1mzgVFO4/rev2cLRda9Tm9HrL70ZPut4rOHgY0FNrUu9BCbXA2sdQ+x0chA==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-weakset": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.2.tgz", - "integrity": "sha512-t2yVvttHkQktwnNNmBQ98AhENLdPUTDTE21uPqAQ0ARwQfGeQKRVS0NNurH7bTf7RrvcVn1OOge45CnBeHCSmg==", - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/isarray": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -3793,46 +3470,7 @@ "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/object-is": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz", - "integrity": "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/object.assign": { - "version": "4.1.4", - "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.4.tgz", - "integrity": "sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.4", - "has-symbols": "^1.0.3", - "object-keys": "^1.1.1" - }, - "engines": { - "node": ">= 0.4" - }, + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -3853,6 +3491,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, "dependencies": { "wrappy": "1" } @@ -3980,6 +3619,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -4248,22 +3888,6 @@ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz", "integrity": "sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==" }, - "node_modules/regexp.prototype.flags": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.1.tgz", - "integrity": "sha512-sy6TXMN+hnP/wMy+ISxg3krXx7BAtWVO4UouuCN/ziM9UEne0euamVNafDfvC83bRNr95y0V5iijeDQFUNpvrg==", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.2.0", - "set-function-name": "^2.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/request-progress": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/request-progress/-/request-progress-3.0.0.tgz", @@ -4326,6 +3950,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, "dependencies": { "glob": "^7.1.3" }, @@ -4487,6 +4112,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz", "integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==", + "dev": true, "dependencies": { "define-data-property": "^1.1.1", "get-intrinsic": "^1.2.1", @@ -4497,19 +4123,6 @@ "node": ">= 0.4" } }, - "node_modules/set-function-name": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.1.tgz", - "integrity": "sha512-tMNCiqYVkXIZgc2Hnoy2IvC/f8ezc5koaRFkCjrpWzGpCd3qbZXPzVy9MAZzK1ch/X0jvSkojys3oqJN0qCmdA==", - "dependencies": { - "define-data-property": "^1.0.1", - "functions-have-names": "^1.2.3", - "has-property-descriptors": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", @@ -4539,6 +4152,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, "dependencies": { "call-bind": "^1.0.0", "get-intrinsic": "^1.0.2", @@ -4614,17 +4228,6 @@ "node": ">= 0.8" } }, - "node_modules/stop-iteration-iterator": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz", - "integrity": "sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==", - "dependencies": { - "internal-slot": "^1.0.4" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -4832,17 +4435,6 @@ "node": ">= 0.8.0" } }, - "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -5029,53 +4621,6 @@ "node": ">= 8" } }, - "node_modules/which-boxed-primitive": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", - "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", - "dependencies": { - "is-bigint": "^1.0.1", - "is-boolean-object": "^1.1.0", - "is-number-object": "^1.0.4", - "is-string": "^1.0.5", - "is-symbol": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/which-collection": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.1.tgz", - "integrity": "sha512-W8xeTUwaln8i3K/cY1nGXzdnVZlidBcagyNFtBdD5kxnb4TvGKR7FfSIS3mYpwWS1QUCutfKz8IY8RjftB0+1A==", - "dependencies": { - "is-map": "^2.0.1", - "is-set": "^2.0.1", - "is-weakmap": "^2.0.1", - "is-weakset": "^2.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/which-typed-array": { - "version": "1.1.13", - "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.13.tgz", - "integrity": "sha512-P5Nra0qjSncduVPEAr7xhoF5guty49ArDTwzJ/yNuPIbZppyRxFQsRCWrocxIY+CnMVG+qfbU2FmDKyvSGClow==", - "dependencies": { - "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.4", - "for-each": "^0.3.3", - "gopd": "^1.0.1", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -5095,7 +4640,8 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true }, "node_modules/ws": { "version": "8.16.0", diff --git a/ui/package.json b/ui/package.json index 3a0bdf8..b231509 100644 --- a/ui/package.json +++ b/ui/package.json @@ -17,12 +17,12 @@ "author": "Chris Reeder ", "license": "MIT", "dependencies": { - "@testing-library/dom": "^9.3.4", + "@testing-library/dom": "^10.0.0", "ace-builds": "^1.32.9", "core-js": "^3.36.1", "esbuild": "^0.20.2", "esbuild-plugin-resolve": "^2.0.0", - "eslint": "^8.57.0", + "eslint": "^9.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", "jsdom": "^24.0.0", @@ -32,7 +32,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "cypress": "^13.7.2", + "cypress": "^13.7.3", "express": "^4.19.2", "nodemon": "^3.1.0" }, diff --git a/wiki/Cargo.toml b/wiki/Cargo.toml index e75d643..8257a78 100644 --- a/wiki/Cargo.toml +++ b/wiki/Cargo.toml @@ -4,10 +4,14 @@ version = "0.1.0" edition = "2021" [dependencies] +clap = "4.5.4" phf = "0.11.2" +rand = "0.8.5" +refinery = { version = "0.8.14", features = ["tokio-postgres"] } regex = "1.10.3" serde_yaml = "0.9.33" tokio = { version = "1.36.0", features = ["full"] } +tokio-postgres = "0.7.10" warp = "0.3.6" [build-dependencies] diff --git a/wiki/src/api.rs b/wiki/src/api.rs new file mode 100644 index 0000000..349fdcb --- /dev/null +++ b/wiki/src/api.rs @@ -0,0 +1,10 @@ +// Configure and create api filter + +use warp::{filters::BoxedFilter, Filter}; + +pub mod subject; + +pub fn filter() -> BoxedFilter<()> +{ + warp::path("api").and(warp::path("v1")).boxed() +} diff --git a/wiki/src/api/subject.rs b/wiki/src/api/subject.rs new file mode 100644 index 0000000..400d711 --- /dev/null +++ b/wiki/src/api/subject.rs @@ -0,0 +1,80 @@ +use std::{convert::Infallible, future::Future, sync::Arc}; + +use warp::{filters::{path::Tail, BoxedFilter}, http::{Response, StatusCode}, reject::Rejection, reply::Reply, Filter}; + +use crate::error::Error; + +pub trait Subject { + fn create(&self, user: &str, title: &str, content: &str) -> impl Future> + Send; + fn read(&self, title: &str) -> impl Future> + Send; + fn update(&self, user: &str, title: &str, content: &str) -> impl Future> + Send; +} + +pub fn filter(provider: Option>) -> BoxedFilter<(impl Reply,)> +where + S: Subject + Send + Sync + 'static +{ + if provider.is_none() { + return warp::any() + .and_then(disabled_handler) + .recover(error_handler) + .boxed(); + } + + let provider = provider.unwrap(); + + read_filter(provider) + .recover(error_handler) + .boxed() +} + +fn read_filter(provider: Arc) -> impl Filter,), Error = Rejection> +where + S: Subject + Send + Sync + 'static +{ + warp::get() + .map(move || provider.clone()) + .and(warp::path::tail()) + .and_then(read_handler) +} + +async fn read_handler(provider: Arc, tail: Tail) -> Result, Rejection> { + let title = tail.as_str(); + match provider.read(title).await { + Ok(content) => { + Ok(Response::builder() + .header("Content-Type", "text/text") + .body(content) + .unwrap()) + }, + Err(e) => Err(warp::reject::custom(e)), + } +} + +async fn disabled_handler() -> Result, Rejection> { + println!("Rejected api request"); + Err(warp::reject::custom(Error::NotFound("".to_string()))) +} + +async fn error_handler(err: Rejection) -> Result, Infallible> { + if let Some(api_error) = err.find::() { + let (status, msg) = match api_error { + Error::Internal(msg) => ( + StatusCode::INTERNAL_SERVER_ERROR, + msg, + ), + Error::NotFound(msg) => ( + StatusCode::NOT_FOUND, + msg, + ), + }; + return Ok(Response::builder() + .status(status) + .body(msg.clone()) + .unwrap()) + } + Ok(Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body("".to_string()) + .unwrap()) +} diff --git a/wiki/src/error.rs b/wiki/src/error.rs new file mode 100644 index 0000000..b218abb --- /dev/null +++ b/wiki/src/error.rs @@ -0,0 +1,7 @@ +#[derive(Debug, Clone)] +pub enum Error { + Internal(String), + NotFound(String), +} + +impl warp::reject::Reject for Error {} diff --git a/wiki/src/lib.rs b/wiki/src/lib.rs new file mode 100644 index 0000000..232b3ff --- /dev/null +++ b/wiki/src/lib.rs @@ -0,0 +1,67 @@ +mod api; +mod dist; +mod error; +mod persistence; +mod spa_server; + +use std::sync::Arc; + +use api::subject; + +use clap::Parser; +use regex::Regex; +use warp::Filter; + +#[derive(Parser)] +#[command(version, about, long_about = None)] +pub struct Cli { + /// Use Postgres-persisted API + #[arg(long)] + enable_postgres: bool, + + /// If enabled, Postgres host + #[arg(long, default_value="localhost")] + postgres_host: String, + + /// If enabled, Postgres user + #[arg(long, default_value="postgres")] + postgres_user: String, + + /// If enabled, Postgres database + #[arg(long, default_value="postgres")] + postgres_database: String, +} + +pub async fn run(args: Cli) { + let ui_filter = spa_server::filter(Arc::new(spa_server::FilterInput{ + assets: &dist::DIST, + entrypoint: "index.html", + path_validator: Regex::new(r"^$|wiki(:?-new)?").unwrap(), + })); + + let db = if args.enable_postgres { + let mut db = persistence::postgres::Postgres::new( + &args.postgres_host, + &args.postgres_user, + &args.postgres_database, + ).await.unwrap(); + db.migrate().await.unwrap(); + Some(Arc::new(db)) + } else { + None + }; + + let filter = ui_filter.or(api::filter().and(subject::filter(db))); + + let (_, fut) = warp::serve(filter) + .bind_with_graceful_shutdown( + ([0, 0, 0, 0], 8080), + async move { + tokio::signal::ctrl_c() + .await + .ok(); + println!("Shutting down"); + } + ); + fut.await; +} diff --git a/wiki/src/main.rs b/wiki/src/main.rs index fdf1c1d..35dc8a4 100644 --- a/wiki/src/main.rs +++ b/wiki/src/main.rs @@ -1,19 +1,8 @@ -use std::sync::Arc; - -use regex::Regex; - -mod dist; -mod spa_server; +use clap::Parser; #[tokio::main] async fn main() { - let filter = spa_server::filter(Arc::new(spa_server::FilterInput{ - assets: &dist::DIST, - entrypoint: "index.html", - path_validator: Regex::new(r"^$|wiki(:?-new)?").unwrap(), - })); - - warp::serve(filter).bind(([0, 0, 0, 0], 8080)).await; + let cli = wiki::Cli::parse(); - println!("hello, world"); -} + wiki::run(cli).await; +} \ No newline at end of file diff --git a/wiki/src/persistence.rs b/wiki/src/persistence.rs new file mode 100644 index 0000000..26e9103 --- /dev/null +++ b/wiki/src/persistence.rs @@ -0,0 +1 @@ +pub mod postgres; diff --git a/wiki/src/persistence/migrations/V1__create_subjects.sql b/wiki/src/persistence/migrations/V1__create_subjects.sql new file mode 100644 index 0000000..777f950 --- /dev/null +++ b/wiki/src/persistence/migrations/V1__create_subjects.sql @@ -0,0 +1,5 @@ +CREATE TABLE subjects ( + title text PRIMARY KEY, + user_id varchar(256), + content text +); diff --git a/wiki/src/persistence/postgres.rs b/wiki/src/persistence/postgres.rs new file mode 100644 index 0000000..606d613 --- /dev/null +++ b/wiki/src/persistence/postgres.rs @@ -0,0 +1,210 @@ +use crate::{api::subject::Subject, error::Error}; + +pub struct Postgres { + client: tokio_postgres::Client, +} + +impl Postgres { + pub async fn new(host: &str, user: &str, database: &str) -> Result { + match connect(host, user, database).await { + Ok(client) => Ok(Postgres{ client }), + Err(e) => Err(e), + } + } + + pub async fn migrate(&mut self) -> Result<(), Error> { + match embedded::migrations::runner().run_async(&mut self.client).await { + Ok(r) => { + for m in r.applied_migrations() { + println!("Applied: {}", m.name()); + } + Ok(()) + }, + Err(e) => Err(Error::Internal(e.to_string())) + } + } +} + +mod embedded { + use refinery::embed_migrations; + embed_migrations!("./src/persistence/migrations"); +} + +impl Subject for Postgres { + async fn create(&self, user: &str, title: &str, content: &str) -> Result { + let r = self.client.query(r" + INSERT INTO subjects VALUES ($1, $2, $3); + ", &[&title, &user, &content]).await; + + match r { + Ok(_) => Ok("".into()), + Err(err) => Err(Error::Internal(err.to_string())), + } + } + + async fn read(&self, title: &str) -> Result { + let r = self.client.query(r" + SELECT content + FROM subjects + WHERE title = $1; + ", &[&title]).await; + + match r { + Ok(rows) => { + if rows.is_empty() { + Err(Error::NotFound(title.to_string())) + } else { + let content: String = rows[0].get(0); + Ok(content) + } + }, + Err(err) => Err(Error::Internal(err.to_string())), + } + } + + async fn update(&self, user: &str, title: &str, content: &str) -> Result { + let r = self.client.execute(r" + UPDATE subjects + SET user_id = $1, content = $2 + WHERE title = $3; + ", &[&user, &content, &title]).await; + + match r { + Ok(rows) => { + println!("Rows updated: {}", rows); + if rows < 1 { + Err(Error::NotFound(title.to_string())) + } else { + Ok("".into()) + } + }, + Err(err) => Err(Error::Internal(err.to_string())) + } + } +} + +async fn connect(host: &str, user: &str, database: &str) -> Result { + let c = tokio_postgres::connect( + &format!("host={} user={} dbname={}", host, user, database), + tokio_postgres::NoTls, + ).await; + + match c { + Err(e) => Err(Error::Internal(e.to_string())), + Ok((client, connection)) => { + tokio::spawn(async move { + if let Err(e) = connection.await { + eprintln!("connection error: {}", e); + } + }); + println!("Connected to database"); + Ok(client) + }, + } +} + +#[cfg(test)] +mod tests { + use std::{mem::ManuallyDrop, time::Duration}; + + use rand::{distributions::Alphanumeric, Rng}; + + use super::*; + + const DATABASE_NAME_LENGTH: usize = 8; + + // TestDB requires a login to a database that can create additional databases (such as postgres) + struct TestDB { + database_name: String, + client: tokio_postgres::Client, + db: ManuallyDrop, + } + + impl TestDB { + async fn new(host: &str, user: &str, database: &str) -> Self { + let database_name = format!("test_{}", rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(DATABASE_NAME_LENGTH) + .map(char::from) + .collect::()) + .to_lowercase(); + + let client = connect(host, user, database).await.unwrap(); + + client.execute(&format!("CREATE DATABASE {};", database_name), &[]).await.unwrap(); + println!("Created database: {}", database_name); + + while !database_exists(&client, &database_name).await { + tokio::time::sleep(Duration::from_millis(500)).await; + } + + let mut db = Postgres::new(host, user, &database_name).await.unwrap(); + db.migrate().await.unwrap(); + + TestDB { + database_name, + client, + db: ManuallyDrop::new(db), + } + } + + async fn new_from_env() -> Self { + use std::env::var; + Self::new( + &var("WIKI_CI_TEST_POSTGRES_HOST").unwrap_or("localhost".into()), + &var("WIKI_CI_TEST_POSTGRES_USER").unwrap_or("postgres".into()), + &var("WIKI_CI_TEST_POSTGRES_DATABASE").unwrap_or("postgres".into()), + ).await + } + } + + impl Drop for TestDB { + fn drop(&mut self) { + unsafe { + ManuallyDrop::drop(&mut self.db) + } + tokio::task::block_in_place(|| { + tokio::runtime::Handle::current().block_on( + drop_database(&self.client, &self.database_name) + ); + }); + } + } + + async fn drop_database(client: &tokio_postgres::Client, database: &str) { + client.execute(&format!("DROP DATABASE IF EXISTS {} WITH (FORCE);", database), &[]).await.unwrap(); + println!("Dropped database: {}", database); + } + + async fn database_exists(client: &tokio_postgres::Client, database: &str) -> bool { + let rows = client.execute("SELECT datname FROM pg_database WHERE datname = $1;", &[&database]) + .await + .unwrap(); + rows == 1 + } + + #[tokio::test(flavor = "multi_thread")] + #[ignore] + async fn test_subject() { + let harness = TestDB::new_from_env().await; + + // 1. Test subject that does not exist returns error + let r = harness.db.read("Does not exist").await; + assert!(matches!(r, Err(Error::NotFound(_))), "{:?}", r); + + // 2. Create subject + let r = harness.db.create("test_user", "Exists", "Some content").await; + assert!(r.is_ok()); + + // 3. Assert subject has old content and not new content + let new_content = "New content".to_string(); + let r = harness.db.read("Exists").await; + assert_ne!(r.unwrap(), new_content); + + // 4. Update subject and assert has new content + let r = harness.db.update("test_user", "Exists", &new_content).await; + assert!(r.is_ok(), "{:?}", r); + let r = harness.db.read("Exists").await; + assert_eq!(r.unwrap(), new_content); + } +} diff --git a/wiki/src/spa_server.rs b/wiki/src/spa_server.rs index afc97fc..307877e 100644 --- a/wiki/src/spa_server.rs +++ b/wiki/src/spa_server.rs @@ -8,20 +8,7 @@ use std::sync::Arc; use phf::Map; use regex::Regex; -use warp::{ - filters::{ - path::Tail, - BoxedFilter, - }, - http::{ - Response, - status::StatusCode, - }, - reject, - reject::Rejection, - reply::Reply, - Filter, -}; +use warp::{Filter, filters::{path::Tail, BoxedFilter}, http::{Response, status::StatusCode}, reject::{self, Rejection}, reply::Reply}; #[derive(Debug)] pub struct Asset {