json_predicate/
lib.rs

1//! ## Introduction
2//!
3//! This specification defines JSON Predicates, a JSON-based
4//! [RFC4627](https://datatracker.ietf.org/doc/html/rfc4627)
5//! syntax for the description and serialization of logical boolean
6//! predicate operations intended to be used in conjunction with other
7//! JSON-based mechanisms, such as JSON Patch [RFC6902](https://datatracker.ietf.org/doc/html/rfc6902),
8//! as a means of incorporating conditional processing.
9//!
10//! JSON Predicates can be used, for instance, to extend a JSON Patch
11//! [RFC6902](https://datatracker.ietf.org/doc/html/rfc6902) document to provide
12//! for a broader range of conditional processing options not currently supported
13//! by JSON Patch.
14//!
15//! ## Example
16//!
17//! Given this JSON:
18//! ```json
19//! {
20//!     "a": {
21//!         "b": {
22//!             "c": "ABC!XYZ"
23//!         }
24//!     }
25//! }
26//! ```
27//!
28//! We could have a predicate like this:
29//! ```json
30//! {
31//!     "op": "and",
32//!     "path": "/a/b/c",
33//!     "apply": [
34//!         {
35//!             "op": "type",
36//!             "value": "string"
37//!         },
38//!         {
39//!             "op": "contains",
40//!             "value": "ABC"
41//!         }
42//!     ]
43//! }
44//! ```
45//!
46//! which would evaluate as `true` if evaluated against the previous JSON.
47//!
48//! ## Rust Example
49//!
50//! ```rust
51//! let predicate = Predicate::deserialize(serde_json::json!({
52//!     "op": "and",
53//!     "path": "/objA",
54//!     "apply": [
55//!       {
56//!         "op": "defined",
57//!         "path": "/stringX"
58//!       },
59//!       {
60//!         "op": "defined",
61//!         "path": "/stringXYZ"
62//!       }
63//!     ],
64//! }))?;
65//!
66//! let evaluted_predicate: bool = predicate
67//!     .test(&ENTRY, PredicateContext::default());
68//! ```
69//!
70//! ## JSON Patch
71//!
72//! The JSON Patch methods described in [draft-snell-json-test-07](https://datatracker.ietf.org/doc/html/draft-snell-json-test-07)
73//! are not implemented yet.
74//!
75//! ## Features
76//!
77//! ### First order predicate
78//!
79//! - [x] "contains"
80//! - [x] "contains-"
81//! - [x] "defined"
82//! - [x] "undefined"
83//! - [x] "starts"
84//! - [x] "starts-"
85//! - [x] "ends"
86//! - [x] "ends-"
87//! - [x] "type"
88//! - [x] "in"
89//! - [x] "in-"
90//! - [x] "matches"
91//! - [x] "matches-"
92//! - [x] "test"
93//! - [x] "test-"
94//! - [x] "less"
95//! - [x] "more"
96//!
97//! ### Second order predicate
98//!
99//! - [x] "and"
100//! - [x] "not"
101//! - [x] "or"
102//!
103//! ## References
104//!
105//! - [Specification draft-snell-json-test-07](https://tools.ietf.org/html/draft-snell-json-test-07)
106//!
107//! ## License
108//!
109//! Licensed under either of
110//!
111//! - Apache License, Version 2.0, (LICENSE-APACHE or [LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))
112//! - MIT license (LICENSE-MIT or [MIT](http://opensource.org/licenses/MIT)) at your option.
113pub mod json_path;
114
115mod predicate;
116mod regex;
117
118pub use predicate::context;
119pub use predicate::first_order::FirstOrder;
120pub use predicate::second_order::SecondOrder;
121pub use predicate::{Predicate, PredicateImpl};
122
123pub mod builder {
124    pub use crate::predicate::first_order::contains::{ContainsBuilder, ContainsBuilderError};
125    pub use crate::predicate::first_order::defined::{DefinedBuilder, DefinedBuilderError};
126    pub use crate::predicate::first_order::end::{EndBuilder, EndBuilderError};
127    pub use crate::predicate::first_order::less::{LessBuilder, LessBuilderError};
128    pub use crate::predicate::first_order::matches::{MatchesBuilder, MatchesBuilderError};
129    pub use crate::predicate::first_order::more::{MoreBuilder, MoreBuilderError};
130    pub use crate::predicate::first_order::r#in::{InBuilder, InBuilderError};
131    pub use crate::predicate::first_order::r#type::{TypeBuilder, TypeBuilderError};
132    pub use crate::predicate::first_order::start::{StartBuilder, StartBuilderError};
133    pub use crate::predicate::first_order::test::{TestBuilder, TestBuilderError};
134    pub use crate::predicate::first_order::undefined::{UndefinedBuilder, UndefinedBuilderError};
135    pub use crate::predicate::second_order::and::{AndBuilder, AndBuilderError};
136    pub use crate::predicate::second_order::not::{NotBuilder, NotBuilderError};
137    pub use crate::predicate::second_order::or::{OrBuilder, OrBuilderError};
138}