From 8b1a75bf931f50a7b047385449914a771e87468f Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Mon, 7 Oct 2024 15:28:00 -0400 Subject: [PATCH] release: v0.1.0 We'll manually release with cargo-release (https://github.com/crate-ci/cargo-release) once merged. --- CONTRIBUTING.md | 20 ++++++++++++ Cargo.toml | 8 +++++ LICENSE | 7 ++++ README.md | 87 ++++++++++++++++++------------------------------- cli/Cargo.toml | 8 +++++ cli/README.md | 70 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 144 insertions(+), 56 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 cli/README.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..36f9e4b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,20 @@ +# Contributing to **cql2-rs** + +First off, thanks for contributing! +We appreciates you. + +## Testing + +We aim for comprehensive unit testing of this library. +Please provide tests for any new features, or to demonstrate bugs. +Draft pull requests with a failing test to demonstrate a bug are much appreciated. + +## Submitting changes + +Please open a [pull request](https://docs.github.com/en/pull-requests) with your changes -- make sure to include unit tests. +Please follow standard git commit formatting (subject line 50 characters max, wrap the body at 72 characters). + +If you can, use `git rebase -i` to create a clean, well-formatted history before opening your pull request. +If you need to make changes after opening your pull request (e.g. to fix CI breakages) we will be grateful if you squash those fixes into their relevant commits. + +Thanks so much! diff --git a/Cargo.toml b/Cargo.toml index 1eeba66..24d8a39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,15 @@ [package] name = "cql2" version = "0.1.0" +authors = ["David Bitner "] edition = "2021" +description = "Parse, validate, and convert Common Query Language (CQL2) text and JSON" +documentation = "https://docs.rs/cql2" +readme = "README.md" +homepage = "https://github.com/developmentseed/cql2-rs" +repository = "https://github.com/developmentseed/cql2-rs" +license = "MIT" +keywords = ["cql2"] [dependencies] boon = "0.6.0" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..763d69e --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2024 Development Seed + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index bb41cff..27e31c4 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,50 @@ -# CQL2-RS +# cql2-rs -## WORK IN PROGRESS, NOT READY FOR USE +[![CI](https://github.com/developmentseed/cql2-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/developmentseed/cql2-rs/actions/workflows/ci.yml) -Parse, validate, and convert CQL2-Text and CQL2-JSON. +Parse, validate, and convert [Common Query Language (CQL2)](https://www.ogc.org/standard/cql2/) text and JSON. -## CLI +## Usage -At its simplest, the command-line interface (CLI) is a pass-through validator: +### API -```shell -$ cql2 < tests/fixtures/text/example01.txt # will succeed if the CQL2 is valid -("landsat:scene_id" = 'LC82030282019133LGN00') +```toml +[dependencies] +cql = "0.1" ``` -You can convert formats: +Then: -```shell -$ cql2 -o json < tests/fixtures/text/example01.txt -{"op":"=","args":[{"property":"landsat:scene_id"},"LC82030282019133LGN00"]} -``` +```rust +use cql2::Expr; -Use `-v` to get detailed validation information: - -```shell -$ cql2 'wrong' -v -[ERROR] Invalid CQL2: wrong -For more detailed validation information, use -vv -jsonschema validation failed with file:///tmp/cql2.json# -- at '': oneOf failed, none matched - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': oneOf failed, none matched - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': missing properties 'op', 'args' - - at '': want boolean, but got object +let expr: Expr = "landsat:scene_id = 'LC82030282019133LGN00'".parse().unwrap(); +assert!(expr.is_valid()); +println!("{}", expr.to_json().unwrap()); ``` -cql2-text parsing errors are pretty-printed: - -```shell -$ cql2 '(foo ~= "bar")' -[ERROR] Parsing error: (foo ~= "bar") - --> 1:6 - | -1 | (foo ~= "bar") - | ^--- - | - = expected NotFlag, And, Or, ConcatInfixOp, Add, Subtract, Multiply, Divide, Modulo, Power, Eq, Gt, GtEq, Lt, LtEq, NotEq, Is, or IsNullPostfix -``` +See [the documentation](https://docs.rs/cql2) for more. + +## CLI -Use `cql2 --help` to get a complete listing of the CLI arguments and formats. +See [the cql-cli README](./cli/README.md) for details. -## Response +## Responses Responses may not match the input. -### CQL2-Text Differences +### cql2-text differences -- all identifiers in output are double quoted -- position of "NOT" keywords is standardized to be before the expression (ie "... NOT LIKE ..." will become "NOT ... LIKE ..." -- The Negative operator on anything besides a literal number becomes "* -1" +- All identifiers in output are double quoted +- The position of "NOT" keywords is standardized to be before the expression (ie "... NOT LIKE ..." will become "NOT ... LIKE ..." +- The negative operator on anything besides a literal number becomes "* -1" - Parentheses are added around all expressions -Tasks to get to ready-to-use state: -- [x] Parse all examples from CQL2 examples into json that passes json schema validation. -- [x] Add tests that compare OGC examples to parsed/standardized/validated CQL2-Text and CQL2-JSON -- [ ] Fix issues with Z, ZM, and M WKT variants +## Development + +See [CONTRIBUTING.md](./CONTRIBUTING.md) for information about contributing to this project. + +## License + +**cql2-rs** is licensed under the MIT license. +See [LICENSE](./LICENSE) for details. diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 36e0756..54d12de 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,7 +1,15 @@ [package] name = "cql2-cli" version = "0.1.0" +authors = ["David Bitner "] edition = "2021" +description = "Command line interface (CLI) for Common Query Language (CQL2)" +readme = "README.md" +homepage = "https://github.com/developmentseed/cql2-rs" +repository = "https://github.com/developmentseed/cql2-rs" +license = "MIT" +keywords = ["cql2"] + [dependencies] cql2 = { path = "..", version = "0.1.0" } diff --git a/cli/README.md b/cli/README.md new file mode 100644 index 0000000..b2f9123 --- /dev/null +++ b/cli/README.md @@ -0,0 +1,70 @@ +# cql2-cli + +A Command Line Interface (CLI) for [Common Query Language (CQL2)](https://www.ogc.org/standard/cql2/). + +## Installation + +Install [Rust](https://rustup.rs/). +Then: + +```shell +cargo install cql2-cli +``` + +## CLI + +At its simplest, the CLI is a pass-through validator: + +```shell +$ cql2 < tests/fixtures/text/example01.txt # will succeed if the CQL2 is valid +("landsat:scene_id" = 'LC82030282019133LGN00') +``` + +You can convert formats: + +```shell +$ cql2 -o json < tests/fixtures/text/example01.txt +{"op":"=","args":[{"property":"landsat:scene_id"},"LC82030282019133LGN00"]} +``` + +Use `-v` to get detailed validation information: + +```shell +$ cql2 'wrong' -v +[ERROR] Invalid CQL2: wrong +For more detailed validation information, use -vv +jsonschema validation failed with file:///tmp/cql2.json# +- at '': oneOf failed, none matched + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': oneOf failed, none matched + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': missing properties 'op', 'args' + - at '': want boolean, but got object +``` + +cql2-text parsing errors are pretty-printed: + +```shell +$ cql2 '(foo ~= "bar")' +[ERROR] Parsing error: (foo ~= "bar") + --> 1:6 + | +1 | (foo ~= "bar") + | ^--- + | + = expected NotFlag, And, Or, ConcatInfixOp, Add, Subtract, Multiply, Divide, Modulo, Power, Eq, Gt, GtEq, Lt, LtEq, NotEq, Is, or IsNullPostfix +``` + +Use `cql2 --help` to get a complete listing of the CLI arguments and formats. + +## More information + +See [the top-level README](../README.md) for license and contributing information.