cel 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +62 -8
- data/lib/cel/ast/elements/protobuf.rb +438 -90
- data/lib/cel/ast/elements.rb +367 -121
- data/lib/cel/ast/types.rb +153 -17
- data/lib/cel/checker.rb +133 -30
- data/lib/cel/context.rb +60 -12
- data/lib/cel/encoder.rb +31 -13
- data/lib/cel/environment.rb +63 -13
- data/lib/cel/errors.rb +22 -1
- data/lib/cel/macro.rb +94 -28
- data/lib/cel/parser.rb +603 -387
- data/lib/cel/program.rb +262 -48
- data/lib/cel/version.rb +1 -1
- data/lib/cel.rb +232 -1
- metadata +19 -10
- data/lib/cel/parser.tab.rb +0 -1023
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82fcb37e45c0553a7c073b58e4c6b7203cc50bd186419724d72f5f1b0217e3f5
|
4
|
+
data.tar.gz: 44170fc7001634abc19860db8dcbc8c05ae8974716ad80dd28c4316dc0cec7f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 593ec20b7001fe593d6df79928ca8411327251fff2405491eb33642299cf6bc09d255d0088fdb6a1deda77eabccf8bcce229ad5038f68ee932f9c10ef162cdc0
|
7
|
+
data.tar.gz: 55eb21528a3ff994f5fc013ca49ded2b7cb0aaf9d5d434c671fc0cd534ed0119269c1e2bf8b5fe9e44ba1f1e05f51d30f5fd84abd1f44d740898dd971b341ece
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.1] - 2025-08-01
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* Support for depth protection, using the defaults from the spec (ex: recursion depth of 32, nesting depth of 32), and supporting API to override them (ex: `Cel::Environment.new(max_recursion_depth: 42))`).
|
8
|
+
* lazy-evaluating bindings to avoid upfront costly transformations of ruby objects into cel objects which are ultimately not used in expressions.
|
9
|
+
|
10
|
+
### Bugfixes
|
11
|
+
|
12
|
+
* `has()` macro correctly works for mapsl
|
13
|
+
|
14
|
+
## [0.3.0] - 2025-06-12
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* Integration with `google-protobuf` (optional dependency) by evaluating messages to protobuf stubs, and making them an integral part of the CEL type set. Some examples:
|
19
|
+
* auto-conversion of protobuf wrapper types.
|
20
|
+
* enums support
|
21
|
+
|
22
|
+
### Improvements
|
23
|
+
|
24
|
+
* More correct parsing, checking and evaluation of CEL expressions, thanks to the issues identified by conformance tests.
|
25
|
+
|
26
|
+
### Chore
|
27
|
+
|
28
|
+
* Incorporation of the oficial cel-spec conformance tests into the test suite, to ensure feature correctness.
|
29
|
+
* `bigdecimal` added as explicit dependency.
|
30
|
+
|
3
31
|
## [0.2.3] - 2023-09-19
|
4
32
|
|
5
33
|
### Bugfixes
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ The usage pattern follows the pattern defined by [cel-go](https://github.com/goo
|
|
32
32
|
require "cel"
|
33
33
|
|
34
34
|
# set the environment
|
35
|
-
env = Cel::Environment.new(name: :string, group: :string)
|
35
|
+
env = Cel::Environment.new(declarations: { name: :string, group: :string })
|
36
36
|
|
37
37
|
# 1.1 parse
|
38
38
|
begin
|
@@ -67,20 +67,52 @@ end
|
|
67
67
|
puts return_value #=> true
|
68
68
|
```
|
69
69
|
|
70
|
-
###
|
70
|
+
### Environment
|
71
71
|
|
72
|
-
`
|
72
|
+
`Cel::Environment` is the entrypoint for parsing, checking and evaluating CEL expressions, as well as customizing/constraining any of these functions. For that matter, it can be initialized with the following keyword arguments:
|
73
|
+
|
74
|
+
* `:declarations`: a hash of the expected variables names-to-cel-types, which are used to validate the expression and data bindings. When variables aren't declared, they assume the `any` type.
|
75
|
+
* `:container`: used to declare the package of protobuf messages only declared by name used in the expression (i.e. `cel.expr.conformance.proto3`).
|
76
|
+
* `:disable_check`: (defaults to `false`) enables/disables expression check phase (except when `env.check(expr)` is explicitly called).
|
77
|
+
* `max_recursion_depth`: (defaults to `32`) max number of parsable recursive/repeating rules, as per what the spec states.
|
78
|
+
* `max_nesting_depth`: (defaults to `12`) max number of parsable nested rules, as per what the spec states.
|
79
|
+
|
80
|
+
#### declarations
|
81
|
+
|
82
|
+
`cel-ruby` supports declaring the types of variables in the environment, which enhances expression type checking:
|
73
83
|
|
74
84
|
```ruby
|
85
|
+
# without declarations
|
86
|
+
env = Cel::Environment.new
|
87
|
+
env.check("[first_name] + middle_names + [last_name]") #=> any
|
88
|
+
|
89
|
+
# with declarations
|
75
90
|
env = Cel::Environment.new(
|
76
|
-
|
77
|
-
|
78
|
-
|
91
|
+
declarations: {
|
92
|
+
first_name: :string, # shortcut for Cel::Types[:string]
|
93
|
+
middle_names: Cel::TYPES[:list, :string], # list of strings
|
94
|
+
last_name: :string
|
95
|
+
}
|
79
96
|
)
|
97
|
+
env.check("[first_name] + middle_names + [last_name]") #=> list(string)
|
98
|
+
|
99
|
+
# you can use Cel::TYPES to access any type of primitive type, i.e. Cel::TYPES[:bytes]
|
100
|
+
```
|
101
|
+
|
102
|
+
#### :container
|
80
103
|
|
81
|
-
|
104
|
+
This can be used to simplify writing CEL expressions with long protobuf package declarations:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
env = Cel::Environment.new
|
108
|
+
env.evaluate("my.company.private.protobufs.Account{id: 2}.id)")
|
109
|
+
# or
|
110
|
+
env = Cel::Environment.new(container: "my.company.private.protobufs.")
|
111
|
+
env.evaluate("Account{id: 2}.id)")
|
82
112
|
```
|
83
113
|
|
114
|
+
**Note**: the `google.protobuf` packaged is already supported OOTB.
|
115
|
+
|
84
116
|
### protobuf
|
85
117
|
|
86
118
|
If `google/protobuf` is available in the environment, `cel-ruby` will also be able to integrate with protobuf declarations in CEL expressions.
|
@@ -107,9 +139,23 @@ env2 = environment(foo: -> (a, b) { a + b})
|
|
107
139
|
env2.evaluate("foo(2, 2)") #=> 4
|
108
140
|
```
|
109
141
|
|
142
|
+
## Spec Coverage
|
143
|
+
|
144
|
+
`cel` is tested against the conformance suite from the [cel-spec repository](https://github.com/google/cel-spec/tree/master/conformance), and supports all features from the language except:
|
145
|
+
|
146
|
+
* math extensions
|
147
|
+
* string extensions
|
148
|
+
* bindings extensions
|
149
|
+
* block extensions
|
150
|
+
* encoders extensions
|
151
|
+
* comprehensions V2 API
|
152
|
+
* optionals
|
153
|
+
|
154
|
+
If this is something you're interested in (helping out), add a mention in the corresponding issue (or create one when non is available already).
|
155
|
+
|
110
156
|
## Supported Rubies
|
111
157
|
|
112
|
-
All Rubies greater or equal to 2.
|
158
|
+
All Rubies greater or equal to 2.7, and always latest JRuby and Truffleruby.
|
113
159
|
|
114
160
|
## Development
|
115
161
|
|
@@ -118,8 +164,16 @@ Clone the repo in your local machine, where you have `ruby` installed. Then you
|
|
118
164
|
```bash
|
119
165
|
# install dev dependencies
|
120
166
|
> bundle install
|
167
|
+
# create protobuf stubs for tests
|
168
|
+
> git clone --depth 1 https://github.com/google/cel-spec.git
|
169
|
+
> git clone --depth 1 https://github.com/googleapis/googleapis.git
|
170
|
+
> bundle exec rake build_test_protos
|
121
171
|
# run tests
|
122
172
|
> bundle exec rake test
|
173
|
+
# build protobuf stubs for conformance tests
|
174
|
+
> bundle exec rake build_conformance_protos
|
175
|
+
# run conformance tests
|
176
|
+
> bundle exec rake conformance
|
123
177
|
```
|
124
178
|
|
125
179
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|