diff --git a/Cargo.lock b/Cargo.lock index 84dc52dd..d8c67c3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anstyle-parse" @@ -91,9 +91,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "async-stream" @@ -320,12 +320,11 @@ dependencies = [ [[package]] name = "build-data" -version = "0.1.5" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aed3884e2cab7c973c8fd2d150314b6a932df7fdc830edcaf1e8e7c4ae9db3c0" +checksum = "eda20fcece9c23f3c3f4c2751a8a5ca9491c05fa7a69920af65953c3b39b7ce4" dependencies = [ "chrono", - "safe-lock", "safe-regex", ] @@ -644,17 +643,27 @@ dependencies = [ "syn 2.0.58", ] +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + [[package]] name = "env_logger" -version = "0.10.1" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" dependencies = [ + "anstream", + "anstyle", + "env_filter", "humantime", - "is-terminal", "log", - "regex", - "termcolor", ] [[package]] @@ -923,9 +932,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -938,7 +947,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", @@ -1065,21 +1074,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] -name = "is-terminal" -version = "0.4.9" +name = "itertools" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ - "hermit-abi", - "rustix", - "windows-sys 0.48.0", + "either", ] [[package]] name = "itertools" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -1135,9 +1142,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "matchers" @@ -1701,7 +1708,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" dependencies = [ "anyhow", - "itertools", + "itertools 0.11.0", "proc-macro2", "quote", "syn 2.0.58", @@ -2107,12 +2114,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" -[[package]] -name = "safe-lock" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077d73db7973cccf63eb4aff1e5a34dc2459baa867512088269ea5f2f4253c90" - [[package]] name = "safe-proc-macro2" version = "1.0.67" @@ -2133,18 +2134,18 @@ dependencies = [ [[package]] name = "safe-regex" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ab4bc484ef480a9ce79b381efd7b6767700f514d47bc599036e9d6f7f3c49d" +checksum = "5194fafa3cb9da89e0cab6dffa1f3fdded586bd6396d12be11b4cae0c7ee45c2" dependencies = [ "safe-regex-macro", ] [[package]] name = "safe-regex-compiler" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71f8c78bffb07962595e1bfa5ed11d24dd855eedc50b6a735f5ef648ce621b" +checksum = "e822ae1e61251bcfd698317c237cf83f7c57161a5dc24ee609a85697f1ed15b3" dependencies = [ "safe-proc-macro2", "safe-quote", @@ -2152,9 +2153,9 @@ dependencies = [ [[package]] name = "safe-regex-macro" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0909ab4b77511df24201cd66541d6a028887c77ecc065f277c68a12a663274ef" +checksum = "2768de7e6ef19f59c5fd3c3ac207ef12b68a49f95e3172d67e4a04cfd992ca06" dependencies = [ "safe-proc-macro2", "safe-regex-compiler", @@ -2243,18 +2244,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", @@ -2274,9 +2275,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "indexmap 2.2.6", "itoa", @@ -2409,16 +2410,6 @@ dependencies = [ "serde", ] -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.5" @@ -2443,11 +2434,11 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "sqlformat" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ - "itertools", + "itertools 0.12.1", "nom", "unicode_categories", ] @@ -2531,29 +2522,20 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "termcolor" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", @@ -2658,7 +2640,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.5", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -3212,15 +3194,6 @@ 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" diff --git a/changelog.md b/changelog.md index 861e3c62..ce1d7751 100644 --- a/changelog.md +++ b/changelog.md @@ -8,9 +8,13 @@ ### Fixed -## [v0.1.0] - 2024-04-27 +## [v0.1.0] - 2024-04-30 -Initial release. +- Initial release with support of ndc-spec v0.1.2 (beta) + - Support for CLI plugin for Hasura v3 CLI, which allows the CLI to + introspect the database on demand. + - Query explain endpoint has been changed from `/explain` to `/query/explain`. + - The default port was changed from 8100 to 8080. diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 3e75c569..504688b2 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -9,17 +9,17 @@ workspace = true [dependencies] ndc-sqlserver = { path = "../ndc-sqlserver" } -anyhow = "1.0.81" +anyhow = "1.0.82" clap = { version = "4.5.4", features = ["derive", "env"] } schemars = { version = "0.8.16", features = ["smol_str", "preserve_order"] } -serde = { version = "1.0.197", features = ["derive"] } -serde_json = { version = "1.0.115", features = ["raw_value"] } +serde = { version = "1.0.198", features = ["derive"] } +serde_json = { version = "1.0.116", features = ["raw_value"] } serde_yaml = "0.9.34" -thiserror = "1.0.58" +thiserror = "1.0.59" tokio = { version = "1.37.0", features = ["full"] } [build-dependencies] -build-data = "0.1.5" +build-data = "0.2.1" [dev-dependencies] insta = "1.38.0" diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 49f41c9d..da5f4c3d 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -9,10 +9,11 @@ use clap::Subcommand; const UPDATE_ATTEMPTS: u8 = 3; /// The various contextual bits and bobs we need to run. +#[derive(Debug)] pub struct Context { pub context_path: PathBuf, pub release_version: Option<&'static str>, - pub uri: String, + pub uri: Option, } /// The command invoked by the user. @@ -64,14 +65,16 @@ async fn initialize(with_metadata: bool, context: Context) -> anyhow::Result<()> Err(Error::DirectoryIsNotEmpty)?; } + let raw_configuration = match context.uri { + Some(uri) => { + ndc_sqlserver::configuration::RawConfiguration::with_mssql_connection_string(uri) + } + None => ndc_sqlserver::configuration::RawConfiguration::empty(), + }; // create the configuration file fs::write( configuration_file, - serde_json::to_string_pretty( - &ndc_sqlserver::configuration::RawConfiguration::with_mssql_connection_string( - context.uri, - ), - )? + "\n", + serde_json::to_string_pretty(&raw_configuration)? + "\n", )?; // create the jsonschema file @@ -133,6 +136,7 @@ async fn update(context: Context) -> anyhow::Result<()> { // It is possible to change the file in the middle of introspection. // We want to detect this scenario and retry, or fail if we are unable to. // We do that with a few attempts. + update_uri_from_context(&context).await?; for _attempt in 1..=UPDATE_ATTEMPTS { let configuration_file_path = context .context_path @@ -189,3 +193,30 @@ async fn read_config_file_contents(configuration_file_path: &PathBuf) -> anyhow: } }) } + +/// Since the URI is not mandatory for `initialize`, we need to update it first. Please not that this will only update +/// the URI if the raw configuration is empty. +async fn update_uri_from_context(context: &Context) -> anyhow::Result<()> { + let configuration_file_path = context + .context_path + .join(ndc_sqlserver::connector::CONFIGURATION_FILENAME); + let mut input: ndc_sqlserver::configuration::RawConfiguration = { + let configuration_file_contents = + read_config_file_contents(&configuration_file_path).await?; + serde_json::from_str(&configuration_file_contents)? + }; + if input.mssql_connection_string.is_empty() { + if let Some(uri) = &context.uri { + input.mssql_connection_string = uri.clone(); + } else { + return Err(anyhow::anyhow!( + "Cannot introspect without a connection URI. Please provide one." + )); + } + fs::write( + &configuration_file_path, + serde_json::to_string_pretty(&input)? + "\n", + )?; + } + Ok(()) +} diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 56c9016a..eb117250 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -31,7 +31,7 @@ pub struct Args { // TODO(PY): Add command in lib.rs pub subcommand: Command, #[arg(long = "connection-uri", env = "CONNECTION_URI")] - pub url: String, + pub url: Option, } /// The application entrypoint. It pulls information from the environment and then calls the [run] diff --git a/crates/ndc-sqlserver/Cargo.toml b/crates/ndc-sqlserver/Cargo.toml index 9dd409d7..84b4c7ce 100644 --- a/crates/ndc-sqlserver/Cargo.toml +++ b/crates/ndc-sqlserver/Cargo.toml @@ -27,11 +27,11 @@ query-engine-translation = { path = "../query-engine/translation" } tiberius = { version = "0.12.2", default-features = false, features = ["rustls"] } bb8 = "0.8.1" bb8-tiberius = "0.15.0" -async-trait = "0.1.74" +async-trait = "0.1.80" schemars = { version = "0.8.16", features = ["smol_str"] } -serde = { version = "^1.0.193", features = ["derive", "rc"] } -serde_json = { version = "^1.0.108", features = ["raw_value"] } -tokio = { version = "1.34.0", features = ["full"] } +serde = { version = "1.0.198", features = ["derive", "rc"] } +serde_json = { version = "1.0.116", features = ["raw_value"] } +tokio = { version = "1.37.0", features = ["full"] } tracing = "0.1.40" prometheus = "0.13.3" thiserror = "1.0" @@ -40,11 +40,11 @@ thiserror = "1.0" ndc-models = { workspace = true } ndc-test = { workspace = true } -axum = "0.6.19" +axum = "0.6.20" axum-test-helper = "0.3.0" -env_logger = "0.10.1" -hyper = { version = "0.14.27", features = ["tcp"] } -insta = { version = "1.34.0", features = ["json"] } -reqwest = { version = "0.11.22", default-features = false, features = ["rustls-tls"] } +env_logger = "0.11.3" +hyper = { version = "0.14.28", features = ["tcp"] } +insta = { version = "1.38.0", features = ["json"] } +reqwest = { version = "0.11.27", default-features = false, features = ["rustls-tls"] } similar-asserts = "1.5.0" serde_derive = "1.0" diff --git a/crates/query-engine/execution/Cargo.toml b/crates/query-engine/execution/Cargo.toml index 28b47e4b..834a74f1 100644 --- a/crates/query-engine/execution/Cargo.toml +++ b/crates/query-engine/execution/Cargo.toml @@ -14,7 +14,7 @@ bb8 = "0.8.1" bb8-tiberius = "0.15.0" bytes = "1.6.0" prometheus = "0.13.3" -serde_json = "1.0.108" -sqlformat = "0.2.2" +serde_json = "1.0.116" +sqlformat = "0.2.3" tokio-stream = "0.1.14" tracing = "0.1.40" diff --git a/crates/query-engine/metadata/Cargo.toml b/crates/query-engine/metadata/Cargo.toml index 87bd06db..bc186c89 100644 --- a/crates/query-engine/metadata/Cargo.toml +++ b/crates/query-engine/metadata/Cargo.toml @@ -9,4 +9,4 @@ workspace = true [dependencies] schemars = { version = "0.8.16", features = ["smol_str"] } -serde = { version = "^1.0.193", features = ["derive"] } +serde = { version = "1.0.198", features = ["derive"] } diff --git a/crates/query-engine/sql/Cargo.toml b/crates/query-engine/sql/Cargo.toml index 4755dc82..c1753a85 100644 --- a/crates/query-engine/sql/Cargo.toml +++ b/crates/query-engine/sql/Cargo.toml @@ -8,4 +8,4 @@ edition = "2021" workspace = true [dependencies] -serde_json = "1.0.108" +serde_json = "1.0.116" diff --git a/crates/query-engine/translation/Cargo.toml b/crates/query-engine/translation/Cargo.toml index 744d2b71..ec42d3cf 100644 --- a/crates/query-engine/translation/Cargo.toml +++ b/crates/query-engine/translation/Cargo.toml @@ -15,8 +15,8 @@ query-engine-metadata = { path = "../metadata" } query-engine-sql = { path = "../sql" } indexmap = "2.1" -serde_json = "1.0.107" +serde_json = "1.0.116" [dev-dependencies] -insta = { version = "1.34.0", features = ["json"] } -sqlformat = "0.2.2" +insta = { version = "1.38.0", features = ["json"] } +sqlformat = "0.2.3"