Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Rust
/target
**/target
**/*.rs.bk
Cargo.lock

Expand Down
10 changes: 8 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
},
"files": {
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.json"],
"ignore": [".nx", "index.js", "index.d.ts", "dist/**/*"]
"ignore": [
".nx",
"dist/**/*",
"src/native.cjs",
"src/native.d.ts",
"libs/core/target/**/*"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"ignore": ["index.js"]
"ignore": ["src/native.cjs", "src/native.d.ts"]
},
"linter": {
"enabled": true,
Expand Down
1 change: 0 additions & 1 deletion cel-rust
Submodule cel-rust deleted from d84558
4 changes: 0 additions & 4 deletions esm/wrapper.js

This file was deleted.

File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions libs/core/cel-rust/.github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release-plz

permissions:
pull-requests: write
contents: write

on:
push:
branches:
- master

jobs:

# Release unpublished packages.
release-plz-release:
name: Release-plz release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

# Create a PR with the new versions and changelog, preparing the next release.
release-plz-pr:
name: Release-plz PR
runs-on: ubuntu-latest
concurrency:
group: release-plz-${{ github.ref }}
cancel-in-progress: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
34 changes: 34 additions & 0 deletions libs/core/cel-rust/.github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Rust

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all -- --check
- name: Build minimal
run: cargo build --verbose --no-default-features
- name: Build with default features
run: cargo build --verbose
- name: Build with all features
run: cargo build --verbose --all-features
- name: Clippy
run: cargo clippy --all-features --all-targets -- -D warnings
- name: Run tests
run: |
cargo test --verbose
cargo test --verbose --features json
cargo test --verbose --features regex
cargo test --verbose --features chrono
2 changes: 2 additions & 0 deletions libs/core/cel-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
8 changes: 8 additions & 0 deletions libs/core/cel-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
members = ["parser", "interpreter", "example"]
resolver = "2"

[profile.bench]
lto = true
codegen-units = 1
opt-level = 3
19 changes: 19 additions & 0 deletions libs/core/cel-rust/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2022 Tom Forbes and Contributors

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.
47 changes: 47 additions & 0 deletions libs/core/cel-rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Common Expression Language (Rust)

[![Rust](https://github.com/clarkmcc/cel-rust/actions/workflows/rust.yml/badge.svg)](https://github.com/clarkmcc/cel-rust/actions/workflows/rust.yml)

The [Common Expression Language (CEL)](https://github.com/google/cel-spec) is a non-Turing complete language designed
for simplicity, speed, safety, and
portability. CEL's C-like syntax looks nearly identical to equivalent expressions in C++, Go, Java, and TypeScript. CEL
is ideal for lightweight expression evaluation when a fully sandboxed scripting language is too resource intensive.

```java
// Check whether a resource name starts with a group name.
resource.name.startsWith("/groups/" + auth.claims.group)
```

```go
// Determine whether the request is in the permitted time window.
request.time - resource.age < duration("24h")
```

```typescript
// Check whether all resource names in a list match a given filter.
auth.claims.email_verified && resources.all(r, r.startsWith(auth.claims.email))
```

## Getting Started

This project includes a CEL-parser and an interpreter which means that it can be used to evaluate CEL-expressions. The
library aims to be very simple to use, while still being fast, safe, and customizable.

```rust
fn main() {
let program = Program::compile("add(2, 3) == 5").unwrap();
let mut context = Context::default();
context.add_function("add", |a: i64, b: i64| a + b);
let value = program.execute(&context).unwrap();
assert_eq!(value, true.into());
}
```

### Examples

Check out these other examples to learn how to use this library:

- [Simple](./example/src/simple.rs) - A simple example of how to use the library.
- [Variables](./example/src/variables.rs) - Passing variables and using them in your program.
- [Functions](./example/src/functions.rs) - Defining and using custom functions in your program.
- [Concurrent Execution](./example/src/threads.rs) - Executing the same program concurrently.
60 changes: 60 additions & 0 deletions libs/core/cel-rust/example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "example"
version = "0.1.0"
edition = "2021"

[features]
axum = ["dep:axum", "dep:tokio", "dep:thiserror"]
json = ["dep:serde_json", "cel-interpreter/json"]
chrono = ["dep:chrono", "cel-interpreter/chrono"]

[dependencies]
cel-interpreter = { path = "../interpreter", default-features = false }

chrono = { version = "0.4", optional = true }

serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }

axum = { version = "0.7.5", default-features = false, features = [
"http1",
"json",
"tokio",
], optional = true }
tokio = { version = "1.38.0", default-features = false, features = [
"macros",
"net",
"rt-multi-thread",
], optional = true }
thiserror = { version = "1.0", optional = true }

[[bin]]
name = "example-simple"
path = "src/simple.rs"

[[bin]]
name = "example-variables"
path = "src/variables.rs"

[[bin]]
name = "example-functions"
path = "src/functions.rs"
required-features = ["chrono"]

[[bin]]
name = "example-threads"
path = "src/threads.rs"

[[bin]]
name = "example-serde"
path = "src/serde.rs"

[[bin]]
name = "example-axum"
path = "src/axum.rs"
required-features = ["axum"]

[[bin]]
name = "example-json"
path = "src/json.rs"
required-features = ["json"]
Loading
Loading